-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphics.rb
More file actions
76 lines (63 loc) · 1.58 KB
/
graphics.rb
File metadata and controls
76 lines (63 loc) · 1.58 KB
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
module Processing
# Draws graphics into an offscreen buffer
#
# @see https://processing.org/reference/PGraphics.html
# @see https://p5js.org/reference/p5/p5.Graphics/
#
class Graphics
include Xot::Inspectable
include GraphicsContext
# Initialize graphics object.
#
# @see https://p5js.org/reference/p5/p5.Graphics/
#
def initialize(width, height, pixelDensity = 1)
image = Rays::Image.new(
width, height, Rays::RGBA, pixel_density: pixelDensity)
init__ image, image.painter
end
def initialize_copy(o)
super
raise 'cannot duplicate during drawing' if @drawing__
raise 'cannot duplicate because each stack is not empty' unless
@matrixStack__.empty? && @styleStack__.empty?
image = getInternal__.dup
updateCanvas__ image, image.painter
restoreStyles__ o.styles__
end
alias w width
alias h height
# Returns the width and height of graphics.
#
# @return [Array<Numeric>] [width, height]
#
def size()
[width, height]
end
# Start drawing.
#
# @see https://processing.org/reference/PGraphics_beginDraw_.html
#
def beginDraw(&block)
@painter__.__send__ :begin_paint
beginDraw__
push
if block
begin
block.call self
ensure
endDraw
end
end
end
# End drawing.
#
# @see https://processing.org/reference/PGraphics_endDraw_.html
#
def endDraw()
pop
endDraw__
@painter__.__send__ :end_paint
end
end# Graphics
end# Processing