Class: GD2::Canvas
- Inherits:
-
Object
- Object
- GD2::Canvas
- Defined in:
- lib/gd2/canvas.rb
Defined Under Namespace
Classes: FilledPolygon, FilledRectangle, Line, NoColorSelectedError, NoFontSelectedError, OpenPolygon, Point, Polygon, Rectangle, Text, TextCircle
Constant Summary collapse
- STYLED =
Special colors
-2
- BRUSHED =
-3
- STYLED_BRUSHED =
-4
- TILED =
-5
- TRANSPARENT =
Line styles only; not a color index
-6 # Line styles only; not a color index
- ANTI_ALIASED =
-7
Instance Attribute Summary collapse
-
#anti_aliasing ⇒ Object
(also: #anti_aliasing?)
Returns the value of attribute anti_aliasing.
-
#brush ⇒ Object
Returns the value of attribute brush.
-
#color ⇒ Object
Returns the value of attribute color.
-
#dont_blend ⇒ Object
Returns the value of attribute dont_blend.
-
#font ⇒ Object
Returns the value of attribute font.
-
#style ⇒ Object
Returns the value of attribute style.
-
#thickness ⇒ Object
Returns the value of attribute thickness.
-
#tile ⇒ Object
Returns the value of attribute tile.
Instance Method Summary collapse
-
#initialize(image) ⇒ Canvas
constructor
A new instance of Canvas.
- #line(x1, y1, x2, y2) ⇒ Object
- #line_to(x, y) ⇒ Object
- #location ⇒ Object
- #move(x, y) ⇒ Object
- #move_to(x, y) ⇒ Object
- #point(x, y) ⇒ Object
- #polygon(points, filled = false, open = false) ⇒ Object
- #rectangle(x1, y1, x2, y2, filled = false) ⇒ Object
- #text(string, angle = 0.0) ⇒ Object
- #text_circle(top, bottom, radius, text_radius, fill_portion) ⇒ Object
Constructor Details
#initialize(image) ⇒ Canvas
Returns a new instance of Canvas.
150 151 152 153 154 155 |
# File 'lib/gd2/canvas.rb', line 150 def initialize(image) @image = image self.thickness = 1 self.anti_aliasing = false move_to(0, 0) end |
Instance Attribute Details
#anti_aliasing ⇒ Object Also known as: anti_aliasing?
Returns the value of attribute anti_aliasing.
138 139 140 |
# File 'lib/gd2/canvas.rb', line 138 def anti_aliasing @anti_aliasing end |
#brush ⇒ Object
Returns the value of attribute brush.
137 138 139 |
# File 'lib/gd2/canvas.rb', line 137 def brush @brush end |
#color ⇒ Object
Returns the value of attribute color.
137 138 139 |
# File 'lib/gd2/canvas.rb', line 137 def color @color end |
#dont_blend ⇒ Object
Returns the value of attribute dont_blend.
137 138 139 |
# File 'lib/gd2/canvas.rb', line 137 def dont_blend @dont_blend end |
#font ⇒ Object
Returns the value of attribute font.
138 139 140 |
# File 'lib/gd2/canvas.rb', line 138 def font @font end |
#style ⇒ Object
Returns the value of attribute style.
137 138 139 |
# File 'lib/gd2/canvas.rb', line 137 def style @style end |
#thickness ⇒ Object
Returns the value of attribute thickness.
137 138 139 |
# File 'lib/gd2/canvas.rb', line 137 def thickness @thickness end |
#tile ⇒ Object
Returns the value of attribute tile.
137 138 139 |
# File 'lib/gd2/canvas.rb', line 137 def tile @tile end |
Instance Method Details
#line(x1, y1, x2, y2) ⇒ Object
211 212 213 |
# File 'lib/gd2/canvas.rb', line 211 def line(x1, y1, x2, y2) Line.new(point(x1, y1), point(x2, y2)).draw(@image, line_pixel) end |
#line_to(x, y) ⇒ Object
215 216 217 218 219 220 |
# File 'lib/gd2/canvas.rb', line 215 def line_to(x, y) point2 = point(x, y) line(@point.x, @point.y, point2.x, point2.y) @point = point2 self end |
#location ⇒ Object
207 208 209 |
# File 'lib/gd2/canvas.rb', line 207 def location @point.coordinates end |
#move(x, y) ⇒ Object
202 203 204 205 |
# File 'lib/gd2/canvas.rb', line 202 def move(x, y) @point = point(@point.x + x, @point.y + y) self end |
#move_to(x, y) ⇒ Object
197 198 199 200 |
# File 'lib/gd2/canvas.rb', line 197 def move_to(x, y) @point = point(x, y) self end |
#point(x, y) ⇒ Object
193 194 195 |
# File 'lib/gd2/canvas.rb', line 193 def point(x, y) Point.new(x, y) end |
#polygon(points, filled = false, open = false) ⇒ Object
227 228 229 230 231 232 233 234 |
# File 'lib/gd2/canvas.rb', line 227 def polygon(points, filled = false, open = false) points = points.map { |(x, y)| point(x, y) } if filled FilledPolygon.new(points).draw(@image, fill_pixel) else (open ? OpenPolygon : Polygon).new(points).draw(@image, line_pixel) end end |
#rectangle(x1, y1, x2, y2, filled = false) ⇒ Object
222 223 224 225 |
# File 'lib/gd2/canvas.rb', line 222 def rectangle(x1, y1, x2, y2, filled = false) (filled ? FilledRectangle : Rectangle).new(point(x1, y1), point(x2, y2)).draw(@image, filled ? fill_pixel : line_pixel) end |
#text(string, angle = 0.0) ⇒ Object
236 237 238 |
# File 'lib/gd2/canvas.rb', line 236 def text(string, angle = 0.0) Text.new(get_font, @point, angle, string).draw(@image, pixel) end |
#text_circle(top, bottom, radius, text_radius, fill_portion) ⇒ Object
240 241 242 243 |
# File 'lib/gd2/canvas.rb', line 240 def text_circle(top, bottom, radius, text_radius, fill_portion) TextCircle.new(get_font, @point, radius, text_radius, fill_portion, top, bottom).draw(@image, pixel) end |