Class: Smalruby::Canvas
Overview
Direct Known Subclasses
Stage
Instance Attribute Summary
Attributes inherited from Character
#checking_hit_targets, #costume_index, #costumes, #enable_pen, #event_handlers, #pen_color, #rotation_style, #threads, #volume
Instance Method Summary
collapse
Methods inherited from Character
#alive?, #angle, #angle=, #await, #button, #change_pen_color_by, #clear, #click, #distance, #down_pen, #draw, #go_to, #hit, #hit?, #join, #key_down, #key_push, #led, #loop, #motor_driver, #move, #move_back, #neo_pixel, #next_costume, #on, #pen_shade=, #play, #point_towards, #position, #position=, #reach_left_or_right_wall?, #reach_top_or_bottom_wall?, #reach_wall?, #rgb_led_anode, #rgb_led_cathode, #rotate, #say, #sensor, #servo, #smalrubot_s1, #smalrubot_v3, #start, #switch_costume, #turn, #turn_if_reach_wall, #turn_x, #turn_y, #two_wheel_drive_car, #up_pen, #visible=, #x=, #y=
Constructor Details
#initialize(options = {}) ⇒ Canvas
Returns a new instance of Canvas.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/smalruby/canvas.rb', line 6
def initialize(options = {})
defaults = {
x: 0,
y: 0,
width: Window.width,
height: Window.height,
color: nil,
}
opts = Util.process_options(options, defaults)
opts[:costume] = Image.new(opts[:width], opts[:height])
super(opts.reject { |k, _| [:width, :height, :color].include?(k) })
fill(color: opts[:color]) if opts[:color]
end
|
Instance Method Details
#box(option) ⇒ Object
44
45
46
47
48
49
|
# File 'lib/smalruby/canvas.rb', line 44
def box(option)
opt = process_rect_option(option)
image.box(opt[:left], opt[:top], opt[:right], opt[:bottom],
Color.smalruby_to_dxruby(opt[:color]))
end
|
#box_fill(option) ⇒ Object
51
52
53
54
55
56
|
# File 'lib/smalruby/canvas.rb', line 51
def box_fill(option)
opt = process_rect_option(option)
image.box_fill(opt[:left], opt[:top], opt[:right], opt[:bottom],
Color.smalruby_to_dxruby(opt[:color]))
end
|
#circle(option) ⇒ Object
58
59
60
61
62
63
|
# File 'lib/smalruby/canvas.rb', line 58
def circle(option)
opt = process_circle_option(option)
image.circle(opt[:x], opt[:y], opt[:r],
Color.smalruby_to_dxruby(opt[:color]))
end
|
#circle_fill(option) ⇒ Object
65
66
67
68
69
70
|
# File 'lib/smalruby/canvas.rb', line 65
def circle_fill(option)
opt = process_circle_option(option)
image.circle_fill(opt[:x], opt[:y], opt[:r],
Color.smalruby_to_dxruby(opt[:color]))
end
|
#draw_font(option) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/smalruby/canvas.rb', line 24
def draw_font(option)
defaults = {
x: 0,
y: 0,
string: "",
size: 32
}.merge(DEFAULT_COLOR_OPTION)
opt = process_optional_arguments(option, defaults)
image.draw_font(opt[:x], opt[:y], opt[:string], new_font(opt[:size]),
Color.smalruby_to_dxruby(opt[:color]))
end
|
#fill(option) ⇒ Object
72
73
74
75
76
77
|
# File 'lib/smalruby/canvas.rb', line 72
def fill(option)
opt = process_optional_arguments(option, DEFAULT_COLOR_OPTION)
image.box_fill(0, 0, image.width, image.height,
Color.smalruby_to_dxruby(opt[:color]))
end
|
#line(option) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/smalruby/canvas.rb', line 37
def line(option)
opt = process_rect_option(option)
image.line(opt[:left], opt[:top], opt[:right], opt[:bottom],
Color.smalruby_to_dxruby(opt[:color]))
end
|