-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
119 lines (73 loc) · 1.83 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
let k1;
let k2;
let squiggliness
let scaleF = 2.3
let nvertexes = 400
let vertexes = []
let r = 150
let alf = 250
let bc, ac
function setup() {
bc = color(100,30,0)
ac = color(0,0,0)
createCanvas(1000, 1000).parent("canvas").mouseClicked(randomOne);
noFill();
background(bc);
frameRate(60)
params = new URLSearchParams(window.location.search)
if(params.get("yp") && params.get("xp") && params.get("sp")) {
k1 = parseInt(params.get("xp"));
k2 = parseInt(params.get("yp"));
squiggliness = params.get("sp")
updateV()
updateLink()
} else {
randomOne()
}
}
function randomOne() {
background(bc);
squiggliness = random([0.001, 0.002, 0.003, 0.004]);
k1 = random([0,1,2,3,4,5,6,7]);
k2 = random([0,1,2,3,4,5,6,7]);
h = random([0, 1])
if ((h == 1) && (k2 != 1)){
k1 = k2
}
alf = 240;
updateV();
updateLink();
}
function updateLink () {
const link = `https://weightan.github.io/RoseNoiseCurveJS?xp=${k1}&yp=${k2}&sp=${squiggliness}`
select("#permalink").html(link).attribute("href", link)
}
function updateV() {
vertexes = [];
for (let i = 0; i < nvertexes; i++) {
let theta = map(i, 0, nvertexes, -PI, PI);
let x_ = width / 2 + scaleF*r*cos(theta) * cos(k1*theta);
let y_ = height / 2 + scaleF*r*sin(theta) * cos(k2*theta);
vertexes.push(new noiseVert(x_, y_));
}
}
function noiseVert(x_, y_) {
this.x = x_;
this.y = y_;
}
function draw() {
alf *=0.979
beginShape()
stroke(255, 255, 255, alf);
strokeWeight(1);
for (let v of vertexes) {
curveVertex(v.x, v.y);
}
endShape(CLOSE)
for (let v of vertexes) {
let theta = noise(v.x * squiggliness, v.y * squiggliness)*PI*4;
let d = p5.Vector.fromAngle(theta, 1);
v.x += d.x;
v.y += d.y;
}
}