Modulær multiplikasjon
Under er en animasjon inspirert av en YouTube video av Burkard Polster.
Se koden her
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
let faktor = 0.0;
let antall = 150;
let radius;
let sentrum;
let lengde = 13;
let nevner = 20;
function setup() {
createCanvas(600, 600);
radius = width / 2 - 10;
sentrum = [width / 2, height / 2];
textSize(32);
}
function draw() {
colorMode(HSB);
background(0);
noFill();
stroke(255);
strokeWeight(6);
circle(width / 2, height / 2, radius * 2);
for (let i = 0; i < antall; i++) {
stroke(i * 255 / antall, 100, 60)
line(sentrum[0] + radius * cos(i * 2 * PI / antall),
sentrum[1] + radius * sin(i * 2 * PI / antall),
(sentrum[0] + radius * cos(i * 2 * PI / antall)) * (lengde / nevner) +
(sentrum[0] + radius * cos((faktor * i * 2 * PI / antall) % antall)) * (nevner - lengde) / nevner,
(sentrum[1] + radius * sin(i * 2 * PI / antall)) * (lengde / nevner) +
(sentrum[1] + radius * sin((faktor * i * 2 * PI / antall) % antall)) * (nevner - lengde) / nevner);
}
faktor += 0.02
}