nyle 0.7.2 → 0.7.3
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 +13 -0
- data/lib/nyle.rb +23 -0
- data/lib/nyle/frame.rb +1 -0
- data/lib/nyle/screen.rb +28 -2
- data/lib/nyle/version.rb +1 -1
- data/samples/application/fourier_series.rb +110 -0
- data/samples/application/pendulum.rb +11 -6
- data/samples/basic/random_walk.rb +4 -3
- data/samples/basic/random_walk_trace.rb +4 -3
- data/samples/basic/random_walk_trace_fadeout.rb +4 -3
- data/samples/basic/random_walk_trace_layer.rb +72 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1ea6c2dc4893acc0c29c5670805d471eb5376086885b2180b7673745c5b5358
|
4
|
+
data.tar.gz: 150ed2bd0c2fb320bdcae3b1f158910f0aa92fb6362e7443dabf6d745510bd57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1995964a2ddc2e9bed684cb42e40014d11856fd3e419aeec9a742c3f65fc1ee529f9eae24a9369994c1f49871942fa5cddad18e22ba8b6e0d3b50b623099a61
|
7
|
+
data.tar.gz: a35c20b4e7caeb0d23778a5f4adaf78e379c85bd75c706cb50a6312c7d26a171fe149dc92dadf8fc7070e4937f796959d1b7a21cb510d4bed250c73e996d2cfb
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
### 0.7.3 (2019/05/26)
|
2
|
+
#### New features
|
3
|
+
* add `Nyle.layer` method
|
4
|
+
|
5
|
+
#### Bug fixes, etc.
|
6
|
+
* adjust `Nyle.draw_text`
|
7
|
+
|
8
|
+
#### Samples
|
9
|
+
* add `random_walk_trace_layer.rb`
|
10
|
+
* add `fourier_series.rb`
|
11
|
+
* adjust `pendulum.rb` to use `Nyle.layer`
|
12
|
+
|
13
|
+
|
1
14
|
### 0.7.2 (2019/04/14)
|
2
15
|
#### Bug fixes, etc.
|
3
16
|
* adjust color names due to update `rcairo 1.16.3`
|
data/lib/nyle.rb
CHANGED
@@ -171,6 +171,10 @@ module Nyle
|
|
171
171
|
private def _clear_running_time
|
172
172
|
@__running_time = 0
|
173
173
|
end
|
174
|
+
|
175
|
+
private def _clear_layer
|
176
|
+
Screen::Layer.clear
|
177
|
+
end
|
174
178
|
end
|
175
179
|
|
176
180
|
|
@@ -297,6 +301,7 @@ module Nyle
|
|
297
301
|
delta = (Nyle.module_eval{ @__os } == :mac ? size * (72.0 / 96.0) : size)
|
298
302
|
cr.move_to(x, y - delta) # Why :mac?
|
299
303
|
cr.show_pango_layout(pango_layout)
|
304
|
+
cr.new_path
|
300
305
|
end
|
301
306
|
end
|
302
307
|
|
@@ -405,6 +410,24 @@ module Nyle
|
|
405
410
|
cr.scale(sx, sy)
|
406
411
|
end
|
407
412
|
|
413
|
+
module_function def layer(id = :__)
|
414
|
+
if block_given?
|
415
|
+
cr = Nyle.cr
|
416
|
+
layer = Screen::Layer.create(id, Nyle.w, Nyle.h)
|
417
|
+
Cairo::Context.new(layer) do |cr_layer|
|
418
|
+
Nyle.module_eval {
|
419
|
+
_set_cr(cr_layer)
|
420
|
+
}
|
421
|
+
yield(layer)
|
422
|
+
end
|
423
|
+
Nyle.module_eval {
|
424
|
+
_set_cr(cr)
|
425
|
+
}
|
426
|
+
Nyle.cr.set_source(layer, 0, 0)
|
427
|
+
Nyle.cr.paint
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
408
431
|
module_function def create_screen(*args)
|
409
432
|
Nyle::Screen.new(*args)
|
410
433
|
end
|
data/lib/nyle/frame.rb
CHANGED
data/lib/nyle/screen.rb
CHANGED
@@ -13,6 +13,30 @@ module Nyle
|
|
13
13
|
|
14
14
|
# Screen
|
15
15
|
class Screen < Gtk::DrawingArea
|
16
|
+
class Layer < Cairo::ImageSurface
|
17
|
+
@@layers = {}
|
18
|
+
private_class_method :new # refuse to make an instance using 'new' from outside, so 'create' instead.
|
19
|
+
def initialize(w, h)
|
20
|
+
super(w, h)
|
21
|
+
end
|
22
|
+
def self.create(id, w, h)
|
23
|
+
#puts "#{id} #{w} #{h}"
|
24
|
+
if @@layers.has_key?(id)
|
25
|
+
@@layers[id] # existing instance
|
26
|
+
else
|
27
|
+
layer = new(w, h)
|
28
|
+
@@layers[id] = layer
|
29
|
+
layer # new instance
|
30
|
+
end
|
31
|
+
end
|
32
|
+
def self.clear
|
33
|
+
@@layers.clear
|
34
|
+
end
|
35
|
+
def self.status
|
36
|
+
p @@layers
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
16
40
|
attr_reader :width, :height, :status
|
17
41
|
def initialize(width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT, bgcolor: :WHITE, trace: false)
|
18
42
|
super()
|
@@ -80,8 +104,10 @@ module Nyle
|
|
80
104
|
|
81
105
|
# Clear
|
82
106
|
def clear_screen
|
83
|
-
Nyle.
|
84
|
-
|
107
|
+
Nyle.save do
|
108
|
+
Nyle.cr.set_operator(Cairo::Operator::CLEAR)
|
109
|
+
Nyle.cr.paint
|
110
|
+
end
|
85
111
|
end
|
86
112
|
|
87
113
|
# When single screen, create frame to show self
|
data/lib/nyle/version.rb
CHANGED
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'nyle'
|
2
|
+
|
3
|
+
|
4
|
+
class Slider
|
5
|
+
def initialize(low, high, default)
|
6
|
+
@low = low
|
7
|
+
@high = high
|
8
|
+
@val = default
|
9
|
+
@label = ""
|
10
|
+
end
|
11
|
+
|
12
|
+
def position(x, y)
|
13
|
+
@x = x
|
14
|
+
@y = y
|
15
|
+
@rectx = @x + _map(@val, @low, @high, 0, 120)
|
16
|
+
@recty = @y - 10
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def set_label(label)
|
21
|
+
@label = label
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def value
|
26
|
+
Nyle.draw_line(@x, @y, @x + 120, @y, {color: :GRAY, weight: 4})
|
27
|
+
|
28
|
+
if Nyle.mouse_down?(MOUSE_L) and _dist(Nyle.mouse_x, Nyle.mouse_y, @rectx, @recty) < 20
|
29
|
+
@rectx = Nyle.mouse_x - 5
|
30
|
+
end
|
31
|
+
@rectx = _constrain(@rectx, (@x..@x + 120))
|
32
|
+
|
33
|
+
Nyle.draw_rect(@rectx, @recty, 10, 20, {color: :GRAY, fill: true})
|
34
|
+
Nyle.draw_rect(@rectx, @recty, 10, 20, {color: :BLACK, weight: 1})
|
35
|
+
|
36
|
+
@val = _map(@rectx, @x, @x + 120, @low, @high)
|
37
|
+
Nyle.draw_text(@rectx, @recty - 5, "#{@val.to_i}", {size: 12})
|
38
|
+
Nyle.draw_text(@x + 135, @y + 5, @label, {size: 12})
|
39
|
+
|
40
|
+
return @val
|
41
|
+
end
|
42
|
+
|
43
|
+
private def _dist(x1, y1, x2, y2)
|
44
|
+
diffx = x1 - x2
|
45
|
+
diffy = y1 - y2
|
46
|
+
Math.sqrt(diffx * diffx + diffy * diffy)
|
47
|
+
end
|
48
|
+
|
49
|
+
private def _map(v, s1, e1, s2, e2)
|
50
|
+
v = v.to_f if v.integer?
|
51
|
+
(v - s1) / (e1 - s1) * (e2 - s2) + s2
|
52
|
+
end
|
53
|
+
|
54
|
+
private def _constrain(x, rang)
|
55
|
+
minx = rang.min
|
56
|
+
maxx = rang.max
|
57
|
+
x = minx if x <= minx
|
58
|
+
x = maxx if x >= maxx
|
59
|
+
x
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
class Screen < Nyle::Screen
|
65
|
+
def initialize
|
66
|
+
super(600, 400, {bgcolor: :WHITE})
|
67
|
+
@time = 0
|
68
|
+
@wave = []
|
69
|
+
@points = []
|
70
|
+
@slider = Slider.new(1, 20, 5).position(70, 50).set_label('N')
|
71
|
+
end
|
72
|
+
|
73
|
+
def draw
|
74
|
+
@n = @slider.value.to_i
|
75
|
+
|
76
|
+
Nyle.translate(150, 200)
|
77
|
+
x = 0
|
78
|
+
y = 0
|
79
|
+
@n.times do |i|
|
80
|
+
prevx = x
|
81
|
+
prevy = y
|
82
|
+
m = i * 2 + 1
|
83
|
+
radius = 75 * (4 / (m * Math::PI))
|
84
|
+
x += radius * Math.cos(m * @time)
|
85
|
+
y += radius * Math.sin(m * @time)
|
86
|
+
|
87
|
+
Nyle.draw_circle(prevx, prevy, radius, {color: :GRAY})
|
88
|
+
Nyle.draw_line(prevx, prevy, x, y, {color: :BLACK})
|
89
|
+
end
|
90
|
+
|
91
|
+
@wave.unshift(y)
|
92
|
+
Nyle.translate(200, 0)
|
93
|
+
Nyle.draw_circle(x - 200, y, 2, {color: :RED})
|
94
|
+
Nyle.draw_line(x - 200, y, 0, @wave[0], {color: :RED})
|
95
|
+
(0...@wave.size).each do |i|
|
96
|
+
@points << [i, @wave[i]]
|
97
|
+
end
|
98
|
+
Nyle.draw_shape(@points, {color: :BLUE})
|
99
|
+
@points.clear
|
100
|
+
|
101
|
+
@time += 0.05
|
102
|
+
@wave.pop if @wave.size > 250
|
103
|
+
|
104
|
+
Nyle.quit if Nyle.key_press?(KEY_Escape)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
Screen.new.show_all
|
109
|
+
Nyle.main
|
110
|
+
|
@@ -169,7 +169,8 @@ class Screen < Nyle::Screen
|
|
169
169
|
@a2_v = 0
|
170
170
|
@a1 = Math::PI / 2
|
171
171
|
@a2 = Math::PI / 2
|
172
|
-
@
|
172
|
+
@last_x = nil
|
173
|
+
@last_y = nil
|
173
174
|
end
|
174
175
|
|
175
176
|
def update
|
@@ -201,12 +202,14 @@ class Screen < Nyle::Screen
|
|
201
202
|
x2 = x1 + @L2 * Math.sin(@a2)
|
202
203
|
y2 = y1 + @L2 * Math.cos(@a2)
|
203
204
|
|
204
|
-
Nyle.
|
205
|
-
|
206
|
-
|
205
|
+
Nyle.layer do
|
206
|
+
Nyle.save do
|
207
|
+
Nyle.translate(@cx, @cy)
|
208
|
+
Nyle.draw_line(@last_x, @last_y, x2, y2, {weight: 1, color: :BLUE}) if @last_x and @last_y
|
209
|
+
end
|
207
210
|
end
|
208
|
-
@
|
209
|
-
@
|
211
|
+
@last_x = x2
|
212
|
+
@last_y = y2
|
210
213
|
|
211
214
|
Nyle.save do
|
212
215
|
Nyle.translate(@cx, @cy)
|
@@ -218,6 +221,8 @@ class Screen < Nyle::Screen
|
|
218
221
|
Nyle.draw_line(x1, y1, x2, y2)
|
219
222
|
Nyle.draw_circle(x2, y2, @M2, {color: :BLACK, fill: true})
|
220
223
|
end
|
224
|
+
|
225
|
+
Nyle.quit if Nyle.key_press?(KEY_Escape)
|
221
226
|
end
|
222
227
|
end
|
223
228
|
|
@@ -2,12 +2,13 @@ require 'nyle'
|
|
2
2
|
|
3
3
|
class Walker
|
4
4
|
RADIUS = 4
|
5
|
-
def initialize(max_x, max_y)
|
5
|
+
def initialize(max_x, max_y, color = :YELLOW)
|
6
6
|
@max_x = max_x
|
7
7
|
@max_y = max_y
|
8
8
|
@x = max_x / 2.0
|
9
9
|
@y = max_y / 2.0
|
10
10
|
@step = 5
|
11
|
+
@color = color
|
11
12
|
end
|
12
13
|
|
13
14
|
# Randomly move up, down, left, right
|
@@ -25,7 +26,7 @@ class Walker
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def draw
|
28
|
-
Nyle.draw_circle(@x, @y, RADIUS, {color:
|
29
|
+
Nyle.draw_circle(@x, @y, RADIUS, {color: @color, fill: true})
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
@@ -33,7 +34,7 @@ end
|
|
33
34
|
class Screen < Nyle::Screen
|
34
35
|
|
35
36
|
def initialize
|
36
|
-
super(
|
37
|
+
super(320, 240, {bgcolor: :BLACK})
|
37
38
|
@walker = Walker.new(@width, @height)
|
38
39
|
end
|
39
40
|
|
@@ -2,12 +2,13 @@ require 'nyle'
|
|
2
2
|
|
3
3
|
class Walker
|
4
4
|
RADIUS = 4
|
5
|
-
def initialize(max_x, max_y)
|
5
|
+
def initialize(max_x, max_y, color = :YELLOW)
|
6
6
|
@max_x = max_x
|
7
7
|
@max_y = max_y
|
8
8
|
@x = max_x / 2.0
|
9
9
|
@y = max_y / 2.0
|
10
10
|
@step = 5
|
11
|
+
@color = color
|
11
12
|
end
|
12
13
|
|
13
14
|
# Randomly move up, down, left, right
|
@@ -25,7 +26,7 @@ class Walker
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def draw
|
28
|
-
Nyle.draw_circle(@x, @y, RADIUS, {color:
|
29
|
+
Nyle.draw_circle(@x, @y, RADIUS, {color: @color, fill: true})
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
@@ -33,7 +34,7 @@ end
|
|
33
34
|
class Screen < Nyle::Screen
|
34
35
|
|
35
36
|
def initialize
|
36
|
-
super(
|
37
|
+
super(320, 240, {bgcolor: :BLACK, trace: true})
|
37
38
|
@walker = Walker.new(@width, @height)
|
38
39
|
end
|
39
40
|
|
@@ -2,12 +2,13 @@ require 'nyle'
|
|
2
2
|
|
3
3
|
class Walker
|
4
4
|
RADIUS = 4
|
5
|
-
def initialize(max_x, max_y)
|
5
|
+
def initialize(max_x, max_y, color = :YELLOW)
|
6
6
|
@max_x = max_x
|
7
7
|
@max_y = max_y
|
8
8
|
@x = max_x / 2.0
|
9
9
|
@y = max_y / 2.0
|
10
10
|
@step = 5
|
11
|
+
@color = color
|
11
12
|
end
|
12
13
|
|
13
14
|
# Randomly move up, down, left, right
|
@@ -25,7 +26,7 @@ class Walker
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def draw
|
28
|
-
Nyle.draw_circle(@x, @y, RADIUS, {color:
|
29
|
+
Nyle.draw_circle(@x, @y, RADIUS, {color: @color, fill: true})
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
@@ -33,7 +34,7 @@ end
|
|
33
34
|
class Screen < Nyle::Screen
|
34
35
|
|
35
36
|
def initialize
|
36
|
-
super(
|
37
|
+
super(320, 240, {bgcolor: :BLACK, trace: true})
|
37
38
|
@walker = Walker.new(@width, @height)
|
38
39
|
end
|
39
40
|
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'nyle'
|
2
|
+
|
3
|
+
class Walker
|
4
|
+
RADIUS = 4
|
5
|
+
def initialize(max_x, max_y, color = :YELLOW)
|
6
|
+
@max_x = max_x
|
7
|
+
@max_y = max_y
|
8
|
+
@x = max_x / 2.0
|
9
|
+
@y = max_y / 2.0
|
10
|
+
@step = 5
|
11
|
+
@color = color
|
12
|
+
end
|
13
|
+
|
14
|
+
# Randomly move up, down, left, right
|
15
|
+
def move
|
16
|
+
stepx = rand(3) - 1
|
17
|
+
stepy = rand(3) - 1
|
18
|
+
@x += stepx * @step
|
19
|
+
@y += stepy * @step
|
20
|
+
|
21
|
+
# x,y limitter
|
22
|
+
@x = 0 if @x < 0
|
23
|
+
@x = @max_x if @x > @max_x
|
24
|
+
@y = 0 if @y < 0
|
25
|
+
@y = @max_y if @y > @max_y
|
26
|
+
end
|
27
|
+
|
28
|
+
def draw
|
29
|
+
Nyle.draw_circle(@x, @y, RADIUS, {color: @color, fill: true})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
class Screen < Nyle::Screen
|
35
|
+
|
36
|
+
def initialize
|
37
|
+
super(320, 240, {bgcolor: :BLACK, trace: false})
|
38
|
+
@walker1 = Walker.new(@width, @height, :YELLOW)
|
39
|
+
@walker2 = Walker.new(@width, @height, :GREEN)
|
40
|
+
@walker3 = Walker.new(@width, @height, :BLUE)
|
41
|
+
@walker4 = Walker.new(@width, @height, :RED)
|
42
|
+
end
|
43
|
+
|
44
|
+
def draw
|
45
|
+
Nyle.layer(:L1) do
|
46
|
+
@walker1.draw
|
47
|
+
Nyle.draw_rect(0, 0, @width, @height, {fill: true, color: :BLACK, a: 0.02})
|
48
|
+
end
|
49
|
+
Nyle.layer(:L2) do
|
50
|
+
@walker2.draw
|
51
|
+
end
|
52
|
+
Nyle.layer(:L3) do
|
53
|
+
Nyle.clear
|
54
|
+
@walker3.draw
|
55
|
+
end
|
56
|
+
@walker4.draw
|
57
|
+
end
|
58
|
+
|
59
|
+
def update
|
60
|
+
@walker1.move
|
61
|
+
@walker2.move
|
62
|
+
@walker3.move
|
63
|
+
@walker4.move
|
64
|
+
Nyle.quit if Nyle.key_press?(KEY_Escape)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
Screen.new.show_all({interval: 30})
|
71
|
+
Nyle.main
|
72
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nyle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koki Kitamura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gtk3
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- samples/application/clock.rb
|
53
53
|
- samples/application/falling.rb
|
54
54
|
- samples/application/flight.rb
|
55
|
+
- samples/application/fourier_series.rb
|
55
56
|
- samples/application/pendulum.rb
|
56
57
|
- samples/application/sketch.rb
|
57
58
|
- samples/application/sugar.rb
|
@@ -71,6 +72,7 @@ files:
|
|
71
72
|
- samples/basic/random_walk.rb
|
72
73
|
- samples/basic/random_walk_trace.rb
|
73
74
|
- samples/basic/random_walk_trace_fadeout.rb
|
75
|
+
- samples/basic/random_walk_trace_layer.rb
|
74
76
|
- samples/basic/rotation.rb
|
75
77
|
- samples/image/n_b_crocodile.png
|
76
78
|
- samples/image/n_c_mogura.png
|