Pi66

randoms
Random C experiments.
git clone https://git.pi66.xyz/randoms

← back to log

Add: images for coordinate-in-c

author: pi66
date: 2025-08-30 19:46
hash: 9174b21ee84d6f656e4f31683dbcea65b190e77e

Diffstat:

M

README.md
3 +-

M

coordinate-in-c/main.c
42 +++++++++++++++++++++++++++---

M

coordinate-in-c/{output.png => o.png}
0

A

coordinate-in-c/o1.png
0
 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
86
87
diff --git a/README.md b/README.md
index 063d5cf..06d7eae 100644
--- a/README.md
+++ b/README.md
@@ -2,5 +2,6 @@


 # Coordinate in c
-<img src="coordinate-in-c/output.png" alt="potato" >
+<img src="coordinate-in-c/o.png" alt="potato" >
+<img src="coordinate-in-c/o1.png" alt="potato" >

diff --git a/coordinate-in-c/main.c b/coordinate-in-c/main.c
index b5cb337..bcb5a91 100644
--- a/coordinate-in-c/main.c
+++ b/coordinate-in-c/main.c
@@ -49,6 +49,40 @@ void draw_pixels(Color bg)

 }

+void draw_graph(Color bg,Color fg)
+{
+    for(int y = 0;y < HEIGHT;++y){
+        for(int x=0;x < WIDTH;++x){
+           draw_px(x, y, bg);
+        }
+    }
+   int cx, cy;
+   cxy(&cx,&cy);
+
+   int min = ( WIDTH < HEIGHT ) ? WIDTH : HEIGHT;
+   for (int i =0;i<min/2 - PADDING ;++i) {
+       draw_px(cx+i,  cy,fg);
+       draw_px(cx,  cy+i,fg);
+       draw_px(cx+(i * -1),  cy,fg);
+       draw_px(cx,  cy+(i * -1),fg);
+   }
+   int c = min /2 - PADDING;
+
+   for (int i=STEPS;i<c;i+=STEPS){
+       for (int j=0;j<10;++j){
+
+           draw_px(cx +i, (cy - 5) +j,RED);
+           draw_px((-1 * i) +cx, (cy - 5) +j,RED);
+
+           draw_px( (cx - 5) +j,cy +i ,RED);
+           draw_px( (cx - 5) +j,(-1 * i) +cy, RED);
+       }
+
+
+   }
+
+}
+
 void draw_circle(int ix, int iy, int radius, Color color)
 {
    for(int y = -radius;y<=radius;++y){
@@ -65,7 +99,7 @@ void draw_circle(int ix, int iy, int radius, Color color)

 void draw_circlef(int ix, int iy, int radius, Color color)
 {
-   for (int i =0;i<=radius;i=i+3)
+   for (int i =0;i<=radius;i=i+1)
        draw_circle(ix,iy,i,color+i*color);

 }
@@ -117,9 +151,9 @@ int main(void) {

    // potato

-   for (int i =0;i<=5;++i){
-       draw_circlef(rand() % (WIDTH +i),rand() % (HEIGHT +i),x/1.5,RED * rand());
-   }
+
+   draw_graph(BG_COLOR,FG_COLOR);
+   draw_circlef(x,y,x/2,GREEN);

    draw_all();
     return 0;
diff --git a/coordinate-in-c/output.png b/coordinate-in-c/o.png
similarity index 100%
rename from coordinate-in-c/output.png
rename to coordinate-in-c/o.png
diff --git a/coordinate-in-c/o1.png b/coordinate-in-c/o1.png
new file mode 100644
index 0000000..5b934ae
Binary files /dev/null and b/coordinate-in-c/o1.png differ