-
Notifications
You must be signed in to change notification settings - Fork 2
/
cubic02.rb.html
118 lines (106 loc) · 4.95 KB
/
cubic02.rb.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE public PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta name="generator" content="ex2html.rb" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/popup.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>
hljs.configure({ cssSelector: "pre" });
hljs.highlightAll();
</script>
<title>RMagick example: cubic02.rb</title>
</head>
<body>
<h1>cubic02.rb</h1>
<div class="bodybox">
<div class="bodyfloat">
<pre class="language-ruby">
# frozen_string_literal: true
require 'rvg/rvg'
Magick::RVG.dpi = 90
BORDER = { fill: 'none', stroke: 'blue', stroke_width: 1 }
CONNECT = { fill: 'none', stroke: '#888888', stroke_width: 2 }
SAMPLE_PATH = { fill: 'none', stroke: 'red', stroke_width: 5 }
END_POINT = { fill: 'none', stroke: '#888888', stroke_width: 2 }
CTL_POINT = { fill: '#888888', stroke: 'none' }
AUTO_CTL_POINT = { fill: 'none', stroke: 'blue', stroke_width: 4 }
LABEL = { text_anchor: 'middle', font_size: 22, font_family: 'Verdana', font_weight: 'normal', font_style: 'normal' }
rvg = Magick::RVG.new(10.cm, 10.cm).viewbox(0, 0, 1000, 1000) do |canvas|
canvas.title = 'Example cubic02 - cubic Bezier commands in path data'
canvas.desc = <<-END_DESC
Picture showing examples of "C" and "S" commands,
along with annotations showing the control points
and end points
END_DESC
canvas.background_fill = 'white'
canvas.rect(996, 996, 1, 1).styles(BORDER)
# Path 1
canvas.polyline(100, 200, 100, 100).styles(CONNECT)
canvas.polyline(400, 100, 400, 200).styles(CONNECT)
canvas.path('M100,200 C100,100 400,100 400,200').styles(SAMPLE_PATH)
canvas.circle(10, 100, 200).styles(END_POINT)
canvas.circle(10, 400, 200).styles(END_POINT)
canvas.circle(10, 100, 100).styles(CTL_POINT)
canvas.circle(10, 400, 100).styles(CTL_POINT)
canvas.text(250, 275, 'M100,200 C100,100 400,100 400,200').styles(LABEL)
# Path 2
canvas.polyline(100, 500, 25, 400).styles(CONNECT)
canvas.polyline(475, 400, 400, 500).styles(CONNECT)
canvas.path('M100,500 C25,400 475,400 400,500').styles(SAMPLE_PATH)
canvas.circle(10, 100, 500).styles(END_POINT)
canvas.circle(10, 400, 500).styles(END_POINT)
canvas.circle(10, 25, 400).styles(CTL_POINT)
canvas.circle(10, 475, 400).styles(CTL_POINT)
canvas.text(250, 575, 'M100,500 C25,400 475,400 400,500').styles(LABEL)
# Path 3
canvas.polyline(100, 800, 175, 700).styles(CONNECT)
canvas.polyline(325, 700, 400, 800).styles(CONNECT)
canvas.path('M100,800 C175,700 325,700 400,800').styles(SAMPLE_PATH)
canvas.circle(10, 100, 800).styles(END_POINT)
canvas.circle(10, 400, 800).styles(END_POINT)
canvas.circle(10, 175, 700).styles(CTL_POINT)
canvas.circle(10, 325, 700).styles(CTL_POINT)
canvas.text(250, 875, 'M100,800 C175,700 325,700 400,800').styles(LABEL)
# Path 4
canvas.polyline(600, 200, 675, 100).styles(CONNECT)
canvas.polyline(975, 100, 900, 200).styles(CONNECT)
canvas.path('M600,200 C675,100 975,100 900,200').styles(SAMPLE_PATH)
canvas.circle(10, 600, 200).styles(END_POINT)
canvas.circle(10, 900, 200).styles(END_POINT)
canvas.circle(10, 675, 100).styles(CTL_POINT)
canvas.circle(10, 975, 100).styles(CTL_POINT)
canvas.text(750, 275, 'M600,200 C675,100 975,100 900,200').styles(LABEL)
# Path 5
canvas.polyline(600, 500, 600, 350).styles(CONNECT)
canvas.polyline(900, 650, 900, 500).styles(CONNECT)
canvas.path('M600,500 C600,350 900,650 900,500').styles(SAMPLE_PATH)
canvas.circle(10, 600, 500).styles(END_POINT)
canvas.circle(10, 900, 500).styles(END_POINT)
canvas.circle(10, 600, 350).styles(CTL_POINT)
canvas.circle(10, 900, 650).styles(CTL_POINT)
canvas.text(750, 575, 'M600,500 C600,350 900,650 900,500').styles(LABEL)
# Path 6 (C and S command)
canvas.polyline(600, 800, 625, 700).styles(CONNECT)
canvas.polyline(725, 700, 750, 800).styles(CONNECT)
canvas.polyline(750, 800, 775, 900).styles(CONNECT)
canvas.polyline(875, 900, 900, 800).styles(CONNECT)
canvas.path('M600,800 C625,700 725,700 750,800 S875,900 900,800').styles(SAMPLE_PATH)
canvas.circle(10, 600, 800).styles(END_POINT)
canvas.circle(10, 750, 800).styles(END_POINT)
canvas.circle(10, 900, 800).styles(END_POINT)
canvas.circle(10, 625, 700).styles(CTL_POINT)
canvas.circle(10, 725, 700).styles(CTL_POINT)
canvas.circle(10, 875, 900).styles(CTL_POINT)
canvas.circle(10, 775, 900).styles(AUTO_CTL_POINT)
canvas.text(750, 945, 'M600,800 C625,700 725,700 750,800').styles(LABEL)
canvas.text(750, 975, 'S875,900 900,800').styles(LABEL)
end
rvg.draw.write('cubic02.gif')
</pre>
</div>
</div>
<div id="close"><a href="javascript:window.close();">Close window</a></div>
</body>
</html>