Class: Termular::Graph::ImplicitPolar

Inherits:
Termular::Graph show all
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

#renderObject



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/termular/graph.rb', line 175

def render
  @needs_redraw = false
  Console.buffered_print do |buff|
    buff << render_axes
    ctx = Context.new Context.global
    ctx["time"] = Time.now.to_f - @start_time
    buff << Console.color(:green)
    1.upto(Console.rows - 1) do |sy|
      1.upto(Console.cols) do |sx|
        x, y = screen_to_point sx, sy
        ctx["r"], ctx["t"] = Math.sqrt(x**2 + y**2), Math.atan2(y, x)
        if expression.eval ctx
          buff << Console.move(sx, Console.rows - sy) << "+"
        end
      end
    end
  end
end