-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
86 lines (63 loc) · 1.36 KB
/
sketch.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var N = 200;
var center_x ;
var center_y ;
var radius ;
var doLoop = true;
var times;
function setup() {
var canvas = createCanvas(windowWidth,500);
center_x = width/2;
center_y = height/2;
radius = min(width,height) / 2;
canvas.parent("p5jsContainer");
frameRate(15);
}
function keyPressed() {
if (key == 'P') {
if (doLoop == true) {
noLoop();
doLoop = false;
} else {
loop();
doLoop = true;
}
}
if (key == 'N') {
redraw();
}
}
function drawLineToNextPoint(i) {
push();
colorMode(HSB);
strokeWeight(1);
stroke(frameCount % 360,100, 100,0.4);
drawingContext.shadowColor = color(frameCount % 360,100, 100,0.5);
translate(center_x,center_y);
var initialPoint = p5.Vector.mult( p5.Vector.fromAngle(2*PI*i/N), radius);
var finalPoint = p5.Vector.mult( p5.Vector.fromAngle(2*PI* ((i*times)%N) / N), radius );
line(initialPoint.x,initialPoint.y,finalPoint.x,finalPoint.y);
pop();
}
function draw() {
background(0);
push();
fill(0);
stroke(255);
translate(center_x,center_y);
ellipse(0,0,2*radius);
pop();
times = (0.1*frameCount) % N ;
for (var i = 0 ; i < N ; i++) {
drawLineToNextPoint(i);
}
if (times % 1 == 0) {
frameRate(1);
} else {
frameRate(12);
}
push();
textSize(20);
fill(255);
text("Frame: " + str(frameCount), 2,20);
pop();
}