-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
51 lines (47 loc) · 1.16 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
let symmetry = 6;
let angle = 360 / symmetry;
let inc = 0;
let slider;
let clearButton;
let saveButton;
function setup() {
createCanvas(450, 450);
angleMode(DEGREES);
background(75);
colorMode(HSB, 255, 255, 255);
saveButton = createButton("Save");
saveButton.mousePressed(saveKaleidoscope);
clearButton = createButton("Clear");
clearButton.mousePressed(clearCanvas);
slider = createSlider(1, 20, 10, 0.05);
}
function saveKaleidoscope() {
save("kaleidoscope.png");
}
function clearCanvas(){
background(75);
}
function draw() {
translate(width / 2, height / 2);
if(mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height){
let mx = mouseX - width / 2;
let my = mouseY - height / 2;
let pmx = pmouseX - width / 2;
let pmy = pmouseY - height / 2;
if(mouseIsPressed) {
let hue = noise(inc) * 255;
inc++;
stroke(hue, 225, 225, 100);
for(let i = 0; i < symmetry; i++) {
rotate(angle);
let sw = slider.value();
strokeWeight(sw);
line(mx, my, pmx, pmy);
push();
scale(1, -1);
line(mx, my, pmx, pmy);
pop();
}
}
}
}