Sha256: 516d59f5845128d246ecfd2b7875524d1c258a6d005bdda861cc1a17854ee171

Contents?: true

Size: 1.31 KB

Versions: 10

Compression:

Stored size: 1.31 KB

Contents

#
#  Polygons
#
#  by Ricard Marxer
#
#  This example shows how to create polygon bodies.
#

load_library :fisica
include_package 'fisica'

attr_reader :world, :poly

def setup
  size(400, 400)
  smooth  
  Fisica.init(self)  
  @world = FWorld.new
  world.set_gravity(0, 800)
  world.set_edges
  world.remove(world.left)
  world.remove(world.right)
  world.remove(world.top)  
  world.set_edges_restitution(0.5)
end

def draw
  background(255)  
  world.step
  world.draw(self)   
  # Draw the polygon while
  # while it is being created
  # and hasn't been added to the
  # world yet  
  poly.draw(self) if (poly)  
end

def mouse_pressed
  unless (world.get_body(mouse_x, mouse_y))    
    @poly = FPoly.new
    poly.set_stroke_weight(3)
    poly.set_fill(120, 30, 90)
    poly.set_density(10)
    poly.set_restitution(0.5)
    poly.vertex(mouse_x, mouse_y)
  end
end

def mouse_dragged  
  poly.vertex(mouse_x, mouse_y) if (poly)
end

def mouse_released
  if (poly)
    world.add(poly)
    @poly = nil
  end
end

#
# Remove object under mouse using backspace 'key'
# any other key should save
#

def key_pressed
  if key_code == BACKSPACE
    hovered = world.get_body(mouse_x, mouse_y)
    if (hovered && hovered.is_static == false)
      world.remove(hovered)
    end    
  else    
    save_frame("screenshot.png")    
  end
end





Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ruby-processing-2.6.3 samples/external_library/java_processing/fisica/polygons.rb
ruby-processing-2.6.2 samples/external_library/java_processing/fisica/polygons.rb
ruby-processing-2.6.1 samples/external_library/java_processing/fisica/polygons.rb
ruby-processing-2.6.0 samples/external_library/java_processing/fisica/polygons.rb
ruby-processing-2.5.1 samples/external_library/java_processing/fisica/polygons.rb
ruby-processing-2.5.0 samples/external_library/java_processing/fisica/polygons.rb
ruby-processing-2.4.4 samples/external_library/java_processing/fisica/polygons.rb
ruby-processing-2.4.3 samples/external_library/java_processing/fisica/polygons.rb
ruby-processing-2.4.2 samples/external_library/java_processing/fisica/polygons.rb
ruby-processing-2.4.1 samples/external_library/java_processing/fisica/polygons.rb