-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecoding-randAppear.js
140 lines (126 loc) · 2.63 KB
/
recoding-randAppear.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
function setup() {
noStroke();
// noLoop();
createCanvas(800, 800);
radius = 10;
colR = [255,255,254,208,219]
colG = [255,211,202,6 ,94 ]
colB = [255,89 ,254,6 ,219]
satprmatrix = [[0.7, 0.3],[0.3, 0.7]];
drawedDotsX = []
drawedDotsY = []
colors = [];
saturation = [];
nbDots = 80;
nbLines = nbDots;
createLines();
addcolor();
choosePalette();
chooseSaturation();
background(255);
}
function draw() {
translate(width / 2, height / 2);
drawLines();
// console.log(saturation);
}
function colorproba(x){
ymin = 0.2;
ymax = 0.6;
return (sin(x)+1)/2*(ymax-ymin)+ymin;
}
function nextSaturation(currentSat){
val = random();
if (val<satprmatrix[currentSat][0]){
return 2;
}
return 0;
}
function createLines(){
for (let i = 0; i<nbLines; i++){
colors.push([]);
saturation.push([]);
}
}
function addcolor(){
for (let i = 0; i < nbLines; i++) {
for (let ii = 0; ii < nbDots; ii++) {
p = colorproba(ii*4*PI/nbDots-PI/2);
r = random();
if (r<p){
colors[i].push(1);
} else {
colors[i].push(0);
}
if (colors[i].length>nbDots){
colors[i].shift()
}
}
}
}
function choosePalette(){
for (let i = 0; i < nbLines; i++) {
for (let ii = 0; ii < nbDots; ii++) {
if (colors[i][ii]){
if(random()<(1-(0.95*(ii>nbDots/2))-(0.05*(ii<nbDots/2)))){
colors[i][ii] = 1;
} else {
colors[i][ii] = 2;
}
}
}
}
}
function chooseSaturation(){
for (let i = 0; i < nbLines; i++) {
for (let ii = 0; ii < nbDots; ii++) {
saturation[i].push(nextSaturation(getEnvSaturation(i, ii)));
if (saturation[i].length > nbDots){
saturation[i].shift();
}
}
}
}
function getEnvSaturation(x, y){
sat=0;
desat=0;
for (let i=x-1; i<x+2; i++){
for (let j=y-1; j<y+2;j++){
if (i>=0 && j>=0 && i<nbLines && j<saturation[0].length && (i==x && j==y) && saturation[i][j]!=0){
if(saturation[i][j]==2){
sat += 1;
} else {
desat += 1;
}
}
}
}
if (desat<sat){
return 0;
} else {
return 1;
}
}
function drawLines(){
// for (let i = 0; i < nbLines; i++) {
// for (let ii = 0; ii < nbDots; ii++) {
randX = floor(random(0,nbDots));
randY = floor(random(0,nbLines));
// while (drawedDotsX.indexOf(randX)!=-1){
// randX = floor(random(0,nbDots));
// }
// while(drawedDotsY.indexOf(randY)!=-1) {
// randY = floor(random(0,nbLines));
// }
drawedDotsX.push(randX);
drawedDotsY.push(randY);
val = colors[randY][randX];
// console.log(val);
if (val>0){
val += saturation[randY][randX];
}
fill(colR[val],colG[val],colB[val]);
ellipse((-(nbDots/2)+randX+1/2)*radius, (-(nbDots/2)+randY+1/2)*radius, radius);
// }
// }
}