# Henon Phase Diagram

**URL:** <https://discourse.processing.org/t/henon-phase-diagram/26932>\
**Category:** Gallery\
**Created:** [January 9, 2021, 7:30pm UTC](https://discourse.processing.org/t/henon-phase-diagram/26932 "2021-01-09T19:30:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [January 9, 2021, 7:30pm UTC](https://discourse.processing.org/t/henon-phase-diagram/26932/1 "2021-01-09T19:30:21Z")

</div>

@tabreturn @villares Jorg Kantel often posts stuff on twitter that should be of interest to python processing fans on twitter @jkantel (usually links to his blog). Inspired by one of his latest posts I created the following JRubyArt sketch (thanks to [Paul Bourke](http://paulbourke.net/fractals/)).

```ruby
MAX = 10.0e+9

attr_reader :a, :h, :cosa, :sina, :x0, :y0

def settings
  size(500, 500)
end

def setup
  sketch_title 'Henon Phase Diagram'
  @a = -10
  @h = 0.02
  @x0 = 0.01
  @y0 = -0.02
  @cosa = cos(a)
  @sina = sin(a)
  fill(20)
  color_mode HSB, 250, 1.0, 1.0
  rect(0, 0, width, height)
  x = x0
  y = y0
  (0..50).each do |j|
    (0..1500).each do |i|
      next unless (x < MAX) && (y < MAX)

      x1 = x * cosa - (y - x * x) * sina
      y = x * sina + (y - x * x) * cosa
      x = x1
      p = (x + 1.25) * 180
      q = (1.4 - y) * 180
      fill(sqrt((250 - p)**2 + (250 - q)**2), 1.0, 1.0)
      circle(p, q, 2)
    end
    x = x0 + j * h
    y = y0 + j * h
  end
  fill(255)
  text_size(14)
  msg = format('Quadratic Henon-Equation for a = %.4f', a)
  text(msg, 20, width - 20)
end

```

![henon](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a0838010e8a44fa6947e2e940844fa47fc220c8b.jpeg)  
Here’s an interesting variant where x\*\*2 is replaced by x \* |x|  
 ![modulo](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/99d4ed6c40aee10534183a75e1006257ea663f3e.jpeg)

I’ve a question for moderators, why is my ‘png’ file getting converted to jpeg it’s not good?  
Here’s another Henon Phase Diagram with a value from [Paul Bourke](http://paulbourke.net/fractals/)  
 ![fractal](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/3587960479c853b90c54ad34fad74a7d546c9779.jpeg)

---

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [January 10, 2021, 4:34pm UTC](https://discourse.processing.org/t/henon-phase-diagram/26932/2 "2021-01-10T16:34:17Z")

</div>

I’ve created a new improved version allowing choice of value and between `x**2` and `x * |x|`

```ruby
load_library :control_panel
H = 0.02
MAX = 10.0e+9
attr_reader :a, :cosa, :sina, :points, :center, :choice, :modulo

def settings
  size(500, 500)
end

def setup
  sketch_title 'Henon Phase Diagram Explorer'
  control_panel do |c|
    c.title 'Select a'
    c.look_feel 'Nimbus'
    c.menu(:choice, %w[-10 1.2 1.6 1.57 2.0 2.2], '2.0') { |m| m }
    c.checkbox :modulo
    c.button :reset!
  end
  @modulo = false
  @center = Vec2D.new(width / 2, height / 2)
  color_mode HSB, 350, 1.0, 1.0
  reset!
end

def reset!
  calculate
  redraw
end

def calculate(x0 = 0.01, y0 = -0.02)
  x = x0
  y = y0
  @a = choice.to_f
  @cosa = cos(a)
  @sina = sin(a)
  @points = []
  funcx = if modulo
            ->(cx) { cx * cx.abs }
          else
            ->(cx) { cx * cx }
          end
  (0..50).each do |j|
    1500.times do
      next unless (x < MAX) && (y < MAX)

      x1 = x * cosa - (y - funcx.call(x)) * sina
      y = x * sina + (y - funcx.call(x)) * cosa
      x = x1
      points << Vec2D.new((x + 1.25) * 180, (1.4 - y) * 180)
    end
    x = x0 + j * H
    y = y0 + j * H
  end
end

def draw
  background 100
  points.each do |pos|
    fill(center.dist(pos), 1.0, 1.0)
    circle(pos.x, pos.y, 2)
  end
  fill(10, 1, 1)
  text_size(14)
  mod = 'x * |x|'
  text(mod, 10, 30) if modulo
  msg = format('Quadratic Henon-Equation for a = %3.4f', a)
  text(msg, 10, height - 30)
  img = format('henon_%3.4f.jpg', a)
  save_frame(data_path(img))
  no_loop
end

```

 ![henon](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/58bc9b60365b2a6906dcf5a5962f9eab8e7a11e5.jpeg)

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [January 10, 2021, 4:47pm UTC](https://discourse.processing.org/t/henon-phase-diagram/26932/3 "2021-01-10T16:47:57Z")

</div>

Wonderful!

Side question: Is this `control_panel` lib a JRubyArt only thing?  
I have played with using some choice dropdowns from java.swing, but I suppose they are what one calls “modal” (is it the right term?), and to make a second window/surface is such a hassle…

---

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [January 10, 2021, 4:53pm UTC](https://discourse.processing.org/t/henon-phase-diagram/26932/4 "2021-01-10T16:53:29Z")

</div>

Yeah `control_panel` is only a [ruby-processing](https://github.com/ruby-processing/JRubyArt/blob/master/library/control_panel/control_panel.rb) thing, it’s swing based. Takes advantage of some cool jruby/ruby features.
