-
Notifications
You must be signed in to change notification settings - Fork 2
/
axes.rb.html
91 lines (83 loc) · 2.85 KB
/
axes.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
<!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: axes.rb</title>
</head>
<body>
<h1>axes.rb</h1>
<div class="bodybox">
<div class="bodyfloat">
<pre class="language-ruby">
# frozen_string_literal: true
require 'rmagick'
# Demonstrate the use of RMagick's Draw class
# and show the default coordinate system.
# Create a canvas to draw on. Use the HatchFill class to
# cross-hatch the background with light gray lines every 10 pixels.
canvas = Magick::ImageList.new
canvas.new_image(250, 250, Magick::HatchFill.new('white', 'gray90'))
# Draw a border around the edges of the canvas.
border = Magick::Draw.new
border.stroke('thistle')
border.fill_opacity(0)
border.rectangle(0, 0, canvas.columns - 1, canvas.rows - 1)
border.draw(canvas)
# Draw gold axes with arrow-heads.
axes = Magick::Draw.new
axes.fill_opacity(0)
axes.stroke('gold3')
axes.stroke_width(4)
axes.stroke_linecap('round')
axes.stroke_linejoin('round')
axes.polyline(
18, canvas.rows - 10, 10, canvas.rows - 3, 3, canvas.rows - 10,
10, canvas.rows - 10, 10, 10, canvas.columns - 10, 10,
canvas.columns - 10, 3, canvas.columns - 3, 10, canvas.columns - 10, 18
)
axes.draw(canvas)
# Draw a red circle to show the direction of rotation.
# Make it slightly transparent so the hatching will show through.
circle = Magick::Draw.new
circle.stroke('tomato')
circle.fill_opacity(0)
circle.stroke_opacity(0.75)
circle.stroke_width(6)
circle.stroke_linecap('round')
circle.stroke_linejoin('round')
circle.ellipse(canvas.rows / 2, canvas.columns / 2, 80, 80, 0, 315)
circle.polyline(180, 70, 173, 78, 190, 78, 191, 62)
circle.draw(canvas)
# Label the axes and the circle.
labels = Magick::Draw.new
labels.font_weight(Magick::NormalWeight)
labels.fill('black')
labels.stroke('transparent')
labels.font_style(Magick::ItalicStyle)
labels.pointsize(14)
labels.gravity(Magick::NorthWestGravity)
labels.text(20, 30, "'0,0'")
labels.gravity(Magick::NorthEastGravity)
labels.text(20, 30, "'+x'")
labels.gravity(Magick::SouthWestGravity)
labels.text(20, 20, "'+y'")
labels.gravity(Magick::CenterGravity)
labels.text(0, 0, 'Rotation')
labels.draw(canvas)
# canvas.display
canvas.write('axes.gif')
exit
</pre>
</div>
</div>
<div id="close"><a href="javascript:window.close();">Close window</a></div>
</body>
</html>