nyle 0.7.0 → 0.7.1
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 +29 -3
- data/lib/nyle.rb +54 -5
- data/lib/nyle/frame.rb +45 -12
- data/lib/nyle/screen.rb +28 -18
- data/lib/nyle/version.rb +1 -1
- data/samples/application/block.rb +1 -1
- data/samples/application/clock.rb +1 -1
- data/samples/application/falling.rb +1 -1
- data/samples/application/flight.rb +1 -1
- data/samples/application/pendulum.rb +242 -0
- data/samples/application/sketch.rb +3 -3
- data/samples/application/sugar.rb +1 -1
- data/samples/application/tree.rb +1 -1
- data/samples/basic/color_chart.rb +17 -9
- data/samples/basic/color_pixel.rb +1 -1
- data/samples/basic/draw_circle.rb +1 -1
- data/samples/basic/draw_line.rb +1 -1
- data/samples/basic/draw_rect.rb +1 -1
- data/samples/basic/draw_shape.rb +3 -3
- data/samples/basic/draw_text.rb +1 -1
- data/samples/basic/image_click.rb +1 -1
- data/samples/basic/image_rotate.rb +1 -1
- data/samples/basic/image_rpg.rb +1 -1
- data/samples/basic/keyboard.rb +1 -1
- data/samples/basic/pause.rb +34 -0
- data/samples/basic/random_walk.rb +4 -4
- data/samples/basic/random_walk_trace.rb +4 -4
- data/samples/basic/random_walk_trace_fadeout.rb +55 -0
- data/samples/basic/rotation.rb +35 -0
- data/samples/launcher.rb +1 -1
- data/samples/tutorial/tut_a10.rb +1 -1
- data/samples/tutorial/tut_a20.rb +1 -1
- data/samples/tutorial/tut_a30.rb +1 -1
- data/samples/tutorial/tut_a40.rb +1 -1
- data/samples/tutorial/tut_a45.rb +1 -1
- data/samples/tutorial/tut_a50.rb +1 -1
- data/samples/tutorial/tut_a60.rb +1 -1
- data/samples/tutorial/tut_a70.rb +1 -1
- data/samples/tutorial/tut_b10.rb +1 -1
- data/samples/tutorial/tut_b20.rb +1 -1
- data/samples/tutorial/tut_b30.rb +1 -1
- data/samples/tutorial/tut_b40.rb +1 -1
- metadata +7 -5
- data/samples/tips/.gitkeep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98fb894b0df670d4987b952d424e3a9d3d0279fb97e4f074a23db75318b7e26a
|
4
|
+
data.tar.gz: cc983b74f64805584372049038945e24c658d3a645e8473517bbcc896fb68ba0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 983b3c340b11617cfb9e8d636fda9ccc1a36039bdf572bc6e7fe250aff722a2d283309ca23f6b54f3ba4fde01e8aa04227a2b27808d8fefc535a5268a2456019
|
7
|
+
data.tar.gz: 3e8ec70297a649d70274784b86c27760c5cee3fcc2e61eb9b2653a4b90099cf2c4b44056a517235da6ffbc289daeeb9b4bf791a60111d8c30e0af91283fe9638
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
### 0.7.1 (2019/03/30)
|
2
|
+
#### New features
|
3
|
+
* add `Nyle.clear` method
|
4
|
+
* add `Nyle.running_time` method
|
5
|
+
* add `Nyle.main` method
|
6
|
+
* add `Nyle.create_screen` method
|
7
|
+
* add `Nyle.create_frame` method
|
8
|
+
* add `Nyle::Screen#start` method
|
9
|
+
* set alias `w` to `screen_width`
|
10
|
+
* set alias `h` to `screen_height`
|
11
|
+
* enhance `Nyle::Screen#show_all` method to be able to specify the interval time
|
12
|
+
|
13
|
+
#### Bug fixes, etc.
|
14
|
+
* adjust `draw_shape` method about `cap` option
|
15
|
+
|
16
|
+
#### Samples
|
17
|
+
* add `pause.rb`
|
18
|
+
* add `random_walk_trace_fadeout.rb`
|
19
|
+
* add `rotation.rb`
|
20
|
+
* add `double_pendulum.rb`
|
21
|
+
* adjust `color_chart.rb`
|
22
|
+
* adjust `random_walk.rb`
|
23
|
+
* adjust `random_walk_trace.rb`
|
24
|
+
* use `Nyle.main` method
|
25
|
+
|
26
|
+
|
1
27
|
### 0.7.0 (2019/02/09)
|
2
28
|
#### New features
|
3
29
|
* enhance `draw_text` to be able to specify font attributes(font-name, italic, bold)
|
@@ -61,9 +87,9 @@
|
|
61
87
|
#### New features
|
62
88
|
* release as RubyGems
|
63
89
|
* add `Nyle.draw_shape` method
|
64
|
-
* add `
|
65
|
-
*
|
66
|
-
*
|
90
|
+
* add `Nyle::Screen#suspend` method and `Nyle::Screen#resume` method
|
91
|
+
* enhance `a`(alpha value) option in `Nyle.draw_*`
|
92
|
+
* append `?` letter to method which returns true ot false
|
67
93
|
|
68
94
|
|
69
95
|
### 0.4.0 (2018/11/04)
|
data/lib/nyle.rb
CHANGED
@@ -27,9 +27,12 @@ MOUSE_R = 3
|
|
27
27
|
module Nyle
|
28
28
|
class Error < StandardError; end
|
29
29
|
|
30
|
-
DEFAULT_WIDTH
|
31
|
-
DEFAULT_HEIGHT
|
32
|
-
DEFAULT_TITLE
|
30
|
+
DEFAULT_WIDTH = 640
|
31
|
+
DEFAULT_HEIGHT = 480
|
32
|
+
DEFAULT_TITLE = 'Nyle'
|
33
|
+
DEFAULT_INTERVAL = 15
|
34
|
+
MIN_INTERVAL = 5
|
35
|
+
MAX_INTERVAL = 1000
|
33
36
|
|
34
37
|
@__cr = nil
|
35
38
|
@__screen_width = DEFAULT_WIDTH
|
@@ -48,6 +51,9 @@ module Nyle
|
|
48
51
|
@__mask_shift = false
|
49
52
|
@__cursor_x = 0
|
50
53
|
@__cursor_y = 0
|
54
|
+
@__running_time = 0
|
55
|
+
|
56
|
+
@__frame = nil # main frame
|
51
57
|
|
52
58
|
@__os = (
|
53
59
|
host_os = RbConfig::CONFIG['host_os']
|
@@ -62,7 +68,6 @@ module Nyle
|
|
62
68
|
:unknown
|
63
69
|
end
|
64
70
|
)
|
65
|
-
@__frame = nil # main frame
|
66
71
|
|
67
72
|
# Singleton class
|
68
73
|
class << self
|
@@ -142,9 +147,30 @@ module Nyle
|
|
142
147
|
else
|
143
148
|
@__cursor_y = 0
|
144
149
|
end
|
145
|
-
|
146
150
|
end
|
147
151
|
end
|
152
|
+
|
153
|
+
private def _clear_mouse_state
|
154
|
+
@__mouse_down.clear
|
155
|
+
@__mouse_down_last.clear
|
156
|
+
@__mouse_press.clear
|
157
|
+
@__mouse_release.clear
|
158
|
+
end
|
159
|
+
|
160
|
+
private def _clear_key_state
|
161
|
+
@__key_down.clear
|
162
|
+
@__key_down_last.clear
|
163
|
+
@__key_press.clear
|
164
|
+
@__key_release.clear
|
165
|
+
end
|
166
|
+
|
167
|
+
private def _set_running_time(rt)
|
168
|
+
@__running_time = rt
|
169
|
+
end
|
170
|
+
|
171
|
+
private def _clear_running_time
|
172
|
+
@__running_time = 0
|
173
|
+
end
|
148
174
|
end
|
149
175
|
|
150
176
|
|
@@ -165,8 +191,14 @@ module Nyle
|
|
165
191
|
module_function def mask_shift? ; Nyle.module_eval{ @__mask_shift } ; end
|
166
192
|
module_function def cursor_x ; Nyle.module_eval{ @__cursor_x } ; end
|
167
193
|
module_function def cursor_y ; Nyle.module_eval{ @__cursor_y } ; end
|
194
|
+
module_function def running_time ; Nyle.module_eval{ @__running_time } ; end
|
168
195
|
module_function def os ; Nyle.module_eval{ @__os } ; end
|
169
196
|
|
197
|
+
alias_method :w, :screen_width
|
198
|
+
alias_method :h, :screen_height
|
199
|
+
module_function :w
|
200
|
+
module_function :h
|
201
|
+
|
170
202
|
module_function def save
|
171
203
|
cr = Nyle.module_eval{ @__cr }
|
172
204
|
cr.save do
|
@@ -230,6 +262,7 @@ module Nyle
|
|
230
262
|
cr.save do
|
231
263
|
cr.line_width = weight
|
232
264
|
cr.line_cap = cap
|
265
|
+
cr.line_join = :ROUND if cap == :ROUND
|
233
266
|
cr.set_source_rgba(Cairo::Color.parse(color).r,
|
234
267
|
Cairo::Color.parse(color).g,
|
235
268
|
Cairo::Color.parse(color).b, a)
|
@@ -353,6 +386,10 @@ module Nyle
|
|
353
386
|
return (c == Cairo::Color.parse(color).to_s[0, 7] ? true : false)
|
354
387
|
end
|
355
388
|
|
389
|
+
module_function def clear
|
390
|
+
Nyle.module_eval{ @__frame.current_screen.clear_screen }
|
391
|
+
end
|
392
|
+
|
356
393
|
module_function def translate(tx, ty)
|
357
394
|
cr = Nyle.module_eval{ @__cr }
|
358
395
|
cr.translate(tx, ty)
|
@@ -368,11 +405,23 @@ module Nyle
|
|
368
405
|
cr.scale(sx, sy)
|
369
406
|
end
|
370
407
|
|
408
|
+
module_function def create_screen(*args)
|
409
|
+
Nyle::Screen.new(*args)
|
410
|
+
end
|
411
|
+
|
412
|
+
module_function def create_frame(*args)
|
413
|
+
Nyle::Frame.new(*args)
|
414
|
+
end
|
415
|
+
|
371
416
|
module_function def quit
|
372
417
|
@__frame.close if @__frame # destroy
|
373
418
|
# Gtk.main_quit
|
374
419
|
end
|
375
420
|
|
421
|
+
module_function def main
|
422
|
+
Gtk.main
|
423
|
+
end
|
424
|
+
|
376
425
|
end
|
377
426
|
|
378
427
|
|
data/lib/nyle/frame.rb
CHANGED
@@ -13,21 +13,15 @@ module Nyle
|
|
13
13
|
|
14
14
|
# Frame
|
15
15
|
class Frame < Gtk::Window
|
16
|
-
|
17
|
-
|
16
|
+
attr_reader :current_screen
|
17
|
+
# include Gdk::Keyval # Include key definication to omit 'Gdk::Keyval::' for subclass
|
18
|
+
def initialize(width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT)
|
18
19
|
super()
|
19
20
|
self.set_size_request(width, height)
|
20
21
|
self.resizable = false
|
21
|
-
self.title =
|
22
|
-
@transition = []
|
23
|
-
@interval_time =
|
24
|
-
@interval_time = 15 if @interval_time < 5 or @interval_time > 1000
|
25
|
-
GLib::Timeout.add(@interval_time) do
|
26
|
-
if @current_screen
|
27
|
-
update
|
28
|
-
@current_screen.queue_draw unless @current_screen.destroyed?
|
29
|
-
end
|
30
|
-
end
|
22
|
+
self.title = DEFAULT_TITLE
|
23
|
+
@transition = [] # Screen transition table
|
24
|
+
@interval_time = DEFAULT_INTERVAL # milli seconds
|
31
25
|
|
32
26
|
# Nyle main frame
|
33
27
|
me = self
|
@@ -78,6 +72,38 @@ module Nyle
|
|
78
72
|
end
|
79
73
|
end
|
80
74
|
|
75
|
+
def show_all(title: nil, interval: nil)
|
76
|
+
super()
|
77
|
+
self.title = title if title
|
78
|
+
if ENV['NYLE_INTERVAL']
|
79
|
+
@interval_time = ENV['NYLE_INTERVAL'].to_i
|
80
|
+
elsif interval
|
81
|
+
@interval_time = interval.to_i
|
82
|
+
end
|
83
|
+
@interval_time = MIN_INTERVAL if @interval_time < MIN_INTERVAL
|
84
|
+
@interval_time = MAX_INTERVAL if @interval_time > MAX_INTERVAL
|
85
|
+
|
86
|
+
@timer = GLib::Timer.new
|
87
|
+
@timer.start
|
88
|
+
|
89
|
+
GLib::Timeout.add(@interval_time, GLib::PRIORITY_HIGH) do
|
90
|
+
# puts "#{@timer.elapsed[0]}" if @timer
|
91
|
+
if @timer
|
92
|
+
elapsed = (@timer.elapsed[0] * 1000).round
|
93
|
+
Nyle.module_eval {
|
94
|
+
_set_running_time(elapsed)
|
95
|
+
}
|
96
|
+
if @current_screen
|
97
|
+
update
|
98
|
+
@current_screen.queue_draw unless @current_screen.destroyed?
|
99
|
+
end
|
100
|
+
true
|
101
|
+
else
|
102
|
+
false
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
81
107
|
def close
|
82
108
|
_quit
|
83
109
|
end
|
@@ -113,6 +139,13 @@ module Nyle
|
|
113
139
|
end
|
114
140
|
|
115
141
|
private def _quit
|
142
|
+
@timer.stop
|
143
|
+
@timer = nil # as block returns false by this, GLib::Timeout will remove and not be called
|
144
|
+
Nyle.module_eval{
|
145
|
+
_clear_mouse_state
|
146
|
+
_clear_key_state
|
147
|
+
_clear_running_time
|
148
|
+
}
|
116
149
|
self.hide
|
117
150
|
Gtk.main_quit
|
118
151
|
end
|
data/lib/nyle/screen.rb
CHANGED
@@ -23,8 +23,6 @@ module Nyle
|
|
23
23
|
@running_count = 0
|
24
24
|
@status = nil
|
25
25
|
|
26
|
-
@fill_done = false
|
27
|
-
|
28
26
|
Nyle.module_eval {
|
29
27
|
_set_screen_size(width, height)
|
30
28
|
}
|
@@ -46,14 +44,10 @@ module Nyle
|
|
46
44
|
Nyle.module_eval {
|
47
45
|
_set_cr(cr)
|
48
46
|
}
|
49
|
-
unless @trace # If not trace,
|
50
|
-
Nyle.
|
51
|
-
|
52
|
-
else
|
53
|
-
unless @fill_done
|
54
|
-
Nyle.cr.set_source_color(@bgcolor) # fill once
|
47
|
+
unless @trace # If not trace, clear screen each time
|
48
|
+
Nyle.save do
|
49
|
+
Nyle.cr.set_operator(Cairo::Operator::CLEAR)
|
55
50
|
Nyle.cr.paint
|
56
|
-
@fill_done = true
|
57
51
|
end
|
58
52
|
end
|
59
53
|
update
|
@@ -63,8 +57,9 @@ module Nyle
|
|
63
57
|
Nyle.module_eval {
|
64
58
|
_set_cr(cairo_context)
|
65
59
|
}
|
66
|
-
|
67
|
-
Nyle.cr.
|
60
|
+
Nyle.cr.set_source_color(@bgcolor)
|
61
|
+
Nyle.cr.paint
|
62
|
+
Nyle.cr.set_source(@canvas, 0, 0)
|
68
63
|
Nyle.cr.paint
|
69
64
|
@running_count += 1
|
70
65
|
end
|
@@ -83,19 +78,34 @@ module Nyle
|
|
83
78
|
end
|
84
79
|
end
|
85
80
|
|
81
|
+
# Clear
|
82
|
+
def clear_screen
|
83
|
+
Nyle.cr.set_operator(Cairo::Operator::CLEAR)
|
84
|
+
Nyle.cr.paint
|
85
|
+
end
|
86
|
+
|
86
87
|
# When single screen, create frame to show self
|
87
|
-
def show_all(title
|
88
|
-
f = Nyle::Frame.new(@width, @height
|
88
|
+
def show_all(title: nil, interval: nil)
|
89
|
+
f = Nyle::Frame.new(@width, @height)
|
89
90
|
f.set_current(self)
|
90
|
-
f.show_all
|
91
|
+
f.show_all({title: title, interval: interval})
|
91
92
|
f
|
92
93
|
end
|
93
94
|
|
95
|
+
# Syntax sugar for starting Nyle aplication
|
96
|
+
def start(*args)
|
97
|
+
self.setup
|
98
|
+
self.show_all(*args)
|
99
|
+
Nyle.main
|
100
|
+
end
|
101
|
+
|
102
|
+
|
94
103
|
# Abstract methods to be overriden
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
104
|
+
def update ; end
|
105
|
+
def draw ; end
|
106
|
+
def suspend ; end
|
107
|
+
def resume ; end
|
108
|
+
def setup ; end
|
99
109
|
end
|
100
110
|
|
101
111
|
end
|
data/lib/nyle/version.rb
CHANGED
@@ -0,0 +1,242 @@
|
|
1
|
+
require 'nyle'
|
2
|
+
|
3
|
+
class Controller < Gtk::Box
|
4
|
+
def initialize(target)
|
5
|
+
super(:vertical, 0)
|
6
|
+
|
7
|
+
@target = target
|
8
|
+
|
9
|
+
@l1_init = @target.L1
|
10
|
+
@m1_init = @target.M1
|
11
|
+
@l2_init = @target.L2
|
12
|
+
@m2_init = @target.M2
|
13
|
+
@g_init = @target.G
|
14
|
+
|
15
|
+
# length of upper pendulum
|
16
|
+
scale_l1 = Gtk::Scale.new(:vertical, 50.0, 150.0, 0.1)
|
17
|
+
scale_l1.set_size_request(65, 150)
|
18
|
+
scale_l1.value = @l1_init
|
19
|
+
scale_l1.draw_value = false
|
20
|
+
label_caption_l1 = Gtk::Label.new("L1")
|
21
|
+
label_value_l1 = Gtk::Label.new(scale_l1.value.round(1).to_s)
|
22
|
+
label_value_l1.override_font(Pango::FontDescription.new('bold'))
|
23
|
+
scale_l1.signal_connect(:value_changed) do |widget|
|
24
|
+
widget.value = widget.value.round(1)
|
25
|
+
label_value_l1.text = widget.value.to_s
|
26
|
+
@target.L1 = widget.value if @target
|
27
|
+
@target.status if @target
|
28
|
+
end
|
29
|
+
|
30
|
+
# mass of upper pendulum
|
31
|
+
scale_m1 = Gtk::Scale.new(:vertical, 10.0, 20.0, 0.5)
|
32
|
+
scale_m1.set_size_request(65, 150)
|
33
|
+
scale_m1.value = @m1_init
|
34
|
+
scale_m1.draw_value = false
|
35
|
+
label_caption_m1 = Gtk::Label.new("M1")
|
36
|
+
label_value_m1 = Gtk::Label.new(scale_m1.value.round(1).to_s)
|
37
|
+
label_value_m1.override_font(Pango::FontDescription.new('bold'))
|
38
|
+
label_value_m1.justify = :right
|
39
|
+
scale_m1.signal_connect(:value_changed) do |widget|
|
40
|
+
widget.value = widget.value.round(1)
|
41
|
+
label_value_m1.text = widget.value.to_s
|
42
|
+
@target.M1 = widget.value if @target
|
43
|
+
@target.status if @target
|
44
|
+
end
|
45
|
+
|
46
|
+
# panel for upper pendulum
|
47
|
+
box_l1 = Gtk::Box.new(:vertical, 0)
|
48
|
+
box_l1.add(label_caption_l1)
|
49
|
+
box_l1.add(Gtk::Separator.new(:horizontal))
|
50
|
+
box_l1.add(label_value_l1)
|
51
|
+
box_l1.add(scale_l1)
|
52
|
+
|
53
|
+
box_m1 = Gtk::Box.new(:vertical, 0)
|
54
|
+
box_m1.add(label_caption_m1)
|
55
|
+
box_m1.add(Gtk::Separator.new(:horizontal))
|
56
|
+
box_m1.add(label_value_m1)
|
57
|
+
box_m1.add(scale_m1)
|
58
|
+
|
59
|
+
box_1 = Gtk::Box.new(:horizontal, 0)
|
60
|
+
box_1.add(box_l1)
|
61
|
+
box_1.add(box_m1)
|
62
|
+
|
63
|
+
frame_1 = Gtk::Frame.new
|
64
|
+
frame_1.add(box_1)
|
65
|
+
|
66
|
+
# length of lower pendulum
|
67
|
+
scale_l2 = Gtk::Scale.new(:vertical, 50.0, 150.0, 0.1)
|
68
|
+
scale_l2.set_size_request(65, 150)
|
69
|
+
scale_l2.value = @l2_init
|
70
|
+
scale_l2.draw_value = false
|
71
|
+
label_caption_l2 = Gtk::Label.new("L2")
|
72
|
+
label_value_l2 = Gtk::Label.new(scale_l2.value.round(1).to_s)
|
73
|
+
label_value_l2.override_font(Pango::FontDescription.new('bold'))
|
74
|
+
scale_l2.signal_connect(:value_changed) do |widget|
|
75
|
+
widget.value = widget.value.round(1)
|
76
|
+
label_value_l2.text = widget.value.to_s
|
77
|
+
@target.L2 = widget.value if @target
|
78
|
+
@target.status if @target
|
79
|
+
end
|
80
|
+
|
81
|
+
# mass of lower pendulum
|
82
|
+
scale_m2 = Gtk::Scale.new(:vertical, 10.0, 20.0, 0.5)
|
83
|
+
scale_m2.set_size_request(65, 150)
|
84
|
+
scale_m2.value = @m2_init
|
85
|
+
scale_m2.draw_value = false
|
86
|
+
label_caption_m2 = Gtk::Label.new("M2")
|
87
|
+
label_value_m2 = Gtk::Label.new(scale_m2.value.round(1).to_s)
|
88
|
+
label_value_m2.override_font(Pango::FontDescription.new('bold'))
|
89
|
+
label_value_m2.justify = :right
|
90
|
+
scale_m2.signal_connect(:value_changed) do |widget|
|
91
|
+
widget.value = widget.value.round(1)
|
92
|
+
label_value_m2.text = widget.value.to_s
|
93
|
+
@target.M2 = widget.value if @target
|
94
|
+
@target.status if @target
|
95
|
+
end
|
96
|
+
|
97
|
+
# panel for lower pendulum
|
98
|
+
box_l2 = Gtk::Box.new(:vertical, 0)
|
99
|
+
box_l2.add(label_caption_l2)
|
100
|
+
box_l2.add(Gtk::Separator.new(:horizontal))
|
101
|
+
box_l2.add(label_value_l2)
|
102
|
+
box_l2.add(scale_l2)
|
103
|
+
|
104
|
+
box_m2 = Gtk::Box.new(:vertical, 0)
|
105
|
+
box_m2.add(label_caption_m2)
|
106
|
+
box_m2.add(Gtk::Separator.new(:horizontal))
|
107
|
+
box_m2.add(label_value_m2)
|
108
|
+
box_m2.add(scale_m2)
|
109
|
+
|
110
|
+
box_2 = Gtk::Box.new(:horizontal, 0)
|
111
|
+
box_2.add(box_l2)
|
112
|
+
box_2.add(box_m2)
|
113
|
+
|
114
|
+
frame_2 = Gtk::Frame.new
|
115
|
+
frame_2.add(box_2)
|
116
|
+
|
117
|
+
# panel for gravity
|
118
|
+
label_caption_g = Gtk::Label.new(" G")
|
119
|
+
spinner_g = Gtk::SpinButton.new(0.1, 2.0, 0.1)
|
120
|
+
spinner_g.value = @g_init
|
121
|
+
spinner_g.wrap = false
|
122
|
+
box_g = Gtk::Box.new(:horizontal, 10)
|
123
|
+
box_g.add(label_caption_g)
|
124
|
+
box_g.add(spinner_g)
|
125
|
+
spinner_g.signal_connect(:value_changed) do |widget|
|
126
|
+
widget.value = widget.value.round(1)
|
127
|
+
@target.G = widget.value if @target
|
128
|
+
@target.status if @target
|
129
|
+
end
|
130
|
+
|
131
|
+
# reset button
|
132
|
+
button = Gtk::Button.new(label: "Reset")
|
133
|
+
button.focus = true
|
134
|
+
button.signal_connect(:clicked) {
|
135
|
+
if @target
|
136
|
+
scale_l1.value = @target.L1 = @l1_init # set/get initial value
|
137
|
+
scale_m1.value = @target.M1 = @m1_init # set/get initial value
|
138
|
+
scale_l2.value = @target.L2 = @l2_init # set/get initial value
|
139
|
+
scale_m2.value = @target.M2 = @m2_init # set/get initial value
|
140
|
+
spinner_g.value = @target.G = @g_init # set/get initial value
|
141
|
+
@target.status
|
142
|
+
end
|
143
|
+
}
|
144
|
+
|
145
|
+
# control panel
|
146
|
+
self.add(frame_1)
|
147
|
+
self.add(frame_2)
|
148
|
+
self.add(Gtk::Separator.new(:horizontal))
|
149
|
+
self.add(box_g)
|
150
|
+
self.add(button)
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
class Screen < Nyle::Screen
|
157
|
+
attr_accessor :L1, :M1, :L2, :M2, :G
|
158
|
+
|
159
|
+
def initialize
|
160
|
+
super(600, 600, {bgcolor: :WHITE})
|
161
|
+
@L1 = 100
|
162
|
+
@L2 = 100
|
163
|
+
@M1 = 15
|
164
|
+
@M2 = 15
|
165
|
+
@G = 1.0
|
166
|
+
@cx = Nyle.w / 2
|
167
|
+
@cy = Nyle.h / 2
|
168
|
+
@a1_v = 0
|
169
|
+
@a2_v = 0
|
170
|
+
@a1 = Math::PI / 2
|
171
|
+
@a2 = Math::PI / 2
|
172
|
+
@points = []
|
173
|
+
end
|
174
|
+
|
175
|
+
def update
|
176
|
+
#calc a1_a
|
177
|
+
num1 = -@G * (2 * @M1 + @M2) * Math.sin(@a1)
|
178
|
+
num2 = -@M2 * @G * Math.sin(@a1 - 2 * @a2)
|
179
|
+
num3 = -2 * Math.sin(@a1 - @a2) * @M2
|
180
|
+
num4 = @a2_v * @a2_v * @L2 + @a1_v * @a1_v * @L1 * Math.cos(@a1 - @a2)
|
181
|
+
den = @L1 * (2 * @M1 + @M2 - @M2 * Math.cos(2 * @a1 - 2 * @a2))
|
182
|
+
a1_a = (num1 + num2 + num3 * num4) / den
|
183
|
+
|
184
|
+
#calc a2_a
|
185
|
+
num1 = 2 * Math.sin(@a1 - @a2)
|
186
|
+
num2 = (@a1_v * @a1_v * @L1 * (@M1 + @M2))
|
187
|
+
num3 = @G * (@M1 + @M2) * Math.cos(@a1)
|
188
|
+
num4 = @a2_v * @a2_v * @L2 * @M2 * Math.cos(@a1 - @a2)
|
189
|
+
den = @L2 * (2 * @M1 + @M2 - @M2 * Math.cos(2 * @a1 - 2.0 * @a2))
|
190
|
+
a2_a = (num1 * (num2 + num3 + num4)) / den
|
191
|
+
|
192
|
+
@a1_v += a1_a
|
193
|
+
@a2_v += a2_a
|
194
|
+
@a1 += @a1_v
|
195
|
+
@a2 += @a2_v
|
196
|
+
end
|
197
|
+
|
198
|
+
def draw
|
199
|
+
x1 = @L1 * Math.sin(@a1)
|
200
|
+
y1 = @L1 * Math.cos(@a1)
|
201
|
+
x2 = x1 + @L2 * Math.sin(@a2)
|
202
|
+
y2 = y1 + @L2 * Math.cos(@a2)
|
203
|
+
|
204
|
+
Nyle.save do
|
205
|
+
Nyle.translate(@cx, @cy)
|
206
|
+
Nyle.draw_shape(@points, {weight: 1, color: :BLUE})
|
207
|
+
end
|
208
|
+
@points << [x2, y2]
|
209
|
+
@points.shift if @points.length > 2000
|
210
|
+
|
211
|
+
Nyle.save do
|
212
|
+
Nyle.translate(@cx, @cy)
|
213
|
+
# draw No1_pendulum
|
214
|
+
Nyle.draw_line(0, 0, x1, y1)
|
215
|
+
Nyle.draw_circle(x1, y1, @M1, {color: :BLACK, fill: true})
|
216
|
+
|
217
|
+
# draw No2_pendulum
|
218
|
+
Nyle.draw_line(x1, y1, x2, y2)
|
219
|
+
Nyle.draw_circle(x2, y2, @M2, {color: :BLACK, fill: true})
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
|
225
|
+
class Frame < Nyle::Frame
|
226
|
+
def initialize
|
227
|
+
super
|
228
|
+
self.set_size_request(740, 600)
|
229
|
+
screen = Screen.new
|
230
|
+
controller = Controller.new(screen)
|
231
|
+
box = Gtk::Box.new(:horizontal)
|
232
|
+
box.add(controller)
|
233
|
+
#box.add(screen)
|
234
|
+
box.pack_start(screen, expand: true, fill: true, padding: 0)
|
235
|
+
self.set_current(box)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
|
240
|
+
Frame.new.show_all
|
241
|
+
Nyle.main
|
242
|
+
|
@@ -12,8 +12,8 @@ class Screen < Nyle::Screen
|
|
12
12
|
Nyle.draw_circle(Nyle.mouse_x, Nyle.mouse_y, 10, {color: @color, fill: true}) if Nyle.mouse_down?(MOUSE_L) # draw (left-click)
|
13
13
|
Nyle.draw_circle(Nyle.mouse_x, Nyle.mouse_y, 10, {color: :WHITE, fill: true}) if Nyle.mouse_down?(MOUSE_R) # erase (right-click)
|
14
14
|
|
15
|
-
Nyle.draw_text( 10, 20, "[mouse left ] draw", {size: 16})
|
16
|
-
Nyle.draw_text( 10, 40, "[mouse right] erase", {size: 16})
|
15
|
+
# Nyle.draw_text( 10, 20, "[mouse left ] draw", {size: 16})
|
16
|
+
# Nyle.draw_text( 10, 40, "[mouse right] erase", {size: 16})
|
17
17
|
|
18
18
|
if @png
|
19
19
|
Nyle.save_image("./sketch.png")
|
@@ -91,5 +91,5 @@ end
|
|
91
91
|
|
92
92
|
|
93
93
|
Frame.new.show_all
|
94
|
-
|
94
|
+
Nyle.main
|
95
95
|
|
data/samples/application/tree.rb
CHANGED
@@ -8,34 +8,42 @@ class Screen < Nyle::Screen
|
|
8
8
|
|
9
9
|
def setup
|
10
10
|
@colors = _color_list
|
11
|
-
@start_index = 0
|
12
11
|
@bar_w = 200
|
13
12
|
@bar_h = 30
|
13
|
+
@start_index = 0
|
14
|
+
@end_index = _end_index
|
14
15
|
end
|
15
16
|
|
16
17
|
def draw
|
17
|
-
@
|
18
|
-
next if i < @start_index
|
18
|
+
(@start_index..@end_index).each do |i|
|
19
19
|
y = (i - @start_index) * @bar_h
|
20
|
-
Nyle.draw_rect(0, y, @bar_w, @bar_h, {color:
|
21
|
-
Nyle.draw_text(@bar_w + 10, y + @bar_h - 10, "#{
|
20
|
+
Nyle.draw_rect(0, y, @bar_w, @bar_h, {color: @colors[i], fill: true})
|
21
|
+
Nyle.draw_text(@bar_w + 10, y + @bar_h - 10, "#{@colors[i].to_s}", {color: :BLACK, size: 16})
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
def update
|
26
26
|
if Nyle.key_press?(KEY_Up) or Nyle.mouse_press?(MOUSE_R)
|
27
|
-
@start_index -= (
|
28
|
-
@start_index = (@colors.length / (
|
27
|
+
@start_index -= (Nyle.screen_height / @bar_h)
|
28
|
+
@start_index = (@colors.length / (Nyle.screen_height / @bar_h)) * (Nyle.screen_height / @bar_h) if @start_index < 0
|
29
|
+
@end_index = _end_index
|
29
30
|
end
|
30
31
|
|
31
32
|
if Nyle.key_press?(KEY_Down) or Nyle.mouse_press?(MOUSE_L)
|
32
|
-
@start_index += (
|
33
|
+
@start_index += (Nyle.screen_height / @bar_h)
|
33
34
|
@start_index = 0 if @start_index >= @colors.length
|
35
|
+
@end_index = _end_index
|
34
36
|
end
|
35
37
|
|
36
38
|
Nyle.quit if Nyle.key_press?(KEY_Escape)
|
37
39
|
end
|
38
40
|
|
41
|
+
def _end_index
|
42
|
+
index = @start_index + Nyle.screen_height / @bar_h - 1
|
43
|
+
index = @colors.length - 1 if index >= @colors.length
|
44
|
+
index
|
45
|
+
end
|
46
|
+
|
39
47
|
def _color_list
|
40
48
|
[
|
41
49
|
:ALICE_BLUE, # #F0F8FF
|
@@ -306,5 +314,5 @@ end
|
|
306
314
|
|
307
315
|
|
308
316
|
Screen.new.show_all
|
309
|
-
|
317
|
+
Nyle.main
|
310
318
|
|
data/samples/basic/draw_line.rb
CHANGED
data/samples/basic/draw_rect.rb
CHANGED
data/samples/basic/draw_shape.rb
CHANGED
@@ -49,11 +49,11 @@ class Screen < Nyle::Screen
|
|
49
49
|
super
|
50
50
|
end
|
51
51
|
def draw
|
52
|
-
Nyle.draw_shape(star(160, 100), {color: :GOLD, weight: 5, close: true})
|
52
|
+
Nyle.draw_shape(star(160, 100), {color: :GOLD, weight: 5, close: true, cap: :ROUND})
|
53
53
|
Nyle.draw_shape(star(320, 100), {color: :GOLD, weight: 5, close: true, fill: true})
|
54
54
|
Nyle.draw_shape(star(480, 100), {color: :GOLD, a: 0.5, weight: 5, close: true, fill: true})
|
55
55
|
|
56
|
-
Nyle.draw_shape(para_star(160, 240), {color: :BROWN, weight: 3, close: true})
|
56
|
+
Nyle.draw_shape(para_star(160, 240), {color: :BROWN, weight: 3, close: true, cap: :ROUND})
|
57
57
|
Nyle.draw_shape(para_star(320, 240), {color: :BROWN, weight: 3, close: true, fill: true})
|
58
58
|
Nyle.draw_shape(para_star(480, 240), {color: :BROWN, a: 0.5, weight: 3, close: true, fill: true})
|
59
59
|
|
@@ -66,5 +66,5 @@ end
|
|
66
66
|
|
67
67
|
|
68
68
|
Screen.new.show_all
|
69
|
-
|
69
|
+
Nyle.main
|
70
70
|
|
data/samples/basic/draw_text.rb
CHANGED
data/samples/basic/image_rpg.rb
CHANGED
data/samples/basic/keyboard.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'nyle'
|
2
|
+
|
3
|
+
class Screen < Nyle::Screen
|
4
|
+
def initialize
|
5
|
+
super(320, 320, {bgcolor: :ALICE_BLUE, trace: true})
|
6
|
+
@draw = true
|
7
|
+
@rt_last = 0
|
8
|
+
end
|
9
|
+
|
10
|
+
def draw
|
11
|
+
if @draw
|
12
|
+
x = rand(Nyle.w)
|
13
|
+
y = rand(Nyle.h)
|
14
|
+
r = rand(3..50)
|
15
|
+
c = rand(0..0xFFFFFF)
|
16
|
+
a = rand(1..5)
|
17
|
+
Nyle.draw_circle(x, y, r, {fill: true, color: "#%06x" % c, a: a / 10.0})
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def update
|
22
|
+
@rt = Nyle.running_time
|
23
|
+
if (@rt - @rt_last) >= 2000
|
24
|
+
@rt_last = @rt
|
25
|
+
@draw = !@draw
|
26
|
+
Nyle.clear if @draw
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
Screen.new.show_all({interval: nil})
|
33
|
+
Nyle.main
|
34
|
+
|
@@ -25,7 +25,7 @@ class Walker
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def draw
|
28
|
-
Nyle.draw_circle(@x, @y, RADIUS, {color: :
|
28
|
+
Nyle.draw_circle(@x, @y, RADIUS, {color: :YELLOW, fill: true})
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -33,7 +33,7 @@ end
|
|
33
33
|
class Screen < Nyle::Screen
|
34
34
|
|
35
35
|
def initialize
|
36
|
-
super(64 * 5, 48 * 5, {bgcolor: :
|
36
|
+
super(64 * 5, 48 * 5, {bgcolor: :BLACK})
|
37
37
|
@walker = Walker.new(@width, @height)
|
38
38
|
end
|
39
39
|
|
@@ -49,6 +49,6 @@ class Screen < Nyle::Screen
|
|
49
49
|
end
|
50
50
|
|
51
51
|
|
52
|
-
Screen.new.show_all
|
53
|
-
|
52
|
+
Screen.new.show_all({interval: 30})
|
53
|
+
Nyle.main
|
54
54
|
|
@@ -25,7 +25,7 @@ class Walker
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def draw
|
28
|
-
Nyle.draw_circle(@x, @y, RADIUS, {color: :
|
28
|
+
Nyle.draw_circle(@x, @y, RADIUS, {color: :YELLOW, fill: true})
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -33,7 +33,7 @@ end
|
|
33
33
|
class Screen < Nyle::Screen
|
34
34
|
|
35
35
|
def initialize
|
36
|
-
super(64 * 5, 48 * 5, {bgcolor: :
|
36
|
+
super(64 * 5, 48 * 5, {bgcolor: :BLACK, trace: true})
|
37
37
|
@walker = Walker.new(@width, @height)
|
38
38
|
end
|
39
39
|
|
@@ -49,6 +49,6 @@ class Screen < Nyle::Screen
|
|
49
49
|
end
|
50
50
|
|
51
51
|
|
52
|
-
Screen.new.show_all
|
53
|
-
|
52
|
+
Screen.new.show_all({interval: 30})
|
53
|
+
Nyle.main
|
54
54
|
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'nyle'
|
2
|
+
|
3
|
+
class Walker
|
4
|
+
RADIUS = 4
|
5
|
+
def initialize(max_x, max_y)
|
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
|
+
end
|
12
|
+
|
13
|
+
# Randomly move up, down, left, right
|
14
|
+
def move
|
15
|
+
stepx = rand(3) - 1
|
16
|
+
stepy = rand(3) - 1
|
17
|
+
@x += stepx * @step
|
18
|
+
@y += stepy * @step
|
19
|
+
|
20
|
+
# x,y limitter
|
21
|
+
@x = 0 if @x < 0
|
22
|
+
@x = @max_x if @x > @max_x
|
23
|
+
@y = 0 if @y < 0
|
24
|
+
@y = @max_y if @y > @max_y
|
25
|
+
end
|
26
|
+
|
27
|
+
def draw
|
28
|
+
Nyle.draw_circle(@x, @y, RADIUS, {color: :YELLOW, fill: true})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
class Screen < Nyle::Screen
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
super(64 * 5, 48 * 5, {bgcolor: :BLACK, trace: true})
|
37
|
+
@walker = Walker.new(@width, @height)
|
38
|
+
end
|
39
|
+
|
40
|
+
def draw
|
41
|
+
@walker.draw
|
42
|
+
Nyle.draw_rect(0, 0, @width, @height, {fill: true, color: :BLACK, a: 0.02})
|
43
|
+
end
|
44
|
+
|
45
|
+
def update
|
46
|
+
@walker.move
|
47
|
+
Nyle.quit if Nyle.key_press?(KEY_Escape)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
Screen.new.show_all({interval: 30})
|
54
|
+
Nyle.main
|
55
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'nyle'
|
2
|
+
|
3
|
+
class Screen < Nyle::Screen
|
4
|
+
def initialize
|
5
|
+
super(320, 320, {bgcolor: :BLACK, trace: true})
|
6
|
+
@th = 0
|
7
|
+
@c1 = :RED
|
8
|
+
@c2 = :ORANGE
|
9
|
+
@c3 = :GOLD
|
10
|
+
@x = Nyle.w / 2
|
11
|
+
@y = Nyle.h / 2
|
12
|
+
@rt_last = 0
|
13
|
+
end
|
14
|
+
|
15
|
+
def draw
|
16
|
+
Nyle.draw_circle(@x + Math::cos(@th) * 30, @y + Math::sin(@th) * 30, 30, {weight: 10, color: @c1})
|
17
|
+
Nyle.draw_circle(@x + Math::cos(@th) * 75, @y + Math::sin(@th) * 75, 30, {weight: 10, color: @c2})
|
18
|
+
Nyle.draw_circle(@x + Math::cos(@th) * 120, @y + Math::sin(@th) * 120, 30, {weight: 10, color: @c3})
|
19
|
+
Nyle.draw_rect(0, 0, Nyle.w, Nyle.h, {color: :BLACK, fill: true, a: 0.05})
|
20
|
+
end
|
21
|
+
|
22
|
+
def update
|
23
|
+
@rt = Nyle.running_time
|
24
|
+
if (@rt - @rt_last) >= 3000
|
25
|
+
@rt_last = @rt
|
26
|
+
@c1, @c2, @c3 = @c2, @c3, @c1
|
27
|
+
end
|
28
|
+
@th += Math::PI / 128
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
Screen.new.show_all({interval: nil})
|
34
|
+
Nyle.main
|
35
|
+
|
data/samples/launcher.rb
CHANGED
data/samples/tutorial/tut_a10.rb
CHANGED
data/samples/tutorial/tut_a20.rb
CHANGED
data/samples/tutorial/tut_a30.rb
CHANGED
data/samples/tutorial/tut_a40.rb
CHANGED
data/samples/tutorial/tut_a45.rb
CHANGED
data/samples/tutorial/tut_a50.rb
CHANGED
data/samples/tutorial/tut_a60.rb
CHANGED
data/samples/tutorial/tut_a70.rb
CHANGED
data/samples/tutorial/tut_b10.rb
CHANGED
data/samples/tutorial/tut_b20.rb
CHANGED
data/samples/tutorial/tut_b30.rb
CHANGED
data/samples/tutorial/tut_b40.rb
CHANGED
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.1
|
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-03-30 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/pendulum.rb
|
55
56
|
- samples/application/sketch.rb
|
56
57
|
- samples/application/sugar.rb
|
57
58
|
- samples/application/tree.rb
|
@@ -66,8 +67,11 @@ files:
|
|
66
67
|
- samples/basic/image_rotate.rb
|
67
68
|
- samples/basic/image_rpg.rb
|
68
69
|
- samples/basic/keyboard.rb
|
70
|
+
- samples/basic/pause.rb
|
69
71
|
- samples/basic/random_walk.rb
|
70
72
|
- samples/basic/random_walk_trace.rb
|
73
|
+
- samples/basic/random_walk_trace_fadeout.rb
|
74
|
+
- samples/basic/rotation.rb
|
71
75
|
- samples/image/n_b_crocodile.png
|
72
76
|
- samples/image/n_c_mogura.png
|
73
77
|
- samples/image/n_f_banana.png
|
@@ -78,7 +82,6 @@ files:
|
|
78
82
|
- samples/image/n_i_bg.jpg
|
79
83
|
- samples/image/n_i_chara.png
|
80
84
|
- samples/launcher.rb
|
81
|
-
- samples/tips/.gitkeep
|
82
85
|
- samples/tutorial/img.jpg
|
83
86
|
- samples/tutorial/tut_a10.rb
|
84
87
|
- samples/tutorial/tut_a20.rb
|
@@ -111,8 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
114
|
- !ruby/object:Gem::Version
|
112
115
|
version: '0'
|
113
116
|
requirements: []
|
114
|
-
|
115
|
-
rubygems_version: 2.7.8
|
117
|
+
rubygems_version: 3.0.1
|
116
118
|
signing_key:
|
117
119
|
specification_version: 4
|
118
120
|
summary: minimal graphics framework using Ruby/GTK3 and rcairo
|
data/samples/tips/.gitkeep
DELETED
File without changes
|