commit cfd2c39
0uppy
·
2026-07-24 22:54:37 +0000 UTC
parent 778f3e3
cotton v0.2 - cot now has a pixel drawing command (brought it back from the grave from the pre v0.1 release) - also cleaned out more messy code that IS STILL HERE FROM A COUPLE COMMITS AGO AND I KEEP FINDING AAAA
1 files changed,
+26,
-6
+26,
-6
1@@ -141,6 +141,26 @@ cmd_print(Cotton *cotton, CottonWindow *cw, char *arg)
2 cottonwindow_update(cw, cotton->video, sizeof(cotton->video[0]) * VIDEO_WIDTH);
3 }
4
5+static void
6+cmd_pixel(Cotton *cotton, CottonWindow *cw, char *arg)
7+{
8+ int x, y;
9+
10+ if (!arg || sscanf(arg, "%d %d", &x, &y) != 2) {
11+ fprintf(stderr, "cot syntax error: usage for pixel is 'pixel <x> <y>' :P\n");
12+ return;
13+ }
14+
15+ if (x < 0 || x >= VIDEO_WIDTH || y < 0 || y >= VIDEO_HEIGHT) {
16+ fprintf(stderr, "cot syntax error: pixel (%d, %d) is out of bounds :<\n", x, y);
17+ return;
18+ }
19+
20+ draw_pixel(cotton, x, y);
21+
22+ cottonwindow_update(cw, cotton->video, sizeof(cotton->video[0]) * VIDEO_WIDTH);
23+}
24+
25 static void
26 cmd_var(Cotton *cotton, char *arg)
27 {
28@@ -201,10 +221,7 @@ cmd_color(Cotton *cotton, char *arg)
29 cotton->c_cottolette = COTTOLETTE[6];
30
31 else
32- fprintf(stderr,
33- "cot syntax error: cotton doesn't know the color \"%s\" "
34- "sorry,, :(\n",
35- arg);
36+ fprintf(stderr, "cot syntax error: cotton doesn't know the color \"%s\" sorry,, :(\n", arg);
37 }
38
39 static void
40@@ -222,8 +239,7 @@ static void
41 cmd_input(Cotton *cotton, char *arg)
42 {
43 if (!arg) {
44- fprintf(stderr,
45- "cotton syntax error: input needs a variable name xP\n");
46+ fprintf(stderr, "cotton syntax error: input needs a variable name xP\n");
47 return;
48 }
49
50@@ -343,6 +359,10 @@ cotton_interpret(Cotton *cotton, CottonWindow *cw, FILE *file)
51 cmd_print(cotton, cw, arg);
52 }
53
54+ else if (strcmp(cmd, "pixel") == 0) {
55+ cmd_pixel(cotton, cw, arg);
56+ }
57+
58 else if (strcmp(cmd, "var") == 0) {
59 cmd_var(cotton, arg);
60 }