nyle 0.5.2 → 0.6.0

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.
@@ -2,7 +2,7 @@
2
2
  require 'nyle'
3
3
 
4
4
  class Field
5
- SKYLINE = 400
5
+ SKYLINE = 400
6
6
 
7
7
  def initialize
8
8
  _init_score
@@ -52,7 +52,7 @@ class Item
52
52
  @x = rand(MOVING_RANGE_X)
53
53
  @y = 0
54
54
  @speed_x = (@xrange == 0 ? 0 : rand(@xrange) - (@xrange - 1) / 2)
55
- @speed_y = rand(10) + 1
55
+ @speed_y = rand(10) + 3
56
56
  end
57
57
 
58
58
  def drop
@@ -77,7 +77,7 @@ class Item
77
77
 
78
78
  def clicked?
79
79
  clicked = false
80
- if Nyle.mouse_press?(1)
80
+ if Nyle.mouse_press?(MOUSE_L)
81
81
  diffx = Nyle.mouse_x - self.centerx
82
82
  diffy = Nyle.mouse_y - self.centery
83
83
  if (diffx > -20) and (diffx < 20) and (diffy > -20) and (diffy < 20)
@@ -0,0 +1,87 @@
1
+
2
+ require 'nyle'
3
+
4
+ class Tree
5
+ def initialize(x, y, z)
6
+ @x, @y, @z = x, y, z
7
+ @image = Nyle.load_image('./image/n_fl_tree32.png')
8
+ end
9
+
10
+ def draw(altitude)
11
+ dx = ((@x - 320) / @z)
12
+ dy = (((@y - 240) / @z - 60) * ((altitude - 100) / 300.0) - (altitude - 230))
13
+ Nyle.cr.save do
14
+ Nyle.translate(dx, dy)
15
+ Nyle.scale(5 / @z, 5 / @z)
16
+ Nyle.draw_image(0, 0, @image)
17
+ end
18
+ end
19
+
20
+ def update
21
+ @z -= 0.15
22
+ @z < 0.5 ? true : false # delete tree by 'delete_if' method when true
23
+ end
24
+ end
25
+
26
+ class Ground
27
+ def initialize
28
+ @altitude = 200
29
+ @angle = 0
30
+ @trees = []
31
+ end
32
+
33
+ def draw
34
+ Nyle.cr.save do
35
+ # draw ground
36
+ Nyle.translate(320, 240)
37
+ Nyle.rotate(@angle)
38
+ Nyle.draw_rect(-500, 240 - @altitude, 1000, 600, {color: :FOREST_GREEN, fill: true})
39
+
40
+ # draw trees
41
+ @trees.unshift(Tree.new(rand(2000) - 1000, 500, 5.0))
42
+ @trees.delete_if do |tree|
43
+ tree.draw(@altitude)
44
+ tree.update
45
+ end
46
+ end
47
+ Nyle.draw_text(10, 30, "altitude: #{@altitude} angle: #{"%2.1f" % (@angle * 180 / Math::PI) }", {color: :RED, size: 20})
48
+ end
49
+
50
+ def update(angle, altitude)
51
+ @angle += (1.8 * angle / 180 * Math::PI)
52
+ if @angle < (-60.0 / 180 * Math::PI) then
53
+ @angle = (-60.0 / 180 * Math::PI)
54
+ end
55
+ if @angle > (60.0 / 180 * Math::PI) then
56
+ @angle = (60.0 / 180 * Math::PI)
57
+ end
58
+ @altitude += (5 * altitude)
59
+ @altitude = 400 if @altitude > 400
60
+ @altitude = 100 if @altitude < 100
61
+ end
62
+ end
63
+
64
+
65
+ class Screen < Nyle::Screen
66
+ def initialize
67
+ super(640, 480, {bgcolor: :LIGHT_CYAN})
68
+ @ground = Ground.new
69
+ end
70
+
71
+ def draw
72
+ @ground.draw
73
+ end
74
+
75
+ def update
76
+ angle = (Nyle.key_down?(KEY_Right) ? -1 : (Nyle.key_down?(KEY_Left) ? 1 : 0))
77
+ altitude = (Nyle.key_down?(KEY_Down) ? -1 : (Nyle.key_down?(KEY_Up) ? 1 : 0))
78
+ @ground.update(angle, altitude)
79
+
80
+ Nyle.quit if Nyle.key_press?(KEY_Escape)
81
+ end
82
+ end
83
+
84
+
85
+ Screen.new.show_all
86
+ Gtk.main
87
+
@@ -0,0 +1,33 @@
1
+
2
+ require 'nyle'
3
+
4
+ class Screen < Nyle::Screen
5
+ def initialize
6
+ super(270, 240)
7
+ end
8
+ def draw
9
+ Nyle.draw_rect( 10, 10, 50, 50, {fill: true, color: :RED })
10
+ Nyle.draw_rect( 60, 60, 50, 50, {fill: true, color: :GREEN })
11
+ Nyle.draw_rect(110, 110, 50, 50, {fill: true, color: :BLUE })
12
+ Nyle.draw_rect( 10, 110, 50, 50, {fill: true, color: :GOLD })
13
+ Nyle.draw_rect(110, 10, 50, 50, {fill: true, color: :BLACK })
14
+ Nyle.draw_rect(160, 60, 50, 50, {fill: true, color: :CHOCOLATE })
15
+ Nyle.draw_rect(210, 110, 50, 50, {fill: true, color: :ORANGE })
16
+ Nyle.draw_rect(210, 10, 50, 50, {fill: true, color: :SILVER })
17
+
18
+ x, y = Nyle.mouse_x, Nyle.mouse_y
19
+ if Nyle.pixel?(x, y, :WHITE)
20
+ Nyle.draw_text(10, 220, 'Move mouse cursor over any tile', {size: 16})
21
+ else
22
+ color = Nyle.pixel(x, y)
23
+ info = "(x=%3d, y=%3d) %s" % [x, y, color]
24
+ Nyle.draw_text(10, 220, info, {size: 20, color: color})
25
+ end
26
+
27
+ Nyle.quit if Nyle.key_press?(KEY_Escape)
28
+ end
29
+ end
30
+
31
+ Screen.new.show_all
32
+ Gtk.main
33
+
@@ -4,42 +4,93 @@ require 'nyle'
4
4
  class Screen < Nyle::Screen
5
5
 
6
6
  def initialize
7
- super(600, 400, {trace: true})
7
+ super(500, 400, {trace: true})
8
8
  @color = :BLUE
9
+ @png = false
9
10
  end
10
11
 
11
12
  def draw
12
- #printf "(%3d , %3d) down:%6s press:%6s release:%6s\n",
13
- # Nyle.mouse_x,
14
- # Nyle.mouse_y,
15
- # Nyle.mouse_down[1],
16
- # Nyle.mouse_press[1],
17
- # Nyle.mouse_release[1]
18
-
19
- Nyle.draw_circle(Nyle.mouse_x, Nyle.mouse_y, 10, {color: @color, fill: true}) if Nyle.mouse_down?(1) # draw (left-click)
20
- Nyle.draw_circle(Nyle.mouse_x, Nyle.mouse_y, 10, {color: :WHITE, fill: true}) if Nyle.mouse_down?(3) # erase (right-click)
21
-
22
- Nyle.draw_text( 10, 20, "[mouse left ] draw", {size: 16})
23
- Nyle.draw_text( 10, 40, "[mouse right] erase", {size: 16})
24
- Nyle.draw_text( 10, 70, "[space] save", {size: 16})
25
- Nyle.draw_text( 10, 380, "[r]", {size: 28, color: :RED })
26
- Nyle.draw_text( 50, 380, "[g]", {size: 28, color: :FOREST_GREEN })
27
- Nyle.draw_text( 90, 380, "[b]", {size: 28, color: :BLUE })
28
- Nyle.draw_text(140, 380, "press key to change color", {size: 18})
29
- end
13
+ Nyle.draw_circle(Nyle.mouse_x, Nyle.mouse_y, 10, {color: @color, fill: true}) if Nyle.mouse_down?(MOUSE_L) # draw (left-click)
14
+ Nyle.draw_circle(Nyle.mouse_x, Nyle.mouse_y, 10, {color: :WHITE, fill: true}) if Nyle.mouse_down?(MOUSE_R) # erase (right-click)
30
15
 
31
- def update
32
- @color = :RED if Nyle.key_press?(KEY_r)
33
- @color = :FOREST_GREEN if Nyle.key_press?(KEY_g)
34
- @color = :BLUE if Nyle.key_press?(KEY_b)
16
+ Nyle.draw_text( 10, 20, "[mouse left ] draw", {size: 16})
17
+ Nyle.draw_text( 10, 40, "[mouse right] erase", {size: 16})
35
18
 
36
- Nyle.save_image("./sketch.png") if Nyle.key_press?(KEY_space)
19
+ if @png
20
+ Nyle.save_image("./sketch.png")
21
+ @png = false
22
+ end
37
23
 
38
24
  Nyle.quit if Nyle.key_press?(KEY_Escape)
39
25
  end
40
26
 
27
+ def change_color(color)
28
+ @color = color
29
+ end
30
+
31
+ def save_pngfile
32
+ # Don't write 'Nyle.save_image' method here
33
+ # Here is out of range about CairoContext
34
+ @png = true
35
+ end
41
36
  end
42
37
 
43
- Screen.new.show_all
38
+
39
+ class Frame < Nyle::Frame
40
+ def initialize
41
+ super(600, 400)
42
+
43
+ # screen
44
+ screen = Screen.new
45
+
46
+ # buttons
47
+ vbox = Gtk::Box.new(:vertical)
48
+ vbox.pack_start(button_r = Gtk::RadioButton.new( label: 'Red'), padding: 3)
49
+ vbox.pack_start(button_g = Gtk::RadioButton.new(member: button_r, label: 'Green'), padding: 3)
50
+ vbox.pack_start(button_b = Gtk::RadioButton.new(member: button_r, label: 'Blue'), padding: 3)
51
+ vbox.pack_start(button_save = Gtk::Button.new(label: 'Save file'), padding: 10)
52
+
53
+ # default active button (:BLUE)
54
+ button_b.active = true
55
+
56
+ # foreground color
57
+ button_r.override_color(:normal, _color_conv(:RED))
58
+ button_g.override_color(:normal, _color_conv(:FOREST_GREEN))
59
+ button_b.override_color(:normal, _color_conv(:BLUE))
60
+
61
+ # pack
62
+ hbox = Gtk::Box.new(:horizontal)
63
+ hbox.pack_start(vbox, expand: false, fill: true, padding: 0) # buttons
64
+ hbox.pack_start(screen, expand: true, fill: true, padding: 0) # screen
65
+ self.set_current(hbox)
66
+
67
+ # signal handlers
68
+ button_r.signal_connect(:toggled) do # change color to RED
69
+ screen.change_color(:RED)
70
+ end
71
+
72
+ button_g.signal_connect(:toggled) do # change color to GREEN
73
+ screen.change_color(:FOREST_GREEN)
74
+ end
75
+
76
+ button_b.signal_connect(:toggled) do # change color to BLUE
77
+ screen.change_color(:BLUE)
78
+ end
79
+
80
+ button_save.signal_connect(:clicked) do # save *.png file
81
+ screen.save_pngfile
82
+ end
83
+ end
84
+
85
+ private def _color_conv(color)
86
+ Gdk::RGBA.new(Cairo::Color.parse(color).r,
87
+ Cairo::Color.parse(color).g,
88
+ Cairo::Color.parse(color).b,
89
+ Cairo::Color.parse(color).a)
90
+ end
91
+ end
92
+
93
+
94
+ Frame.new.show_all
44
95
  Gtk.main
45
96
 
@@ -0,0 +1,63 @@
1
+
2
+ require 'nyle'
3
+
4
+ class Dot
5
+ FGCOLOR = :WHITE
6
+ BGCOLOR = :BLACK
7
+ SIZE = 2
8
+ SPEED = 2
9
+
10
+ def initialize(x, y)
11
+ @x = x
12
+ @y = y
13
+ end
14
+
15
+ def move
16
+ if Nyle.pixel?(@x, @y + SPEED, BGCOLOR) # just below
17
+ Nyle.draw_rect(@x, @y, SIZE, SIZE, {color: BGCOLOR, fill: true})
18
+ @y = @y + SPEED
19
+ return true if @y >= (240 - SPEED)
20
+ elsif rand(2) == 0
21
+ if Nyle.pixel?(@x - SPEED, @y + SPEED, BGCOLOR) # bottom left
22
+ Nyle.draw_rect(@x, @y, SIZE, SIZE, {color: BGCOLOR, fill: true})
23
+ @y = @y + SPEED
24
+ @x = @x - SPEED
25
+ return true if @y >= (240 - SPEED)
26
+ end
27
+ else
28
+ if Nyle.pixel?(@x + SPEED, @y + SPEED, BGCOLOR) # bottom right
29
+ Nyle.draw_rect(@x, @y, SIZE, SIZE, {color: BGCOLOR, fill: true})
30
+ @y = @y + SPEED
31
+ @x = @x + SPEED
32
+ return true if @y >= (240 - SPEED)
33
+ end
34
+ end
35
+ Nyle.draw_rect(@x, @y, SIZE, SIZE, {color: FGCOLOR, fill: true})
36
+ return false
37
+ end
38
+ end
39
+
40
+ class Screen < Nyle::Screen
41
+ FGCOLOR = :GOLD
42
+ BGCOLOR = :BLACK
43
+
44
+ def initialize
45
+ super(120, 240, {bgcolor: BGCOLOR, trace: true})
46
+ @dots = []
47
+ end
48
+
49
+ def draw
50
+ x, y = Nyle.mouse_x, Nyle.mouse_y
51
+ Nyle.draw_circle(x, y, 5, {color: FGCOLOR, fill: true}) if Nyle.mouse_down?(MOUSE_L)
52
+ Nyle.draw_circle(x, y, 5, {color: BGCOLOR, fill: true}) if Nyle.mouse_down?(MOUSE_R)
53
+ @dots << Dot.new(rand(20) + 50, 0) if @dots.size <= 300 # create dots (limit = 300)
54
+ @dots.delete_if do |dot|
55
+ dot.move # move dots
56
+ end
57
+ Nyle.quit if Nyle.key_press?(KEY_Escape)
58
+ end
59
+ end
60
+
61
+ Screen.new.show_all
62
+ Gtk.main
63
+
@@ -4,11 +4,16 @@
4
4
  nyle_basics.rb ... basics
5
5
  nyle_basics2.rb ... basics (in case of using 'include' statement to ommit 'Nyle.' modifier)
6
6
  nyle_block.rb ... breakout
7
+ nyle_click.rb ... click a strawberry
8
+ nyle_clock.rb ... analog clock
7
9
  nyle_colors.rb ... color list
8
10
  nyle_falling.rb ... falling game
11
+ nyle_flight.rb ... flight simulator
12
+ nyle_pixel.rb ... getting color information
9
13
  nyle_rpg.rb ... roll playing game like
10
14
  nyle_shape.rb ... shapes
11
15
  nyle_sketch.rb ... sketch tool
16
+ nyle_sugar.rb ... sugar
12
17
  nyle_tree.rb ... fractal tree
13
18
  nyle_walk_notrace.rb ... random walk (no trace)
14
19
  nyle_walk_trace.rb ... random walk (trace)
@@ -21,9 +26,11 @@
21
26
 
22
27
  image/n_f_banana.png ... banana (image for nyle_falling.rb)
23
28
  image/n_f_panda.png ... panda (image for nyle_falling.rb)
24
- image/n_f_strawberry.png ... strawberry(image for nyle_falling.rb)
29
+ image/n_f_strawberry.png ... strawberry(image for nyle_falling.rb, nyle_click.rb)
25
30
  image/n_f_weapon.png ... weapon (image for nyle_falling.rb))
26
31
 
32
+ image/n_fl_tree.png ... tree (image fo nyle_flight.rb)
33
+
27
34
  image/n_i_bg.png ... background(image for nyle_rgb.rb)
28
35
  image/n_i_chara.png ... character (image for nyle_rgb.rb)
29
36
 
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.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koki Kitamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-11 00:00:00.000000000 Z
11
+ date: 2018-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -78,7 +78,7 @@ dependencies:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
80
  version: 3.3.0
81
- description: "'Nyle' is a minimal graphics framework using Ruby/GTK3 with Cairo"
81
+ description: "'Nyle' is a minimal graphics framework using Ruby/GTK3 and Cairo"
82
82
  email:
83
83
  - spool.kitamura@nifty.ne.jp
84
84
  executables: []
@@ -86,6 +86,7 @@ extensions: []
86
86
  extra_rdoc_files: []
87
87
  files:
88
88
  - ".gitignore"
89
+ - CHANGELOG.md
89
90
  - Gemfile
90
91
  - LICENSE.txt
91
92
  - README.md
@@ -102,16 +103,22 @@ files:
102
103
  - samples/image/n_f_panda.png
103
104
  - samples/image/n_f_strawberry.png
104
105
  - samples/image/n_f_weapon.png
106
+ - samples/image/n_fl_tree32.png
105
107
  - samples/image/n_i_bg.jpg
106
108
  - samples/image/n_i_chara.png
107
109
  - samples/nyle_basics.rb
108
110
  - samples/nyle_basics2.rb
109
111
  - samples/nyle_block.rb
112
+ - samples/nyle_click.rb
113
+ - samples/nyle_clock.rb
110
114
  - samples/nyle_colors.rb
111
115
  - samples/nyle_falling.rb
116
+ - samples/nyle_flight.rb
117
+ - samples/nyle_pixel.rb
112
118
  - samples/nyle_rpg.rb
113
119
  - samples/nyle_shape.rb
114
120
  - samples/nyle_sketch.rb
121
+ - samples/nyle_sugar.rb
115
122
  - samples/nyle_tree.rb
116
123
  - samples/nyle_walk_notrace.rb
117
124
  - samples/nyle_walk_trace.rb
@@ -139,5 +146,5 @@ rubyforge_project:
139
146
  rubygems_version: 2.7.8
140
147
  signing_key:
141
148
  specification_version: 4
142
- summary: minimal graphics framework using Ruby/GTK3 with Cairo
149
+ summary: minimal graphics framework using Ruby/GTK3 and Cairo
143
150
  test_files: []