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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8b2f60d62255936247fe75932dc27426760a1e9
4
- data.tar.gz: 05cc12291ebbf0518a608b1f1e0f3ef6f0ca376d
3
+ metadata.gz: 9f2a81c654f8816e7d1d0bbc53c0f75c928c7146
4
+ data.tar.gz: 546d460caabdfd47c16025a53fe54c851d898007
5
5
  SHA512:
6
- metadata.gz: 176f4ae297d81ab3c94e6daf7a0ea0aa3ad94cd12594ead81123822e0704ba6b7dd56f2026a1e9094e5840eb0320fc7c64c2e8b49787e1468f52e2e2c8e059aa
7
- data.tar.gz: 8e600b22c8cf4463e7a55e5d1883da258e81ea4668e8e686f36af5dbbe0bc35e9e7b277c39a651f6431dbe3ce81703143d14167b630567ddc4b857a1998c9ab6
6
+ metadata.gz: 4b9515f8995dbcf87e7d494b867171b31001880c07498682295b17e2f0c6caf7eb497e6fe411e1bfb736a2b8531a57493c89be149751d85ec865a3d0682fcf4a
7
+ data.tar.gz: 18339a4a432ad8ee3dcf21357277d30083cb7a40eb55809f2f18a450cdc183261b6f26ecb1187819cf89521454b60a6e5819c1b31d6bf1d6f8823833e4552236
@@ -4,5 +4,9 @@ module Straightedge::Aspects
4
4
  def paint(c=Straightedge::Colors.pick)
5
5
  @color = c
6
6
  end
7
+
8
+ def dim
9
+ @color = Straightedge::Colors.hex_value(@color) - 0x4B4B4B4B
10
+ end
7
11
  end
8
12
  end
@@ -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
 
@@ -15,8 +15,7 @@ module Straightedge
15
15
 
16
16
  def current_scene
17
17
  Scene.new({
18
- ORIGIN => @space,
19
- [10,10] => "grid",
18
+ ORIGIN => [ @space, "grid" ],
20
19
 
21
20
  [200,300] => Quadrilateral.new(dimensions: [200,100], color: :green),
22
21
  [200,305] => "rectangle",
@@ -2,8 +2,15 @@ class Array
2
2
  include Straightedge::Aspects::Positional
3
3
  include Straightedge::Aspects::Figural
4
4
 
5
- def sum
6
- inject(&:+)
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, :project
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(:project)).flatten(1).uniq
27
- actual_adjacent = approximate_adjacent.reject(&method(:include?))
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
- Straightedge::Toolkit::Ruler.distance(xy,center)
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] ||= Figures::Quadrilateral.new(dimensions: [@scale, @scale], location: to_pixels(xy)) #[xy.x+1,xy.y+1])) #to_pixels(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| yield cell_at(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 = *xy
44
- _x < 0 || _y < 0 || x >= _x || y >= _y
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(dimensions)
49
- dimensions.x.times do |x|
50
- dimensions.y.times do |y|
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
@@ -0,0 +1,8 @@
1
+ #module Straightedge
2
+ # module Figures
3
+ # class GridCell < Figure
4
+ # include Colorable
5
+ # attr_accessor :visible, :color
6
+ # end
7
+ # end
8
+ #end
@@ -13,7 +13,6 @@ module Straightedge
13
13
 
14
14
  def corners(w=width, h=height)
15
15
  @corners ||= [[x,y],[x,y+h],[x+w,y+h],[x+w,y]]
16
- #Rose.simple.project(origin).map { |xy| [xy.x*w, xy.y*h] }
17
16
  end
18
17
  end
19
18
  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
@@ -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,figure|
13
- figure = Figures::Label.new.says(figure) if figure.is_a?(String)
14
- figure.location = location
15
- presenter = adapter.presenter_for(figure)
16
- presenter.display(figure)
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
@@ -3,7 +3,7 @@ module Straightedge
3
3
  class Compass
4
4
  extend Forwardable
5
5
  attr_accessor :rose
6
- def_delegator :rose, :project
6
+ def_delegator :rose, :orbit
7
7
 
8
8
  def initialize(rose=Rose.extended)
9
9
  @rose = rose
@@ -7,12 +7,18 @@ module Straightedge
7
7
  @directions = directions
8
8
  end
9
9
 
10
- def project(point)
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: {
@@ -1,4 +1,4 @@
1
1
  module Straightedge
2
2
  # straightedge version
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
@@ -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.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: 2014-12-30 00:00:00.000000000 Z
11
+ date: 2015-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini-config