------ art_92499_31185912.1229992572314 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, I was wondering about this expression and its siblings: > Math.sin(rand(2 * Math::PI)) The documentation <http://www.ruby-doc.org/core/classes/Kernel.html#M005977>states that rand(num) will pick a random integer between 0 and num.abs.to_i (unless this is different in JRuby). Therefore, the only values that can come out of this expression are sin(0), sin(1), ... sin(6) which are 0, .841, .909, .141, -.757, -.960, and -.279 (of course these are different for cosine). Is it just the range -1<y<1? Would rand(2)-1 suffice? What is the significance of these numbers and doing rand(2pi) instead of rand(6)? I did enjoy seeing a JRuby solution, especially a GUI-based one. Kudos. Thanks, Dan 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) > > > > 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 avax.swing.JFrame > JPanel avax.swing.JPanel > Color ava.awt.Color > > frame Frame.new("Merry JRuby Christmas") > frame.default_close_operation Frame::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 and(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 bMasTry.new > frame.add(tree) > tree.repaint > tree.revalidate > > ------ art_92499_31185912.1229992572314--