41223110 cp2023

  • Home
    • SMap
    • reveal
    • blog
  • About
  • editing functions
  • w2
    • 請逐行詳細說明程式用法
  • w4
  • w5
  • w6
    • Flag
    • ROC單一菱形
    • GD 圖形庫中的函數
    • 說明基本 gd 繪圖
  • w7
    • China flag Program Usage
    • Korea flag Program Usage
  • w11
  • w12
  • w13
    • 心得
  • w15
    • 1
    • 2
  • Brython
w15 << Previous Next >> 2

1

直接在青天與滿地紅的圖案中, 利用白色作為畫線顏色, 將第二組的 ABED 等四個點的座標, 以直線相連

#include <stdio.h>
#include <gd.h>
#include <math.h>

void draw_roc_flag(gdImagePtr img);

int main() {
    int width = 1200;
    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.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;
    int center_x = (int)(width / 4);
    int center_y = (int)(height / 4);

    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);

    int A_x = 429;
    int A_y = 125;
    int B_x = 279;
    int B_y = 165;
    int E_x = 170;
    int E_y = 274;
    int D_x = 319;
    int D_y = 234;

    gdImageLine(img, A_x, A_y, B_x, B_y, white);
    gdImageLine(img, B_x, B_y, E_x, E_y, white);
    gdImageLine(img, E_x, E_y, D_x, D_y, white);
    gdImageLine(img, D_x, D_y, A_x, A_y, white);
}


w15 << Previous Next >> 2

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