Class: Graphics::Simulation
- Inherits:
-
AbstractSimulation
- Object
- AbstractSimulation
- Graphics::Simulation
- Defined in:
- lib/graphics/simulation.rb,
lib/graphics/rainbows.rb
Overview
A simulation. This ties everything together and provides a bunch of convenience methods to make life easier.
In the Model View Controller (MVC) pattern, the simulation is the Controller and controls both the window and all bodies involved in the simulation. The bodies are the Model and each body class is expected to have an inner View class w/ a #draw class method for the View.
For example, in examples/bounce.rb:
+ BounceSimulation subclasses Graphics::Simulation + BounceSimulation has many Balls + Ball#update maintains all ball movement. + BounceSimulation#draw automatically calls Ball::View.draw on all balls. + Ball::View.draw takes a window and a ball and draws it.
Constant Summary
Constants inherited from AbstractSimulation
AbstractSimulation::CLEAR_COLOR, AbstractSimulation::D2R, AbstractSimulation::DEBUG_COLOR, AbstractSimulation::DEFAULT_FONT, AbstractSimulation::FONT_GLOB, AbstractSimulation::LOG_INTERVAL, AbstractSimulation::R2D, AbstractSimulation::SCREEN_FLAGS
Instance Attribute Summary
Attributes inherited from AbstractSimulation
#_bodies, #color, #done, #font, #h, #iter_per_tick, #key_handler, #keydown_handler, #paused, #renderer, #start_time, #w
Instance Method Summary collapse
-
#initialize_rainbow(rainbow, name) ⇒ Object
Generate colors using a rainbow and a prefix name.
Methods inherited from AbstractSimulation
#add_key_handler, #add_keydown_handler, #angle, #audio, #bezier, #blit, #circle, #clear, #debug, #draw, #draw_and_flip, #draw_collection, #ellipse, #fast_rect, #find_font, #fps, #from_hsl, #from_hsv, #handle_event, #handle_keys, #hline, #image, #initialize, #initialize_colors, #initialize_keys, #line, #mouse, #open_mixer, #point, #polygon, #populate, #post_draw, #pre_draw, #project, #put, #rect, #register_bodies, #register_body, #register_color, #register_hsla, #register_hsva, #render_text, #run, #save, #sprite, #text, #text_size, #update, #vline
Constructor Details
This class inherits a constructor from Graphics::AbstractSimulation
Instance Method Details
#initialize_rainbow(rainbow, name) ⇒ Object
Generate colors using a rainbow and a prefix name.
114 115 116 117 118 119 |
# File 'lib/graphics/rainbows.rb', line 114 def initialize_rainbow rainbow, name rainbow.cache.each do |degree, color| color_name = "#{name}_#{degree}".to_sym self.register_color(color_name, *color, 255) end end |