forked from phg98/phg98p5sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
79 lines (69 loc) · 1.82 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
let degree = 0;
let degreeStep = 19;
let radius = 50;
let radiusStep;
let colorStep;
let screen
let screensize
let isPaused=false
function setup() {
screen = Math.min(window.innerWidth, window.innerHeight)
screensize = [screen ,screen]
createCanvas(screensize[0], screensize[1]);
background(220);
radius = random(100);
degreeStep = random(20,90);
radiusStep = random(20);
colorStep = int(random(2,50));
showCurrentParam(radius, degreeStep, radiusStep, colorStep)
print('Pause : Space bar');
print('radius: '+radius + ', degreeStep: ' + degreeStep + ', radiusStep: ' + radiusStep);
print('colorStep: '+colorStep);
}
function draw() {
if (isPaused) return;
degree = degree + degreeStep;
if (degree > 360) {
degree -= 360;
}
radius = radius + 0.2;
if (radius > screen/2) {
radius = 0;
setup();
}
centerX = cos(radians(degree))*radius;
centerY = sin(radians(degree))*radius;
bigCenterX = screensize[0]/2;
bigCenterY = screensize[1]/2;
circle(bigCenterX+centerX,bigCenterY+centerY,30);
if (int(degree) % colorStep == 0) {
fill('#000000')
} else {
fill('#ffffff')
}
}
function keyPressed() {
let keyIndex = -1;
if (key == 'a') {
step -= 1;
}
if (key == 's') {
step += 1;
}
if (key == ' ') {
isPaused = !isPaused
//pause();
}
}
function showCurrentParam(radius, degreeStep, radiusStep, colorStep) {
let param = document.getElementsByClassName('currentParam')[0];
if (param != undefined) {
param.remove()
} else {
param = document.createElement('h1')
}
param.style.textAlign = "center";
param.className = 'currentParam'
param.textContent = `radius: ${radius} degreeStep: ${degreeStep} radiusStep: ${radiusStep} colorStep: ${colorStep}`
document.getElementsByTagName('body')[0].insertAdjacentElement('afterbegin', param)
}