Sha256: d48d5fef6f6adc1eace5c6067a79fb6d1576b27e04dea1d614528f4c004416f2

Contents?: true

Size: 521 Bytes

Versions: 4

Compression:

Stored size: 521 Bytes

Contents

require 'ruby-processing'

class SwappingImagesSketch < Processing::App

  def setup
    @index = 0
    @count = 7
    # loading the images into the array
    @images = (0...@count).map { |i| load_image("animal#{i}.jpg") }
  end

  def draw
    # displaying one images
    image @images[@index], 0, 0 
  end

  def mouse_pressed
    # A new image is picked randomly when the mouse is clicked
    @index = rand(@images.size)
  end

end

SwappingImagesSketch.new :title => "Swapping Images", :width => 200, :height => 200

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby-processing-1.0.1 samples/learning_processing/chapter_15/03_swapping_images.rb
ruby-processing-1.0.2 samples/learning_processing/chapter_15/03_swapping_images.rb
ruby-processing-1.0.3 samples/learning_processing/chapter_15/03_swapping_images.rb
ruby-processing-1.0.4 samples/learning_processing/chapter_15/03_swapping_images.rb