dyi 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +11 -0
- data/README +2 -3
- data/examples/animation.rb +104 -28
- data/examples/clock.rb +152 -0
- data/examples/data/money.csv +13 -12
- data/examples/external_files/asian_map.png +0 -0
- data/examples/external_files/xslt.xsl +71 -0
- data/examples/letter.rb +125 -0
- data/examples/line_and_bar.rb +32 -19
- data/examples/logo.rb +1 -62
- data/examples/map.rb +30705 -0
- data/examples/panther.rb +1602 -0
- data/examples/pie_chart.rb +27 -20
- data/examples/rainbow.rb +31 -0
- data/examples/simple_animation.rb +28 -0
- data/examples/thumbnail.rb +73 -0
- data/examples/xslt.rb +9 -0
- data/lib/dyi.rb +71 -2
- data/lib/dyi/animation.rb +270 -79
- data/lib/dyi/canvas.rb +10 -1
- data/lib/dyi/chart/line_chart.rb +75 -27
- data/lib/dyi/drawing/color_effect.rb +117 -0
- data/lib/dyi/drawing/pen.rb +6 -2
- data/lib/dyi/element.rb +11 -10
- data/lib/dyi/event.rb +3 -3
- data/lib/dyi/formatter/svg_formatter.rb +113 -25
- data/lib/dyi/shape.rb +2 -0
- data/lib/dyi/shape/base.rb +42 -3
- data/lib/dyi/shape/graphical_template.rb +106 -0
- data/lib/dyi/shape/reused_shape.rb +99 -0
- metadata +14 -3
- data/examples/class_diagram.rb +0 -154
data/CHANGES
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
= DYI Changelog
|
2
2
|
|
3
|
+
== Version 1.3.0 / 2012-06-01
|
4
|
+
* Major Enhancement
|
5
|
+
* Can draw a predefined shape.
|
6
|
+
* Radial gradient support.
|
7
|
+
* Minor Enhancement
|
8
|
+
* Adds options to LineChart.
|
9
|
+
* Changes project URL.
|
10
|
+
* Adds method that draws logomark of DYI.
|
11
|
+
* Bug Fixes
|
12
|
+
* Revises spell-miss in DYI::Element#add_css_class.
|
13
|
+
|
3
14
|
== Version 1.2.1 / 2012-05-01
|
4
15
|
* Bug Fixes
|
5
16
|
* A name of marker-option of LineChart is wrong.
|
data/README
CHANGED
@@ -6,7 +6,7 @@ to output other format; for example, EPS.
|
|
6
6
|
|
7
7
|
== License
|
8
8
|
|
9
|
-
Copyright (c) 2009-
|
9
|
+
Copyright (c) 2009-2012 Sound-F Co., Ltd. All rights reserved.
|
10
10
|
|
11
11
|
DYI is free software: you can redistribute it and/or modify it
|
12
12
|
under the terms of the GNU General Public License as published by
|
@@ -29,5 +29,4 @@ and forums.
|
|
29
29
|
|
30
30
|
We are also preparing the Japanese mailing list. More infomation
|
31
31
|
about the mailing list is indicated to
|
32
|
-
<http://open-dyi.org/
|
33
|
-
including how to join it.
|
32
|
+
<http://open-dyi.org/community.html>, including how to join it.
|
data/examples/animation.rb
CHANGED
@@ -1,28 +1,104 @@
|
|
1
|
-
# -*- encoding: UTF-8 -*-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'dyi'
|
5
|
-
|
6
|
-
canvas = DYI::Canvas.new(
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
:
|
26
|
-
:
|
27
|
-
|
28
|
-
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'dyi'
|
5
|
+
|
6
|
+
canvas = DYI::Canvas.new(250, 140)
|
7
|
+
canvas.title = 'Animation Icons without Script'
|
8
|
+
canvas.description = 'This image is a sample of DYI which uses SVG animation.'
|
9
|
+
|
10
|
+
# Left-Hand Icon
|
11
|
+
icon1 = DYI::Shape::ShapeGroup.draw_on(canvas)
|
12
|
+
pen = DYI::Drawing::Pen.new(:stroke_width => 6, :stroke_linecap => 'round')
|
13
|
+
pen.color = '#DDD'
|
14
|
+
line = pen.draw_line(icon1, [10,0], [18,0])
|
15
|
+
line.add_painting_animation(:from => {:stroke => '#DDD'},
|
16
|
+
:relays => [{:stroke => '#DDD'}, {:stroke => '#333'}, {:stroke => '#DDD'}],
|
17
|
+
:to => {:stroke => '#DDD'},
|
18
|
+
:relay_times => [0.125, 0.125, 0.75],
|
19
|
+
:duration => 1,
|
20
|
+
:repeat_count => 0)
|
21
|
+
line = pen.draw_line(icon1, [10,0], [18,0])
|
22
|
+
line.rotate(45)
|
23
|
+
line.add_painting_animation(:from => {:stroke => '#DDD'},
|
24
|
+
:relays => [{:stroke => '#DDD'}, {:stroke => '#333'}, {:stroke => '#DDD'}],
|
25
|
+
:to => {:stroke => '#DDD'},
|
26
|
+
:relay_times => [0.25, 0.25, 0.825],
|
27
|
+
:duration => 1,
|
28
|
+
:repeat_count => 0)
|
29
|
+
line = pen.draw_line(icon1, [10,0], [18,0])
|
30
|
+
line.rotate(90)
|
31
|
+
line.add_painting_animation(:from => {:stroke => '#DDD'},
|
32
|
+
:relays => [{:stroke => '#DDD'}, {:stroke => '#333'}],
|
33
|
+
:to => {:stroke => '#DDD'},
|
34
|
+
:relay_times => [0.375, 0.375, 1],
|
35
|
+
:duration => 1,
|
36
|
+
:repeat_count => 0)
|
37
|
+
line = pen.draw_line(icon1, [10,0], [18,0])
|
38
|
+
line.rotate(135)
|
39
|
+
line.add_painting_animation(:from => {:stroke => '#BBB'},
|
40
|
+
:relays => [{:stroke => '#DDD'}, {:stroke => '#DDD'}, {:stroke => '#333'}],
|
41
|
+
:to => {:stroke => '#BBB'},
|
42
|
+
:relay_times => [0.125, 0.5, 0.5],
|
43
|
+
:duration => 1,
|
44
|
+
:repeat_count => 0)
|
45
|
+
pen.color = '#999'
|
46
|
+
line = pen.draw_line(icon1, [10,0], [18,0])
|
47
|
+
line.rotate(180)
|
48
|
+
line.add_painting_animation(:from => {:stroke => '#999'},
|
49
|
+
:relays => [{:stroke => '#DDD'}, {:stroke => '#DDD'}, {:stroke => '#333'}],
|
50
|
+
:to => {:stroke => '#999'},
|
51
|
+
:relay_times => [0.25, 0.625, 0.625],
|
52
|
+
:duration => 1,
|
53
|
+
:repeat_count => 0)
|
54
|
+
pen.color = '#777'
|
55
|
+
line = pen.draw_line(icon1, [10,0], [18,0])
|
56
|
+
line.rotate(225)
|
57
|
+
line.add_painting_animation(:from => {:stroke => '#777'},
|
58
|
+
:relays => [{:stroke => '#DDD'}, {:stroke => '#DDD'}, {:stroke => '#333'}],
|
59
|
+
:to => {:stroke => '#777'},
|
60
|
+
:relay_times => [0.375, 0.75, 0.75],
|
61
|
+
:duration => 1,
|
62
|
+
:repeat_count => 0)
|
63
|
+
pen.color = '#555'
|
64
|
+
line = pen.draw_line(icon1, [10,0], [18,0])
|
65
|
+
line.rotate(270)
|
66
|
+
line.add_painting_animation(:from => {:stroke => '#555'},
|
67
|
+
:relays => [{:stroke => '#DDD'}, {:stroke => '#DDD'}, {:stroke => '#333'}],
|
68
|
+
:to => {:stroke => '#555'},
|
69
|
+
:relay_times => [0.5, 0.875, 0.875],
|
70
|
+
:duration => 1,
|
71
|
+
:repeat_count => 0)
|
72
|
+
pen.color = '#333'
|
73
|
+
line = pen.draw_line(icon1, [10,0], [18,0])
|
74
|
+
line.rotate(315)
|
75
|
+
line.add_painting_animation(:from => {:stroke => '#333'},
|
76
|
+
:relays => [{:stroke => '#DDD'}, {:stroke => '#DDD'}],
|
77
|
+
:to => {:stroke => '#333'},
|
78
|
+
:relay_times => [0.625, 1],
|
79
|
+
:duration => 1,
|
80
|
+
:repeat_count => 0)
|
81
|
+
icon1.translate(70,70)
|
82
|
+
|
83
|
+
# Right-Hand Icon
|
84
|
+
icon2 = DYI::Shape::ShapeGroup.draw_on(canvas)
|
85
|
+
brush = DYI::Drawing::Brush.new(:color => '#08A')
|
86
|
+
brush.draw_closed_path(icon2, [-14.489, -3.882]){|path|
|
87
|
+
path.arc_to([12.99, -7.5], 15, 15)
|
88
|
+
path.line_to([17.321, -10], [14.5, 0], [4.33, -2.5], [8.66, -5])
|
89
|
+
path.arc_to([-9.397, -3.42], 10, 10, 0, false, false)
|
90
|
+
}
|
91
|
+
brush.draw_closed_path(icon2, [14.489, 3.882]){|path|
|
92
|
+
path.arc_to([-12.99, 7.5], 15, 15)
|
93
|
+
path.line_to([-17.321, 10], [-14.5, 0], [-4.33, 2.5], [-8.66, 5])
|
94
|
+
path.arc_to([9.397, 3.42], 10, 10, 0, false, false)
|
95
|
+
}
|
96
|
+
icon2.add_transform_animation(:rotate,
|
97
|
+
:from => 0,
|
98
|
+
:to => 360,
|
99
|
+
:duration => 1.5,
|
100
|
+
:repeat_count => 0,
|
101
|
+
:additive => 'sum')
|
102
|
+
icon2.translate(180,70)
|
103
|
+
|
104
|
+
canvas.save('output/animation.svg')
|
data/examples/clock.rb
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'dyi'
|
5
|
+
|
6
|
+
include DYI::Script::EcmaScript::DomLevel2
|
7
|
+
|
8
|
+
settings = {
|
9
|
+
:hour => {:center => [250, 60], :rx => 220, :ry => 20},
|
10
|
+
:minute => {:center => [250, 91], :rx => 220, :ry => 32},
|
11
|
+
:second => {:center => [250, 122], :rx => 220, :ry => 44}}
|
12
|
+
settings.each do |key, value|
|
13
|
+
value[:label_position] = DYI::Coordinate.new(value[:center][0],
|
14
|
+
value[:center][1] + value[:ry] + 10)
|
15
|
+
end
|
16
|
+
|
17
|
+
canvas = DYI::Canvas.new(500, 200)
|
18
|
+
canvas.title = 'Circle Clock'
|
19
|
+
canvas.description = 'This image is a sample of DYI which uses a client script.'
|
20
|
+
|
21
|
+
pen = DYI::Drawing::Pen.new
|
22
|
+
|
23
|
+
gradient = DYI::Drawing::ColorEffect::LinearGradient.new([0,0],[0,1])
|
24
|
+
gradient.add_color(0, 'gainsboro')
|
25
|
+
gradient.add_color(1, 'grey')
|
26
|
+
line_pen = DYI::Drawing::Pen.new
|
27
|
+
line_pen.color = gradient
|
28
|
+
|
29
|
+
setting = settings[:second]
|
30
|
+
sec_group = DYI::Shape::ShapeGroup.draw_on(canvas)
|
31
|
+
line_pen.draw_ellipse(sec_group, setting[:center], setting[:rx], setting[:ry])
|
32
|
+
60.times do |i|
|
33
|
+
pen.draw_text(sec_group, [0, 0], i.to_s,
|
34
|
+
:text_anchor => 'middle',
|
35
|
+
:css_class => i % 5 == 0 ? 'large' : 'small')
|
36
|
+
end
|
37
|
+
pen.draw_text(canvas, setting[:label_position], 'seconds',
|
38
|
+
:text_anchor => 'middle',
|
39
|
+
:css_class => 'label')
|
40
|
+
|
41
|
+
setting = settings[:minute]
|
42
|
+
min_group = DYI::Shape::ShapeGroup.draw_on(canvas)
|
43
|
+
line_pen.draw_ellipse(min_group, setting[:center], setting[:rx], setting[:ry])
|
44
|
+
60.times do |i|
|
45
|
+
pen.draw_text(min_group, [0, 0], i.to_s,
|
46
|
+
:text_anchor => 'middle',
|
47
|
+
:css_class => i % 5 == 0 ? 'large' : 'small')
|
48
|
+
end
|
49
|
+
pen.draw_text(canvas, setting[:label_position], 'minutes',
|
50
|
+
:text_anchor => 'middle',
|
51
|
+
:css_class => 'label')
|
52
|
+
|
53
|
+
setting = settings[:hour]
|
54
|
+
hour_group = DYI::Shape::ShapeGroup.draw_on(canvas)
|
55
|
+
line_pen.draw_ellipse(hour_group, setting[:center], setting[:rx], setting[:ry])
|
56
|
+
12.times do |i|
|
57
|
+
pen.draw_text(hour_group, [0, 0], (i + 1).to_s,
|
58
|
+
:text_anchor => 'middle',
|
59
|
+
:css_class => 'large')
|
60
|
+
end
|
61
|
+
pen.draw_text(canvas, setting[:label_position], 'hours',
|
62
|
+
:text_anchor => 'middle',
|
63
|
+
:css_class => 'label')
|
64
|
+
ap_label = pen.draw_text(canvas, setting[:label_position] + [18, -10], 'A.M.',
|
65
|
+
:css_class => 'label')
|
66
|
+
|
67
|
+
canvas.add_initialize_script(<<-SCRIPT)
|
68
|
+
var hourTexts = #{get_element(hour_group)}.getElementsByTagName('text');
|
69
|
+
var minTexts = #{get_element(min_group)}.getElementsByTagName('text');
|
70
|
+
var secTexts = #{get_element(sec_group)}.getElementsByTagName('text');
|
71
|
+
var apLabel = #{get_element(ap_label)};
|
72
|
+
var hour = -1, minute = -1, second = -1;
|
73
|
+
|
74
|
+
function rewrite(){
|
75
|
+
var currentTime = new Date();
|
76
|
+
var text, i, angle, baseSize;
|
77
|
+
|
78
|
+
if(hour != currentTime.getHours()){
|
79
|
+
hour = currentTime.getHours();
|
80
|
+
for(i = 0; i < 12; i++){
|
81
|
+
text = hourTexts.item(i);
|
82
|
+
angle = Math.PI / 6 * (hour % 12 - i - 1);
|
83
|
+
text.setAttribute('x', #{settings[:hour][:rx]} * Math.sin(angle) + #{settings[:hour][:center][0]});
|
84
|
+
text.setAttribute('y', #{settings[:hour][:ry]} * Math.cos(angle) + #{settings[:hour][:center][1]});
|
85
|
+
text.setAttribute('opacity', (Math.cos(angle) + 1) * 0.375 + 0.25);
|
86
|
+
if(hour % 12 == i + 1){
|
87
|
+
text.setAttribute('font-size', '20pt');
|
88
|
+
}
|
89
|
+
else{
|
90
|
+
text.setAttribute('font-size', (16 * 200 / (300 - 100 * Math.cos(angle))).toString() + 'pt');
|
91
|
+
}
|
92
|
+
}
|
93
|
+
apLabel.childNodes.item(0).data = hour < 12 ? 'A.M.' : 'P.M.';
|
94
|
+
}
|
95
|
+
|
96
|
+
if(minute != currentTime.getMinutes()){
|
97
|
+
minute = currentTime.getMinutes();
|
98
|
+
for(i = 0; i < 60; i++){
|
99
|
+
text = minTexts.item(i);
|
100
|
+
angle = Math.PI / 30 * (minute - i);
|
101
|
+
text.setAttribute('x', #{settings[:minute][:rx]} * Math.sin(angle) + #{settings[:minute][:center][0]});
|
102
|
+
text.setAttribute('y', #{settings[:minute][:ry]} * Math.cos(angle) + #{settings[:minute][:center][1]});
|
103
|
+
text.setAttribute('opacity', (Math.cos(angle) + 1) * 0.375 + 0.25);
|
104
|
+
if(minute == i){
|
105
|
+
text.setAttribute('font-size', '20pt');
|
106
|
+
}
|
107
|
+
else{
|
108
|
+
baseSize = text.className.baseVal == 'large' ? 12 : 6;
|
109
|
+
text.setAttribute('font-size', (baseSize * 200 / (300 - 100 * Math.cos(angle))).toString() + 'pt');
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
if(second != currentTime.getSeconds()){
|
115
|
+
second = currentTime.getSeconds();
|
116
|
+
for(i = 0; i < 60; i++){
|
117
|
+
text = secTexts.item(i);
|
118
|
+
angle = Math.PI / 30 * (second - i);
|
119
|
+
text.setAttribute('x', #{settings[:second][:rx]} * Math.sin(angle) + #{settings[:second][:center][0]});
|
120
|
+
text.setAttribute('y', #{settings[:second][:ry]} * Math.cos(angle) + #{settings[:second][:center][1]});
|
121
|
+
text.setAttribute('opacity', (Math.cos(angle) + 1) * 0.375 + 0.25);
|
122
|
+
if(second == i){
|
123
|
+
text.setAttribute('font-size', '20pt');
|
124
|
+
}
|
125
|
+
else{
|
126
|
+
baseSize = text.className.baseVal == 'large' ? 12 : 6;
|
127
|
+
text.setAttribute('font-size', (baseSize * 200 / (300 - 100 * Math.cos(angle))).toString() + 'pt');
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
rewrite();
|
134
|
+
setInterval(rewrite, 250);
|
135
|
+
SCRIPT
|
136
|
+
|
137
|
+
canvas.reference_stylesheet_file('http://fonts.googleapis.com/css?family=Great+Vibes')
|
138
|
+
|
139
|
+
canvas.add_stylesheet(<<-CSS)
|
140
|
+
text {
|
141
|
+
font-family: 'Great Vibes', cursive;
|
142
|
+
}
|
143
|
+
text.large {
|
144
|
+
font-weight: bold;
|
145
|
+
}
|
146
|
+
text.label {
|
147
|
+
font-size: 10pt;
|
148
|
+
text-decoration: underline;
|
149
|
+
}
|
150
|
+
CSS
|
151
|
+
|
152
|
+
canvas.save('output/clock.svg')
|
data/examples/data/money.csv
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
Year,Money Stock,Monetary Base,Color
|
2
|
+
2000,976798,67395,#008000
|
3
|
+
2001,975687,72144,#008000
|
4
|
+
2002,994527,89643,#008000
|
5
|
+
2003,1005732,103726,#008000
|
6
|
+
2004,1023448,110030,#ffa500
|
7
|
+
2005,1028507,111765,#ffa500
|
8
|
+
2006,1025202,96727,#ffa500
|
9
|
+
2007,1026995,90034,#ffa500
|
10
|
+
2008,1034705,91336,#ffa500
|
11
|
+
2009,1053287,96311,#ffa500
|
12
|
+
2010,1075186,100946,#ffa500
|
13
|
+
2011,1098966,114671,#ffa500
|
Binary file
|
@@ -0,0 +1,71 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
3
|
+
xmlns:svg="http://www.w3.org/2000/svg">
|
4
|
+
<xsl:template match="/svg:svg">
|
5
|
+
<xsl:copy>
|
6
|
+
<xsl:copy-of select="@version"/>
|
7
|
+
<xsl:copy-of select="@viewBox"/>
|
8
|
+
<xsl:copy-of select="@preserveAspectRatio"/>
|
9
|
+
<xsl:attribute name="viewBox">0 0 861 488</xsl:attribute>
|
10
|
+
<xsl:attribute name="width">861</xsl:attribute>
|
11
|
+
<xsl:attribute name="height">488</xsl:attribute>
|
12
|
+
<svg:defs>
|
13
|
+
<svg:filter id="effect1" filterUnits="userSpaceOnUse" x="-5" y="-5"
|
14
|
+
width="305" height="185">
|
15
|
+
<svg:feGaussianBlur in="SourceAlpha" stdDeviation="4" result="blur"/>
|
16
|
+
<svg:feOffset in="blur" dx="8" dy="12" result="offsetBlur"/>
|
17
|
+
<svg:feMerge>
|
18
|
+
<svg:feMergeNode in="offsetBlur"/>
|
19
|
+
<svg:feMergeNode in="SourceGraphic"/>
|
20
|
+
</svg:feMerge>
|
21
|
+
</svg:filter>
|
22
|
+
<svg:filter id="effect2" filterUnits="userSpaceOnUse" x="-5" y="-5"
|
23
|
+
width="305" height="185">
|
24
|
+
<svg:feGaussianBlur in="SourceAlpha" stdDeviation="4" result="blur"/>
|
25
|
+
<svg:feOffset in="blur" dx="8" dy="12" result="offsetBlur"/>
|
26
|
+
<svg:feSpecularLighting in="blur" surfaceScale="5" specularConstant=".75"
|
27
|
+
specularExponent="20" lighting-color="#bbbbbb" result="specOut">
|
28
|
+
<svg:fePointLight x="-5000" y="-10000" z="20000"/>
|
29
|
+
</svg:feSpecularLighting>
|
30
|
+
<svg:feComposite in="specOut" in2="SourceAlpha" operator="in" result="specOut"/>
|
31
|
+
<svg:feComposite in="SourceGraphic" in2="specOut" operator="arithmetic"
|
32
|
+
k1="0" k2="1" k3="1" k4="0" result="litPaint"/>
|
33
|
+
</svg:filter>
|
34
|
+
</svg:defs>
|
35
|
+
<svg:g transform="translate(143.5,81.32) scale(2)">
|
36
|
+
<xsl:apply-templates mode="normal"/>
|
37
|
+
</svg:g>
|
38
|
+
<svg:g transform="translate(95.67,162.64)">
|
39
|
+
<xsl:apply-templates mode="line"/>
|
40
|
+
</svg:g>
|
41
|
+
<svg:g transform="translate(478.35,162.64)" filter="url(#effect1)">
|
42
|
+
<xsl:apply-templates mode="effect"/>
|
43
|
+
</svg:g>
|
44
|
+
</xsl:copy>
|
45
|
+
</xsl:template>
|
46
|
+
|
47
|
+
<xsl:template match="svg:path" mode="normal">
|
48
|
+
<xsl:copy>
|
49
|
+
<xsl:copy-of select="@*"/>
|
50
|
+
</xsl:copy>
|
51
|
+
</xsl:template>
|
52
|
+
|
53
|
+
<xsl:template match="svg:path" mode="line">
|
54
|
+
<xsl:copy>
|
55
|
+
<xsl:copy-of select="@d"/>
|
56
|
+
<xsl:attribute name="fill">#fff</xsl:attribute>
|
57
|
+
<xsl:attribute name="fill-opacity">0.9</xsl:attribute>
|
58
|
+
<xsl:attribute name="stroke">
|
59
|
+
<xsl:value-of select="@fill"/>
|
60
|
+
</xsl:attribute>
|
61
|
+
<xsl:attribute name="stroke-width">2</xsl:attribute>
|
62
|
+
</xsl:copy>
|
63
|
+
</xsl:template>
|
64
|
+
|
65
|
+
<xsl:template match="svg:path" mode="effect">
|
66
|
+
<xsl:copy>
|
67
|
+
<xsl:copy-of select="@*"/>
|
68
|
+
<xsl:attribute name="filter">url(#effect2)</xsl:attribute>
|
69
|
+
</xsl:copy>
|
70
|
+
</xsl:template>
|
71
|
+
</xsl:stylesheet>
|
data/examples/letter.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'dyi'
|
5
|
+
|
6
|
+
include DYI::Script::EcmaScript::DomLevel2
|
7
|
+
|
8
|
+
path_points = [
|
9
|
+
[197, 42.141], [419.42, 172.747], [197, 306.472],
|
10
|
+
[241.055, 264.061], [374, 172.748], [241.055, 84.553]
|
11
|
+
]
|
12
|
+
ctrl_points = [
|
13
|
+
[262.211, 42.141], [419.42, 27.495], [419.42, 323.496], [260.69, 306.472],
|
14
|
+
[270.044, 264.061], [374, 272.829], [374, 75.829], [269.211, 84.553]
|
15
|
+
]
|
16
|
+
|
17
|
+
canvas = DYI::Canvas.new(625, 350)
|
18
|
+
canvas.title = 'Letter D'
|
19
|
+
canvas.description = 'This image is a sample of DYI which is drawn Bezier curves.'
|
20
|
+
|
21
|
+
pen = DYI::Drawing::Pen.new(:width => 0, :color => nil)
|
22
|
+
rect = pen.draw_rectangle(canvas, [1,1], canvas.width - 2, canvas.height - 2)
|
23
|
+
|
24
|
+
letter = pen.draw_path(canvas, path_points[0]){|path|
|
25
|
+
path.curve_to(ctrl_points[0], ctrl_points[1], path_points[1])
|
26
|
+
path.curve_to(ctrl_points[2], ctrl_points[3], path_points[2])
|
27
|
+
path.close_path
|
28
|
+
path.move_to(path_points[3])
|
29
|
+
path.curve_to(ctrl_points[4], ctrl_points[5], path_points[4])
|
30
|
+
path.curve_to(ctrl_points[6], ctrl_points[7], path_points[5])
|
31
|
+
path.close_path
|
32
|
+
path.set_marker(:all, :circle, :size => 5)
|
33
|
+
}
|
34
|
+
|
35
|
+
lines = []
|
36
|
+
lines << pen.draw_line(canvas, path_points[0], ctrl_points[0])
|
37
|
+
lines << pen.draw_line(canvas, path_points[1], ctrl_points[1])
|
38
|
+
lines << pen.draw_line(canvas, path_points[1], ctrl_points[2])
|
39
|
+
lines << pen.draw_line(canvas, path_points[2], ctrl_points[3])
|
40
|
+
lines << pen.draw_line(canvas, path_points[3], ctrl_points[4])
|
41
|
+
lines << pen.draw_line(canvas, path_points[4], ctrl_points[5])
|
42
|
+
lines << pen.draw_line(canvas, path_points[4], ctrl_points[6])
|
43
|
+
lines << pen.draw_line(canvas, path_points[5], ctrl_points[7])
|
44
|
+
|
45
|
+
circles = ctrl_points.map do |ctrl_pt|
|
46
|
+
circle = pen.draw_circle(canvas, ctrl_pt, 7.5)
|
47
|
+
circle.set_event(nil)
|
48
|
+
circle
|
49
|
+
end
|
50
|
+
|
51
|
+
dragging = DYI::Script::EcmaScript::EventListener.new(<<SCRIPT)
|
52
|
+
if(target_id == null) return;
|
53
|
+
var x = evt.pageX;
|
54
|
+
var y = evt.pageY;
|
55
|
+
circles[target_id].cx.baseVal.value = x;
|
56
|
+
circles[target_id].cy.baseVal.value = y;
|
57
|
+
lines[target_id].x2.baseVal.value = x;
|
58
|
+
lines[target_id].y2.baseVal.value = y;
|
59
|
+
letter.pathSegList.getItem(command_ids[target_id])['x' + (target_id % 2 == 0 ? '1' : '2')] = x;
|
60
|
+
letter.pathSegList.getItem(command_ids[target_id])['y' + (target_id % 2 == 0 ? '1' : '2')] = y;
|
61
|
+
SCRIPT
|
62
|
+
|
63
|
+
end_drag = DYI::Script::EcmaScript::EventListener.new(<<SCRIPT)
|
64
|
+
if(target_id == null) return;
|
65
|
+
circles[target_id].className.baseVal = '';
|
66
|
+
lines[target_id].className.baseVal = '';
|
67
|
+
target_id = null;
|
68
|
+
SCRIPT
|
69
|
+
|
70
|
+
canvas.add_script(<<SCRIPT)
|
71
|
+
var target_id = null;
|
72
|
+
var command_ids = [1, 1, 2, 2, 5, 5, 6, 6];
|
73
|
+
var letter, lines, circles
|
74
|
+
SCRIPT
|
75
|
+
|
76
|
+
canvas.add_initialize_script(<<SCRIPT)
|
77
|
+
letter = #{get_element(letter)};
|
78
|
+
lines = [#{lines.map{|l| get_element(l)}.join(',')}];
|
79
|
+
circles = [#{circles.map{|c| get_element(c)}.join(',')}];
|
80
|
+
SCRIPT
|
81
|
+
|
82
|
+
circles.each_with_index do |circle, i|
|
83
|
+
start_drag = DYI::Script::EcmaScript::EventListener.new(<<-SCRIPT)
|
84
|
+
if(target_id != null) return;
|
85
|
+
target_id = #{i};
|
86
|
+
circles[target_id].className.baseVal = 'target';
|
87
|
+
lines[target_id].className.baseVal = 'target';
|
88
|
+
SCRIPT
|
89
|
+
|
90
|
+
circle.add_event_listener(:mousedown, start_drag)
|
91
|
+
circle.add_event_listener(:mousemove, dragging)
|
92
|
+
circle.add_event_listener(:mouseup, end_drag)
|
93
|
+
end
|
94
|
+
rect.add_event_listener(:mousemove, dragging)
|
95
|
+
rect.add_event_listener(:mouseup, end_drag)
|
96
|
+
|
97
|
+
canvas.add_stylesheet(<<CSS)
|
98
|
+
path {
|
99
|
+
fill: #C3DAFF;
|
100
|
+
stroke: #666666;
|
101
|
+
stroke-width: 3;
|
102
|
+
}
|
103
|
+
svg > circle {
|
104
|
+
fill: white;
|
105
|
+
stroke: #336699;
|
106
|
+
stroke-width: 1;
|
107
|
+
cursor: move;
|
108
|
+
}
|
109
|
+
marker circle{
|
110
|
+
fill: #666666
|
111
|
+
}
|
112
|
+
line {
|
113
|
+
stroke: #003DA2;
|
114
|
+
stroke-width: 2;
|
115
|
+
stroke-dasharray: 6,4;
|
116
|
+
}
|
117
|
+
circle.target{
|
118
|
+
fill: #33CCFF;
|
119
|
+
}
|
120
|
+
line.target{
|
121
|
+
stroke: #33CCFF;
|
122
|
+
}
|
123
|
+
CSS
|
124
|
+
|
125
|
+
canvas.save('output/letter.svg')
|