basis-processing 0.5.3 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/basis.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = "basis-processing"
3
- s.version = "0.5.3"
3
+ s.version = "0.5.4"
4
4
  s.add_dependency('knnball', '>= 0.0.6')
5
5
  s.author = "Avishek Sen Gupta"
6
6
  s.email = "avishek.sen.gupta@gmail.com"
@@ -15,10 +15,22 @@ end
15
15
 
16
16
  class CoordinateSystem
17
17
  CROSSHAIR_SCALE = 5000
18
+ UNIT_TRANSFORM = [[1,0],[0,1]]
19
+
18
20
  include MatrixOperations
19
21
  attr_accessor :x_basis_vector, :y_basis_vector
20
22
 
21
- def initialize(x_axis, y_axis, transform, artist)
23
+ def self.standard(x_range, y_range, artist)
24
+ x_basis_vector = {:x => 1.0, :y => 0.0}
25
+ y_basis_vector = {:x => 0.0, :y => 1.0}
26
+
27
+ x_range = ContinuousRange.new(x_range)
28
+ y_range = ContinuousRange.new(y_range)
29
+
30
+ CoordinateSystem.new(Axis.new(x_basis_vector,x_range), Axis.new(y_basis_vector,y_range), artist, UNIT_TRANSFORM)
31
+ end
32
+
33
+ def initialize(x_axis, y_axis, artist, transform = UNIT_TRANSFORM)
22
34
  @artist = artist
23
35
  @x_axis = x_axis
24
36
  @y_axis = y_axis
@@ -102,5 +114,22 @@ class CoordinateSystem
102
114
  crosshair_y_p2 = (@y_basis_vector*(-CROSSHAIR_SCALE)) + standard_basis(p)
103
115
  [{:from => crosshair_x_p1, :to => crosshair_x_p2}, {:from => crosshair_y_p1, :to => crosshair_y_p2}]
104
116
  end
117
+
118
+ def grid_lines(x_basis_interval, y_basis_interval)
119
+ lines = []
120
+ @x_axis.range.run(x_basis_interval) do |i,v|
121
+ raw_origin = {:x => i, :y => @y_axis.range.minimum}
122
+ hair_origin = standard_basis(raw_origin)
123
+ hair_end = standard_basis((@y_basis_vector*@y_axis.range.interval) + raw_origin)
124
+ lines << {:from => hair_origin, :to => hair_end}
125
+ end
126
+ @y_axis.range.run(y_basis_interval) do |i,v|
127
+ raw_origin = {:x => @x_axis.range.minimum, :y => i}
128
+ hair_origin = standard_basis(raw_origin)
129
+ hair_end = standard_basis((@x_basis_vector*@x_axis.range.interval) + raw_origin)
130
+ lines << {:from => hair_origin, :to => hair_end}
131
+ end
132
+ lines
133
+ end
105
134
  end
106
135
 
data/lib/demo.rb CHANGED
@@ -31,14 +31,15 @@ class Demo < Processing::App
31
31
  points = []
32
32
  200.times {|n|points << {:x => n, :y => random(300)}}
33
33
 
34
- x_basis_vector = {:x => 1.0, :y => 0.0}
35
- y_basis_vector = {:x => 0.2, :y => 1.0}
36
-
37
- x_range = ContinuousRange.new({:minimum => 0, :maximum => 200})
38
- y_range = ContinuousRange.new({:minimum => 0, :maximum => 300})
39
-
40
- @basis = CoordinateSystem.new(Axis.new(x_basis_vector,x_range), Axis.new(y_basis_vector,y_range), [[1,0],[0,1]], self)
41
- screen_transform = Transform.new({:x => 3, :y => -2}, {:x => 300, :y => 900})
34
+ # Long-winded way of doing the same thing
35
+
36
+ # @x_unit_vector = {:x => 1.0, :y => 1.0}
37
+ # @y_unit_vector = {:x => -1.0, :y => 1.0}
38
+ # x_range = ContinuousRange.new({:minimum => 0, :maximum => 200})
39
+ # y_range = ContinuousRange.new({:minimum => 0, :maximum => 300})
40
+ # @basis = CoordinateSystem.new(Axis.new(@x_unit_vector,x_range), Axis.new(@y_unit_vector,y_range), [[1,0],[0,1]], self)
41
+ @basis = CoordinateSystem.standard({:minimum => 0, :maximum => 200}, {:minimum => 0, :maximum => 300}, self)
42
+ screen_transform = Transform.new({:x => 2, :y => -2}, {:x => 300, :y => 900})
42
43
  @screen = Screen.new(screen_transform, self, @basis)
43
44
  @screen.draw_axes(10,10)
44
45
  stroke(1,1,0,1)
@@ -48,6 +49,9 @@ class Demo < Processing::App
48
49
  @screen.plot(p, :track => true) {|p| rect(p[:x], p[:y], 5, 5)}
49
50
  end
50
51
  end
52
+
53
+ def draw
54
+ end
51
55
  end
52
56
 
53
57
  w = 1200
data/lib/ranges.rb CHANGED
@@ -24,9 +24,12 @@ class ContinuousRange
24
24
  end
25
25
 
26
26
  class DiscreteRange
27
+ attr_accessor :minimum, :maximum
27
28
  attr_accessor :values
28
29
  def initialize(v)
29
30
  @values = v[:values]
31
+ @minimum = @values.first
32
+ @maximum = @values.last
30
33
  end
31
34
 
32
35
  def interval
data/lib/screen.rb CHANGED
@@ -96,6 +96,12 @@ class Screen
96
96
 
97
97
  draw_ticks(x_ticks, {:x => 0, :y => 20})
98
98
  draw_ticks(y_ticks, {:x => -50, :y => 0})
99
+
100
+ @artist.stroke(0.4, 1.0, 0.5, 0.2)
101
+ grid_lines = @basis.grid_lines(x_interval, y_interval).collect {|gl| {:from => @transform.apply(gl[:from]), :to => @transform.apply(gl[:to])}}
102
+ grid_lines.each do |l|
103
+ @artist.line(l[:from][:x],l[:from][:y],l[:to][:x],l[:to][:y])
104
+ end
99
105
  end
100
106
 
101
107
  def write(p)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basis-processing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.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: 2011-10-07 00:00:00.000000000Z
12
+ date: 2011-10-08 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: knnball
16
- requirement: &20813600 !ruby/object:Gem::Requirement
16
+ requirement: &23000300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.0.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *20813600
24
+ version_requirements: *23000300
25
25
  description: Basis provides a set of classes for easily plotting and transforming
26
26
  arbitrary 2D coordinate systems by specifying their basis vectors in Ruby-Processing.
27
27
  email: avishek.sen.gupta@gmail.com