straightedge 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/straightedge/aspects/colorable.rb +4 -0
- data/lib/straightedge/colors.rb +12 -3
- data/lib/straightedge/director.rb +1 -2
- data/lib/straightedge/extend/array.rb +9 -2
- data/lib/straightedge/figures/figure.rb +7 -8
- data/lib/straightedge/figures/grid.rb +14 -7
- data/lib/straightedge/figures/grid_cell.rb +8 -0
- data/lib/straightedge/figures/quadrilateral.rb +0 -1
- data/lib/straightedge/presenter.rb +0 -15
- data/lib/straightedge/scene.rb +15 -5
- data/lib/straightedge/toolkit/compass.rb +1 -1
- data/lib/straightedge/toolkit/rose.rb +8 -1
- data/lib/straightedge/version.rb +1 -1
- data/spec/straightedge/extend/array_spec.rb +0 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f2a81c654f8816e7d1d0bbc53c0f75c928c7146
|
4
|
+
data.tar.gz: 546d460caabdfd47c16025a53fe54c851d898007
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b9515f8995dbcf87e7d494b867171b31001880c07498682295b17e2f0c6caf7eb497e6fe411e1bfb736a2b8531a57493c89be149751d85ec865a3d0682fcf4a
|
7
|
+
data.tar.gz: 18339a4a432ad8ee3dcf21357277d30083cb7a40eb55809f2f18a450cdc183261b6f26ecb1187819cf89521454b60a6e5819c1b31d6bf1d6f8823833e4552236
|
data/lib/straightedge/colors.rb
CHANGED
@@ -8,11 +8,11 @@ module Straightedge
|
|
8
8
|
@names_and_values = names_and_hex_values
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
11
|
def list; @names_and_values.keys end
|
13
12
|
def_delegator :list, :sample
|
14
13
|
|
15
14
|
def hex_value_for(name)
|
15
|
+
return name if name.is_a?(Integer)
|
16
16
|
raise "no such color: #{name}" unless list.include?(name)
|
17
17
|
@names_and_values[name]
|
18
18
|
end
|
@@ -20,7 +20,7 @@ module Straightedge
|
|
20
20
|
def self.base
|
21
21
|
@core ||= new({
|
22
22
|
white: 0xFFFFFFFF,
|
23
|
-
black: 0xFF000000,
|
23
|
+
#black: 0xFF000000,
|
24
24
|
none: 0x00000000,
|
25
25
|
})
|
26
26
|
end
|
@@ -62,8 +62,17 @@ module Straightedge
|
|
62
62
|
palette.sample
|
63
63
|
end
|
64
64
|
|
65
|
+
# http://stackoverflow.com/questions/1698318/ruby-generate-a-random-hex-color
|
66
|
+
def self.random
|
67
|
+
("%08x" % (rand * 0xffffffff)).to_i(16)
|
68
|
+
end
|
69
|
+
|
65
70
|
def self.hex_value(color)
|
66
|
-
palette.hex_value_for color
|
71
|
+
palette.hex_value_for(color) #rescue color
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.dim(color, factor=0x2A000000) #2A2A2A)
|
75
|
+
Colors.hex_value(color) - factor
|
67
76
|
end
|
68
77
|
end
|
69
78
|
|
@@ -2,8 +2,15 @@ class Array
|
|
2
2
|
include Straightedge::Aspects::Positional
|
3
3
|
include Straightedge::Aspects::Figural
|
4
4
|
|
5
|
-
def
|
6
|
-
|
5
|
+
def second; self[1] end
|
6
|
+
def third; self[2] end
|
7
|
+
|
8
|
+
def sum(&blk)
|
9
|
+
if block_given?
|
10
|
+
map(&blk).sum
|
11
|
+
else
|
12
|
+
inject(&:+)
|
13
|
+
end
|
7
14
|
end
|
8
15
|
|
9
16
|
def mean
|
@@ -9,7 +9,7 @@ module Straightedge
|
|
9
9
|
include Enumerable
|
10
10
|
|
11
11
|
def_delegators :marks, :each
|
12
|
-
def_delegators :compass, :
|
12
|
+
def_delegators :compass, :orbit
|
13
13
|
def_delegators :location, :x, :y
|
14
14
|
|
15
15
|
attr_accessor :marks, :color, :location
|
@@ -23,12 +23,11 @@ module Straightedge
|
|
23
23
|
def compass; @compass ||= Straightedge::Toolkit::Compass.default end
|
24
24
|
|
25
25
|
def adjacent
|
26
|
-
approximate_adjacent = map(&method(:
|
27
|
-
|
28
|
-
actual_adjacent.sort_by(&method(:distance_from_center))
|
26
|
+
approximate_adjacent = map(&method(:orbit)).flatten(1).uniq
|
27
|
+
approximate_adjacent.reject(&method(:include?))
|
28
|
+
#actual_adjacent.sort_by(&method(:distance_from_center))
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
31
|
# note this is center of the collection of raw marks
|
33
32
|
# in terms of their own space; not displaced by location
|
34
33
|
# or scaled by dimensions
|
@@ -36,9 +35,9 @@ module Straightedge
|
|
36
35
|
[map(&:x).mean, map(&:y).mean]
|
37
36
|
end
|
38
37
|
|
39
|
-
def distance_from_center(xy)
|
40
|
-
|
41
|
-
end
|
38
|
+
#def distance_from_center(xy)
|
39
|
+
# Straightedge::Toolkit::Ruler.distance(xy,center)
|
40
|
+
#end
|
42
41
|
end
|
43
42
|
end
|
44
43
|
end
|
@@ -18,19 +18,25 @@ module Straightedge
|
|
18
18
|
[xy.x, xy.y]
|
19
19
|
end
|
20
20
|
|
21
|
+
def orbit(xy)
|
22
|
+
clip compass.orbit(xy)
|
23
|
+
end
|
24
|
+
|
21
25
|
def each
|
22
26
|
Grid.each_coordinate([width, height]) do |x, y|
|
23
27
|
yield(at([x,y]))
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
31
|
+
# over-ride with data
|
32
|
+
def color_at(_); :none end
|
27
33
|
def cell_at(xy)
|
28
34
|
@cells ||= {}
|
29
|
-
@cells[xy]
|
35
|
+
@cells[xy] = Figures::Quadrilateral.new(color: color_at(xy), dimensions: [@scale, @scale], location: to_pixels(xy))
|
30
36
|
end
|
31
37
|
|
32
38
|
def each_cell
|
33
|
-
each { |xy|
|
39
|
+
each { |xy| c = cell_at(xy); yield c if c }
|
34
40
|
end
|
35
41
|
|
36
42
|
def paint!
|
@@ -40,19 +46,20 @@ module Straightedge
|
|
40
46
|
|
41
47
|
def clip(xys=[])
|
42
48
|
xys.reject do |xy|
|
43
|
-
_x,_y =
|
44
|
-
_x < 0 || _y < 0 ||
|
49
|
+
_x, _y = xy.x, xy.y
|
50
|
+
_x < 0 || _y < 0 || _x >= width || _y >= height
|
45
51
|
end
|
46
52
|
end
|
47
53
|
|
48
|
-
def self.each_coordinate(
|
49
|
-
|
50
|
-
|
54
|
+
def self.each_coordinate(dim)
|
55
|
+
dim.x.times do |x|
|
56
|
+
dim.y.times do |y|
|
51
57
|
yield [x,y]
|
52
58
|
end
|
53
59
|
end
|
54
60
|
end
|
55
61
|
|
62
|
+
# why scale/2? there's something goofy somewhere
|
56
63
|
def to_pixels(xy)
|
57
64
|
[xy.x * (@scale/2), xy.y * (@scale/2)]
|
58
65
|
end
|
@@ -1,29 +1,14 @@
|
|
1
1
|
module Straightedge
|
2
|
-
# TODO something with this
|
3
2
|
class Presenter
|
4
3
|
extend Forwardable
|
5
|
-
#def_delegators :location, :x, :y
|
6
4
|
|
7
5
|
def on(surface)
|
8
6
|
@surface = surface
|
9
7
|
self
|
10
8
|
end
|
11
9
|
|
12
|
-
#def at(p)
|
13
|
-
# @location = p
|
14
|
-
# self
|
15
|
-
#end
|
16
|
-
|
17
10
|
def display(figure)
|
18
11
|
raise 'implement in subclass'
|
19
12
|
end
|
20
|
-
|
21
|
-
#def location
|
22
|
-
# @location ||= [0,0]
|
23
|
-
#end
|
24
|
-
|
25
|
-
#def color(figure)
|
26
|
-
# @color ||= 0xEFEFEFEF
|
27
|
-
#end
|
28
13
|
end
|
29
14
|
end
|
data/lib/straightedge/scene.rb
CHANGED
@@ -9,12 +9,22 @@ module Straightedge
|
|
9
9
|
|
10
10
|
def render(adapter=nil)
|
11
11
|
return false unless adapter
|
12
|
-
@locations_and_figures.each do |location,
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
@locations_and_figures.each do |location,f|
|
13
|
+
if f.is_a?(Array)
|
14
|
+
f.map do |figure|
|
15
|
+
Scene.render_figure(figure, location,adapter)
|
16
|
+
end
|
17
|
+
else
|
18
|
+
Scene.render_figure(f, location,adapter)
|
19
|
+
end
|
17
20
|
end
|
18
21
|
end
|
22
|
+
|
23
|
+
def self.render_figure(figure,location,adapter)
|
24
|
+
figure = Figures::Label.new.says(figure) if figure.is_a?(String)
|
25
|
+
figure.location = location
|
26
|
+
presenter = adapter.presenter_for(figure)
|
27
|
+
presenter.display(figure)
|
28
|
+
end
|
19
29
|
end
|
20
30
|
end
|
@@ -7,12 +7,18 @@ module Straightedge
|
|
7
7
|
@directions = directions
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def orbit(point)
|
11
11
|
@directions.values.collect do |delta|
|
12
12
|
Ruler.translate(point, delta)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
def orbits(points, depth: 1)
|
17
|
+
return if depth.zero?
|
18
|
+
obs = points.map(&method(:orbit)).flatten(1)
|
19
|
+
(obs + orbits(obs, depth: depth-1)).uniq
|
20
|
+
end
|
21
|
+
|
16
22
|
class << self
|
17
23
|
def simple
|
18
24
|
return @simple_rose unless @simple_rose.nil?
|
@@ -25,6 +31,7 @@ module Straightedge
|
|
25
31
|
end
|
26
32
|
|
27
33
|
# for hex navigation (nb coords are in cube-space)
|
34
|
+
# TODO use for hex oriented grids
|
28
35
|
def hexagonal
|
29
36
|
return @hex_rose unless @hex_rose.nil?
|
30
37
|
@hex_rose = new directions: {
|
data/lib/straightedge/version.rb
CHANGED
@@ -17,24 +17,5 @@ describe Array do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
21
|
-
describe ".to_points" do
|
22
|
-
subject do
|
23
|
-
[[1,2],[3,2]]
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'should decode as a set of points' do
|
27
|
-
it 'should have a center' do
|
28
|
-
expect(subject.center).to eql([2,2])
|
29
|
-
end
|
30
|
-
|
31
|
-
let(:expected_adjacent) do
|
32
|
-
[[2, 2], [2, 3], [2, 1], [1, 1], [3, 1], [1, 3], [3, 3], [4, 2], [0, 2], [0, 1], [0, 3], [4, 1], [4, 3]]
|
33
|
-
end
|
34
|
-
it 'should have adjacent coordinates' do
|
35
|
-
expect(subject.adjacent).to eql(expected_adjacent)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
20
|
end
|
40
21
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: straightedge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Weissman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mini-config
|