sketch 0.0.2 → 0.0.3
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/Gemfile +2 -0
- data/examples/star.rb +7 -0
- data/lib/sketch.rb +1 -0
- data/lib/sketch/line.rb +13 -0
- data/lib/sketch/path.rb +7 -10
- data/lib/sketch/star.rb +42 -9
- data/lib/sketch/triangle.rb +27 -0
- data/sketch.version +1 -1
- data/test/star_test.rb +12 -0
- metadata +14 -10
data/Gemfile
CHANGED
data/examples/star.rb
ADDED
data/lib/sketch.rb
CHANGED
data/lib/sketch/line.rb
ADDED
data/lib/sketch/path.rb
CHANGED
@@ -1,17 +1,14 @@
|
|
1
1
|
class Sketch::Path < Sketch::Element
|
2
|
-
|
3
|
-
has_value :fill
|
4
|
-
has_value :stroke
|
5
|
-
has_value :stroke_width
|
2
|
+
|
3
|
+
has_value :fill, :default => 'none'
|
4
|
+
has_value :stroke, :default => 'black'
|
5
|
+
has_value :stroke_width, :default => 1
|
6
6
|
has_value :stroke_linecap
|
7
|
-
has_value :d, :alias => 'commands', :default => []
|
8
|
-
|
9
|
-
def draw(canvas)
|
10
|
-
canvas.path(svg_attributes)
|
11
|
-
end
|
7
|
+
has_value :d, :alias => 'commands', :default => []
|
12
8
|
|
13
9
|
def svg_attributes
|
14
|
-
|
10
|
+
out = super
|
11
|
+
out['d'] = out['d'].join(' ') if out.has_key('d')
|
15
12
|
end
|
16
13
|
end
|
17
14
|
|
data/lib/sketch/star.rb
CHANGED
@@ -5,17 +5,50 @@ class Sketch::Star < Sketch::Element
|
|
5
5
|
has_value :radius
|
6
6
|
has_value :orientation, :default => 0
|
7
7
|
|
8
|
+
has_value :number_of_points, :default => 5
|
9
|
+
|
10
|
+
has_value :fill
|
11
|
+
has_value :stroke
|
12
|
+
has_value :stroke_width
|
13
|
+
|
8
14
|
central_point :x, :y
|
9
15
|
|
16
|
+
def degrees_to_radians( degrees )
|
17
|
+
degrees * Math::PI / 180
|
18
|
+
end
|
19
|
+
|
20
|
+
def angle_between_points
|
21
|
+
360 / number_of_points
|
22
|
+
end
|
23
|
+
|
24
|
+
def drawing_order_indexes
|
25
|
+
self.number_of_points.times.map do |n|
|
26
|
+
(n*2) % self.number_of_points
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def points_in_drawing_order
|
31
|
+
drawing_order_indexes.map do |index|
|
32
|
+
points[index]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def points
|
37
|
+
@points ||= list = number_of_points.times.map do |point_number|
|
38
|
+
current_angle = orientation + ( angle_between_points * point_number )
|
39
|
+
[ x + (radius * Math.sin( degrees_to_radians( current_angle ))), y - (radius * Math.cos( degrees_to_radians( current_angle ))) ]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
10
43
|
def draw(canvas)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
44
|
+
if x && y && radius
|
45
|
+
atts = {}
|
46
|
+
atts['points'] = points_in_drawing_order.each{|point| point.join(',')}.join(' ')
|
47
|
+
atts['fill'] = attributes[:fill] if attributes.has_key?(:fill)
|
48
|
+
atts['stroke'] = attributes[:stroke] if attributes.has_key?(:stroke)
|
49
|
+
atts['stroke-width'] = attributes[:stroke_width] if attributes.has_key?(:stroke_width)
|
50
|
+
|
51
|
+
canvas.polygon( atts )
|
52
|
+
end
|
20
53
|
end
|
21
54
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Sketch::Triangle < Sketch::Element
|
2
|
+
|
3
|
+
has_value :point
|
4
|
+
has_value :height
|
5
|
+
has_value :direction
|
6
|
+
has_value :stroke
|
7
|
+
has_value :stroke_width
|
8
|
+
has_value :fill
|
9
|
+
|
10
|
+
def draw(canvas)
|
11
|
+
case direction
|
12
|
+
when :up
|
13
|
+
point1 = "M#{point.join(',')}"
|
14
|
+
point2 = "l-#{0.5*height},#{height*0.5}"
|
15
|
+
point3 = "l#{height},0"
|
16
|
+
point4 = "l-#{height*0.5},-#{height*0.5}"
|
17
|
+
when :down
|
18
|
+
point1 = "M#{point.join(',')}"
|
19
|
+
point2 = "l-#{0.5*height},-#{height*0.5}"
|
20
|
+
point3 = "l#{height},0"
|
21
|
+
point4 = "l-#{height*0.5},#{height*0.5}"
|
22
|
+
end
|
23
|
+
|
24
|
+
Sketch::Path.new(:stroke_width => self.stroke_width, :fill => self.fill, :stroke => self.stroke, :commands => [point1, point2, point3, point4]).draw(canvas)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
data/sketch.version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/test/star_test.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class StarTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_that_star_is_drawn_as_a_polygon
|
6
|
+
canvas = stub
|
7
|
+
canvas.expects(:polygon).with(:points => '100,10 40,180 190,60 10,60 160,180 100,10')
|
8
|
+
art = Sketch::Star.new.draw(canvas)
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sketch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Johnathon Wright
|
@@ -15,12 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-11 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
-
prerelease: false
|
22
|
+
type: :runtime
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
26
25
|
requirements:
|
@@ -31,11 +30,11 @@ dependencies:
|
|
31
30
|
- 0
|
32
31
|
- 8
|
33
32
|
version: "0.8"
|
34
|
-
|
33
|
+
name: valuable
|
35
34
|
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: nokogiri
|
38
35
|
prerelease: false
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
type: :runtime
|
39
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
41
40
|
requirements:
|
@@ -46,8 +45,9 @@ dependencies:
|
|
46
45
|
- 1
|
47
46
|
- 4
|
48
47
|
version: "1.4"
|
49
|
-
|
48
|
+
name: nokogiri
|
50
49
|
version_requirements: *id002
|
50
|
+
prerelease: false
|
51
51
|
description: build SVG images
|
52
52
|
email: jw@mustmodify.com
|
53
53
|
executables: []
|
@@ -63,17 +63,20 @@ files:
|
|
63
63
|
- Rakefile
|
64
64
|
- TODO.txt
|
65
65
|
- examples/smile.rb
|
66
|
+
- examples/star.rb
|
66
67
|
- lib/sketch.rb
|
67
68
|
- lib/sketch/base.rb
|
68
69
|
- lib/sketch/canvas.rb
|
69
70
|
- lib/sketch/circle.rb
|
70
71
|
- lib/sketch/element.rb
|
71
72
|
- lib/sketch/ellipse.rb
|
73
|
+
- lib/sketch/line.rb
|
72
74
|
- lib/sketch/path.rb
|
73
75
|
- lib/sketch/polygon.rb
|
74
76
|
- lib/sketch/rect.rb
|
75
77
|
- lib/sketch/rectangle.rb
|
76
78
|
- lib/sketch/star.rb
|
79
|
+
- lib/sketch/triangle.rb
|
77
80
|
- sketch.gemspec
|
78
81
|
- sketch.version
|
79
82
|
- test/.canvas_test.rb.swp
|
@@ -82,6 +85,7 @@ files:
|
|
82
85
|
- test/doctype_test.rb
|
83
86
|
- test/element_test.rb
|
84
87
|
- test/helper.rb
|
88
|
+
- test/star_test.rb
|
85
89
|
- test/svg_namespace_test.rb
|
86
90
|
has_rdoc: true
|
87
91
|
homepage: http://sketch.mustmodify.com/
|