Henon Attractor in JRubyArt

Sketch started from Atom my ide of choice with JRubyArt

ALPHA = 1.4
BETA = 0.3

attr_reader :x, :y

def setup
  sketch_title 'Henon Attractor'
  frame_rate(360)
  background(0)
  @x = map1d(rand, 0..1.0, -0.1..0.1)
  @y = map1d(rand, 0..1.0, -0.1..0.1)
end

def draw
  stroke(255)
  stroke_weight 2
  translate(width / 2, height / 2)
  nextX = 1 - ALPHA * x**2 + y
  nextY = BETA * x
  @x = nextX
  @y = nextY
  sx = map1d(x, -1.5..1.5, -250..250)
  sy = map1d(y, -0.5..0.5, -250..250)
  point(sx, sy)
end

def settings
  size(500, 500)
  smooth 4
end

2 Likes

Nothing beats Peter de Jong attractors

Nice! Learning all the time.

A P5.js version

These are really good!
http://paulbourke.net/fractals/peterdejong/

Just a point attempt.

2 Likes

Here’s my JRubyArt version

attr_reader :x, :y, :b, :timer

B = -2.3

def settings
  size(450, 450)
end

def setup
  sketch_title 'De Jong Attractor'
  @x = @y = 0
  @timer = 0
  stroke(255)
  stroke_weight(3)
end

def draw
  @timer += 0.01
  background(0, 0, 200)
  ac = 3 * cos(timer)
  d = 3 * sin(timer)
  calculate_points ac, d
end

def calculate_points(ac, d)
  3_000.times do
    xn = x
    yn = y
    @x = sin(ac * yn) - cos(B * xn)
    @y = sin(ac * xn) - cos(d * yn)
    point(width / 2 + 100 * x, height / 2 + 100 * y)
  end
end
1 Like