rubysketch 0.3.20 → 0.3.21
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/.github/workflows/release.yml +2 -2
- data/ChangeLog.md +10 -0
- data/Gemfile +1 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/examples/glsl.rb +5 -8
- data/lib/rubysketch/glsl.rb +23 -16
- data/lib/rubysketch/processing.rb +149 -24
- data/lib/rubysketch-glsl.rb +11 -0
- data/rubysketch.gemspec +3 -1
- metadata +20 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acfaff485263c8e6557c8610df2a4643e53d1046e55cf813c79b648492e84d52
|
4
|
+
data.tar.gz: d7beb5170988d554771d50d5a726b1f51c961cded8a3cf3370dc55ccc91059fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95ce0e61b8db2f0046bfd43070dd9d10f24b48f7838b267509b98e9a4b6930aa8958c065ae7af253c3877c754a5187ce970b80722421c32e6fbb9de4d1ebc05a
|
7
|
+
data.tar.gz: a810edf5f210a8a505fc3830697a46a76a743860a90118d1de38e99192d0cf43639dd5410409baf040c4b6feb0275a90d2cb330230b7457890d8555b9f257d5e
|
data/ChangeLog.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
# RubySketch ChangeLog
|
2
2
|
|
3
3
|
|
4
|
+
## [0.3.21] - 2022-x-x
|
5
|
+
|
6
|
+
- add rubysketch-glsl.rb
|
7
|
+
- add blend(), createImage(), setTitle(), tint() and noTint()
|
8
|
+
- add save() that saves screen image to file
|
9
|
+
- circle() function is affected by ellipseMode()
|
10
|
+
- point() draws by line(x, y, x, y)
|
11
|
+
- change initial values for strokeCap and strokeJoin to ROUND and MITER
|
12
|
+
|
13
|
+
|
4
14
|
## [0.3.20] - 2022-07-24
|
5
15
|
|
6
16
|
- add mouseClicked()
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.21
|
data/examples/glsl.rb
CHANGED
@@ -2,16 +2,13 @@
|
|
2
2
|
.map {|s| File.expand_path "../../#{s}/lib", __dir__}
|
3
3
|
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
4
4
|
|
5
|
-
require 'rubysketch'
|
5
|
+
require 'rubysketch-glsl'
|
6
6
|
|
7
|
-
|
8
|
-
RubySketch::GLSL.start <<END
|
9
|
-
varying vec4 v_TexCoord;
|
7
|
+
RubySketch::GLSL.run <<END
|
10
8
|
uniform vec2 resolution;
|
11
9
|
uniform float time;
|
12
|
-
void main
|
13
|
-
|
14
|
-
|
15
|
-
gl_FragColor = vec4(pos, float(mod(time, 1.0)), 1);
|
10
|
+
void main() {
|
11
|
+
vec2 pos = gl_FragCoord.xy / resolution;
|
12
|
+
gl_FragColor = vec4(pos * abs(sin(time)), 0, 1);
|
16
13
|
}
|
17
14
|
END
|
data/lib/rubysketch/glsl.rb
CHANGED
@@ -1,29 +1,36 @@
|
|
1
1
|
module RubySketch
|
2
2
|
|
3
3
|
|
4
|
-
#
|
5
|
-
|
4
|
+
# OpenGL Shader Language
|
5
|
+
#
|
6
|
+
module GLSL
|
6
7
|
|
7
|
-
def initialize(glsl)
|
8
|
-
@shader = Reflex::Shader.new glsl
|
9
|
-
end
|
10
8
|
|
11
9
|
# @private
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
window
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
p.shader
|
10
|
+
class Context
|
11
|
+
|
12
|
+
# @private
|
13
|
+
def initialize(window, shader_source)
|
14
|
+
shader = Rays::Shader.new shader_source
|
15
|
+
start = now__
|
16
|
+
window.draw = proc do |e|
|
17
|
+
i, p = window.canvas_image, window.canvas_painter
|
18
|
+
w, h = i.width, i.height
|
19
|
+
p.shader shader, resolution: [w, h], time: now__ - start
|
22
20
|
p.fill 1
|
23
21
|
p.rect 0, 0, w, h
|
24
22
|
end
|
25
23
|
end
|
26
|
-
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# @private
|
28
|
+
def now__()
|
29
|
+
Time.now.to_f
|
30
|
+
end
|
31
|
+
|
32
|
+
end# Context
|
33
|
+
|
27
34
|
|
28
35
|
end# GLSL
|
29
36
|
|
@@ -624,9 +624,34 @@ module RubySketch
|
|
624
624
|
# @return [nil] nil
|
625
625
|
#
|
626
626
|
def copy(img = nil, sx, sy, sw, sh, dx, dy, dw, dh)
|
627
|
+
blend img, sx, sy, sw, sh, dx, dy, dw, dh, :normal
|
628
|
+
end
|
629
|
+
|
630
|
+
# Blends image.
|
631
|
+
#
|
632
|
+
# @overload blend(sx, sy, sw, sh, dx, dy, dw, dh, mode)
|
633
|
+
# @overload blend(img, sx, sy, sw, sh, dx, dy, dw, dh, mode)
|
634
|
+
#
|
635
|
+
# @param img [Image] image for blend source
|
636
|
+
# @param sx [Numrtic] x position of source region
|
637
|
+
# @param sy [Numrtic] y position of source region
|
638
|
+
# @param sw [Numrtic] width of source region
|
639
|
+
# @param sh [Numrtic] height of source region
|
640
|
+
# @param dx [Numrtic] x position of destination region
|
641
|
+
# @param dy [Numrtic] y position of destination region
|
642
|
+
# @param dw [Numrtic] width of destination region
|
643
|
+
# @param dh [Numrtic] height of destination region
|
644
|
+
# @param mode [BLEND, ADD, SUBTRACT, LIGHTEST, DARKEST, EXCLUSION, MULTIPLY, SCREEN, REPLACE] blend mode
|
645
|
+
#
|
646
|
+
# @return [nil] nil
|
647
|
+
#
|
648
|
+
def blend(img = nil, sx, sy, sw, sh, dx, dy, dw, dh, mode)
|
627
649
|
img ||= self
|
628
650
|
@image.paint do |painter|
|
651
|
+
current = painter.blend_mode
|
652
|
+
painter.blend_mode = mode
|
629
653
|
painter.image img.getInternal__, sx, sy, sw, sh, dx, dy, dw, dh
|
654
|
+
painter.blend_mode = current
|
630
655
|
end
|
631
656
|
end
|
632
657
|
|
@@ -850,13 +875,17 @@ module RubySketch
|
|
850
875
|
#
|
851
876
|
TAU = PI * 2
|
852
877
|
|
853
|
-
#
|
878
|
+
# RGBA format for createImage().
|
879
|
+
#
|
880
|
+
RGBA = :rgba
|
881
|
+
|
882
|
+
# RGB format for createImage, or RGB mode for colorMode().
|
854
883
|
#
|
855
|
-
RGB
|
884
|
+
RGB = :rgb
|
856
885
|
|
857
886
|
# HSB mode for colorMode().
|
858
887
|
#
|
859
|
-
HSB
|
888
|
+
HSB = :hsb
|
860
889
|
|
861
890
|
# Radian mode for angleMode().
|
862
891
|
#
|
@@ -1007,6 +1036,7 @@ module RubySketch
|
|
1007
1036
|
@rectMode__ = nil
|
1008
1037
|
@ellipseMode__ = nil
|
1009
1038
|
@imageMode__ = nil
|
1039
|
+
@tint__ = nil
|
1010
1040
|
@textAlignH__ = nil
|
1011
1041
|
@textAlignV__ = nil
|
1012
1042
|
@matrixStack__ = []
|
@@ -1021,11 +1051,14 @@ module RubySketch
|
|
1021
1051
|
ellipseMode CENTER
|
1022
1052
|
imageMode CORNER
|
1023
1053
|
blendMode BLEND
|
1054
|
+
strokeCap ROUND
|
1055
|
+
strokeJoin MITER
|
1024
1056
|
textAlign LEFT
|
1025
1057
|
|
1026
1058
|
fill 255
|
1027
1059
|
stroke 0
|
1028
1060
|
strokeWeight 1
|
1061
|
+
noTint
|
1029
1062
|
end
|
1030
1063
|
|
1031
1064
|
# @private
|
@@ -1186,6 +1219,17 @@ module RubySketch
|
|
1186
1219
|
end
|
1187
1220
|
end
|
1188
1221
|
|
1222
|
+
# Sets blend mode. Default is BLEND.
|
1223
|
+
#
|
1224
|
+
# @param mode [BLEND, ADD, SUBTRACT, LIGHTEST, DARKEST, EXCLUSION, MULTIPLY, SCREEN, REPLACE]
|
1225
|
+
#
|
1226
|
+
# @return [nil] nil
|
1227
|
+
#
|
1228
|
+
def blendMode(mode)
|
1229
|
+
@painter__.blend_mode = mode
|
1230
|
+
nil
|
1231
|
+
end
|
1232
|
+
|
1189
1233
|
# Sets fill color.
|
1190
1234
|
#
|
1191
1235
|
# @overload fill(rgb)
|
@@ -1283,6 +1327,37 @@ module RubySketch
|
|
1283
1327
|
nil
|
1284
1328
|
end
|
1285
1329
|
|
1330
|
+
# Sets fill color for drawing images.
|
1331
|
+
#
|
1332
|
+
# @overload tint(rgb)
|
1333
|
+
# @overload tint(rgb, alpha)
|
1334
|
+
# @overload tint(gray)
|
1335
|
+
# @overload tint(gray, alpha)
|
1336
|
+
# @overload tint(r, g, b)
|
1337
|
+
# @overload tint(r, g, b, alpha)
|
1338
|
+
#
|
1339
|
+
# @param rgb [String] color code like '#00AAFF'
|
1340
|
+
# @param gray [Integer] gray value (0..255)
|
1341
|
+
# @param r [Integer] red value (0..255)
|
1342
|
+
# @param g [Integer] green value (0..255)
|
1343
|
+
# @param b [Integer] blue value (0..255)
|
1344
|
+
# @param alpha [Integer] alpha value (0..255)
|
1345
|
+
#
|
1346
|
+
# @return [nil] nil
|
1347
|
+
#
|
1348
|
+
def tint(*args)
|
1349
|
+
@tint__ = args
|
1350
|
+
nil
|
1351
|
+
end
|
1352
|
+
|
1353
|
+
# Resets tint color.
|
1354
|
+
#
|
1355
|
+
# @return [nil] nil
|
1356
|
+
#
|
1357
|
+
def noTint()
|
1358
|
+
@tint__ = nil
|
1359
|
+
end
|
1360
|
+
|
1286
1361
|
# Limits the drawable rectangle.
|
1287
1362
|
#
|
1288
1363
|
# The parameters a, b, c, and d are determined by rectMode().
|
@@ -1309,17 +1384,6 @@ module RubySketch
|
|
1309
1384
|
nil
|
1310
1385
|
end
|
1311
1386
|
|
1312
|
-
# Sets blend mode. Default is BLEND.
|
1313
|
-
#
|
1314
|
-
# @param mode [BLEND, ADD, SUBTRACT, LIGHTEST, DARKEST, EXCLUSION, MULTIPLY, SCREEN, REPLACE]
|
1315
|
-
#
|
1316
|
-
# @return [nil] nil
|
1317
|
-
#
|
1318
|
-
def blendMode(mode)
|
1319
|
-
@painter__.blend_mode = mode
|
1320
|
-
nil
|
1321
|
-
end
|
1322
|
-
|
1323
1387
|
# Sets font.
|
1324
1388
|
#
|
1325
1389
|
# @overload textFont(font)
|
@@ -1402,7 +1466,7 @@ module RubySketch
|
|
1402
1466
|
if rgba[3] == 1
|
1403
1467
|
@painter__.background(*rgba)
|
1404
1468
|
else
|
1405
|
-
@painter__.push fill: rgba, stroke:
|
1469
|
+
@painter__.push fill: rgba, stroke: :none do |_|
|
1406
1470
|
@painter__.rect 0, 0, width, height
|
1407
1471
|
end
|
1408
1472
|
end
|
@@ -1418,9 +1482,7 @@ module RubySketch
|
|
1418
1482
|
#
|
1419
1483
|
def point(x, y)
|
1420
1484
|
assertDrawing__
|
1421
|
-
|
1422
|
-
w = 1 if w == 0
|
1423
|
-
@painter__.ellipse x - (w / 2.0), y - (w / 2.0), w, w
|
1485
|
+
@painter__.line x, y, x, y
|
1424
1486
|
nil
|
1425
1487
|
end
|
1426
1488
|
|
@@ -1498,9 +1560,7 @@ module RubySketch
|
|
1498
1560
|
# @return [nil] nil
|
1499
1561
|
#
|
1500
1562
|
def circle(x, y, extent)
|
1501
|
-
|
1502
|
-
@painter__.ellipse x, y, extent, extent
|
1503
|
-
nil
|
1563
|
+
ellipse x, y, extent, extent
|
1504
1564
|
end
|
1505
1565
|
|
1506
1566
|
# Draws an arc.
|
@@ -1667,9 +1727,12 @@ module RubySketch
|
|
1667
1727
|
#
|
1668
1728
|
def image(img, a, b, c = nil, d = nil)
|
1669
1729
|
assertDrawing__
|
1670
|
-
i
|
1730
|
+
i = img.getInternal__
|
1671
1731
|
x, y, w, h = toXYWH__ @imageMode__, a, b, c || i.width, d || i.height
|
1672
|
-
@
|
1732
|
+
tint = @tint__ ? toRGBA__(*@tint__) : 1
|
1733
|
+
@painter__.push fill: tint, stroke: :none do |_|
|
1734
|
+
@painter__.image i, x, y, w, h
|
1735
|
+
end
|
1673
1736
|
nil
|
1674
1737
|
end
|
1675
1738
|
|
@@ -1691,9 +1754,43 @@ module RubySketch
|
|
1691
1754
|
# @return [nil] nil
|
1692
1755
|
#
|
1693
1756
|
def copy(img = nil, sx, sy, sw, sh, dx, dy, dw, dh)
|
1757
|
+
blend img, sx, sy, sw, sh, dx, dy, dw, dh, BLEND
|
1758
|
+
end
|
1759
|
+
|
1760
|
+
# Blends image.
|
1761
|
+
#
|
1762
|
+
# @overload blend(sx, sy, sw, sh, dx, dy, dw, dh, mode)
|
1763
|
+
# @overload blend(img, sx, sy, sw, sh, dx, dy, dw, dh, mode)
|
1764
|
+
#
|
1765
|
+
# @param img [Image] image for blend source
|
1766
|
+
# @param sx [Numrtic] x position of source region
|
1767
|
+
# @param sy [Numrtic] y position of source region
|
1768
|
+
# @param sw [Numrtic] width of source region
|
1769
|
+
# @param sh [Numrtic] height of source region
|
1770
|
+
# @param dx [Numrtic] x position of destination region
|
1771
|
+
# @param dy [Numrtic] y position of destination region
|
1772
|
+
# @param dw [Numrtic] width of destination region
|
1773
|
+
# @param dh [Numrtic] height of destination region
|
1774
|
+
# @param mode [BLEND, ADD, SUBTRACT, LIGHTEST, DARKEST, EXCLUSION, MULTIPLY, SCREEN, REPLACE] blend mode
|
1775
|
+
#
|
1776
|
+
# @return [nil] nil
|
1777
|
+
#
|
1778
|
+
def blend(img = nil, sx, sy, sw, sh, dx, dy, dw, dh, mode)
|
1694
1779
|
assertDrawing__
|
1695
|
-
src
|
1780
|
+
src = img&.getInternal__ || @window__.canvas_image
|
1781
|
+
current = @painter__.blend_mode
|
1782
|
+
|
1783
|
+
@painter__.blend_mode = mode
|
1696
1784
|
@painter__.image src, sx, sy, sw, sh, dx, dy, dw, dh
|
1785
|
+
@painter__.blend_mode = current
|
1786
|
+
end
|
1787
|
+
|
1788
|
+
# Saves screen image to file.
|
1789
|
+
#
|
1790
|
+
# @param filename [String] file name to save image
|
1791
|
+
#
|
1792
|
+
def save(filename)
|
1793
|
+
@window__.canvas_image.save filename
|
1697
1794
|
end
|
1698
1795
|
|
1699
1796
|
# Applies translation matrix to current transformation matrix.
|
@@ -2185,6 +2282,17 @@ module RubySketch
|
|
2185
2282
|
nil
|
2186
2283
|
end
|
2187
2284
|
|
2285
|
+
# Changes title of window.
|
2286
|
+
#
|
2287
|
+
# @param title [String] new title
|
2288
|
+
#
|
2289
|
+
# @return [nil] nil
|
2290
|
+
#
|
2291
|
+
def setTitle(title)
|
2292
|
+
@window__.title = title
|
2293
|
+
nil
|
2294
|
+
end
|
2295
|
+
|
2188
2296
|
# Changes and returns canvas pixel density.
|
2189
2297
|
#
|
2190
2298
|
# @param density [Numeric] new pixel density
|
@@ -2716,6 +2824,23 @@ module RubySketch
|
|
2716
2824
|
Vector.new(*args, context: self)
|
2717
2825
|
end
|
2718
2826
|
|
2827
|
+
# Creates a new image.
|
2828
|
+
#
|
2829
|
+
# @overload createImage(w, h)
|
2830
|
+
# @overload createImage(w, h, format)
|
2831
|
+
#
|
2832
|
+
# @param w [Numeric] width of new image
|
2833
|
+
# @param h [Numeric] height of new image
|
2834
|
+
# @param format [RGB, RGBA] image format
|
2835
|
+
#
|
2836
|
+
# @return [Image] new image
|
2837
|
+
#
|
2838
|
+
def createImage(w, h, format = RGBA)
|
2839
|
+
colorspace = {RGB => Rays::RGB, RGBA => Rays::RGBA}[format]
|
2840
|
+
raise ArgumentError, "Unknown image format" unless colorspace
|
2841
|
+
Image.new Rays::Image.new(w, h, colorspace).paint {background 0, 0}
|
2842
|
+
end
|
2843
|
+
|
2719
2844
|
# Creates a camera object as a video input device.
|
2720
2845
|
#
|
2721
2846
|
# @return [Capture] camera object
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubysketch'
|
2
|
+
|
3
|
+
|
4
|
+
def (RubySketch::GLSL).run(
|
5
|
+
shader_source,
|
6
|
+
title: 'RubySketch',
|
7
|
+
width: 500, height: 500)
|
8
|
+
w = RubySketch::Window.new(title: title, w: width, h: height) {start}
|
9
|
+
RubySketch::GLSL::Context.new w, shader_source
|
10
|
+
at_exit {RubySketch::App.new {w.show}.start unless $!}
|
11
|
+
end
|
data/rubysketch.gemspec
CHANGED
@@ -28,7 +28,9 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.platform = Gem::Platform::RUBY
|
29
29
|
s.required_ruby_version = '>= 2.6.0'
|
30
30
|
|
31
|
-
s.add_runtime_dependency 'reflexion', '~> 0.1.
|
31
|
+
s.add_runtime_dependency 'reflexion', '~> 0.1.28'
|
32
|
+
|
33
|
+
s.add_development_dependency 'yard'
|
32
34
|
|
33
35
|
s.files = `git ls-files`.split $/
|
34
36
|
s.test_files = s.files.grep %r{^(test|spec|features)/}
|
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.3.
|
4
|
+
version: 0.3.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xordog
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reflexion
|
@@ -16,14 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1.
|
19
|
+
version: 0.1.28
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1.
|
26
|
+
version: 0.1.28
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: yard
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: Creative Coding Framework have API compatible to Processing API or p5.js.
|
28
42
|
email: xordog@gmail.com
|
29
43
|
executables: []
|
@@ -49,6 +63,7 @@ files:
|
|
49
63
|
- examples/hello.rb
|
50
64
|
- examples/image.rb
|
51
65
|
- examples/shapes.rb
|
66
|
+
- lib/rubysketch-glsl.rb
|
52
67
|
- lib/rubysketch-processing.rb
|
53
68
|
- lib/rubysketch.rb
|
54
69
|
- lib/rubysketch/app.rb
|
@@ -80,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
95
|
- !ruby/object:Gem::Version
|
81
96
|
version: '0'
|
82
97
|
requirements: []
|
83
|
-
rubygems_version: 3.
|
98
|
+
rubygems_version: 3.2.33
|
84
99
|
signing_key:
|
85
100
|
specification_version: 4
|
86
101
|
summary: Processing like Creative Coding Framework.
|