ruby bounce

Ruby code posted by jimmy schementi
created at 11 Jun 21:35

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# create a ton of random sized, colored, and stroked rectangles

include System::Windows::Shapes
include System::Windows::Media
include System::Windows::Controls

canvas.children.clear
colors = %W(red orange yellow lime blue purple violet)
brushes = colors.map{|c| SolidColorBrush.new(Colors.send(c)) }
canvas_dim = lambda{ [canvas.actual_width, canvas.actual_height] }

500.times do
  size = rand(canvas_dim[].max / 10)
  shape = Rectangle.new
  shape.width, shape.height = size, size
  shape.fill = brushes[rand brushes.size]
  shape.stroke = brushes[rand brushes.size]
  shape.stroke_thickness = rand(canvas_dim[].max / 70) + 4
  canvas.children.add shape
  Canvas.set_left shape, rand(canvas_dim[].first - size)
  Canvas.set_top  shape, rand(canvas_dim[].last  - size)
end
797 Bytes in 2 ms with coderay