Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
99 lines (85 sloc) 2.38 KB
<html>
<head>
<title>Ruby - Circles</title>
<style type="text/css">
html, body { height: 100%; overflow: hidden; }
body { padding: 0; margin: 0; }
#circles { height: 100%; }
</style>
<script type="text/javascript">
window.DLR = {settings: {id: 'circles', width:'100%', height:'100%'}}
</script>
<script src="ironruby/dlr.js" type="text/javascript"></script>
</head>
<body>
<script type="text/ruby" src="repl.rb"></script>
<script type="text/ruby" src="wpf_ext.rb"></script>
<script type="text/ruby" src="bouncer.rb"></script>
<script type="text/ruby" src="sketch.rb"></script>
<script type="text/ruby">
class Circles < Sketch
# called one at the creation of this animation
def setup
@draw_on = false
@d = @d_start = 10
@color_set = [[255,0, 113,118],
[255,0, 173,239],
[255,68, 199,244],
[255,157,220,249],
[255,255,235,149]]
end
#
# the following methods are event hooks
#
def mouse_pressed(s,e)
@draw_on = true
@mouse = e
end
def mouse_released(s,e)
@draw_on = false
@d = @d_start
end
def mouse_dragged(s,e)
@mouse = e
@d += 2
end
# called for each frame of animation
def draw
if @draw_on
mouse_pos = @mouse.get_position @container
my_circle(mouse_pos.x, mouse_pos.y, @d)
end
if @bounce_on
container.children.each{ |obj| obj.tag.update(obj) if obj.tag }
end
end
#
# helper methods
#
def random_color
@color_set[rand(@color_set.size)]
end
def random_brush
SolidColorBrush.new(Color.from_argb(*random_color))
end
def random_transparency
rand
end
def my_circle(x,y,d)
container.children.add(circle(
:size => d,
:fill => random_brush, 'fill.opacity' => random_transparency,
:stroke => random_brush, 'stroke.opacity' => random_transparency,
:stroke_thickness => 10,
:tag => Bouncer.new(rand(10)-5, rand(10)-5, container),
:left => (x-d/2), :top => (y-d/2)
))
end
def toggle_bounce
@bounce_on = !@bounce_on
end
end
Circles.create_sketch
</script>
</body>
</html>