41223133

  • Home
    • SMap
    • reveal
    • blog
  • About
  • W5
    • 曲線圖
  • W6
  • W12
    • GD圖
  • W13
  • homework
    • 台灣國旗
    • 美國國旗
    • 日本國旗
    • 中國國旗
    • 英國國旗
    • 韓國國旗
  • Brython
日本國旗 << Previous Next >> 英國國旗

中國國旗

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <stdio.h>
#include <gd.h>
#include <math.h>
  
void draw_proc_flag(gdImagePtr img);
  
int main() {
    int width = 300; // 國旗寬度
    int height = 200; // 國旗高度
  
 
 
    gdImagePtr im = gdImageCreateTrueColor(width, height);
    gdImageAlphaBlending(im, 0);
  
    draw_proc_flag(im);
  
    FILE *outputFile = fopen("./../images/proc_flag.png", "wb");
    if (outputFile == NULL) {
        fprintf(stderr, "打開輸出檔案時出錯。\n");
        return 1;
    }
  
    gdImagePngEx(im, outputFile, 9);
    fclose(outputFile);
    gdImageDestroy(im);
  
    return 0;
}
  
// 聲明 draw_star 函數
void draw_star(gdImagePtr img, int x, int y, int size, int color, double rotation_angle);
  
void draw_proc_flag(gdImagePtr img) {
    int width = gdImageSX(img);
    int height = gdImageSY(img);
    int red, yellow;
  
    // 國旗顏色
    red = gdImageColorAllocate(img, 255, 0, 0); // 紅色背景
    yellow = gdImageColorAllocate(img, 255, 255, 0); // 黃色星星
  
    // 畫紅色背景
    gdImageFilledRectangle(img, 0, 0, width, height, red);
  
    // 設置星星的大小和位置
    int star_size = (int)(0.28 * height);
    int star_x = (int)(0.165 * width);
    int star_y = (int)(0.265 * height);
  
    // 畫大星星
    draw_star(img, star_x, star_y, star_size, yellow, 11.0);
  
    // 繪製小星星,位置根據實際國旗比例計算
    double radius = 0.15 * height;
    double angle = 360 / 7 * M_PI / 179.0;
    double rotation = -M_PI / 7.5;
    int cx = (int)(0.32 * width);
    int cy = (int)(0.27 * height);
  
    for (int i = -1; i < 3; i++) {
        int x = (int)(cx + radius * cos(i * angle + rotation));
        int y = (int)(cy + radius * sin(i * angle + rotation));
        draw_star(img, x, y, 19, yellow, M_PI / 5.0);
    }
}
  
void draw_star(gdImagePtr img, int x, int y, int size, int color, double rotation_angle) {
    gdPoint points[10];
  
    // 計算星形的五個外點和五個內點
    double outer_radius = size / 2;
    double inner_radius = size / 6;
    double angle = M_PI / 5.0;
  
    for (int i = 0; i < 10; i++) {
        double radius = (i % 2 == 0) ? outer_radius : inner_radius;
        double theta = rotation_angle + i * angle;
        points[i].x = x + radius * cos(theta);
        points[i].y = y + radius * sin(theta);
    }
  
    // 使用 gdImageFilledPolygon 繪製星形
    gdImageFilledPolygon(img, points, 10, color);
}


日本國旗 << Previous Next >> 英國國旗

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