xxxxxxxxxx
285
// based on https://blbadger.github.io/clifford-attractor.html
let windowScale;
let iterations = 1000000;
let _density;
let points;
const BASE_H = 15;
const BASE_S = 10;
const BASE_B = 100;
function clifford(x, y) {
let _x = sin(a * y) + c * cos(a * x);
let _y = sin(b * x) + d * cos(b * y);
return { x: _x, y: _y };
}
function setup() {
// createCanvas(800, 800);
createCanvas(2000,2000);
windowScale = width / 1000;
pixelDensity(1);
iterations *= windowScale;
gfx = createGraphics(width, height);
colorMode(HSB, 100);
background(BASE_H, BASE_S, BASE_B);
gfx.colorMode(HSB, 100);
image(gfx, 0, 0);
x = random(width - 1);
y = height / 2;
maxAmp = height / 8;
maxFreq = 10;
amp = height / 16;
gfx.stroke(color(10, 10, 10));
yh = height / 2;
t = 0;
r = 1;
gfx.strokeWeight(windowScale);
box.w = width / 2;
box.h = height / 2;
box.x = width / 2 - box.w / 2;
box.y = height / 2 - box.h / 2;
noFill();
rect(box.x, box.y, box.w, box.h);
a = -1.4;
b = 1.6;
c = 1.0;
d = 0.7;
// a = -1.2;
// b = 1.8;
// c = 1.5;
// d = 0.7;
// a= -2.847662847119377
// b=2.931870189722269
// c=-0.8300603741326125
// d=0.9008061783583923
// a=-2.0617836780956775;
// b=-2.8070907164444607;
// c=1.832323105674508;
// d=-1.2798272030573616;
// a=-2.903552873401133
// b=2.748700925875572
// c=-0.8426685065111044
// d=-1.009950580743391
// // -2.903552873401133, 2.748700925875572, -0.8426685065111044, -1.009950580743391
// a=2.6518487920744906
// b=-2.380055197485654
// c=0.9274888523145517
// d=-0.9528520415440633
// a=-2.628856837981032
// b=-2.9030765487764834
// c=0.966585877738896
// d=-0.9844920842262566
// a=-49.10919232285793
// b=82.70156925618852
// c=0.6805306056225646
// d=0.9687536886677179
// a = 2.0;
// b = 2.0;
// c = 1.0;
// d = -1.0;
// a = random(-3,3);
// b = random(-3,3);
// c = random(-3,3);
// d = random(-3,3);
console.table(a, b, c, d);
x = width / 2;
y = height / 2;
loadPixels();
_density = pixelDensity();
gfx.noFill();
gfx.rect(box.x, box.y, box.w, box.h);
points = [];
points.push({ x: 0.1, y: -0.1 });
for (let i = 1; i < iterations; i++) {
let retval = clifford(points[i - 1].x, points[i - 1].y);
points.push({ x: retval.x, y: retval.y });
let _x = (retval.x * width) / 4 + width / 2;
let _y = (retval.y * height) / 4 + height / 2;
let _alpha = 255;
let h = 100;
let s = 25;
let l = 25;
if (_x > box.x && _x < box.x + box.w && _y > box.y && _y < box.y + box.h) {
h = 100;
s = 25;
l = 25;
} else {
h = 0;
s = 1.0;
l = 0;
}
const idx = 4 * _density * (int(_y) * _density * width + int(_x));
pixels[idx] = h; //100;
pixels[idx + 1] = s; //25;
pixels[idx + 2] = l; //25;
pixels[idx + 3] = _alpha;
}
updatePixels();
console.log("done setting up");
noLoop();
}
function draw() {}
function keyPressed() {
if (key == "s") save("strange-attractor.png");
}
/*
Interesting values:
// a = 1.6300528949327253;
// b = -1.1665088619061788;
// c = 0.7289128306157528;
// d = -0.45054657914843244;
// a=1.7396868410523938
// b=1.2057728836154231
// c=-0.6429443212384114
// d=-0.9523556469715748
// a = 3; //1.7396868410523938
// b = 2.2057728836154231;
// c = -0.6429443212384114;
// d = -0.9523556469715748;
// a=3;//1.7396868410523938
// b=1.2057728836154231
// c=-0.6429443212384114
// d=-0.9523556469715748
2.499785171148009
-2.0587203720036737
-0.04606838001509983
-0.5803111611511214
1.649330201780736
-1.6430943363781152
0.8414575048674875
0.554545676467775
1.5092754311879109
1.870845887108568
0.7132513042592685
0.895748822337993
-0.5431719933431847
1.947321183153238
0.10366014842540672
0.1824426415775271
0.6690529719386378
1.1133489035770259
-2.1991588590885387
1.8014468591631205
1.4379892461670414
2.387548606682879
2.185387746605439
-1.8418414326215813
1.2087086254257624
2.048917034749339
1.802407734432765
-1.0050935934302685
1.5669859618451314
1.585451951825383
-0.42579143679385956
1.61853891842778
-1.7904904552591216
1.8609665629760297
0.9855210826065925
0.2524458906195939
-2.5300423967902903
-2.3599400016278533
-2.96520276858747
-1.68929158745558
-1.6450269619989735
-0.5334233807478803
-2.4772365500724143
2.4272822836671573
-1.9756306808721198
2.342471755588165
-1.9085820424132227
-2.5538650497221753
-2.0205601682187853
2.9991315827041607
0.3986894690699634
2.2202050843514076
-2.364095219872157
0.5779484261312513
1.4274525030488325
-0.2172308034589796
-0.6031478592470023
-2.2146431640610174
-1.144113754171375
2.89353531741801
1.516208354509657
1.2562197774624533
-0.7255060110039007
1.3705390214527293
-1.5112923576624153
2.0346374016991575
0.26805166008810044
0.6948614717177515
-1.2823154959744376
1.3995568206334354
1.973654616974203
-1.8675632183751176
*/