rubysketch 0.5.30 → 0.5.31

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbbb972756576a0aa6c5dfc70ba1682776dd0f95c1bc0d0ec20a06dce0e1bd01
4
- data.tar.gz: 7ce985bbaee1c81f3b20dea0392cd2b5459af3e520eb8552840306d32ba03adb
3
+ metadata.gz: ee4bec833e545d64ac7822c59d7b52e92a507ac23d909fd6143f15dace1ed8c4
4
+ data.tar.gz: 8151adda147364200efe13a96b2fce82b00c01fa25cb84c69f4de6ba5d9a6a4d
5
5
  SHA512:
6
- metadata.gz: f0f53b5fb3464b8cc6e0f9ff3b3c4d76d465816a5c6414b99a3d5724ca9c20411c37091f8a2b9ed850e05b863c8ef958ed7dceaf8257189dbdb1df125033d7fa
7
- data.tar.gz: 1e9696d6e23b5333f4c784abd7847fd2ebb00e4dd210945c4f92b251eed80f7485cc1694fd1d09003c9a7cfe9e8ff1a95275cca6cb928d53814c65cdeb184781
6
+ metadata.gz: d85c90842181d311cee151604fc1c38edc6d5b2d1caba4d3c9f206f512d98b5f93ced450f8ec6aaa760781bdfc61c8d92644cdc2f2b4811c63b7f81f70091ca2
7
+ data.tar.gz: 94978e5eadf6fbd607c4762adec4049df1930123be74c5cee46dfb582c0ec76f907f8a3e214cc162d779a9b96bc12a4904cd054f60ecae921db3abdb57a5ff0c
data/ChangeLog.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # rubysketch ChangeLog
2
2
 
3
3
 
4
+ ## [v0.5.31] - 2023-10-25
5
+
6
+ - Add toon.rb
7
+
8
+
4
9
  ## [v0.5.30] - 2023-08-24
5
10
 
6
11
  - Fix failed test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.30
1
+ 0.5.31
data/examples/toon.rb ADDED
@@ -0,0 +1,181 @@
1
+ %w[xot rucy beeps rays reflex processing rubysketch]
2
+ .map {|s| File.expand_path "../../#{s}/lib", __dir__}
3
+ .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
4
+
5
+ require 'rubysketch'
6
+ using RubySketch
7
+
8
+
9
+ class Canvas < Sprite
10
+
11
+ def initialize(width, height, scale: 1)
12
+ super 0, 0, width, height
13
+
14
+ @width, @height, @scale = width, height, scale
15
+ @images, @frame = [], 0
16
+
17
+ brushSize 1
18
+ brushColor 0, 0, 0, 255
19
+
20
+ self.draw do
21
+ drawImage self.image, 0, 0, self.width * self.scale, self.height * self.scale
22
+ end
23
+
24
+ self.mousePressed {brushStarted self.mouseX / self.scale, self.mouseY / self.scale}
25
+ self.mouseReleased {brushEnded self.mouseX / self.scale, self.mouseY / self.scale}
26
+ self.mouseDragged {brushMoved self.mouseX / self.scale, self.mouseY / self.scale}
27
+ end
28
+
29
+ attr_reader :width, :height, :scale
30
+
31
+ def image()
32
+ @images.insert @frame, createImage(width, height) if @frame >= @images.size
33
+ @images[@frame]
34
+ end
35
+
36
+ def play()
37
+ setInterval 0.2, id: :play do
38
+ @frame += 1
39
+ @frame = 0 if @frame >= @images.size
40
+ end
41
+ end
42
+
43
+ def stop()
44
+ clearInterval :play
45
+ end
46
+
47
+ def nextFrame()
48
+ @frame += 1
49
+ end
50
+
51
+ def prevFrame()
52
+ @frame -= 1
53
+ @frame = 0 if @frame < 0
54
+ end
55
+
56
+ def brushSize(size)
57
+ @brushSize = size
58
+ end
59
+
60
+ def brushColor(r, g, b, a = 255)
61
+ @brushColor = [r, g, b, a]
62
+ end
63
+
64
+ def drawPoint(x, y)
65
+ image.beginDraw do |g|
66
+ g.noFill
67
+ g.strokeWeight @brushSize
68
+ g.stroke *@brushColor
69
+ g.point x, y
70
+ end
71
+ end
72
+
73
+ def drawLine(x1, y1, x2, y2)
74
+ image.beginDraw do |g|
75
+ g.noFill
76
+ g.strokeWeight @brushSize
77
+ g.stroke *@brushColor
78
+ g.line x1, y1, x2, y2
79
+ end
80
+ end
81
+
82
+ def brushStarted(x, y)
83
+ drawPoint x, y
84
+ @prevPoint = [x, y]
85
+ end
86
+
87
+ def brushEnded(x, y)
88
+ @prevPoint = nil
89
+ end
90
+
91
+ def brushMoved(x, y)
92
+ return unless @prevPoint
93
+ drawLine *@prevPoint, x, y
94
+ @prevPoint = [x, y]
95
+ end
96
+
97
+ private
98
+
99
+ def createImage(w, h)
100
+ createGraphics(w, h).tap do |g|
101
+ g.beginDraw do
102
+ g.background 255
103
+ end
104
+ end
105
+ end
106
+
107
+ end# Canvas
108
+
109
+
110
+ class Button < Sprite
111
+
112
+ def initialize(label, x = 0, y = 0, w = 100, h = 44, rgb: [200, 200, 200], &block)
113
+ super x, y, w, h
114
+
115
+ draw do
116
+ round, offset = 12, 8
117
+ ww, hh = self.w, self.h - offset
118
+ yy = mousePressed ? 6 : 0
119
+
120
+ fill *rgb.map {_1 - 32}
121
+ rect 0, offset, ww, hh, round
122
+
123
+ fill *rgb
124
+ rect 0, yy, ww, hh, round
125
+
126
+ textAlign CENTER, CENTER
127
+ fill 0
128
+ text label, 0, yy, ww, hh
129
+ end
130
+
131
+ mouseClicked do
132
+ block.call
133
+ end
134
+ end
135
+
136
+ end# Button
137
+
138
+
139
+ class App
140
+
141
+ MARGIN = 10
142
+
143
+ def initialize()
144
+ setTitle 'Toon!'
145
+ size 800, 600
146
+ noStroke
147
+
148
+ @canvas = Canvas.new 160, 120, scale: 3
149
+ @buttons = [
150
+ Button.new('Play', rgb: [240, 180, 180]) {@canvas.play},
151
+ Button.new('Stop', rgb: [240, 180, 180]) {@canvas.stop},
152
+ Button.new('Next', rgb: [180, 240, 180]) {@canvas.nextFrame},
153
+ Button.new('Previous', rgb: [180, 240, 180]) {@canvas.prevFrame},
154
+ Button.new('Brush 1px', rgb: [180, 180, 240]) {@canvas.brushSize 1},
155
+ Button.new('Brush 3px', rgb: [180, 180, 240]) {@canvas.brushSize 3},
156
+ Button.new('Brush 5px', rgb: [180, 180, 240]) {@canvas.brushSize 5},
157
+ ]
158
+ @sprites = [@canvas, *@buttons]
159
+ @sprites.each {addSprite _1}
160
+ end
161
+
162
+ def draw()
163
+ background 100
164
+ sprite *@sprites
165
+ end
166
+
167
+ def resized()
168
+ @buttons.first.pos = [MARGIN, MARGIN]
169
+ @buttons.each_cons(2) {_2.pos = [MARGIN, _1.bottom + MARGIN]}
170
+
171
+ @canvas.pos = [@buttons.first.right + MARGIN, MARGIN]
172
+ @canvas.right = windowWidth
173
+ @canvas.bottom = windowHeight
174
+ end
175
+
176
+ end# App
177
+
178
+
179
+ setup {$app = App.new}
180
+ draw {$app.draw}
181
+ windowResized {$app.resized if $app}
data/rubysketch.gemspec CHANGED
@@ -26,11 +26,11 @@ Gem::Specification.new do |s|
26
26
  s.required_ruby_version = '>= 3.0.0'
27
27
 
28
28
  s.add_runtime_dependency 'xot', '~> 0.1.39'
29
- s.add_runtime_dependency 'rucy', '~> 0.1.39'
30
- s.add_runtime_dependency 'beeps', '~> 0.1.41'
31
- s.add_runtime_dependency 'rays', '~> 0.1.43'
32
- s.add_runtime_dependency 'reflexion', '~> 0.1.51'
33
- s.add_runtime_dependency 'processing', '~> 0.5.27'
29
+ s.add_runtime_dependency 'rucy', '~> 0.1.40'
30
+ s.add_runtime_dependency 'beeps', '~> 0.1.42'
31
+ s.add_runtime_dependency 'rays', '~> 0.1.44'
32
+ s.add_runtime_dependency 'reflexion', '~> 0.1.52'
33
+ s.add_runtime_dependency 'processing', '~> 0.5.28'
34
34
 
35
35
  s.add_development_dependency 'rake'
36
36
  s.add_development_dependency 'test-unit'
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.5.30
4
+ version: 0.5.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-23 00:00:00.000000000 Z
11
+ date: 2023-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xot
@@ -30,70 +30,70 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.39
33
+ version: 0.1.40
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.1.39
40
+ version: 0.1.40
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: beeps
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.1.41
47
+ version: 0.1.42
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.1.41
54
+ version: 0.1.42
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rays
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.1.43
61
+ version: 0.1.44
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.1.43
68
+ version: 0.1.44
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: reflexion
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.1.51
75
+ version: 0.1.52
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.1.51
82
+ version: 0.1.52
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: processing
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.5.27
89
+ version: 0.5.28
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.5.27
96
+ version: 0.5.28
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -158,6 +158,7 @@ files:
158
158
  - examples/hello.rb
159
159
  - examples/physics.rb
160
160
  - examples/sprite.rb
161
+ - examples/toon.rb
161
162
  - lib/rubysketch.rb
162
163
  - lib/rubysketch/all.rb
163
164
  - lib/rubysketch/context.rb