samples/processing_app/basics/image/sprite.rb in ruby-processing-1.0.11 vs samples/processing_app/basics/image/sprite.rb in ruby-processing-2.4.1
- old
+ new
@@ -1,38 +1,32 @@
-require 'ruby-processing'
# Sprite (Teddy)
# by James Patterson.
#
# Demonstrates loading and displaying a transparent GIF image.
-class Sprite < Processing::App
- def setup
- @teddy = load_image "teddy.gif"
- @xpos, @ypos = width/2, height/2
- @drag = 30.0
-
- frame_rate 60
+def setup
+ size 200, 200
+ @teddy = load_image "teddy.gif"
+ @xpos, @ypos = width/2, height/2
+ @drag = 30.0
+ frame_rate 60
+end
+
+def draw
+ background 102
+ difx = mouse_x - @xpos - @teddy.width/2
+ if difx.abs > 1.0
+ @xpos += difx/@drag
+ @xpos = constrain( @xpos, 0, width-@teddy.width/2 )
end
- def draw
- background 102
-
- difx = mouse_x - @xpos - @teddy.width/2
- if difx.abs > 1.0
- @xpos += difx/@drag
- @xpos = constrain( @xpos, 0, width-@teddy.width/2 )
- end
-
- dify = mouse_y - @ypos - @teddy.height/2
- if dify.abs > 1.0
- @ypos += dify/@drag
- @ypos = constrain( @ypos, 0, height-@teddy.height/2 )
- end
-
- image @teddy, @xpos, @ypos
+ dify = mouse_y - @ypos - @teddy.height/2
+ if dify.abs > 1.0
+ @ypos += dify/@drag
+ @ypos = constrain( @ypos, 0, height-@teddy.height/2 )
end
+ image @teddy, @xpos, @ypos
end
-Sprite.new :title => "Sprite", :width => 200, :height => 200
\ No newline at end of file