Random Chords
Accumulates random chords of a circle. Each chord in translucent so they accumulate to give the illusion of a shaded sphere. Contributed by Aatish Bhatia, inspired by Anders Hoff
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
function setup() {
createCanvas(400, 400);
background(255, 255, 255);
// translucent stroke using alpha value
stroke(0, 0, 0, 15);
}
function draw() {
// draw two random chords each frame
randomChord();
randomChord();
}
function randomChord() {
// find a random point on a circle
let angle1 = random(0, 2 * PI);
let xpos1 = 200 + 200 * cos(angle1);
let ypos1 = 200 + 200 * sin(angle1);
// find another random point on the circle
let angle2 = random(0, 2 * PI);
let xpos2 = 200 + 200 * cos(angle2);
let ypos2 = 200 + 200 * sin(angle2);
// draw a line between them
line(xpos1, ypos1, xpos2, ypos2);
}