Sha256: 4326034a96435e6c1da4d97a0337524b3ec657a7d1eecfc44ca6f7502d6a4762

Contents?: true

Size: 614 Bytes

Versions: 10

Compression:

Stored size: 614 Bytes

Contents

# Sprite (Teddy)
# by James Patterson. 
# 
# Demonstrates loading and displaying a transparent GIF image. 


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
  
  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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ruby-processing-2.6.3 samples/processing_app/basics/image/sprite.rb
ruby-processing-2.6.2 samples/processing_app/basics/image/sprite.rb
ruby-processing-2.6.1 samples/processing_app/basics/image/sprite.rb
ruby-processing-2.6.0 samples/processing_app/basics/image/sprite.rb
ruby-processing-2.5.1 samples/processing_app/basics/image/sprite.rb
ruby-processing-2.5.0 samples/processing_app/basics/image/sprite.rb
ruby-processing-2.4.4 samples/processing_app/basics/image/sprite.rb
ruby-processing-2.4.3 samples/processing_app/basics/image/sprite.rb
ruby-processing-2.4.2 samples/processing_app/basics/image/sprite.rb
ruby-processing-2.4.1 samples/processing_app/basics/image/sprite.rb