On Mon, Dec 22, 2008 at 12:44 PM,  <brabuhr / gmail.com> wrote:
> On Fri, Dec 19, 2008 at 3:08 PM, Matthew Moss <matt / moss.name> wrote:
>> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>> ## Dreaming of a Ruby Christmas (#187)
>
> I doubt I will find time to do more with this, so Merry Christmas:

I did make a few modifications:
  * removed unnecessary require
  * removed unnecessary trig functions
  * changed background color to black
  * "animated" the star :)
  * removed the snow :(
I never did get around to:
  * decorating the tree
  * putting presents under the tree

http://github.com/fjc/rubyquiz/tree/master/187

#!/usr/bin/env jruby
require 'java'

JFrame = javax.swing.JFrame
JPanel = javax.swing.JPanel
Color  = java.awt.Color

frame = JFrame.new("Merry JRuby Christmas")
frame.default_close_operation = JFrame::EXIT_ON_CLOSE
frame.set_size(300, 400)

frame.show

class RbMasTry < JPanel
  def paintComponent(graphics)
    super(graphics)

    srand(@tree_seed ||= srand)
    [
      [400, 150,  50, 125,  50, 400, 50,  50, 50],
      [300, 150, 200,  50, 200, 350,  0, 200,  0],
      [200, 150, 100,  75, 150, 250],
      [100, 150,  50, 100, 100, 150],
    ].each do |a|
      graphics.set_color(Color.new(*a[6..8])) if a[6]

      a[0].times do
        graphics.draw_line(a[1], a[2], a[3] + rand(a[4]), a[5])
      end
    end
    srand

    graphics.set_color(Color.new(255, 255, 0))

    360.times do
      graphics.draw_line(
        150, 50,
        150 + rand(25) * (rand * 2 - 1),
         50 + rand(25) * (rand * 2 - 1)
      )
    end
  end
end

tree = RbMasTry.new
tree.background = Color.new(0, 0, 0)
frame.add(tree)

loop do
  tree.repaint
  tree.revalidate
  sleep 0.1
end