basis-processing 0.4.8 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README +68 -0
- data/basis.gemspec +1 -1
- data/lib/demo.rb +4 -2
- data/lib/screen.rb +9 -0
- metadata +4 -4
data/README
CHANGED
@@ -1 +1,69 @@
|
|
1
1
|
Basis provides a set of classes for easily plotting and transforming arbitrary 2D coordinate systems by specifying their basis vectors in Ruby-Processing.
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
To install the Basis gem, first head to the location where the jruby-complete.jar is located, for Ruby-Processing. There, do this:
|
6
|
+
|
7
|
+
java -jar jruby-complete.jar -S gem install basis-processing --user-install
|
8
|
+
|
9
|
+
Alternatively, if you're using a conventional JRuby installation, do this:
|
10
|
+
|
11
|
+
sudo jruby -S gem install basis-processing
|
12
|
+
|
13
|
+
To use Basis functionality in your code, it is enough to:
|
14
|
+
|
15
|
+
require 'basis_processing'
|
16
|
+
|
17
|
+
## Example Code
|
18
|
+
|
19
|
+
Here's some example code, which plots random points.
|
20
|
+
|
21
|
+
require 'rubygems'`
|
22
|
+
require 'basis_processing'`
|
23
|
+
|
24
|
+
class Demo < Processing::App
|
25
|
+
app = self
|
26
|
+
def setup
|
27
|
+
smooth
|
28
|
+
background(0,0,0)
|
29
|
+
color_mode(RGB, 1.0)
|
30
|
+
|
31
|
+
points = []
|
32
|
+
100.times {points << {:x => random(200), :y => random(300)}}
|
33
|
+
|
34
|
+
x_basis_vector = {:x => 1.0, :y => 0.0}
|
35
|
+
y_basis_vector = {:x => 0.0, :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), [[4,0],[0,2]], self)
|
41
|
+
screen_transform = SignedTransform.new({:x => 1, :y => -1}, {:x => 300, :y => 900})
|
42
|
+
screen = Screen.new(screen_transform, self)
|
43
|
+
screen.join = true
|
44
|
+
screen.draw_axes(basis,10,10)
|
45
|
+
stroke(1,1,0,1)
|
46
|
+
fill(1,1,0)
|
47
|
+
rect_mode(CENTER)
|
48
|
+
points.each do |p|
|
49
|
+
screen.plot(p, basis, :bar => true) {|p| rect(p[:x], p[:y], 5, 5)}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def draw
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
w = 1200
|
58
|
+
h = 1000
|
59
|
+
|
60
|
+
Demo.new(:title => "My Sketch", :width => w, :height => h)
|
61
|
+
|
62
|
+
You have a few options when plotting a point. Consider the line:
|
63
|
+
|
64
|
+
screen.plot(p, basis, :bar => true) {|p| rect(p[:x], p[:y], 5, 5)}
|
65
|
+
|
66
|
+
If you omit `:bar => true` or don't specify any options, Basis will plot the points without connecting them to the X-axis.
|
67
|
+
If you omit the block at the end of the call, Basis will plot the point using a circle. Use the block to customise how you wish to represent the point graphically.
|
68
|
+
You can toggle the joining of the points with lines by setting the join attribute of Screen to on (joins points)/off (no joining). The default is false.
|
69
|
+
|
data/basis.gemspec
CHANGED
data/lib/demo.rb
CHANGED
@@ -14,7 +14,7 @@ class Demo < Processing::App
|
|
14
14
|
stroke(1,1,0,1)
|
15
15
|
|
16
16
|
points = []
|
17
|
-
|
17
|
+
200.times {|n|points << {:x => n, :y => random(300)}}
|
18
18
|
|
19
19
|
x_basis_vector = {:x => 1.0, :y => 0.0}
|
20
20
|
y_basis_vector = {:x => 0.0, :y => 1.0}
|
@@ -25,11 +25,13 @@ class Demo < Processing::App
|
|
25
25
|
basis = CoordinateSystem.new(Axis.new(x_basis_vector,x_range), Axis.new(y_basis_vector,y_range), [[4,0],[0,2]], self)
|
26
26
|
screen_transform = SignedTransform.new({:x => 1, :y => -1}, {:x => 300, :y => 900})
|
27
27
|
screen = Screen.new(screen_transform, self)
|
28
|
+
screen.join=true
|
28
29
|
screen.draw_axes(basis,10,10)
|
29
30
|
stroke(1,1,0,1)
|
30
31
|
fill(1,1,0)
|
32
|
+
rect_mode(CENTER)
|
31
33
|
points.each do |p|
|
32
|
-
screen.plot(p, basis)
|
34
|
+
screen.plot(p, basis) {|p| rect(p[:x], p[:y], 5, 5)}
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
data/lib/screen.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
require 'transform'
|
2
2
|
|
3
3
|
class Screen
|
4
|
+
def join=(should_join)
|
5
|
+
@should_join = should_join
|
6
|
+
@buffer = nil if !@should_join
|
7
|
+
end
|
8
|
+
|
4
9
|
def initialize(transform, artist)
|
5
10
|
@transform = transform
|
6
11
|
@artist = artist
|
12
|
+
join = false
|
7
13
|
end
|
8
14
|
|
9
15
|
def plot(point, basis, options = {:bar => false}, &block)
|
@@ -17,6 +23,9 @@ class Screen
|
|
17
23
|
@artist.ellipse(p[:x], p[:y], 5, 5)
|
18
24
|
end
|
19
25
|
@artist.line(standard_x_axis_point[:x], standard_x_axis_point[:y], p[:x], p[:y]) if options[:bar]
|
26
|
+
return if !@should_join
|
27
|
+
@artist.line(@buffer[:x], @buffer[:y], p[:x], p[:y]) if @buffer
|
28
|
+
@buffer = p
|
20
29
|
end
|
21
30
|
|
22
31
|
def original(onscreen_point, basis)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basis-processing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 9
|
10
|
+
version: 0.4.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Avishek Sen Gupta
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-03 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: Basis provides a set of classes for easily plotting and transforming arbitrary 2D coordinate systems by specifying their basis vectors in Ruby-Processing.
|