Sha256: 2b5dbe4796d7bcfdc5e6fe622698765aaabb2a6534d09177f9518dd529134c02

Contents?: true

Size: 841 Bytes

Versions: 10

Compression:

Stored size: 841 Bytes

Contents

#
# Vector 
# by Daniel Shiffman.  
# PVector was used in the original (instead of Vec2D)
# Demonstration some basic vector math: subtraction, normalization, scaling
# Normalizing a vector sets its length to 1.
#
load_library :vecmath

def setup
  size(640,360)
  smooth
end

def draw
  background(0)
  
  # A vector that points to the mouse location
  mouse = Vec2D.new(mouse_x, mouse_y)
  # A vector that points to the center of the window
  center = Vec2D.new(width/2, height/2)
  # Subtract center from mouse which results in a vector that points from center to mouse
  mouse -= center
  
  # Normalize the vector
  mouse.normalize!
  
  # Multiply its length by 150 (Scaling its length)
  mouse *= 150

  translate(width/2,height/2)
  # Draw the resulting vector
  stroke(255)
  stroke_weight(4)
  line(0, 0, mouse.x, mouse.y)
  
end


Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ruby-processing-2.6.3 samples/processing_app/library/vecmath/vec2d/vector_math.rb
ruby-processing-2.6.2 samples/processing_app/library/vecmath/vec2d/vector_math.rb
ruby-processing-2.6.1 samples/processing_app/library/vecmath/vec2d/vector_math.rb
ruby-processing-2.6.0 samples/processing_app/library/vecmath/vec2d/vector_math.rb
ruby-processing-2.5.1 samples/processing_app/library/vecmath/vec2d/vector_math.rb
ruby-processing-2.5.0 samples/processing_app/library/vecmath/vec2d/vector_math.rb
ruby-processing-2.4.4 samples/processing_app/library/vecmath/vector_math.rb
ruby-processing-2.4.3 samples/processing_app/library/vecmath/vector_math.rb
ruby-processing-2.4.2 samples/processing_app/library/vecmath/vector_math.rb
ruby-processing-2.4.1 samples/processing_app/library/vecmath/vector_math.rb