Skip to content

Commit

Permalink
fiddling with particle
Browse files Browse the repository at this point in the history
  • Loading branch information
monkstone committed Sep 15, 2014
1 parent 4b93e78 commit ce3c30d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
6 changes: 3 additions & 3 deletions library/control_panel/control_panel.rb
Expand Up @@ -59,7 +59,7 @@ def value

# Creates check-box elements for control_panel
class Checkbox < javax.swing.JCheckBox
def initialize(control_panel, name, proc=nil)
def initialize(control_panel, name, proc = nil)
@control_panel = control_panel
super(name.to_s)
set_preferred_size(java.awt.Dimension.new(190, 64))
Expand Down Expand Up @@ -107,7 +107,7 @@ def display
set_size 200, 30 + (64 * elements.size)
set_default_close_operation javax.swing.JFrame::HIDE_ON_CLOSE
set_resizable false
set_location($app.width + 10, 0) unless ($app.width + 10 > $app.displayWidth)
set_location($app.width + 10, 0) unless $app.width + 10 > $app.displayWidth
panel.visible = true
end

Expand Down Expand Up @@ -154,7 +154,7 @@ def set_feel(lf = 'metal')
laf = lafinfo.select do |info|
info.getName.eql? lf.capitalize
end
javax.swing.UIManager.setLookAndFeel(laf[0].getClassName)
javax.swing.UIManager.setLookAndFeel(laf[0].getClassName)
end
end

Expand Down
Expand Up @@ -40,16 +40,17 @@ def display

class Particle
include Processing::Proxy

GRAVITY = Vec2D.new(0, 0.1)

attr_reader :center, :velocity, :lifespan, :s_shape, :part_size,
:width, :height, :sprite

:boundary_x, :boundary_y, :sprite

def initialize width, height, sprite
@width, @height, @sprite = width, height, sprite
part_size = rand(10 .. 60)
@sprite = sprite
@boundary_x = Boundary.new(0, width)
@boundary_y = Boundary.new(0, height)
part_size = rand(10..60)
# The particle is a textured quad
@s_shape = create_shape
s_shape.begin_shape(QUAD)
Expand All @@ -61,10 +62,8 @@ def initialize width, height, sprite
s_shape.vertex(+part_size / 2.0, +part_size / 2.0, sprite.width, sprite.height)
s_shape.vertex(-part_size / 2.0, +part_size / 2.0, 0, sprite.height)
s_shape.end_shape

# Initialize center vector
@center = Vec2D.new

# Set the particle starting location
rebirth(width / 2.0, height / 2.0)
end
Expand All @@ -87,8 +86,8 @@ def rebirth(x, y)
# Is it off the screen, or its lifespan is over?
def dead?
return true if lifespan < 0
return true if center.y > height || center.y < 0
return true if center.x > width || center.x < 0
return true if boundary_y.exclude? center.y
return true if boundary_x.exclude? center.x
false
end

Expand All @@ -100,8 +99,15 @@ def update
s_shape.set_tint(color(255, lifespan))
# Move the particle according to its velocity
s_shape.translate(velocity.x, velocity.y)
# and also update the center
# and also update the center location
@center += velocity
end
end

# unusually in this case we are looking for excluded values

Boundary = Struct.new(:lower, :upper) do
def exclude? val
true unless (lower...upper).cover? val
end
end

0 comments on commit ce3c30d

Please sign in to comment.