# star.rb author Martin Prout
class Star
# makes use of mixin to replace java inner class
include Processing::Proxy
attr_reader :acc, :loc, :star_size, :vel, :focus # NB accessors used by animation class
def initialize(sz = 0.0, acc = nil, x = 0.0, y = 0.0)
@star_size = sz
@vel = PVector.new
@acc = acc
@focus = PVector.new X_FOCUS, Y_FOCUS
# ensure stars are spread out from focus initially in correct direction
@loc = PVector.new(X_FOCUS + acc.x * 8000, Y_FOCUS + acc.y * 5000)
end
def distance # from focus
@focus.dist loc
end
def brightness # star brightness
distance * 1.3
end
def update
@vel.x += acc.x
@vel.y += acc.y
@loc.x += vel.x
@loc.y += vel.y
end
# reset_x == reset_y included to have common
# interface with Saucer class
def reset_x
@loc.x = focus.x
@loc.y = focus.y
@vel.x = acc.x
@vel.y = acc.y
end
def reset_y
reset_x
end
def width
star_size * 2
end
def height
star_size * 2
end
def render
fill 255, 255, 255, brightness
rect loc.x, loc.y, star_size, star_size
end
end