Sha256: f05e3e87ff404c6b00aba8b581762852543a8aac1b5a95bf36f5290b9d2188bc

Contents?: true

Size: 948 Bytes

Versions: 4

Compression:

Stored size: 948 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.
#
require 'propane'

class VectorMath < Propane::App  
  
  def setup
    size(640, 360)
    stroke(255)
    stroke_weight(4)
  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
    line(0, 0, mouse.x, mouse.y)  
  end
end

VectorMath.new title: 'Vector Math'

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
propane-0.6.0-java examples/regular/vector_math.rb
propane-0.5.0-java examples/regular/vector_math.rb
propane-0.4.0.pre-java examples/regular/vector_math.rb
propane-0.3.0.pre-java examples/regular/vector_math.rb