41223114

  • Home
    • SMap
    • reveal
    • blog
  • First
  • W1~W3(登入並設定筆記作業網站之密碼)
  • W2~W4
    • IPV4
    • IPV6
    • INFO
  • W5(初次嘗試gd繪圖,以三角函數波型圖為例)
  • w6(以gd繪圖嘗試各國之國旗繪製)
    • 中華民國國旗
    • 日本國旗
    • 美國國旗
    • gd繪圖之流程簡介
  • W9(嘗試遠端連結S1511)
  • W11(使用瀏覽器開啟國旗檔)
  • W13(開啟github倉儲)
  • putty使用
    • 步驟1
    • 步驟2
    • 步驟3
  • W15
    • Q1
  • experience
  • Brython
中華民國國旗 << Previous Next >> 美國國旗

日本國旗

#include <stdio.h>
#include <gd.h>
#include <math.h>
  
void draw_japan_flag(gdImagePtr img);
void draw_red_sun(gdImagePtr img, int x, int y, int size, int color);
  
int main() {
    int originalWidth = 1200;
    int originalHeight = (int)(originalWidth * 2.0 / 3.0);
    gdImagePtr img = gdImageCreateTrueColor(originalWidth, originalHeight);
    gdImageAlphaBlending(img, 0);
  
    draw_japan_flag(img);
  
    // 新的宽度和高度以适应 "images" 文件夹
    int newWidth = 600;
    int newHeight = (int)(newWidth * 2.0 / 3.0);
  
    // 创建新图像并进行缩放
    gdImagePtr resizedImage = gdImageCreateTrueColor(newWidth, newHeight);
    gdImageAlphaBlending(resizedImage, 0);
    gdImageCopyResampled(resizedImage, img, 0, 0, 0, 0, newWidth, newHeight, originalWidth, originalHeight);
  
  FILE *outputFile = fopen("./../images/japan_flag.png", "wb");
    if (outputFile == NULL) {
        fprintf(stderr, "Error opening the output file.\n");
        return 1;
    }
    gdImagePng(resizedImage, outputFile);
    fclose(outputFile);
    gdImageDestroy(img);
    gdImageDestroy(resizedImage);
  
    return 0;
}
  
void draw_japan_flag(gdImagePtr img) {
    int width = gdImageSX(img);
    int height = gdImageSY(img);
  
    // 创建一个白色背景
    int white = gdImageColorAllocate(img, 255, 255, 255);
    gdImageFilledRectangle(img, 0, 0, width - 1, height - 1, white);
  
    // 绘制红色圆圈(太阳)
    int red = gdImageColorAllocate(img, 255, 0, 0);
    int center_x = width / 2;
    int center_y = height / 2;
    int radius = (int)((width * 2) / 3);
    draw_red_sun(img, center_x, center_y, radius, red);
}
  
void draw_red_sun(gdImagePtr img, int x, int y, int size, int color) {
  // 減小 size 的值,例如將他的值減半
  size = size / 2;
    gdImageArc(img, x, y, size, size, 0, 360, color);
    gdImageFillToBorder(img, x, y, color, color);
}


中華民國國旗 << Previous Next >> 美國國旗

Copyright © All rights reserved | This template is made with by Colorlib