Skip to content

Instantly share code, notes, and snippets.

@monkstone
Created January 31, 2021 12:48
Show Gist options
  • Save monkstone/7a81e456b21342a5773e5a09aa1448c1 to your computer and use it in GitHub Desktop.
Save monkstone/7a81e456b21342a5773e5a09aa1448c1 to your computer and use it in GitHub Desktop.
PiCrate De Jong Attractor sketch
# frozen_string_literal: true
require 'picrate'
class DeJongAttractor < Processing::App
B = -2.3
attr_reader :x, :y, :xn, :yn, :timer
def settings
size(450, 450)
end
def setup
sketch_title 'De Jong Attractor'
@x = @y = @a = @c = 0
@timer = 0
stroke(255)
stroke_weight(3)
end
def draw
@timer += 0.01
background(0, 0, 200)
c = 3 * sin(timer)
a = 3 * cos(timer)
3_000.times do
@xn = x
@yn = y
@x = sin(a * yn) - cos(B * xn)
@y = sin(a * xn) - cos(c * yn)
point(width / 2 + 100 * x, height / 2 + 100 * y)
end
end
end
DeJongAttractor.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment