-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulatedCode.js
66 lines (50 loc) · 1.47 KB
/
simulatedCode.js
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
// Based on https://www.youtube.com/watch?v=3_7rxEQKCIk
let w = 700;
let h = 700;
const CODE_START = h/20;
const CODE_END = h - h/20;
const LINES_OF_CODE = 30;
const LINE_SEP = (CODE_END - CODE_START) / LINES_OF_CODE;
function setup() {
createCanvas(w, h);
background(30);
strokeWeight(10);
strokeCap(ROUND);
noLoop();
}
function randomColor() {
// Palette is from https://github.com/taniarascia/new-moon/.
const PALETTE = [
color(229, 115, 118),
color(235, 167, 114),
color(114, 178, 241),
color(211, 173, 223),
color(170, 198, 166),
];
return random(PALETTE);
}
function draw() {
let lineY = CODE_START;
let indent = 0;
for (const i of Array(LINES_OF_CODE).keys()) {
if (indent > 0 || random(1) < 0.9) {
let lineX = 50 + indent*50;
const lineSegments = parseInt(random(2, 8));
stroke(randomColor());
for (const j of Array(lineSegments).keys()) {
if (random(1) < 0.7) {
stroke(randomColor());
}
const segmentLength = random(10, 80);
line(lineX, lineY, lineX + segmentLength, lineY);
lineX += segmentLength + 20;
}
if (indent < 5 && random(1) < 0.2) {
++indent;
} else if (indent > 0 && random(1) < 0.5) {
--indent;
}
}
lineY += LINE_SEP;
}
}