This repository has been archived by the owner on Sep 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
126 lines (93 loc) · 2.08 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
116
117
118
119
120
121
122
123
124
125
126
// Code by Aleix Ferre
// The Lorentz Attractor
// https://en.wikipedia.org/wiki/Lorenz_system
// p5 Sketch: https://editor.p5js.org/thecatalahd/sketches/zXC_WD0S3
// Based on the code by TheCodingTrain
// See more: https://www.youtube.com/watch?v=f0lkz2gSsIk
let a = 10;
let b = 28;
let c = 8 / 3;
let dt = 0.01;
let x = 1.0;
let y = 1.0;
let z = 1.0;
let noiseEnable = false;
let xoff = 0.0;
let yoff = 10000.0;
let zoff = 90000.0;
let points = [];
let hueEnable = false;
let h = 0;
let noiseCheckbox;
let hueCheckbox;
let easycam;
function setup() {
pixelDensity(1);
createCanvas(windowWidth, 600, WEBGL);
createDiv("<h1>LORENZ ATTRACTOR</h1>");
createDiv("Double click the canvas to save the frame!");
noiseCheckbox = createCheckbox("Noise");
noiseCheckbox.input(noiseChanged);
hueCheckbox = createCheckbox("Hue");
hueCheckbox.input(hueChanged);
setAttributes('antialias', true);
colorMode(HSB, 100);
}
function draw() {
background(0);
orbitControl();
// translate(width / 2, height / 2);
let dx = (a * (y - x)) * dt;
let dy = (x * (b - z) - y) * dt;
let dz = (x * y - c * z) * dt;
x = x + dx;
y = y + dy;
z = z + dz;
let p = new p5.Vector(x, y, z);
if (p.x) {
points.push(p);
}
scale(5);
if (hueEnable) {
h += 0.1;
if (h > 100) {
h = 0;
}
}
noFill();
beginShape();
for (let p of points) {
stroke(h, 100, 100);
if (noiseEnable) {
vertex(p.x + noise(xoff), p.y + noise(yoff), p.z + noise(zoff));
} else {
vertex(p.x, p.y, p.z);
}
xoff++;
yoff++;
zoff++;
}
endShape();
}
function windowResized() {
resizeCanvas(windowWidth, 600);
}
function hueChanged() {
hueEnable = !hueEnable;
points = [];
x = 1.0;
y = 1.0;
z = 1.0;
h = 0;
}
function noiseChanged() {
noiseEnable = !noiseEnable;
points = [];
x = 1.0;
y = 1.0;
z = 1.0;
xoff = 0.0;
}
function doubleClicked() {
saveCanvas("lorenz", "png");
}