generated from drawwithcode/P5-empty-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketchhome.js
126 lines (114 loc) · 3.62 KB
/
sketchhome.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
116
117
118
119
120
121
122
123
124
125
126
let kMax;
let step;
let n = 100; // number of blobs
let radius = 0; // diameter of the circle
let inter = 0.5; // difference between the sizes of two blobs
let maxNoise = 500; //grandezza
let maxNoisenucleo = maxNoise / 3; //grandezza nucleo
let lapse = 0; // timer
let noiseProg = (x) => x;
function setup() {
let canva = createCanvas(windowWidth, windowHeight);
canva.parent("canvasp5");
colorMode(HSB);
angleMode(DEGREES);
//kMax = random(0.1, 4.0);
step = 0.01;
kMaxcella = random(0.2, 0.3);
step2 = 0.01;
myColorcella = random(360);
randcella = random(7);
}
function draw() {
push();
background("#101010");
kMax = map(mouseX, 0, width, 2, 4.0);
let t = frameCount / 200;
for (let i = n; i > 0; i--) {
strokeWeight(3);
noFill();
let alpha = 1 - noiseProg(i / n);
stroke(191, 5, 90, 0.2);
let size = radius + i * inter;
let k = kMax * sqrt(i / n);
let noisiness = maxNoise * noiseProg(i / n);
blob(size, width / 2, height / 2, k, t - i * step, noisiness);
}
/* for (let p = 0; p < 5; p++) {
drawcella();
} */
pop();
}
function blob(size, xCenter, yCenter, k, t, noisiness) {
beginShape();
let angleStep = 360 / 40;
for (let theta = 0; theta <= 360 + 2 * angleStep; theta += angleStep) {
let r1, r2;
r1 = sin(theta);
r2 = cos(theta);
let r = size + noise(k * r1, k * r2, t) * noisiness;
let x = xCenter + r * cos(theta);
let y = yCenter + r * sin(theta);
curveVertex(x, y);
}
endShape();
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
wi = windowWidth / 2;
he = windowHeight / 2;
}
/* // By Roni Kaufman
let kMaxcella;
let step2;
let ncella = 10; // number of blobs
let radiuscella = 0; // diameter of the circle
let intercella = 0; // difference between the sizes of two blobs
let maxNoisecella = 300; //grandezza
let lapsecella = 0; // timer
let myColorcella;
let randcella;
let seed = 0;
function drawcella() {
let t = frameCount / 80;
let bright = 0;
for (let i = ncella; i > 0; i--) {
seed++;
let x2 = noise(((seed + 1000) / 1000) * 2) * windowWidth;
let y2 = noise(((seed - 1000) / 1000) * 2) * windowHeight;
let x3 = noise((seed + 1000) / 1000 / 2) * windowWidth;
let y3 = noise((seed - 1000) / 1000 / 2) * windowHeight;
let x4 = noise((seed + 1000) / 1000) * windowWidth;
let y4 = noise((seed - 1000) / 1000) * windowHeight;
let x5 = noise((seed + 1000) / 1000) * windowWidth;
let y5 = noise((seed - 1000) / 1000) * windowHeight;
let x6 = noise((seed + 1000) / 1000) * windowWidth;
let y6 = noise((seed - 1000) / 1000) * windowHeight;
noStroke();
fill(myColorcella, 60 - bright, 70 + bright);
let size = radiuscella + i * intercella;
let k = kMaxcella * sqrt(i / n);
let noisiness = maxNoisecella * (i / n);
nucleo(size, x2, y2, k, t - i * step2, noisiness);
nucleo(size, x3, y3, k, t - i * step2, noisiness);
nucleo(size, x4, y4, k, t - i * step2, noisiness);
nucleo(size, x5, y5, k, t - i * step2, noisiness);
nucleo(size, x6, y6, k, t - i * step2, noisiness);
bright = bright + 6;
}
}
function nucleo(size, xCenter, yCenter, k, t, noisiness) {
beginShape();
let angleStep = 360 / 200;
for (let theta = 0; theta <= 360 + 2 * angleStep; theta += angleStep) {
let r1, r2;
r1 = cos(theta) + 2 * 10;
r2 = sin(theta) + 2 * 10;
let r = size + noise(k * r1, k * r2, t) * noisiness;
let x = xCenter + r * cos(theta);
let y = yCenter + r * sin(theta);
curveVertex(x, y);
}
endShape();
}
*/