On Fri, Dec 19, 2008 at 3:08 PM, Matthew Moss <matt / moss.name> wrote:
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> ## Dreaming of a Ruby Christmas (#187)
>
> It's six more days of Advent, and then... Christmas! Your task is to create
> a Ruby script that celebrates Christmas. Create a virtual, ASCII Christmas
> tree completely with blinking lights. Or a countdown calendar 'til December
> 25th. Or a script that generates the lyrics to _The Twelve Days of
> Christmas_. Or whatever you like: some Christmas creativity.
>
> And...  Merry Christmas and a Happy New Year!!!

I doubt I will find time to do more with this, so Merry Christmas:

> cat RbMasTry.rb
#!/usr/bin/env jruby
require 'java'
require 'mathn'

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)

    [
      [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

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

    360.times do
      graphics.draw_line(
        150, 50,
        150 + rand(25) * Math.sin(rand(2 * Math::PI)),
         50 + rand(25) * Math.cos(rand(2 * Math::PI))
      )
    end

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

    rand(90).times do
      x, y = rand(300), rand(400)
      rand(180).times do
        graphics.draw_line(
          x, y,
          x + rand(5) * Math.sin(rand(2 * Math::PI)),
          y + rand(5) * Math.cos(rand(2 * Math::PI))
        )
      end
    end
  end
end

tree = RbMasTry.new
frame.add(tree)
tree.repaint
tree.revalidate