termular 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -126,6 +126,26 @@ module Termular
126
126
  end
127
127
  end
128
128
 
129
+ class ImplicitCartesian < Graph
130
+ def render
131
+ @needs_redraw = false
132
+ Console.buffered_print do |buff|
133
+ buff << render_axes
134
+ ctx = Context.new Context.global
135
+ ctx["time"] = Time.now.to_f - @start_time
136
+ buff << Console.color(:green)
137
+ 1.upto(Console.rows - 1) do |sy|
138
+ 1.upto(Console.cols) do |sx|
139
+ ctx["x"], ctx["y"] = screen_to_point sx, sy
140
+ if expression.eval ctx
141
+ buff << Console.move(sx, Console.rows - sy) << "+"
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
148
+
129
149
  class Polar < Graph
130
150
  def render
131
151
  @needs_redraw = false
@@ -150,5 +170,26 @@ module Termular
150
170
  end
151
171
  end
152
172
  end
173
+
174
+ class ImplicitPolar < Graph
175
+ def render
176
+ @needs_redraw = false
177
+ Console.buffered_print do |buff|
178
+ buff << render_axes
179
+ ctx = Context.new Context.global
180
+ ctx["time"] = Time.now.to_f - @start_time
181
+ buff << Console.color(:green)
182
+ 1.upto(Console.rows - 1) do |sy|
183
+ 1.upto(Console.cols) do |sx|
184
+ x, y = screen_to_point sx, sy
185
+ ctx["r"], ctx["t"] = Math.sqrt(x**2 + y**2), Math.atan2(y, x)
186
+ if expression.eval ctx
187
+ buff << Console.move(sx, Console.rows - sy) << "+"
188
+ end
189
+ end
190
+ end
191
+ end
192
+ end
193
+ end
153
194
  end
154
195
  end
@@ -12,11 +12,15 @@ module Termular
12
12
  attr_accessor :left, :right
13
13
  end
14
14
 
15
- class Add < Binary; def eval(ctx) left.eval(ctx) + right.eval(ctx) end end
16
- class Subtract < Binary; def eval(ctx) left.eval(ctx) - right.eval(ctx) end end
17
- class Multiply < Binary; def eval(ctx) left.eval(ctx) * right.eval(ctx) end end
18
- class Divide < Binary; def eval(ctx) left.eval(ctx) / right.eval(ctx) end end
19
- class Power < Binary; def eval(ctx) left.eval(ctx) ** right.eval(ctx) end end
15
+ class Add < Binary; def eval(ctx) left.eval(ctx) + right.eval(ctx) end end
16
+ class Subtract < Binary; def eval(ctx) left.eval(ctx) - right.eval(ctx) end end
17
+ class Multiply < Binary; def eval(ctx) left.eval(ctx) * right.eval(ctx) end end
18
+ class Divide < Binary; def eval(ctx) left.eval(ctx) / right.eval(ctx) end end
19
+ class Power < Binary; def eval(ctx) left.eval(ctx) ** right.eval(ctx) end end
20
+ class LessThan < Binary; def eval(ctx) left.eval(ctx) < right.eval(ctx) end end
21
+ class LessThanEqual < Binary; def eval(ctx) left.eval(ctx) <= right.eval(ctx) end end
22
+ class GreaterThan < Binary; def eval(ctx) left.eval(ctx) > right.eval(ctx) end end
23
+ class GreaterThanEqual < Binary; def eval(ctx) left.eval(ctx) >= right.eval(ctx) end end
20
24
 
21
25
  class Negate < Base
22
26
  attr_accessor :expression
@@ -51,10 +55,18 @@ module Termular
51
55
  attr_accessor :expression
52
56
  end
53
57
 
58
+ class ImplicitCartesianCommand < Base
59
+ attr_accessor :relation
60
+ end
61
+
54
62
  class PolarCommand < Base
55
63
  attr_accessor :expression
56
64
  end
57
65
 
66
+ class ImplicitPolarCommand < Base
67
+ attr_accessor :relation
68
+ end
69
+
58
70
  class OptionCommand < Base
59
71
  attr_accessor :option, :expression
60
72
  end
@@ -78,7 +90,11 @@ module Termular
78
90
  [ :OPEN_BRACKET, /\[/ ],
79
91
  [ :CLOSE_BRACKET, /\]/ ],
80
92
  [ :COMMA, /\,/ ],
81
- [ :COMMAND, /:([a-z][a-z0-9]*)/, ->m { m[1] } ]
93
+ [ :COMMAND, /:([a-z][a-z0-9]*)/, ->m { m[1] } ],
94
+ [ :LTE, /<=/ ],
95
+ [ :LT, /</ ],
96
+ [ :GTE, />=/ ],
97
+ [ :GT, />/ ]
82
98
  ].map { |a| [a[0], Regexp.new("\\A#{a[1].source}", Regexp::MULTILINE), a[2]] }
83
99
 
84
100
  def self.lex!(original_src)
@@ -139,18 +155,29 @@ module Termular
139
155
  assert_type next_token, :COMMAND
140
156
  case token[1]
141
157
  when "q"; AST::QuitCommand.new
158
+ when "ic"; AST::ImplicitCartesianCommand.new relation: relation
142
159
  when "c"; AST::CartesianCommand.new expression: expression
160
+ when "ip"; AST::ImplicitPolarCommand.new relation: relation
143
161
  when "p"; AST::PolarCommand.new expression: expression
144
162
  when "opt"; option_command
145
163
  end
146
164
  end
147
165
 
166
+ def relation
167
+ left = expression
168
+ assert_type next_token, :LT, :LTE, :GT, :GTE
169
+ op = token[0]
170
+ right = expression
171
+ { LT: AST::LessThan, LTE: AST::LessThanEqual, GT: AST::GreaterThan,
172
+ GTE: AST::GreaterThanEqual }[op].new left: left, right: right
173
+ end
174
+
148
175
  def option_command
149
176
  assert_type next_token, :BAREWORD
150
177
  opt = token[1]
151
178
  AST::OptionCommand.new option: opt, expression: expression
152
179
  end
153
-
180
+
154
181
  def expression
155
182
  additive_expression
156
183
  end
@@ -84,9 +84,15 @@ module Termular
84
84
  if current_command.is_a? AST::CartesianCommand
85
85
  @current_graph = Graph::Cartesian.new current_command.expression
86
86
  @needs_tick = expression =~ /time/
87
+ elsif current_command.is_a? AST::ImplicitCartesianCommand
88
+ @current_graph = Graph::ImplicitCartesian.new current_command.relation
89
+ @needs_tick = expression =~ /time/
87
90
  elsif current_command.is_a? AST::PolarCommand
88
91
  @current_graph = Graph::Polar.new current_command.expression
89
92
  @needs_tick = expression =~ /time/
93
+ elsif current_command.is_a? AST::ImplicitPolarCommand
94
+ @current_graph = Graph::ImplicitPolar.new current_command.relation
95
+ @needs_tick = expression =~ /time/
90
96
  elsif current_command.is_a? AST::OptionCommand
91
97
  if current_graph
92
98
  current_graph.options[current_command.option] = current_command.expression.eval(Context.global)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: termular
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-07 00:00:00.000000000 Z
12
+ date: 2012-01-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ncurses-ruby
16
- requirement: &2154884800 !ruby/object:Gem::Requirement
16
+ requirement: &2169471840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2154884800
24
+ version_requirements: *2169471840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: paint
27
- requirement: &2154883580 !ruby/object:Gem::Requirement
27
+ requirement: &2169471380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2154883580
35
+ version_requirements: *2169471380
36
36
  description: Termular Grapher is a simple graphing program that's capable of cartesian
37
37
  and polar graphs
38
38
  email: