Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 99 lines (85 sloc) 2.433 kb
bcc2ef6 @jschementi .toggle_bounce for squares, rather than bouncing by defaul, and adds rub...
authored
1 <html>
2 <head>
e338f39 @jschementi Add more images/videos and make HTML files have 'ruby' at the front
authored
3 <title>Ruby - Circles</title>
8f3bdda @jschementi Fix indenting and some refactoring: shape helpers accept dotted keys
authored
4 <style type="text/css">
bcc2ef6 @jschementi .toggle_bounce for squares, rather than bouncing by defaul, and adds rub...
authored
5 html, body { height: 100%; overflow: hidden; }
6 body { padding: 0; margin: 0; }
7 #circles { height: 100%; }
8 </style>
6335930 @jschementi checkin local copy of ironruby, and update examples to use it
authored
9 <script type="text/javascript">
10 window.DLR = {settings: {id: 'circles', width:'100%', height:'100%'}}
8f3bdda @jschementi Fix indenting and some refactoring: shape helpers accept dotted keys
authored
11 </script>
6335930 @jschementi checkin local copy of ironruby, and update examples to use it
authored
12 <script src="ironruby/dlr.js" type="text/javascript"></script>
bcc2ef6 @jschementi .toggle_bounce for squares, rather than bouncing by defaul, and adds rub...
authored
13 </head>
14 <body>
15 <script type="text/ruby" src="repl.rb"></script>
16 <script type="text/ruby" src="wpf_ext.rb"></script>
17 <script type="text/ruby" src="bouncer.rb"></script>
18 <script type="text/ruby" src="sketch.rb"></script>
19 <script type="text/ruby">
20 class Circles < Sketch
21
22 # called one at the creation of this animation
8f3bdda @jschementi Fix indenting and some refactoring: shape helpers accept dotted keys
authored
23 def setup
bcc2ef6 @jschementi .toggle_bounce for squares, rather than bouncing by defaul, and adds rub...
authored
24 @draw_on = false
25 @d = @d_start = 10
26 @color_set = [[255,0, 113,118],
27 [255,0, 173,239],
28 [255,68, 199,244],
29 [255,157,220,249],
30 [255,255,235,149]]
31 end
32
8f3bdda @jschementi Fix indenting and some refactoring: shape helpers accept dotted keys
authored
33 #
bcc2ef6 @jschementi .toggle_bounce for squares, rather than bouncing by defaul, and adds rub...
authored
34 # the following methods are event hooks
8f3bdda @jschementi Fix indenting and some refactoring: shape helpers accept dotted keys
authored
35 #
36
bcc2ef6 @jschementi .toggle_bounce for squares, rather than bouncing by defaul, and adds rub...
authored
37 def mouse_pressed(s,e)
38 @draw_on = true
39 @mouse = e
40 end
41
42 def mouse_released(s,e)
43 @draw_on = false
44 @d = @d_start
45 end
46
47 def mouse_dragged(s,e)
48 @mouse = e
49 @d += 2
50 end
51
52 # called for each frame of animation
53 def draw
54 if @draw_on
55 mouse_pos = @mouse.get_position @container
56 my_circle(mouse_pos.x, mouse_pos.y, @d)
57 end
58 if @bounce_on
8f3bdda @jschementi Fix indenting and some refactoring: shape helpers accept dotted keys
authored
59 container.children.each{ |obj| obj.tag.update(obj) if obj.tag }
bcc2ef6 @jschementi .toggle_bounce for squares, rather than bouncing by defaul, and adds rub...
authored
60 end
61 end
62
8f3bdda @jschementi Fix indenting and some refactoring: shape helpers accept dotted keys
authored
63 #
bcc2ef6 @jschementi .toggle_bounce for squares, rather than bouncing by defaul, and adds rub...
authored
64 # helper methods
8f3bdda @jschementi Fix indenting and some refactoring: shape helpers accept dotted keys
authored
65 #
bcc2ef6 @jschementi .toggle_bounce for squares, rather than bouncing by defaul, and adds rub...
authored
66
67 def random_color
68 @color_set[rand(@color_set.size)]
69 end
70
8f3bdda @jschementi Fix indenting and some refactoring: shape helpers accept dotted keys
authored
71 def random_brush
72 SolidColorBrush.new(Color.from_argb(*random_color))
73 end
74
bcc2ef6 @jschementi .toggle_bounce for squares, rather than bouncing by defaul, and adds rub...
authored
75 def random_transparency
76 rand
77 end
78
79 def my_circle(x,y,d)
8f3bdda @jschementi Fix indenting and some refactoring: shape helpers accept dotted keys
authored
80 container.children.add(circle(
81 :size => d,
82 :fill => random_brush, 'fill.opacity' => random_transparency,
83 :stroke => random_brush, 'stroke.opacity' => random_transparency,
84 :stroke_thickness => 10,
85 :tag => Bouncer.new(rand(10)-5, rand(10)-5, container),
86 :left => (x-d/2), :top => (y-d/2)
87 ))
bcc2ef6 @jschementi .toggle_bounce for squares, rather than bouncing by defaul, and adds rub...
authored
88 end
89
90 def toggle_bounce
91 @bounce_on = !@bounce_on
92 end
93 end
94
95 Circles.create_sketch
96 </script>
97 </body>
98 </html>
Something went wrong with that request. Please try again.