Sha256: 588c90b44dcfa3f4877a74c9821c1da14f5c9294d69f57079d4cd6dcedf54a3a

Contents?: true

Size: 895 Bytes

Versions: 10

Compression:

Stored size: 895 Bytes

Contents

#
# Linear Interpolation. 
# 
# Move the mouse across the screen and the symbol will follow.  
# Between drawing each frame of the animation, the ellipse moves 
# part of the distance (0.05) from its current position toward 
# the cursor using the lerp() function
#
# This is the same as the Easing under input only with lerp() instead. 
#
 
attr_reader :x, :y

def setup
  size(640, 360) 
  no_stroke  
end

def draw 
  background(51)
  
  # lerp() calculates a number between two numbers at a specific increment. 
  # The amt parameter is the amount to interpolate between the two values 
  # where 0.0 equal to the first point, 0.1 is very near the first point, 0.5 
  # is half-way in between, etc.  
  
  # Here we are moving 5% of the way to the mouse location each frame
  @x = lerp(x, mouse_x, 0.05)
  @y = lerp(y, mouse_y, 0.05)
  
  fill(255)
  stroke(255)
  ellipse(x, y, 66, 66)
end

Version data entries

10 entries across 10 versions & 1 rubygems

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