rubysketch 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog.md +17 -0
- data/VERSION +1 -1
- data/examples/clock.rb +4 -13
- data/lib/rubysketch-processing.rb +30 -1
- data/lib/rubysketch.rb +0 -1
- data/lib/rubysketch/glsl.rb +0 -2
- data/lib/rubysketch/processing.rb +231 -103
- data/lib/rubysketch/window.rb +7 -6
- metadata +3 -3
- data/lib/rubysketch/starter.rb +0 -67
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9068a9fe7e5239420f8e32fb2e30912748bf9c90c52f40516604997b1166830a
|
4
|
+
data.tar.gz: 2a75b3ec215aeb15bfba929f561abd2a4f94c4c8093b27bad4de1ee74dd15efa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7a6252c38ab1fdda0c761c390bb5d0bb3583e740d7beea5efe3c5939a1f52840aac93c41aee693870dde4539df3f69dba20476c34b85a2eb5791fb3bcd63498
|
7
|
+
data.tar.gz: ccd6c65ff6b5e0340e7a8e779c2d1da2f277294ae9e03386a7d1317568badade0d4fe51758559680ef22ccc080486a3d2df43dab0501c91c9a6da3cc7144eb1d
|
data/ChangeLog.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# RubySketch ChangeLog
|
2
|
+
|
3
|
+
|
4
|
+
## [0.2.6] - 2020-04-17
|
5
|
+
|
6
|
+
- push(), pushMatrix() and pushStyle() take block to automatic pop
|
7
|
+
- add stroke_cap() and stroke_join()
|
8
|
+
- refine startup process
|
9
|
+
- add curve() and bezier()
|
10
|
+
- add imageMode(), Image#resize(), Image#copy() and copy()
|
11
|
+
- add loop(), noLoop() and redraw()
|
12
|
+
|
13
|
+
|
14
|
+
## [0.2.5] - 2020-03-29
|
15
|
+
|
16
|
+
- delete debug prints
|
17
|
+
- show unsupported image type
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.6
|
data/examples/clock.rb
CHANGED
@@ -20,12 +20,10 @@ end
|
|
20
20
|
draw do
|
21
21
|
background 0
|
22
22
|
|
23
|
-
|
24
|
-
pushMatrix
|
23
|
+
pushMatrix do
|
25
24
|
translate width / 2, height / 2
|
26
25
|
|
27
|
-
|
28
|
-
pushMatrix
|
26
|
+
pushMatrix do
|
29
27
|
fill COLORS[0]
|
30
28
|
ellipse 0, 0, 20, 20
|
31
29
|
rotate (now - start) / 60.0 * 360
|
@@ -33,32 +31,25 @@ draw do
|
|
33
31
|
strokeWeight 5
|
34
32
|
line 0, 0, 200, 0
|
35
33
|
fill 1
|
36
|
-
popMatrix
|
37
34
|
end
|
38
35
|
|
39
|
-
|
40
|
-
pushMatrix
|
36
|
+
pushMatrix do
|
41
37
|
strokeWeight 3
|
42
38
|
60.times do
|
43
39
|
rotate 6
|
44
40
|
stroke COLORS[1]
|
45
41
|
line 200, 0, 210, 0
|
46
42
|
end
|
47
|
-
popMatrix
|
48
43
|
end
|
49
44
|
|
50
|
-
|
51
|
-
pushMatrix
|
45
|
+
pushMatrix do
|
52
46
|
strokeWeight 5
|
53
47
|
12.times do
|
54
48
|
rotate 30
|
55
49
|
stroke COLORS[3]
|
56
50
|
line 190, 0, 210, 0
|
57
51
|
end
|
58
|
-
popMatrix
|
59
52
|
end
|
60
|
-
|
61
|
-
popMatrix
|
62
53
|
end
|
63
54
|
|
64
55
|
textSize 20
|
@@ -1,4 +1,33 @@
|
|
1
1
|
require 'rubysketch'
|
2
2
|
|
3
3
|
|
4
|
-
|
4
|
+
begin
|
5
|
+
context = RubySketch::Processing.new
|
6
|
+
methods = context.class.instance_methods(false)
|
7
|
+
.reject {|name| name =~ /__$/}
|
8
|
+
consts = context.class.constants
|
9
|
+
.reject {|name| name =~ /__$/}
|
10
|
+
.each_with_object({}) {|name, h| h[name] = context.class.const_get name}
|
11
|
+
|
12
|
+
self.class.class_eval do
|
13
|
+
methods.each do |name|
|
14
|
+
define_method name do |*args, &block|
|
15
|
+
context.__send__ name, *args, &block
|
16
|
+
end
|
17
|
+
end
|
18
|
+
consts.each do |(name, value)|
|
19
|
+
const_set name, value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
window = RubySketch::Window.new do |_|
|
24
|
+
window.start
|
25
|
+
end
|
26
|
+
context.setup__ window
|
27
|
+
|
28
|
+
window.canvas_painter.__send__ :begin_paint
|
29
|
+
at_exit do
|
30
|
+
window.canvas_painter.__send__ :end_paint
|
31
|
+
Reflex.start {window.show}
|
32
|
+
end
|
33
|
+
end
|
data/lib/rubysketch.rb
CHANGED
data/lib/rubysketch/glsl.rb
CHANGED
@@ -7,8 +7,6 @@ module RubySketch
|
|
7
7
|
|
8
8
|
include Math
|
9
9
|
|
10
|
-
extend Starter
|
11
|
-
|
12
10
|
HALF_PI = PI / 2
|
13
11
|
QUARTER_PI = PI / 4
|
14
12
|
TWO_PI = PI * 2
|
@@ -43,6 +41,8 @@ module RubySketch
|
|
43
41
|
|
44
42
|
# @private
|
45
43
|
def initialize ()
|
44
|
+
@loop__ = true
|
45
|
+
@redraw__ = false
|
46
46
|
@matrixStack__ = []
|
47
47
|
@styleStack__ = []
|
48
48
|
@frameCount__ = 0
|
@@ -59,18 +59,67 @@ module RubySketch
|
|
59
59
|
angleMode RADIANS
|
60
60
|
rectMode CORNER
|
61
61
|
ellipseMode CENTER
|
62
|
+
imageMode CORNER
|
62
63
|
end
|
63
64
|
|
64
65
|
# @private
|
65
|
-
def
|
66
|
+
def setup__ (window)
|
66
67
|
@window__ = window
|
67
|
-
@painter__ = window.canvas_painter
|
68
|
+
@painter__ = window.canvas_painter.tap do |o|
|
69
|
+
o.miter_limit = 10
|
70
|
+
end
|
68
71
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
drawFrame = -> event {
|
73
|
+
@painter__ = window.canvas_painter
|
74
|
+
@matrixStack__.clear
|
75
|
+
@styleStack__.clear
|
76
|
+
begin
|
77
|
+
push
|
78
|
+
@drawBlock__.call event if @drawBlock__
|
79
|
+
ensure
|
80
|
+
pop
|
81
|
+
end
|
82
|
+
@frameCount__ += 1
|
83
|
+
}
|
84
|
+
|
85
|
+
updateMouseState = -> x, y, pressed = nil {
|
86
|
+
@mouseX__ = x
|
87
|
+
@mouseY__ = y
|
88
|
+
@mousePressed__ = pressed if pressed != nil
|
89
|
+
}
|
90
|
+
|
91
|
+
updateMousePrevPos = -> {
|
92
|
+
@mousePrevX__ = @mouseX__
|
93
|
+
@mousePrevY__ = @mouseY__
|
94
|
+
}
|
95
|
+
|
96
|
+
@window__.draw = proc do |e|
|
97
|
+
if @loop__ || @redraw__
|
98
|
+
@redraw__ = false
|
99
|
+
drawFrame.call e
|
100
|
+
end
|
101
|
+
updateMousePrevPos.call
|
102
|
+
end
|
103
|
+
|
104
|
+
@window__.pointer_down = proc do |e|
|
105
|
+
updateMouseState.call e.x, e.y, true
|
106
|
+
@mousePressedBlock__.call e if @mousePressedBlock__
|
107
|
+
end
|
108
|
+
|
109
|
+
@window__.pointer_up = proc do |e|
|
110
|
+
updateMouseState.call e.x, e.y, false
|
111
|
+
@mouseReleasedBlock__.call e if @mouseReleasedBlock__
|
112
|
+
end
|
113
|
+
|
114
|
+
@window__.pointer_move = proc do |e|
|
115
|
+
updateMouseState.call e.x, e.y
|
116
|
+
@mouseMovedBlock__.call e if @mouseMovedBlock__
|
117
|
+
end
|
118
|
+
|
119
|
+
@window__.pointer_drag = proc do |e|
|
120
|
+
updateMouseState.call e.x, e.y
|
121
|
+
@mouseDraggedBlock__.call e if @mouseDraggedBlock__
|
122
|
+
end
|
74
123
|
end
|
75
124
|
|
76
125
|
# Returns the absolute number of the value.
|
@@ -293,23 +342,6 @@ module RubySketch
|
|
293
342
|
nil
|
294
343
|
end
|
295
344
|
|
296
|
-
# @private
|
297
|
-
private def setupDrawBlock__ ()
|
298
|
-
@window__.draw = proc do |e, painter|
|
299
|
-
@painter__ = painter
|
300
|
-
@matrixStack__.clear
|
301
|
-
@styleStack__.clear
|
302
|
-
begin
|
303
|
-
push
|
304
|
-
@drawBlock__.call e if @drawBlock__
|
305
|
-
ensure
|
306
|
-
pop
|
307
|
-
end
|
308
|
-
@frameCount__ += 1
|
309
|
-
updateMousePrevPos__
|
310
|
-
end
|
311
|
-
end
|
312
|
-
|
313
345
|
# Define draw block.
|
314
346
|
#
|
315
347
|
def draw (&block)
|
@@ -322,71 +354,26 @@ module RubySketch
|
|
322
354
|
nil
|
323
355
|
end
|
324
356
|
|
325
|
-
# @private
|
326
|
-
private def setupMousePressedBlock__ ()
|
327
|
-
@window__.pointer_down = proc do |e|
|
328
|
-
updateMouseState__ e.x, e.y, true
|
329
|
-
@mousePressedBlock__.call e if @mousePressedBlock__
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
357
|
def mousePressed (&block)
|
334
358
|
@mousePressedBlock__ = block if block
|
335
359
|
@mousePressed__
|
336
360
|
end
|
337
361
|
|
338
|
-
# @private
|
339
|
-
private def setupMouseReleasedBlock__ ()
|
340
|
-
@window__.pointer_up = proc do |e|
|
341
|
-
updateMouseState__ e.x, e.y, false
|
342
|
-
@mouseReleasedBlock__.call e if @mouseReleasedBlock__
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
362
|
def mouseReleased (&block)
|
347
363
|
@mouseReleasedBlock__ = block if block
|
348
364
|
nil
|
349
365
|
end
|
350
366
|
|
351
|
-
# @private
|
352
|
-
private def setupMouseMovedBlock__ ()
|
353
|
-
@window__.pointer_move = proc do |e|
|
354
|
-
updateMouseState__ e.x, e.y
|
355
|
-
@mouseMovedBlock__.call e if @mouseMovedBlock__
|
356
|
-
end
|
357
|
-
end
|
358
|
-
|
359
367
|
def mouseMoved (&block)
|
360
368
|
@mouseMovedBlock__ = block if block
|
361
369
|
nil
|
362
370
|
end
|
363
371
|
|
364
|
-
# @private
|
365
|
-
private def setupMouseDraggedBlock__ ()
|
366
|
-
@window__.pointer_drag = proc do |e|
|
367
|
-
updateMouseState__ e.x, e.y
|
368
|
-
@mouseDraggedBlock__.call e if @mouseDraggedBlock__
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
372
|
def mouseDragged (&block)
|
373
373
|
@mouseDraggedBlock__ = block if block
|
374
374
|
nil
|
375
375
|
end
|
376
376
|
|
377
|
-
# @private
|
378
|
-
private def updateMouseState__ (x, y, pressed = nil)
|
379
|
-
@mouseX__ = x
|
380
|
-
@mouseY__ = y
|
381
|
-
@mousePressed__ = pressed if pressed != nil
|
382
|
-
end
|
383
|
-
|
384
|
-
# @private
|
385
|
-
private def updateMousePrevPos__ ()
|
386
|
-
@mousePrevX__ = @mouseX__
|
387
|
-
@mousePrevY__ = @mouseY__
|
388
|
-
end
|
389
|
-
|
390
377
|
# @private
|
391
378
|
private def size__ (width, height)
|
392
379
|
raise 'size() must be called on startup or setup block' if @started__
|
@@ -577,6 +564,20 @@ module RubySketch
|
|
577
564
|
@ellipseMode__ = mode
|
578
565
|
end
|
579
566
|
|
567
|
+
# Sets image mode. Default is CORNER.
|
568
|
+
#
|
569
|
+
# CORNER -> image(img, left, top, width, height)
|
570
|
+
# CORNERS -> image(img, left, top, right, bottom)
|
571
|
+
# CENTER -> image(img, center_x, center_y, width, height)
|
572
|
+
#
|
573
|
+
# @param mode [CORNER, CORNERS, CENTER]
|
574
|
+
#
|
575
|
+
# @return [nil] nil
|
576
|
+
#
|
577
|
+
def imageMode (mode)
|
578
|
+
@imageMode__ = mode
|
579
|
+
end
|
580
|
+
|
580
581
|
# @private
|
581
582
|
private def toXYWH__ (mode, a, b, c, d)
|
582
583
|
case mode
|
@@ -588,6 +589,30 @@ module RubySketch
|
|
588
589
|
end
|
589
590
|
end
|
590
591
|
|
592
|
+
# Enables calling draw block on every frame.
|
593
|
+
#
|
594
|
+
# @return [nil] nil
|
595
|
+
#
|
596
|
+
def loop ()
|
597
|
+
@loop__ = true
|
598
|
+
end
|
599
|
+
|
600
|
+
# Disables calling draw block on every frame.
|
601
|
+
#
|
602
|
+
# @return [nil] nil
|
603
|
+
#
|
604
|
+
def noLoop ()
|
605
|
+
@loop__ = false
|
606
|
+
end
|
607
|
+
|
608
|
+
# Calls draw block to redraw frame.
|
609
|
+
#
|
610
|
+
# @return [nil] nil
|
611
|
+
#
|
612
|
+
def redraw ()
|
613
|
+
@redraw__ = true
|
614
|
+
end
|
615
|
+
|
591
616
|
# Clears screen.
|
592
617
|
#
|
593
618
|
# @overload background(str)
|
@@ -732,10 +757,10 @@ module RubySketch
|
|
732
757
|
|
733
758
|
# Draws a line.
|
734
759
|
#
|
735
|
-
# @param x1 [Numeric] horizontal position
|
736
|
-
# @param y1 [Numeric] vertical position
|
737
|
-
# @param x2 [Numeric] horizontal position
|
738
|
-
# @param y2 [Numeric] vertical position
|
760
|
+
# @param x1 [Numeric] horizontal position of first point
|
761
|
+
# @param y1 [Numeric] vertical position of first point
|
762
|
+
# @param x2 [Numeric] horizontal position of second point
|
763
|
+
# @param y2 [Numeric] vertical position of second point
|
739
764
|
#
|
740
765
|
# @return [nil] nil
|
741
766
|
#
|
@@ -865,6 +890,42 @@ module RubySketch
|
|
865
890
|
nil
|
866
891
|
end
|
867
892
|
|
893
|
+
# Draws a Catmull-Rom spline curve.
|
894
|
+
#
|
895
|
+
# @param cx1 [Numeric] horizontal position of beginning control point
|
896
|
+
# @param cy1 [Numeric] vertical position of beginning control point
|
897
|
+
# @param x1 [Numeric] horizontal position of first point
|
898
|
+
# @param y1 [Numeric] vertical position of first point
|
899
|
+
# @param x2 [Numeric] horizontal position of second point
|
900
|
+
# @param y2 [Numeric] vertical position of second point
|
901
|
+
# @param cx2 [Numeric] horizontal position of ending control point
|
902
|
+
# @param cy2 [Numeric] vertical position of ending control point
|
903
|
+
#
|
904
|
+
# @return [nil] nil
|
905
|
+
#
|
906
|
+
def curve (cx1, cy1, x1, y1, x2, y2, cx2, cy2)
|
907
|
+
@painter__.curve cx1, cy1, x1, y1, x2, y2, cx2, cy2
|
908
|
+
nil
|
909
|
+
end
|
910
|
+
|
911
|
+
# Draws a Bezier spline curve.
|
912
|
+
#
|
913
|
+
# @param x1 [Numeric] horizontal position of first point
|
914
|
+
# @param y1 [Numeric] vertical position of first point
|
915
|
+
# @param cx1 [Numeric] horizontal position of first control point
|
916
|
+
# @param cy1 [Numeric] vertical position of first control point
|
917
|
+
# @param cx2 [Numeric] horizontal position of second control point
|
918
|
+
# @param cy2 [Numeric] vertical position of second control point
|
919
|
+
# @param x2 [Numeric] horizontal position of second point
|
920
|
+
# @param y2 [Numeric] vertical position of second point
|
921
|
+
#
|
922
|
+
# @return [nil] nil
|
923
|
+
#
|
924
|
+
def bezier (x1, y1, cx1, cy1, cx2, cy2, x2, y2)
|
925
|
+
@painter__.bezier x1, y1, cx1, cy1, cx2, cy2, x2, y2
|
926
|
+
nil
|
927
|
+
end
|
928
|
+
|
868
929
|
# Draws a text.
|
869
930
|
#
|
870
931
|
# @overload text(str)
|
@@ -883,24 +944,45 @@ module RubySketch
|
|
883
944
|
|
884
945
|
# Draws an image.
|
885
946
|
#
|
886
|
-
# @overload image(img,
|
887
|
-
# @overload image(img,
|
947
|
+
# @overload image(img, a, b)
|
948
|
+
# @overload image(img, a, b, c, d)
|
888
949
|
#
|
889
950
|
# @param img [Image] image to draw
|
890
|
-
# @param
|
891
|
-
# @param
|
892
|
-
# @param
|
893
|
-
# @param
|
951
|
+
# @param a [Numeric] horizontal position of the image
|
952
|
+
# @param b [Numeric] vertical position of the image
|
953
|
+
# @param c [Numeric] width of the image
|
954
|
+
# @param d [Numeric] height of the image
|
894
955
|
#
|
895
956
|
# @return [nil] nil
|
896
957
|
#
|
897
|
-
def image (img,
|
898
|
-
w
|
899
|
-
|
900
|
-
@painter__.image img.internal, x, y, w, h
|
958
|
+
def image (img, a, b, c = nil, d = nil)
|
959
|
+
x, y, w, h = toXYWH__ @imageMode__, a, b, c || img.width, d || img.height
|
960
|
+
@painter__.image img.to_internal__, x, y, w, h
|
901
961
|
nil
|
902
962
|
end
|
903
963
|
|
964
|
+
# Copies image.
|
965
|
+
#
|
966
|
+
# @overload copy(sx, sy, sw, sh, dx, dy, dw, dh)
|
967
|
+
# @overload copy(img, sx, sy, sw, sh, dx, dy, dw, dh)
|
968
|
+
#
|
969
|
+
# @param img [Image] image for copy source
|
970
|
+
# @param sx [Numrtic] x position of source region
|
971
|
+
# @param sy [Numrtic] y position of source region
|
972
|
+
# @param sw [Numrtic] width of source region
|
973
|
+
# @param sh [Numrtic] height of source region
|
974
|
+
# @param dx [Numrtic] x position of destination region
|
975
|
+
# @param dy [Numrtic] y position of destination region
|
976
|
+
# @param dw [Numrtic] width of destination region
|
977
|
+
# @param dh [Numrtic] height of destination region
|
978
|
+
#
|
979
|
+
# @return [nil] nil
|
980
|
+
#
|
981
|
+
def copy (img = nil, sx, sy, sw, sh, dx, dy, dw, dh)
|
982
|
+
src = img&.to_internal__ || @window__.canvas
|
983
|
+
@painter__.image src, sx, sy, sw, sh, dx, dy, dw, dh
|
984
|
+
end
|
985
|
+
|
904
986
|
# Applies translation matrix to current transformation matrix.
|
905
987
|
#
|
906
988
|
# @param x [Numeric] horizontal transformation
|
@@ -944,8 +1026,12 @@ module RubySketch
|
|
944
1026
|
#
|
945
1027
|
# @return [nil] nil
|
946
1028
|
#
|
947
|
-
def pushMatrix ()
|
1029
|
+
def pushMatrix (&block)
|
948
1030
|
@matrixStack__.push @painter__.matrix
|
1031
|
+
if block
|
1032
|
+
block.call
|
1033
|
+
popMatrix
|
1034
|
+
end
|
949
1035
|
nil
|
950
1036
|
end
|
951
1037
|
|
@@ -972,18 +1058,25 @@ module RubySketch
|
|
972
1058
|
#
|
973
1059
|
# @return [nil] nil
|
974
1060
|
#
|
975
|
-
def pushStyle ()
|
1061
|
+
def pushStyle (&block)
|
976
1062
|
@styleStack__.push [
|
977
1063
|
@painter__.fill,
|
978
1064
|
@painter__.stroke,
|
979
1065
|
@painter__.stroke_width,
|
1066
|
+
@painter__.stroke_cap,
|
1067
|
+
@painter__.stroke_join,
|
980
1068
|
@painter__.font,
|
981
1069
|
@hsbColor__,
|
982
1070
|
@colorMaxes__,
|
983
1071
|
@angleScale__,
|
984
1072
|
@rectMode__,
|
985
|
-
@ellipseMode__
|
1073
|
+
@ellipseMode__,
|
1074
|
+
@imageMode__
|
986
1075
|
]
|
1076
|
+
if block
|
1077
|
+
block.call
|
1078
|
+
popStyle
|
1079
|
+
end
|
987
1080
|
nil
|
988
1081
|
end
|
989
1082
|
|
@@ -996,12 +1089,15 @@ module RubySketch
|
|
996
1089
|
@painter__.fill,
|
997
1090
|
@painter__.stroke,
|
998
1091
|
@painter__.stroke_width,
|
1092
|
+
@painter__.stroke_cap,
|
1093
|
+
@painter__.stroke_join,
|
999
1094
|
@painter__.font,
|
1000
1095
|
@hsbColor__,
|
1001
1096
|
@colorMaxes__,
|
1002
1097
|
@angleScale__,
|
1003
1098
|
@rectMode__,
|
1004
|
-
@ellipseMode__
|
1099
|
+
@ellipseMode__,
|
1100
|
+
@imageMode__ = @styleStack__.pop
|
1005
1101
|
nil
|
1006
1102
|
end
|
1007
1103
|
|
@@ -1009,9 +1105,13 @@ module RubySketch
|
|
1009
1105
|
#
|
1010
1106
|
# @return [nil] nil
|
1011
1107
|
#
|
1012
|
-
def push ()
|
1108
|
+
def push (&block)
|
1013
1109
|
pushMatrix
|
1014
1110
|
pushStyle
|
1111
|
+
if block
|
1112
|
+
block.call
|
1113
|
+
pop
|
1114
|
+
end
|
1015
1115
|
end
|
1016
1116
|
|
1017
1117
|
# Restore styles and transformations from stack.
|
@@ -1080,8 +1180,7 @@ module RubySketch
|
|
1080
1180
|
#
|
1081
1181
|
class Processing::Image
|
1082
1182
|
|
1083
|
-
#
|
1084
|
-
#
|
1183
|
+
# @private
|
1085
1184
|
def initialize (image)
|
1086
1185
|
@image = image
|
1087
1186
|
end
|
@@ -1102,6 +1201,44 @@ module RubySketch
|
|
1102
1201
|
@image.height
|
1103
1202
|
end
|
1104
1203
|
|
1204
|
+
# Resizes image.
|
1205
|
+
#
|
1206
|
+
# @param width [Numeric] width for resized image
|
1207
|
+
# @param height [Numeric] height for resized image
|
1208
|
+
#
|
1209
|
+
# @return [nil] nil
|
1210
|
+
#
|
1211
|
+
def resize (width, height)
|
1212
|
+
@image = Rays::Image.new(width, height).paint do |painter|
|
1213
|
+
painter.image @image, 0, 0, width, height
|
1214
|
+
end
|
1215
|
+
nil
|
1216
|
+
end
|
1217
|
+
|
1218
|
+
# Copies image.
|
1219
|
+
#
|
1220
|
+
# @overload copy(sx, sy, sw, sh, dx, dy, dw, dh)
|
1221
|
+
# @overload copy(img, sx, sy, sw, sh, dx, dy, dw, dh)
|
1222
|
+
#
|
1223
|
+
# @param img [Image] image for copy source
|
1224
|
+
# @param sx [Numrtic] x position of source region
|
1225
|
+
# @param sy [Numrtic] y position of source region
|
1226
|
+
# @param sw [Numrtic] width of source region
|
1227
|
+
# @param sh [Numrtic] height of source region
|
1228
|
+
# @param dx [Numrtic] x position of destination region
|
1229
|
+
# @param dy [Numrtic] y position of destination region
|
1230
|
+
# @param dw [Numrtic] width of destination region
|
1231
|
+
# @param dh [Numrtic] height of destination region
|
1232
|
+
#
|
1233
|
+
# @return [nil] nil
|
1234
|
+
#
|
1235
|
+
def copy (img = nil, sx, sy, sw, sh, dx, dy, dw, dh)
|
1236
|
+
img ||= self
|
1237
|
+
@image.paint do |painter|
|
1238
|
+
painter.image img.to_internal__, sx, sy, sw, sh, dx, dy, dw, dh
|
1239
|
+
end
|
1240
|
+
end
|
1241
|
+
|
1105
1242
|
# Saves image to file.
|
1106
1243
|
#
|
1107
1244
|
# @param filename [String] file name to save image
|
@@ -1111,7 +1248,7 @@ module RubySketch
|
|
1111
1248
|
end
|
1112
1249
|
|
1113
1250
|
# @private
|
1114
|
-
def
|
1251
|
+
def to_internal__ ()
|
1115
1252
|
@image
|
1116
1253
|
end
|
1117
1254
|
|
@@ -1122,10 +1259,7 @@ module RubySketch
|
|
1122
1259
|
#
|
1123
1260
|
class Processing::Font
|
1124
1261
|
|
1125
|
-
# Initialize font.
|
1126
|
-
#
|
1127
1262
|
# @private
|
1128
|
-
#
|
1129
1263
|
def initialize (font)
|
1130
1264
|
@font = font
|
1131
1265
|
end
|
@@ -1171,13 +1305,7 @@ module RubySketch
|
|
1171
1305
|
#
|
1172
1306
|
attr_reader :h
|
1173
1307
|
|
1174
|
-
#
|
1175
|
-
#
|
1176
|
-
# @param x [Numeric] horizontal position
|
1177
|
-
# @param y [Numeric] vertical position
|
1178
|
-
# @param w [Numeric] width of bounding box
|
1179
|
-
# @param h [Numeric] height of bounding box
|
1180
|
-
#
|
1308
|
+
# @private
|
1181
1309
|
def initialize (x, y, w, h)
|
1182
1310
|
@x, @y, @w, @h = x, y, w, h
|
1183
1311
|
end
|
data/lib/rubysketch/window.rb
CHANGED
@@ -17,9 +17,7 @@ module RubySketch
|
|
17
17
|
|
18
18
|
reset_canvas 1, 1
|
19
19
|
|
20
|
-
super *args, size: [width, height]
|
21
|
-
start &block if block
|
22
|
-
end
|
20
|
+
super *args, size: [width, height], &block
|
23
21
|
end
|
24
22
|
|
25
23
|
def start (&block)
|
@@ -43,8 +41,8 @@ module RubySketch
|
|
43
41
|
end
|
44
42
|
|
45
43
|
def on_draw (e)
|
46
|
-
@canvas_painter.paint do |
|
47
|
-
call_block @draw, e
|
44
|
+
@canvas_painter.paint do |_|
|
45
|
+
call_block @draw, e
|
48
46
|
end
|
49
47
|
e.painter.image @canvas
|
50
48
|
end
|
@@ -80,7 +78,7 @@ module RubySketch
|
|
80
78
|
old_canvas = @canvas
|
81
79
|
old_painter = @canvas_painter
|
82
80
|
|
83
|
-
cs = old_canvas&.color_space || Rays::
|
81
|
+
cs = old_canvas&.color_space || Rays::RGBA
|
84
82
|
@canvas = Rays::Image.new width, height, cs, painter.pixel_density
|
85
83
|
@canvas_painter = @canvas.painter
|
86
84
|
|
@@ -94,6 +92,9 @@ module RubySketch
|
|
94
92
|
to.fill = from.fill
|
95
93
|
to.stroke = from.stroke
|
96
94
|
to.stroke_width = from.stroke_width
|
95
|
+
to.stroke_cap = from.stroke_cap
|
96
|
+
to.stroke_join = from.stroke_join
|
97
|
+
to.miter_limit = from.miter_limit
|
97
98
|
to.font = from.font
|
98
99
|
end
|
99
100
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubysketch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xordog
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|
@@ -103,6 +103,7 @@ extra_rdoc_files: []
|
|
103
103
|
files:
|
104
104
|
- ".gitignore"
|
105
105
|
- ".yardopts"
|
106
|
+
- ChangeLog.md
|
106
107
|
- LICENSE
|
107
108
|
- README.md
|
108
109
|
- Rakefile
|
@@ -117,7 +118,6 @@ files:
|
|
117
118
|
- lib/rubysketch/glsl.rb
|
118
119
|
- lib/rubysketch/module.rb
|
119
120
|
- lib/rubysketch/processing.rb
|
120
|
-
- lib/rubysketch/starter.rb
|
121
121
|
- lib/rubysketch/window.rb
|
122
122
|
- rubysketch.gemspec
|
123
123
|
homepage: https://github.com/xord/rubysketch
|
data/lib/rubysketch/starter.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
module RubySketch
|
2
|
-
|
3
|
-
|
4
|
-
extend module Functions
|
5
|
-
|
6
|
-
def start (context, start_at_exit: false, &block)
|
7
|
-
window = Window.new do
|
8
|
-
context.instance_eval &block if block
|
9
|
-
end
|
10
|
-
|
11
|
-
context.on_start__ window
|
12
|
-
|
13
|
-
start = proc do
|
14
|
-
Reflex.start {window.show}
|
15
|
-
end
|
16
|
-
|
17
|
-
if start_at_exit
|
18
|
-
at_exit {start.call unless $!}
|
19
|
-
else
|
20
|
-
start.call
|
21
|
-
end
|
22
|
-
|
23
|
-
window
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def start_on_object_at_exit (object, context)
|
29
|
-
klass = context.class
|
30
|
-
methods = klass.instance_methods(false)
|
31
|
-
.reject {|name| name =~ /__$/}
|
32
|
-
consts = klass.constants
|
33
|
-
.reject {|name| name =~ /__$/}
|
34
|
-
.each_with_object({}) {|name, h| h[name] = klass.const_get name}
|
35
|
-
|
36
|
-
object.class.class_eval do
|
37
|
-
methods.each do |name|
|
38
|
-
define_method name do |*args, &block|
|
39
|
-
context.__send__ name, *args, &block
|
40
|
-
end
|
41
|
-
end
|
42
|
-
consts.each do |(name, value)|
|
43
|
-
const_set name, value
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
window = start context, start_at_exit: true
|
48
|
-
|
49
|
-
window.canvas_painter.__send__ :begin_paint
|
50
|
-
at_exit {window.canvas_painter.__send__ :end_paint}
|
51
|
-
end
|
52
|
-
|
53
|
-
self
|
54
|
-
|
55
|
-
end# Functions
|
56
|
-
|
57
|
-
|
58
|
-
module Starter
|
59
|
-
|
60
|
-
def start (*args, &block)
|
61
|
-
RubySketch.start self.new(*args), start_at_exit: true, &block
|
62
|
-
end
|
63
|
-
|
64
|
-
end# Starter
|
65
|
-
|
66
|
-
|
67
|
-
end# RubySketch
|