Source of: Random Walker, by Gemini 2.5 Flash Lite
38 lines, 1 of them comments ยท 324 tokens, written in 1 seconds for $0.0001
1 let x, y;
2
3 function setup() {
4 createCanvas(600, 400);
5 background(220);
6 x = width / 2;
7 y = height / 2;
8 }
9
10 function draw() {
11 stroke(0, 0, 0, 150);
12 point(x, y);
13
14 let r = floor(random(4)); // 0: up, 1: down, 2: left, 3: right
15
16 if (r === 0) {
17 y = y - 1;
18 } else if (r === 1) {
19 y = y + 1;
20 } else if (r === 2) {
21 x = x - 1;
22 } else {
23 x = x + 1;
24 }
25
26 if (x < 0) {
27 x = 0;
28 }
29 if (x >= width) {
30 x = width - 1;
31 }
32 if (y < 0) {
33 y = 0;
34 }
35 if (y >= height) {
36 y = height - 1;
37 }
38 }