work <<
Previous Next >> file
program
曲線圖
#include <stdio.h>
int main() {
// Open a file to write displacement and velocity data
FILE *outputFile = fopen("motion_data.txt", "w");
if (!outputFile) {
fprintf(stderr, "Failed to create data file.\n");
return 1;
}
// Simulate motion for 10 seconds and calculate displacement and velocity, while writing data to the file
double x = 0.2; // Initial displacement
double v = 0.0; // Initial velocity
double dt = 0.01; // Time step
double t = 0.0; // Time
while (t <= 10.0) {
double acceleration = (-10.0 * x - 0.5 * v) / 1.0; // Modified system parameters here
v += acceleration * dt;
x += v * dt;
fprintf(outputFile, "%lf %lf %lf\n", t, x, v);
t += dt;
}
// Close the data file
fclose(outputFile);
// Start a Gnuplot process using popen
FILE *gnuplotPipe = popen("gnuplot -persistent", "w");
if (!gnuplotPipe) {
fprintf(stderr, "Failed to start Gnuplot.\n");
return 1;
}
// Use Gnuplot plotting commands, specify font and output as PNG
fprintf(gnuplotPipe, "set terminal pngcairo enhanced font 'default,10' size 800,400\n");
fprintf(gnuplotPipe, "set output 'motion_plot.png'\n");
fprintf(gnuplotPipe, "set title 'Displacement and Velocity vs. Time'\n");
fprintf(gnuplotPipe, "set xlabel 'Time (s)'\n");
fprintf(gnuplotPipe, "set ylabel 'Displacement (m)'\n");
fprintf(gnuplotPipe, "plot 'motion_data.txt' using 1:2 with lines lw 2 title 'Displacement', \
'motion_data.txt' using 1:3 with lines lw 2 title 'Velocity'\n");
// Close the Gnuplot process
fprintf(gnuplotPipe, "exit\n");
pclose(gnuplotPipe);
return 0;
}
台灣國旗
// 內政部國旗參考資料: https://www.moi.gov.tw/cp.aspx?n=10621
// 幾何形狀著色與繪圖練習
#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("./../images/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);
// gdImageFilledEllipse 需以長寬方向的 diameter 作圖
// 由於中央白日圓形的半徑為青天寬度的 1/8
// 因此中央白日圓形的直徑為青天寬度的 1/4, 也就是國旗寬度的 1/8
// 而且白日十二道光芒的外圍圓形其半徑也是國旗寬度的1/8
int sun_radius = (int)(width/8);
// 中央白日圓形的直徑等於十二道光芒外圍圓形的半徑
int white_circle_dia = sun_radius;
// 中央藍色圓形半徑為中央白日的 1又 2/15
int blue_circle_dia = white_circle_dia + white_circle_dia*2/15;
// 根據 https://www.moi.gov.tw/cp.aspx?n=10621 訂定國旗三種顏色值
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);
// 青天面積為整面國旗的 1/4, 也是採用長方形塗色
gdImageFilledRectangle(img, 0, 0, (int)(width/2.0), (int)(height/2.0), blue);
// 先設法以填色畫出六個白色堆疊菱形
draw_white_sun(img, center_x, center_y, sun_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);
}
void draw_white_sun(gdImagePtr img, int center_x, int center_y, int sun_radius, int color) {
// M_PI 大小定義於 math.h 標頭檔中, 因為三角函數中採用徑度為角度單位
// 因此定義將角度轉為徑度的轉換變數為 deg, 角度值乘上 deg 就可轉為徑度
float deg = M_PI/180;
// 根據十二道光芒的每一尖角的角度為 15 度, 求出其對應直角三角形的另一角度為 75 度
// 求出十二道光芒中任一菱形的 small radius, 也就是菱形的另一個對應小圓的半徑大小
float sr = sun_radius/tan(75*deg);
int ax, ay, bx, by, dx, dy, ex, ey;
gdPoint points[4];
/* 在塗上十二道光芒中的單一菱形區域之前, 先以座標點畫線測試是否正確
ax = center_x;
ay = center_y - sun_radius;
bx = center_x - sun_radius*tan(15*deg);
by = center_y;
ex = center_x;
ey = center_y + sun_radius;
dx = center_x + sun_radius*tan(15*deg);
dy = center_y;
// AB
gdImageLine(img, ax, ay, bx, by, color);
// BE
gdImageLine(img, bx, by, ex, ey, color);
// ED
gdImageLine(img, ex, ey, dx, dy, color);
// DA
gdImageLine(img, dx, dy, ax, ay, color);
*/
ax = center_x;
ay = center_y - sun_radius;
bx = center_x - sun_radius*tan(15*deg);
by = center_y;
ex = center_x;
ey = center_y + sun_radius;
dx = center_x + sun_radius*tan(15*deg);
dy = center_y;
// 確定單一菱形區域的塗色正確後, 利用迴圈每次轉動 30 度, 總共轉六次即可塗上十二道光芒區域
for (int i=1;i<=6;i++){
// A
points[0].x = ax+sun_radius*sin(30*deg*i);
points[0].y = ay+sun_radius-sun_radius*cos(30*deg*i);
// B
points[1].x = bx+sr-sr*cos(30*deg*i);
points[1].y = by-sr*sin(30*deg*i);
// E
points[2].x = ex-sun_radius*sin(30*deg*i);
points[2].y = ey-(sun_radius-sun_radius*cos(30*deg*i));
// D
points[3].x = dx-(sr-sr*cos(30*deg*i));
points[3].y = dy+sr*sin(30*deg*i);
// 對菱形區域範圍塗色
gdImageFilledPolygon(img, points, 4, color);
// 在菱形區域外圍畫線, 明確界定菱形範圍
gdImagePolygon(img, points, 4, color);
}
}
美國國旗
#include <stdio.h>
#include <gd.h>
#include <math.h>
void draw_usa_flag(gdImagePtr img);
void draw_star(gdImagePtr img, int x, int y, int size, int color);
int main() {
int width = 800;
int height = (int)(width / 1.9);
gdImagePtr img = gdImageCreateTrueColor(width, height);
gdImageAlphaBlending(img, 0);
draw_usa_flag(img);
FILE *outputFile = fopen("./../images/usa_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_usa_flag(gdImagePtr img) {
int width = gdImageSX(img);
int height = gdImageSY(img);
int red, white, blue;
// Colors for the flag
red = gdImageColorAllocate(img, 178, 34, 52); // Red stripes
white = gdImageColorAllocate(img, 255, 255, 255); // White stripes
blue = gdImageColorAllocate(img, 60, 59, 110); // Blue field
int stripe_height = height / 13;
int stripe_width = width;
int star_size = (int)(0.0308 * height); // Corrected star size (half the original size)
for (int y = 0; y < height; y += stripe_height) {
if (y / stripe_height % 2 == 0) {
gdImageFilledRectangle(img, 0, y, stripe_width, y + stripe_height, red);
} else {
gdImageFilledRectangle(img, 0, y, stripe_width, y + stripe_height, white);
}
}
gdImageFilledRectangle(img, 0, 0, width * 2 / 5, stripe_height * 7, blue);
int star_spacing_x = (int)(0.126 * height); // Horizontal spacing between stars
int star_spacing_y = (int)(0.054 * height); // Vertical spacing between stars
int star_start_x = (int)(0.122 * height); // Starting X position for stars
int star_start_y = (int)(0.0485 * height); // Starting Y position for stars
for (int row = 0; row < 9; row++) {
int starsPerRow = (row % 2 == 0) ? 6 : 5;
int space_x = (row % 2 == 0) ? star_spacing_x / -2 : 0;
for (int star = 0; star < starsPerRow; star++) {
int x = star_start_x + star * star_spacing_x+space_x;
int y = star_start_y + row * star_spacing_y;
draw_star(img, x, y, star_size, white);
}
}
}
void draw_star(gdImagePtr img, int x, int y, int size, int color) {
gdPoint points[10];
for (int i = 0; i < 10; i++) {
double angle = M_PI / 2 + i * 2 * M_PI / 10+M_PI;
int radius = (i % 2 == 0) ? size : size / 2;
points[i].x = x + radius * cos(angle);
points[i].y = y + radius * sin(angle);
}
// Fill the star with white color
gdImageFilledPolygon(img, points, 10, color);
}
日本國旗
#include <stdio.h>
#include <gd.h>
#include <math.h>
void draw_japan_flag(gdImagePtr img);
void draw_white_sun(gdImagePtr img, int center_x, int center_y, int sun_radius, int white, int red );
int main() {
// width 3: height 2
int width = 1200;
int height = 2 * width / 3;
gdImagePtr img = gdImageCreateTrueColor(width, height);
gdImageAlphaBlending(img, 0);
draw_japan_flag(img);
FILE *outputFile = fopen("./../images/japan_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_japan_flag(gdImagePtr img) {
int width = gdImageSX(img);
int height = gdImageSY(img);
int red, white ;
int center_x = 0.5 * width;
int center_y = 0.5 * height;
int sun_radius = 145 ;
// Colors for the flag
red = gdImageColorAllocate(img, 242, 0, 0); // Red color
white = gdImageColorAllocate(img, 255, 255, 255); // White stripes
// 繪製白色矩形區域
gdImageFilledRectangle(img, 0, 0, width, height, white);
// 繪製太陽內部
gdImageFilledEllipse(img, center_x, center_y, sun_radius * 3, sun_radius * 3, red);
}
中國國旗
#include <stdio.h>
#include <gd.h>
#include <math.h>
void draw_chinese_flag(gdImagePtr img);
int main() {
int width = 300; // 國旗寬度
int height = 200; // 國旗高度
gdImagePtr im = gdImageCreateTrueColor(width, height);
gdImageAlphaBlending(im, 0);
draw_chinese_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_chinese_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);
}
英國國旗
#include <stdio.h>
#include <gd.h>
#include <math.h>
void draw_uk_flag(gdImagePtr img);
void fillTriangle(gdImagePtr img, int x1, int y1, int x2, int y2, int x3, int y3, int color);
int main() {
// 設置國旗的寬和高
int width = 1200;
int height = width / 2;
// 創建圖像
gdImagePtr img = gdImageCreateTrueColor(width, height);
gdImageAlphaBlending(img, 0);
// 繪製英國國旗
draw_uk_flag(img);
// 將圖像保存到文件
FILE *outputFile = fopen("./../images/uk_flag.png", "wb");
if (outputFile == NULL) {
fprintf(stderr, "打開输出文件時發生錯誤。\n");
return 1;
}
gdImagePngEx(img, outputFile, 9);
fclose(outputFile);
gdImageDestroy(img);
return 0;
}
void draw_uk_flag(gdImagePtr img) {
int width = gdImageSX(img);
int height = gdImageSY(img);
int red, white, blue;
red = gdImageColorAllocate(img, 204, 0, 0); // 红色
white = gdImageColorAllocate(img, 255, 255, 255); // 白色
blue = gdImageColorAllocate(img, 0, 0, 153); // 藍色
gdImageFilledRectangle(img, 0, 0, width, height, blue);
int x1, y1, x2, y2, x3, y3;
{
int line_thickness = 100;
gdImageSetThickness(img, line_thickness);
int x1, y1, x2, y2, x3, y3;
// 繪製白色斜線
x1 = 0;
y1 = 600;
x2 = 1200;
y2 = 0;
gdImageLine(img, x1, y1, x2, y2, white);
x1 = 0;
y1 = 0;
x2 = 1200;
y2 = 600;
gdImageLine(img, x1, y1, x2, y2, white);
}
{
int line_thickness = 33;
gdImageSetThickness(img, line_thickness);
// 繪製红色斜線
x1 = 566;
y1 = 300;
x2 = 1166;
y2 = 0;
gdImageLine(img, x1, y1, x2, y2, red);
x1 = 1233;
y1 = 600;
x2 = 633;
y2 = 300;
gdImageLine(img, x1, y1, x2, y2, red);
x1 = 566;
y1 = 300;
x2 = -33;
y2 = 0;
gdImageLine(img, x1, y1, x2, y2, red);
x1 = 600;
y1 = 316.5;
x2 = 0;
y2 = 616.5;
gdImageLine(img, x1, y1, x2, y2, red);
}
{
int line_thickness = 33;
gdImageSetThickness(img, line_thickness);
int x1, y1, x2, y2, x3, y3;
// 繪製 斜線
x1 = 0;
y1 = 600;
x2 = 1200;
y2 = 0;
gdImageLine(img, x1, y1, x2, y2, red );
x1 = 1200;
y1 = 16.5;
x2 = 600;
y2 = 316.5;
gdImageLine(img, x1, y1, x2, y2, white);
x1 = 0;
y1 = 583.5;
x2 = 600;
y2 = 283.5;
gdImageLine(img, x1, y1, x2, y2, white);
}
// 繪製白色十字
int cross_width = width / 32;
int cross_arm_width = width / 32;
int center_x = width / 2;
int center_y = height / 2;
gdImageFilledRectangle(img, center_x + 2.7 * cross_width, 0, center_x - 2.7 * cross_width, height, white);
gdImageFilledRectangle(img, 0, center_y + 2.7 * cross_arm_width, width, center_y - 2.7 * cross_arm_width, white);
// 繪製红色十字
gdImageFilledRectangle(img, center_x + 1.5 * cross_width, 0, center_x - 1.5 * cross_width, height, red);
gdImageFilledRectangle(img, 0, center_y + 1.5 * cross_arm_width, width, center_y - 1.5 * cross_arm_width, red);
}
韓國國旗
#include <stdio.h>
#include <gd.h>
#include <math.h>
#define WIDTH 900
#define HEIGHT 600
#define FILENAME "south_korea_flag.png"
int main() {
gdImagePtr im;
FILE *pngout;
int white, black, red, blue;
im = gdImageCreate(WIDTH, HEIGHT);
white = gdImageColorAllocate(im, 255, 255, 255);
black = gdImageColorAllocate(im, 0, 0, 0);
red = gdImageColorAllocate(im, 205, 0, 0);
blue = gdImageColorAllocate(im, 0, 56, 168);
// Background (white)
gdImageFilledRectangle(im, 0, 0, WIDTH, HEIGHT , white);
// Blue Circle (Yin-Yang Symbol)
gdImageFilledArc(im, WIDTH / 2, HEIGHT / 2, WIDTH / 3, HEIGHT / 2, 210, 30, red, gdArc);
// Red Circle (Yin-Yang Symbol)
gdImageFilledArc(im, WIDTH / 2, HEIGHT / 2, WIDTH / 3, HEIGHT / 2, 30, 210, blue, gdArc);
int circleX = 385; // 圓心的 X 座標
int circleY = 262.5; // 圓心的 Y 座標
int circleRadius = 75;
// 繪製圓形
gdImageFilledEllipse(im, circleX, circleY, circleRadius * 2, circleRadius * 2, red);
int circleX2 = 515; // 圓心的 X 座標
int circleY2 = 337.5;
// 繪製圓形
gdImageFilledEllipse(im, circleX2, circleY2, circleRadius * 2, circleRadius * 2, blue);
{
// 起點和終點位置
int startX = 340;
// 線的起點 X 座標
int startY = 90;
// 線的起點 Y 座標
int endX = 200;
// 線的終點 X 座標
int endY = 260;
// 線的終點 Y 座標
int lineWidth = 23; // 線的寬度
// 繪製線段
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX, startY, endX, endY, black);
// 繪製線段
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX -35, startY -10, endX -35, endY -10, black);
// 繪製線段
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX -70, startY -20, endX -70, endY -20, black);
int startX2 = 213;
// 線的起點 X 座標
int startY2 = 270;
// 線的起點 Y 座標
int endX2 = 133;
// 線的終點 X 座標
int endY2 = 210;
// 線的終點 Y 座標
int lineWidth2 = 25; // 線的寬度
// 繪製線段
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX2 +3, startY2, endX2 +3, endY2, white);
gdImageSetThickness(im, lineWidth +10);
gdImageLine(im, startX2 -17, startY2 +9 , endX2 -17, endY2 +9 , white);
gdImageSetThickness(im, lineWidth );
gdImageLine(im, startX2 +115, startY2 -145, endX2 +115, endY2 -145, white);
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX2 +120, startY2 -155, endX2 +120, endY2 -155, white);
gdImageSetThickness(im, lineWidth +12);
gdImageLine(im, startX2 +145, startY2 -155, endX2 +145, endY2 -155, white);
}
{
// 起點和終點位置
int startX = 330;
// 線的起點 X 座標
int startY = 520;
// 線的起點 Y 座標
int endX = 190;
// 線的終點 X 座標
int endY = 350;
// 線的終點 Y 座標
int lineWidth = 23; // 線的寬度
// 繪製線段
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX, startY, endX, endY, black);
// 繪製線段
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX -35, startY +10, endX -35, endY +10, black);
// 繪製線段
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX -70, startY +20, endX -70, endY +20, black);
int startX2 = 213;
// 線的起點 X 座標
int startY2 = 330;
// 線的起點 Y 座標
int endX2 = 133;
// 線的終點 X 座標
int endY2 = 390;
// 線的終點 Y 座標
int lineWidth2 = 25; // 線的寬度
// 繪製線段
gdImageSetThickness(im, lineWidth +8);
gdImageLine(im, startX2 -11, startY2, endX2 -11, endY2, white);
gdImageSetThickness(im, lineWidth +10);
gdImageLine(im, startX2 -30, startY2 -9 , endX2 -30, endY2 -9 , white);
gdImageSetThickness(im, lineWidth );
gdImageLine(im, startX2 +100, startY2 +150, endX2 +100, endY2 +150, white);
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX2 +120, startY2 +155, endX2 +120, endY2 +155, white);
gdImageSetThickness(im, lineWidth +14);
gdImageLine(im, startX2 +145, startY2 +157, endX2 +145, endY2 +157, white);
gdImageSetThickness(im, lineWidth -10);
gdImageLine(im, 232, 426, 206, 448, white);
}
{
// 起點和終點位置
int startX = 564;
// 線的起點 X 座標
int startY = 520;
// 線的起點 Y 座標
int endX = 704;
// 線的終點 X 座標
int endY = 350;
// 線的終點 Y 座標
int lineWidth = 23; // 線的寬度
// 繪製線段
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX +70, startY +20, endX +70, endY +20, black);
// 繪製線段
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX, startY, endX, endY, black);
// 繪製線段
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX +35, startY +10, endX +35, endY +10, black);
gdImageSetThickness(im, lineWidth -10);
gdImageLine(im, 624, 400, 734, 490, white);
int startX2 = 553;
// 線的起點 X 座標
int startY2 = 330;
// 線的起點 Y 座標
int endX2 = 633;
// 線的終點 X 座標
int endY2 = 390;
// 線的終點 Y 座標
int lineWidth2 = 25; // 線的寬度
// 繪製線段
gdImageSetThickness(im, lineWidth +8);
gdImageLine(im, startX2 +139, startY2, endX2 +139, endY2, white);
gdImageSetThickness(im, lineWidth +10);
gdImageLine(im, startX2 +157, startY2 -9 , endX2 +157, endY2 -9 , white);
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX2 +25, startY2 +155, endX2 +25, endY2 +155, white);
gdImageSetThickness(im, lineWidth +30);
gdImageLine(im, startX2 -3, startY2 +170, endX2 , endY2 +170, white);
}
{
// 起點和終點位置
int startX = 330;
// 線的起點 X 座標
int startY = 520;
// 線的起點 Y 座標
int endX = 190;
// 線的終點 X 座標
int endY = 350;
// 線的終點 Y 座標
int lineWidth = 23; // 線的寬度
// 繪製線段
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX, startY, endX, endY, black);
// 繪製線段
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX -35, startY +10, endX -35, endY +10, black);
// 繪製線段
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX -70, startY +20, endX -70, endY +20, black);
int startX2 = 213;
// 線的起點 X 座標
int startY2 = 330;
// 線的起點 Y 座標
int endX2 = 133;
// 線的終點 X 座標
int endY2 = 390;
// 線的終點 Y 座標
int lineWidth2 = 25; // 線的寬度
// 繪製線段
gdImageSetThickness(im, lineWidth +8);
gdImageLine(im, startX2 -11, startY2, endX2 -11, endY2, white);
gdImageSetThickness(im, lineWidth +10);
gdImageLine(im, startX2 -30, startY2 -9 , endX2 -30, endY2 -9 , white);
gdImageSetThickness(im, lineWidth );
gdImageLine(im, startX2 +100, startY2 +150, endX2 +100, endY2 +150, white);
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX2 +120, startY2 +155, endX2 +120, endY2 +155, white);
gdImageSetThickness(im, lineWidth +14);
gdImageLine(im, startX2 +145, startY2 +157, endX2 +145, endY2 +157, white);
gdImageSetThickness(im, lineWidth -10);
gdImageLine(im, 232, 426, 206, 448, white);
}
{
// 起點和終點位置
int startX = 564;
// 線的起點 X 座標
int startY = 97;
// 線的起點 Y 座標
int endX = 704;
// 線的終點 X 座標
int endY = 267;
// 線的終點 Y 座標
int lineWidth = 23; // 線的寬度
// 繪製線段
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX +70, startY -20, endX +70, endY -20, black);
// 繪製線段
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX, startY, endX, endY, black);
gdImageSetThickness(im, lineWidth -10);
gdImageLine(im, 624, 212, 734, 118, white);
// 繪製線段
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX +35, startY -10, endX +35, endY -10, black);
int startX2 = 553;
// 線的起點 X 座標
int startY2 = 277;
// 線的起點 Y 座標
int endX2 = 633;
// 線的終點 X 座標
int endY2 = 217;
// 線的終點 Y 座標
int lineWidth2 = 25; // 線的寬度
// 繪製線段
gdImageSetThickness(im, lineWidth +8);
gdImageLine(im, startX2 +134, startY2, endX2 +134, endY2, white);
gdImageSetThickness(im, lineWidth +10);
gdImageLine(im, startX2 +157, startY2 +9 , endX2 +157, endY2 +9 , white);
gdImageSetThickness(im, lineWidth);
gdImageLine(im, startX2 +25, startY2 -155, endX2 +25, endY2 -155, white);
gdImageSetThickness(im, lineWidth +30);
gdImageLine(im, startX2 -5, startY2 -155, endX2 -5, endY2 -155, white);
}
// Save image
FILE *outputFile = fopen("./../images/korea_flag.png", "wb");
if (outputFile == NULL) {
fprintf(stderr, "Error opening the output file.\n");
return 1;
}
gdImagePngEx(im, outputFile, 9);
fclose(outputFile);
gdImageDestroy(im);
return 0;
}
work <<
Previous Next >> file