Class: StdDraw
- Inherits:
-
Object
- Object
- StdDraw
- Defined in:
- lib/standard_draw_tk.rb
Constant Summary collapse
- BLACK =
:black
- BLUE =
:blue
- CYAN =
:cyan
- DARK_GRAY =
:DarkGray
- GRAY =
:gray
- GREEN =
:green
- LIGHT_GRAY =
:LightGray
- MAGENTA =
:magenta
- ORANGE =
:orange
- PINK =
:pink
- RED =
:red
- WHITE =
:white
- YELLOW =
:yellow
- BOOK_BLUE =
'#095AA6'
- BOOK_LIGHT_BLUE =
'#67C6F3'
- BOOK_RED =
'#96231F'
- PRINCETON_ORANGE =
'#F58025'
- @@pen_radius =
DEFAULT_PEN_RADIUS = 0.002
- @@coords =
StandardDrawTk::Coordinates.new
- @@color =
BLACK
- @@bg_color =
WHITE
- @@root =
TkRoot.new
- @@canvas =
TkCanvas.new(@@root) do height @@coords.height width @@coords.width bg @@bg_color end
Class Method Summary collapse
- .arc(x, y, radius, angle1, angle2) ⇒ Object
- .circle(x, y, radius) ⇒ Object
- .color ⇒ Object
- .coords ⇒ Object
- .ellipse(x, y, w, h) ⇒ Object
- .filled_circle(x, y, radius) ⇒ Object
- .filled_ellipse(x, y, w, h) ⇒ Object
- .filled_polygon(x, y) ⇒ Object
- .filled_rectangle(x, y, half_width, half_height) ⇒ Object
- .filled_square(x, y, half_length) ⇒ Object
- .line(x0, y0, x1, y1) ⇒ Object
-
.pause ⇒ Object
should make this real.
- .pen_color=(color) ⇒ Object
- .pen_radius=(radius) ⇒ Object
- .pixel(x, y) ⇒ Object
- .point(x, y) ⇒ Object
- .polygon(x, y) ⇒ Object
- .rectangle(x, y, half_width, half_height) ⇒ Object
- .run ⇒ Object
- .set_xscale(min, max) ⇒ Object
- .set_yscale(min, max) ⇒ Object
- .square(x, y, half_length) ⇒ Object
Class Method Details
.arc(x, y, radius, angle1, angle2) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/standard_draw_tk.rb', line 82 def self.arc(x, y, radius, angle1, angle2) throw 'arc radius must be nonnegative' if radius < 0 while angle2 < angle1 angle2 += 360 end xs = coords.scale_x(x) ys = coords.scale_y(y) ws = coords.factor_x(2*radius) hs = coords.factor_y(2*radius) if ws <= 1 && hs <= 1 pixel(x, y) else x1 = xs - ws/2 y1 = ys - hs/2 x2 = x1 + ws y2 = y1 + hs TkcArc.new(@@canvas, x1, y1, x2, y2, style: :arc, start: angle1, extent: angle2 - angle1, fill: color, width: scaled_pen_radius, outline: color) end end |
.circle(x, y, radius) ⇒ Object
102 103 104 |
# File 'lib/standard_draw_tk.rb', line 102 def self.circle(x, y, radius) draw_circle(x, y, radius, outline: color) end |
.color ⇒ Object
70 71 72 |
# File 'lib/standard_draw_tk.rb', line 70 def self.color @@color end |
.coords ⇒ Object
49 50 51 |
# File 'lib/standard_draw_tk.rb', line 49 def self.coords @@coords end |
.ellipse(x, y, w, h) ⇒ Object
106 107 108 |
# File 'lib/standard_draw_tk.rb', line 106 def self.ellipse(x, y, w, h) draw_ellipse(x, y, w, h, outline: color) end |
.filled_circle(x, y, radius) ⇒ Object
114 115 116 |
# File 'lib/standard_draw_tk.rb', line 114 def self.filled_circle(x, y, radius) draw_circle(x, y, radius, fill: color) end |
.filled_ellipse(x, y, w, h) ⇒ Object
110 111 112 |
# File 'lib/standard_draw_tk.rb', line 110 def self.filled_ellipse(x, y, w, h) draw_ellipse(x, y, w, h, fill: color) end |
.filled_polygon(x, y) ⇒ Object
148 149 150 |
# File 'lib/standard_draw_tk.rb', line 148 def self.filled_polygon(x, y) draw_polygon(x, y, fill: color) end |
.filled_rectangle(x, y, half_width, half_height) ⇒ Object
122 123 124 |
# File 'lib/standard_draw_tk.rb', line 122 def self.filled_rectangle(x, y, half_width, half_height) draw_rectangle(x, y, half_width, half_height, fill: color) end |
.filled_square(x, y, half_length) ⇒ Object
130 131 132 |
# File 'lib/standard_draw_tk.rb', line 130 def self.filled_square(x, y, half_length) draw_rectangle(x, y, half_length, half_length, fill: color) end |
.line(x0, y0, x1, y1) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/standard_draw_tk.rb', line 74 def self.line(x0, y0, x1, y1) x0 = coords.scale_x(x0) y0 = coords.scale_y(y0) x1 = coords.scale_x(x1) y1 = coords.scale_y(y1) TkcLine.new(@@canvas, x0, y0, x1, y1, width: scaled_pen_radius, fill: color) end |
.pause ⇒ Object
should make this real
45 46 47 |
# File 'lib/standard_draw_tk.rb', line 45 def self.pause Tk.mainloop end |
.pen_color=(color) ⇒ Object
66 67 68 |
# File 'lib/standard_draw_tk.rb', line 66 def self.pen_color=(color) @@color = color end |
.pen_radius=(radius) ⇒ Object
61 62 63 64 |
# File 'lib/standard_draw_tk.rb', line 61 def self.pen_radius=(radius) throw 'pen radius must be nonnegative' if radius <= 0 @@pen_radius = radius end |
.pixel(x, y) ⇒ Object
138 139 140 141 142 |
# File 'lib/standard_draw_tk.rb', line 138 def self.pixel(x, y) x1 = coords.scale_x(x).round y1 = coords.scale_y(y).round TkcRectangle.new(@@canvas, [x1, y1, x1 + 1, y1 + 1], outline: color, fill: color) end |
.point(x, y) ⇒ Object
134 135 136 |
# File 'lib/standard_draw_tk.rb', line 134 def self.point(x, y) draw_circle(x, y, @@pen_radius/2, outline: color, fill: color) end |
.polygon(x, y) ⇒ Object
144 145 146 |
# File 'lib/standard_draw_tk.rb', line 144 def self.polygon(x, y) draw_polygon(x, y, outline: color) end |
.rectangle(x, y, half_width, half_height) ⇒ Object
118 119 120 |
# File 'lib/standard_draw_tk.rb', line 118 def self.rectangle(x, y, half_width, half_height) draw_rectangle(x, y, half_width, half_height, outline: color) end |
.run ⇒ Object
40 41 42 |
# File 'lib/standard_draw_tk.rb', line 40 def self.run Tk.mainloop end |
.set_xscale(min, max) ⇒ Object
53 54 55 |
# File 'lib/standard_draw_tk.rb', line 53 def self.set_xscale(min,max) coords.set_xscale(min,max) end |
.set_yscale(min, max) ⇒ Object
57 58 59 |
# File 'lib/standard_draw_tk.rb', line 57 def self.set_yscale(min,max) coords.set_yscale(min,max) end |
.square(x, y, half_length) ⇒ Object
126 127 128 |
# File 'lib/standard_draw_tk.rb', line 126 def self.square(x, y, half_length) draw_rectangle(x, y, half_length, half_length, outline: color) end |