Class: Termular::Graph::Polar
- Inherits:
-
Termular::Graph
- Object
- Termular::Graph
- Termular::Graph::Polar
- Defined in:
- lib/termular/graph.rb
Instance Attribute Summary
Attributes inherited from Termular::Graph
#expression, #max_x, #max_y, #min_x, #min_y, #needs_redraw, #options, #start_time
Instance Method Summary collapse
Methods inherited from Termular::Graph
#center, #initialize, #invalidate, #pan, #point_to_screen, #render_axes, #screen_to_point, #zoom
Constructor Details
This class inherits a constructor from Termular::Graph
Instance Method Details
#render ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/termular/graph.rb', line 150 def render @needs_redraw = false Console.buffered_print do |buff| buff << render_axes # render actual graph ctx = Context.new Context.global buff << Console.color(:green) ctx["time"] = Time.now.to_f - @start_time old_y = nil (["tmin"] || 0).upto(((["tmax"] || 2 * Math::PI) * 100).round).map { |t| t / 100.0 }.each do |theta| ctx["t"] = theta radius = expression.eval ctx next if radius.is_a? Complex or (radius.respond_to? :nan and radius.nan?) scr_pt = point_to_screen(radius*Math.cos(theta), radius*Math.sin(theta)) if scr_pt[0] >= 0 and scr_pt[0] <= Console.cols and scr_pt[1] >= 0 and scr_pt[1] <= Console.rows buff << Console.move(scr_pt[0], scr_pt[1]) buff << "+" end end buff << Console.reset end end |