rubysketch 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +41 -0
- data/LICENSE +21 -0
- data/README.md +3 -0
- data/Rakefile +24 -0
- data/VERSION +1 -0
- data/examples/clock.rb +57 -0
- data/examples/glsl.rb +17 -0
- data/examples/hello.rb +12 -0
- data/examples/image.rb +13 -0
- data/examples/shapes.rb +121 -0
- data/lib/rubysketch-processing.rb +15 -0
- data/lib/rubysketch.rb +10 -0
- data/lib/rubysketch/glsl.rb +31 -0
- data/lib/rubysketch/module.rb +23 -0
- data/lib/rubysketch/processing.rb +1581 -0
- data/lib/rubysketch/window.rb +130 -0
- data/rubysketch.gemspec +44 -0
- metadata +145 -0
@@ -0,0 +1,130 @@
|
|
1
|
+
module RubySketch
|
2
|
+
|
3
|
+
|
4
|
+
class Window < Reflex::Window
|
5
|
+
|
6
|
+
attr_accessor :setup, :update, :draw, :before_draw, :after_draw, :resize,
|
7
|
+
:pointer_down, :pointer_up, :pointer_move, :pointer_drag,
|
8
|
+
:key, :motion
|
9
|
+
|
10
|
+
attr_accessor :auto_resize
|
11
|
+
|
12
|
+
attr_reader :canvas, :canvas_painter
|
13
|
+
|
14
|
+
def initialize (width = 500, height = 500, *args, &block)
|
15
|
+
@events = []
|
16
|
+
@auto_resize = true
|
17
|
+
@error = nil
|
18
|
+
|
19
|
+
reset_canvas 1, 1
|
20
|
+
|
21
|
+
super *args, size: [width, height], &block
|
22
|
+
end
|
23
|
+
|
24
|
+
def start (&block)
|
25
|
+
draw_canvas do
|
26
|
+
block.call if block
|
27
|
+
on_setup
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def event ()
|
32
|
+
@events.last
|
33
|
+
end
|
34
|
+
|
35
|
+
def on_setup ()
|
36
|
+
call_block @setup, nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def on_update (e)
|
40
|
+
call_block @update, e
|
41
|
+
redraw
|
42
|
+
end
|
43
|
+
|
44
|
+
def on_draw (e)
|
45
|
+
draw_canvas {call_block @draw, e} if @draw
|
46
|
+
e.painter.image @canvas
|
47
|
+
end
|
48
|
+
|
49
|
+
def on_key (e)
|
50
|
+
draw_canvas {call_block @key, e} if @key
|
51
|
+
end
|
52
|
+
|
53
|
+
def on_pointer (e)
|
54
|
+
block = case e.type
|
55
|
+
when :down then @pointer_down
|
56
|
+
when :up then @pointer_up
|
57
|
+
when :move then e.drag? ? @pointer_drag : @pointer_move
|
58
|
+
end
|
59
|
+
draw_canvas {call_block block, e} if block
|
60
|
+
end
|
61
|
+
|
62
|
+
def on_motion (e)
|
63
|
+
draw_canvas {call_block @motion, e} if @motion
|
64
|
+
end
|
65
|
+
|
66
|
+
def on_resize (e)
|
67
|
+
reset_canvas e.width, e.height if @auto_resize
|
68
|
+
draw_canvas {call_block @resize, e} if @resize
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def reset_canvas (width, height)
|
74
|
+
return if width * height == 0
|
75
|
+
return if width == @canvas&.width && height == @canvas&.height
|
76
|
+
|
77
|
+
old_canvas = @canvas
|
78
|
+
old_painter = @canvas_painter
|
79
|
+
|
80
|
+
cs = old_canvas&.color_space || Rays::RGBA
|
81
|
+
@canvas = Rays::Image.new width, height, cs, painter.pixel_density
|
82
|
+
@canvas_painter = @canvas.painter
|
83
|
+
|
84
|
+
if old_canvas
|
85
|
+
@canvas_painter.paint {image old_canvas}
|
86
|
+
copy_painter_attributes old_painter, @canvas_painter
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def copy_painter_attributes (from, to)
|
91
|
+
to.fill = from.fill
|
92
|
+
to.stroke = from.stroke
|
93
|
+
to.stroke_width = from.stroke_width
|
94
|
+
to.stroke_cap = from.stroke_cap
|
95
|
+
to.stroke_join = from.stroke_join
|
96
|
+
to.miter_limit = from.miter_limit
|
97
|
+
to.font = from.font
|
98
|
+
end
|
99
|
+
|
100
|
+
def draw_canvas (&block)
|
101
|
+
begin_draw
|
102
|
+
block.call
|
103
|
+
ensure
|
104
|
+
end_draw
|
105
|
+
end
|
106
|
+
|
107
|
+
def begin_draw ()
|
108
|
+
@canvas_painter.__send__ :begin_paint
|
109
|
+
@before_draw&.call
|
110
|
+
end
|
111
|
+
|
112
|
+
def end_draw ()
|
113
|
+
@after_draw&.call
|
114
|
+
@canvas_painter.__send__ :end_paint
|
115
|
+
end
|
116
|
+
|
117
|
+
def call_block (block, event, *args)
|
118
|
+
@events.push event
|
119
|
+
block.call event, *args if block && !@error
|
120
|
+
rescue Exception => e
|
121
|
+
@error = e
|
122
|
+
$stderr.puts e.full_message
|
123
|
+
ensure
|
124
|
+
@events.pop
|
125
|
+
end
|
126
|
+
|
127
|
+
end# Window
|
128
|
+
|
129
|
+
|
130
|
+
end# RubySketch
|
data/rubysketch.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
|
3
|
+
|
4
|
+
File.expand_path('lib', __dir__)
|
5
|
+
.tap {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
6
|
+
|
7
|
+
require 'rubysketch/module'
|
8
|
+
|
9
|
+
|
10
|
+
Gem::Specification.new do |s|
|
11
|
+
glob = -> *patterns do
|
12
|
+
patterns.map {|pat| Dir.glob(pat).to_a}.flatten
|
13
|
+
end
|
14
|
+
|
15
|
+
mod = RubySketch::Module
|
16
|
+
name = mod.name.downcase
|
17
|
+
rdocs = glob.call *%w[README]
|
18
|
+
|
19
|
+
s.name = name
|
20
|
+
s.summary = 'Processing like Creative Coding Framework.'
|
21
|
+
s.description = 'Creative Coding Framework have API compatible to Processing API or p5.js.'
|
22
|
+
s.version = mod.version
|
23
|
+
|
24
|
+
s.authors = %w[xordog]
|
25
|
+
s.email = 'xordog@gmail.com'
|
26
|
+
s.homepage = "https://github.com/xord/rubysketch"
|
27
|
+
|
28
|
+
s.platform = Gem::Platform::RUBY
|
29
|
+
s.required_ruby_version = '~> 2'
|
30
|
+
|
31
|
+
s.add_runtime_dependency 'yard'
|
32
|
+
s.add_runtime_dependency 'xot', '~> 0.1'
|
33
|
+
s.add_runtime_dependency 'beeps', '~> 0.1'
|
34
|
+
s.add_runtime_dependency 'rucy', '~> 0.1'
|
35
|
+
s.add_runtime_dependency 'rays', '~> 0.1'
|
36
|
+
s.add_runtime_dependency 'reflexion', '~> 0.1'
|
37
|
+
|
38
|
+
s.files = `git ls-files`.split $/
|
39
|
+
s.test_files = s.files.grep %r{^(test|spec|features)/}
|
40
|
+
s.extra_rdoc_files = rdocs.to_a
|
41
|
+
s.has_rdoc = true
|
42
|
+
|
43
|
+
s.extensions << 'Rakefile'
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubysketch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- xordog
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: yard
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: xot
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: beeps
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rucy
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rays
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: reflexion
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.1'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.1'
|
97
|
+
description: Creative Coding Framework have API compatible to Processing API or p5.js.
|
98
|
+
email: xordog@gmail.com
|
99
|
+
executables: []
|
100
|
+
extensions:
|
101
|
+
- Rakefile
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".yardopts"
|
106
|
+
- ChangeLog.md
|
107
|
+
- LICENSE
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- VERSION
|
111
|
+
- examples/clock.rb
|
112
|
+
- examples/glsl.rb
|
113
|
+
- examples/hello.rb
|
114
|
+
- examples/image.rb
|
115
|
+
- examples/shapes.rb
|
116
|
+
- lib/rubysketch-processing.rb
|
117
|
+
- lib/rubysketch.rb
|
118
|
+
- lib/rubysketch/glsl.rb
|
119
|
+
- lib/rubysketch/module.rb
|
120
|
+
- lib/rubysketch/processing.rb
|
121
|
+
- lib/rubysketch/window.rb
|
122
|
+
- rubysketch.gemspec
|
123
|
+
homepage: https://github.com/xord/rubysketch
|
124
|
+
licenses: []
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - "~>"
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '2'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubygems_version: 3.0.3
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Processing like Creative Coding Framework.
|
145
|
+
test_files: []
|