Sha256: 5ab6beeb24b406e37495aaa46f2c570c059757575dce9d70cf3ffe72426d31e4

Contents?: true

Size: 898 Bytes

Versions: 6

Compression:

Stored size: 898 Bytes

Contents

# From the Processing Examples
# Uses the "bare" style, where a Processing::App sketch is implicitly wrapped
# around the code.
# -- omygawshkenas

FRAME_COUNT = 12

def setup
  size 350, 350
  @frames         = []
  @last_time      = 0
  @current_frame  = 0
  @draw           = false
  @back_color     = 204
  stroke_weight 4
  smooth
  background @back_color
  FRAME_COUNT.times { @frames << get }
end

def draw
  time = millis
  if time > @last_time + 100
    next_frame
    @last_time = time
  end
  line(pmouse_x, pmouse_y, mouse_x, mouse_y) if @draw
end

def mouse_pressed
  @draw = true
end

def mouse_released
  @draw = false
end

def key_pressed
  background @back_color
  @frames.size.times { |i| @frames[i] = get }
end

def next_frame
  @frames[@current_frame] = get
  @current_frame += 1
  @current_frame = 0 if @current_frame >= @frames.size
  image(@frames[@current_frame], 0, 0)
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-processing-2.6.3 samples/contributed/animator.rb
ruby-processing-2.6.2 samples/contributed/animator.rb
ruby-processing-2.6.1 samples/contributed/animator.rb
ruby-processing-2.6.0 samples/contributed/animator.rb
ruby-processing-2.5.1 samples/contributed/animator.rb
ruby-processing-2.5.0 samples/contributed/animator.rb