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
W15 << Previous Next >> experience

Q1

ANS:

#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 >> experience

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