xxxxxxxxxx
65
// Reference: http://paulbourke.net/fractals/peterdejong/
function setup() {
createCanvas(800, 800)
frameRate(30)
noLoop()
background(0)
num_iterations = 6000
q = new controls()
gui = new dat.GUI()
sliders = []
sliders.push(gui.add(q, "a", -3, 3))
sliders.push(gui.add(q, "b", -3, 3))
sliders.push(gui.add(q, "c", -3, 3))
sliders.push(gui.add(q, "d", -3, 3))
sliders.push(gui.add(q, "stroke_weight", 1.01, 10))
for (let i = 0; i < sliders.length; i++) {
sliders[i].onChange(sliderChanges)
}
}
function draw() {
drawAttractor(q.a, q.b, q.c, q.d, num_iterations, q.stroke_weight)
}
function controls() {
this.a = 1.641
this.b = 1.902
this.c = 0.316
this.d = 1.525
this.stroke_weight = 2.0
}
function sliderChanges() {
background(0)
redraw()
}
function drawAttractor(a, b, c, d, num_steps, stroke_weight=1.01) {
translate(width / 2, height / 2)
colorMode(HSB, num_steps, num_steps, num_steps)
let x_prev = 0
let y_prev = 0
for (let i = 0; i < num_steps; i++) {
x = sin(a * y_prev) - cos(b * x_prev)
y = sin(c * x_prev) - cos(d * y_prev)
strokeWeight(stroke_weight)
h = map(i, 0, num_steps, num_steps * 0.6, num_steps * 0.9)
stroke(h, num_steps, num_steps, 10)
// line(x_prev * width / 4, y_prev* height/ 4, x* width / 4, y*height/ 4)
point(x * width / 4, y * height / 4)
x_prev = x
y_prev = y
}
}