41223221 cp2023

  • Home
    • SMap
    • reveal
    • blog
  • 關於
  • 韓國國旗解說
    • 國旗程式詳細解說
  • w2-3
  • w4-5
  • w6
  • w7
  • w8
  • W11-12
  • w13
  • w15
  • w16
  • cEX
    • 課程1
    • 練習1
  • ANSIC
    • 課程2
    • 練習2
  • 期末總結
w13 << Previous Next >> w16

w15

1.根據 roc_list_coord_flag.7z 程式內容所印出的六組 ABED 等繪製 ROC 國旗白日圖案中的菱形四個關鍵點, 請直接在青天與滿地紅的圖案中, 利用白色作為畫線顏色, 將第二組的 ABED 等四個點的座標, 以直線相連.

#include <stdio.h>
#include <gd.h>
#include <math.h>
 
void draw_roc_flag(gdImagePtr img);
void draw_white_sun(gdImagePtr img, int x, int y, int size, int color);
 
int main() {
    // width 3: height 2
    int width = 1200;
    // 國旗長寬比為 3:2
    int height = (int)(width * 2.0 / 3.0);
 
    gdImagePtr img = gdImageCreateTrueColor(width, height);
    gdImageAlphaBlending(img, 0);
 
    draw_roc_flag(img);
 
    FILE *outputFile = fopen("roc_flag_in_gd.png", "wb");
    if (outputFile == NULL) {
        fprintf(stderr, "Error opening the output file.\n");
        return 1;
    }
    gdImagePngEx(img, outputFile, 9);
    fclose(outputFile);
    gdImageDestroy(img);
    return 0;
}
 
void draw_roc_flag(gdImagePtr img) {
    int width = gdImageSX(img);
    int height = gdImageSY(img);
    int red, white, blue;
 
    // 白日位於青天面積正中央, 因此中心點座標為長寬各 1/4 處
    int center_x = (int)(width / 4);
    int center_y = (int)(height / 4);
 
    int sun_radius = (int)(width / 8);
    int white_circle_dia = sun_radius;
    int blue_circle_dia = white_circle_dia + white_circle_dia * 2 / 15;
 
    red = gdImageColorAllocate(img, 255, 0, 0); // 紅色
    white = gdImageColorAllocate(img, 255, 255, 255); // 白色
    blue = gdImageColorAllocate(img, 0, 0, 149); // 藍色
 
    gdImageFilledRectangle(img, 0, 0, width, height, red);
    gdImageFilledRectangle(img, 0, 0, (int)(width / 2.0), (int)(height / 2.0), blue);
    draw_white_sun(img, center_x, center_y, sunS_radius, white);
    gdImageFilledEllipse(img, center_x, center_y, blue_circle_dia, blue_circle_dia, blue);
    gdImageFilledEllipse(img, center_x, center_y, white_circle_dia, white_circle_dia, white);
 
    // 在青天與滿地紅的圖案中以白色畫線繪製連接菱形的四個關鍵點
    gdImageSetThickness(img, 10); // 設置線條粗度為10
    gdImageLine(img, 429, 125, 279, 165, white);
    gdImageLine(img, 279, 165, 170, 274, white);
    gdImageLine(img, 170, 274, 170, 274, white);
    gdImageLine(img, 429, 125, 170, 274, white); // 加入第四條連線
}
void draw_white_sun(gdImagePtr img, int x, int y, int size, int color) {
    // 實現 draw_white_sun 函數的內容
    // 可以在此處繪製白日的內部圖案
}

2.承上題, 請列出第二組 ABED 的四條直線與白日中的大圓所相交 (intersect) 的四個點座標.


w13 << Previous Next >> w16

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