cyg41223103 cp2023

  • Home
    • SMap
    • reveal
    • blog
  • About
  • Brython
  • w15
    • Q2
    • Q1
  • 作業內容
    • W3
    • W4
    • w5
    • w6
      • 台灣國旗
      • 日本國旗
      • 美國國旗
      • 英國國旗
      • 韓國國旗
      • 中國國旗
    • W7
    • W10
    • W13
  • ANSI C
    • c1.
    • c2.
    • c3.
    • c4.
    • c5.
    • c6.
    • c7.
    • c8.
    • c9.
    • c10.
  • C_EX
    • ex1.
    • ex2.
    • ex3.
    • ex4.
    • ex5.
    • ex6.
    • ex7.
    • ex8.
    • ex9.
    • ex10.
  • NOTE
    • ssh
台灣國旗 << 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