nyle 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -3
  3. data/CHANGELOG.md +21 -0
  4. data/Gemfile.lock +61 -0
  5. data/README.md +2 -2
  6. data/doc/.gitkeep +0 -0
  7. data/lib/nyle.rb +53 -44
  8. data/lib/nyle/frame.rb +18 -3
  9. data/lib/nyle/screen.rb +5 -4
  10. data/lib/nyle/version.rb +1 -1
  11. data/nyle.gemspec +2 -2
  12. data/samples/{nyle_block.rb → application/block.rb} +0 -1
  13. data/samples/{nyle_clock.rb → application/clock.rb} +0 -1
  14. data/samples/{nyle_falling.rb → application/falling.rb} +5 -7
  15. data/samples/{nyle_flight.rb → application/flight.rb} +6 -9
  16. data/samples/{nyle_sketch.rb → application/sketch.rb} +0 -1
  17. data/samples/{nyle_sugar.rb → application/sugar.rb} +1 -1
  18. data/samples/{nyle_tree.rb → application/tree.rb} +2 -3
  19. data/samples/basic/color_chart.rb +316 -0
  20. data/samples/{nyle_pixel.rb → basic/color_pixel.rb} +1 -1
  21. data/samples/basic/draw_circle.rb +52 -0
  22. data/samples/basic/draw_line.rb +82 -0
  23. data/samples/basic/draw_rect.rb +58 -0
  24. data/samples/{nyle_shape.rb → basic/draw_shape.rb} +70 -70
  25. data/samples/basic/draw_text.rb +55 -0
  26. data/samples/basic/image_click.rb +33 -0
  27. data/samples/basic/image_rotate.rb +42 -0
  28. data/samples/{nyle_rpg.rb → basic/image_rpg.rb} +15 -15
  29. data/samples/basic/keyboard.rb +84 -0
  30. data/samples/{nyle_walk_notrace.rb → basic/random_walk.rb} +3 -3
  31. data/samples/{nyle_walk_trace.rb → basic/random_walk_trace.rb} +3 -3
  32. data/samples/image/n_c_mogura.png +0 -0
  33. data/samples/launcher.rb +125 -0
  34. data/samples/tips/.gitkeep +0 -0
  35. data/samples/tutorial/img.jpg +0 -0
  36. data/samples/tutorial/tut_a10.rb +10 -0
  37. data/samples/tutorial/tut_a20.rb +13 -0
  38. data/samples/tutorial/tut_a30.rb +18 -0
  39. data/samples/tutorial/tut_a40.rb +19 -0
  40. data/samples/tutorial/tut_a45.rb +21 -0
  41. data/samples/tutorial/tut_a50.rb +25 -0
  42. data/samples/tutorial/tut_a60.rb +30 -0
  43. data/samples/tutorial/tut_a70.rb +34 -0
  44. data/samples/tutorial/tut_b10.rb +14 -0
  45. data/samples/tutorial/tut_b20.rb +14 -0
  46. data/samples/tutorial/tut_b30.rb +14 -0
  47. data/samples/tutorial/tut_b40.rb +18 -0
  48. metadata +42 -23
  49. data/doc/Nyle_reference.pdf +0 -0
  50. data/samples/image/n_b_river.gif +0 -0
  51. data/samples/nyle_basics.rb +0 -69
  52. data/samples/nyle_basics2.rb +0 -70
  53. data/samples/nyle_click.rb +0 -34
  54. data/samples/nyle_colors.rb +0 -315
  55. data/samples/readme_samples.txt +0 -36
@@ -0,0 +1,82 @@
1
+ require 'nyle'
2
+
3
+ class Screen < Nyle::Screen
4
+ def initialize
5
+ super
6
+ end
7
+
8
+ def draw
9
+ Nyle.draw_line( 40, 70, 100, 10)
10
+ Nyle.draw_line( 90, 70, 150, 10, {weight: 4})
11
+ Nyle.draw_line(140, 70, 200, 10, {weight: 6})
12
+ Nyle.draw_line(190, 70, 250, 10, {weight: 8})
13
+ Nyle.draw_line(240, 70, 300, 10, {weight: 10})
14
+ Nyle.draw_line(310, 70, 370, 10, { cap: :ROUND})
15
+ Nyle.draw_line(360, 70, 420, 10, {weight: 4, cap: :ROUND})
16
+ Nyle.draw_line(410, 70, 470, 10, {weight: 6, cap: :ROUND})
17
+ Nyle.draw_line(460, 70, 520, 10, {weight: 8, cap: :ROUND})
18
+ Nyle.draw_line(510, 70, 570, 10, {weight: 10, cap: :ROUND})
19
+
20
+ Nyle.draw_line( 40, 150, 100, 90, { a: 0.2})
21
+ Nyle.draw_line( 90, 150, 150, 90, {weight: 4 , a: 0.4})
22
+ Nyle.draw_line(140, 150, 200, 90, {weight: 6 , a: 0.6})
23
+ Nyle.draw_line(190, 150, 250, 90, {weight: 8 , a: 0.8})
24
+ Nyle.draw_line(240, 150, 300, 90, {weight: 10 , a: 1.0})
25
+ Nyle.draw_line(310, 150, 370, 90, { cap: :ROUND, a: 0.2})
26
+ Nyle.draw_line(360, 150, 420, 90, {weight: 4, cap: :ROUND, a: 0.4})
27
+ Nyle.draw_line(410, 150, 470, 90, {weight: 6, cap: :ROUND, a: 0.6})
28
+ Nyle.draw_line(460, 150, 520, 90, {weight: 8, cap: :ROUND, a: 0.8})
29
+ Nyle.draw_line(510, 150, 570, 90, {weight: 10, cap: :ROUND, a: 1.0})
30
+
31
+ Nyle.draw_line( 40, 230, 100, 170, { a: 0.2, color: :RED})
32
+ Nyle.draw_line( 90, 230, 150, 170, {weight: 4 , a: 0.4, color: :RED})
33
+ Nyle.draw_line(140, 230, 200, 170, {weight: 6 , a: 0.6, color: :RED})
34
+ Nyle.draw_line(190, 230, 250, 170, {weight: 8 , a: 0.8, color: :RED})
35
+ Nyle.draw_line(240, 230, 300, 170, {weight: 10 , a: 1.0, color: :RED})
36
+ Nyle.draw_line(310, 230, 370, 170, { cap: :ROUND, a: 0.2, color: :RED})
37
+ Nyle.draw_line(360, 230, 420, 170, {weight: 4, cap: :ROUND, a: 0.4, color: :RED})
38
+ Nyle.draw_line(410, 230, 470, 170, {weight: 6, cap: :ROUND, a: 0.6, color: :RED})
39
+ Nyle.draw_line(460, 230, 520, 170, {weight: 8, cap: :ROUND, a: 0.8, color: :RED})
40
+ Nyle.draw_line(510, 230, 570, 170, {weight: 10, cap: :ROUND, a: 1.0, color: :RED})
41
+
42
+ Nyle.draw_line( 40, 310, 100, 250, { a: 0.2, color: :FOREST_GREEN})
43
+ Nyle.draw_line( 90, 310, 150, 250, {weight: 4 , a: 0.4, color: :FOREST_GREEN})
44
+ Nyle.draw_line(140, 310, 200, 250, {weight: 6 , a: 0.6, color: :FOREST_GREEN})
45
+ Nyle.draw_line(190, 310, 250, 250, {weight: 8 , a: 0.8, color: :FOREST_GREEN})
46
+ Nyle.draw_line(240, 310, 300, 250, {weight: 10 , a: 1.0, color: :FOREST_GREEN})
47
+ Nyle.draw_line(310, 310, 370, 250, { cap: :ROUND, a: 0.2, color: :FOREST_GREEN})
48
+ Nyle.draw_line(360, 310, 420, 250, {weight: 4, cap: :ROUND, a: 0.4, color: :FOREST_GREEN})
49
+ Nyle.draw_line(410, 310, 470, 250, {weight: 6, cap: :ROUND, a: 0.6, color: :FOREST_GREEN})
50
+ Nyle.draw_line(460, 310, 520, 250, {weight: 8, cap: :ROUND, a: 0.8, color: :FOREST_GREEN})
51
+ Nyle.draw_line(510, 310, 570, 250, {weight: 10, cap: :ROUND, a: 1.0, color: :FOREST_GREEN})
52
+
53
+ Nyle.draw_line( 40, 390, 100, 330, { a: 0.2, color: :COBALT})
54
+ Nyle.draw_line( 90, 390, 150, 330, {weight: 4 , a: 0.4, color: :COBALT})
55
+ Nyle.draw_line(140, 390, 200, 330, {weight: 6 , a: 0.6, color: :COBALT})
56
+ Nyle.draw_line(190, 390, 250, 330, {weight: 8 , a: 0.8, color: :COBALT})
57
+ Nyle.draw_line(240, 390, 300, 330, {weight: 10 , a: 1.0, color: :COBALT})
58
+ Nyle.draw_line(310, 390, 370, 330, { cap: :ROUND, a: 0.2, color: :COBALT})
59
+ Nyle.draw_line(360, 390, 420, 330, {weight: 4, cap: :ROUND, a: 0.4, color: :COBALT})
60
+ Nyle.draw_line(410, 390, 470, 330, {weight: 6, cap: :ROUND, a: 0.6, color: :COBALT})
61
+ Nyle.draw_line(460, 390, 520, 330, {weight: 8, cap: :ROUND, a: 0.8, color: :COBALT})
62
+ Nyle.draw_line(510, 390, 570, 330, {weight: 10, cap: :ROUND, a: 1.0, color: :COBALT})
63
+
64
+ Nyle.draw_line( 40, 470, 100, 410, { a: 0.2, color: :GOLD})
65
+ Nyle.draw_line( 90, 470, 150, 410, {weight: 4 , a: 0.4, color: :GOLD})
66
+ Nyle.draw_line(140, 470, 200, 410, {weight: 6 , a: 0.6, color: :GOLD})
67
+ Nyle.draw_line(190, 470, 250, 410, {weight: 8 , a: 0.8, color: :GOLD})
68
+ Nyle.draw_line(240, 470, 300, 410, {weight: 10 , a: 1.0, color: :GOLD})
69
+ Nyle.draw_line(310, 470, 370, 410, { cap: :ROUND, a: 0.2, color: :GOLD})
70
+ Nyle.draw_line(360, 470, 420, 410, {weight: 4, cap: :ROUND, a: 0.4, color: :GOLD})
71
+ Nyle.draw_line(410, 470, 470, 410, {weight: 6, cap: :ROUND, a: 0.6, color: :GOLD})
72
+ Nyle.draw_line(460, 470, 520, 410, {weight: 8, cap: :ROUND, a: 0.8, color: :GOLD})
73
+ Nyle.draw_line(510, 470, 570, 410, {weight: 10, cap: :ROUND, a: 1.0, color: :GOLD})
74
+
75
+ Nyle.quit if Nyle.key_press?(KEY_Escape)
76
+ end
77
+ end
78
+
79
+
80
+ Screen.new.show_all
81
+ Gtk.main
82
+
@@ -0,0 +1,58 @@
1
+ require 'nyle'
2
+
3
+ class Screen < Nyle::Screen
4
+ def initialize
5
+ super
6
+ end
7
+
8
+ def draw
9
+ Nyle.draw_rect( 90, 40, 60, 40)
10
+ Nyle.draw_rect(190, 40, 60, 40, {weight: 4})
11
+ Nyle.draw_rect(290, 40, 60, 40, {weight: 6})
12
+ Nyle.draw_rect(390, 40, 60, 40, {weight: 8})
13
+ Nyle.draw_rect(490, 40, 60, 40, {weight: 10})
14
+
15
+ Nyle.draw_rect( 90, 100, 60, 40, {round: 4})
16
+ Nyle.draw_rect(190, 100, 60, 40, {round: 8})
17
+ Nyle.draw_rect(290, 100, 60, 40, {round: 12})
18
+ Nyle.draw_rect(390, 100, 60, 40, {round: 16})
19
+ Nyle.draw_rect(490, 100, 60, 40, {round: 20})
20
+
21
+ Nyle.draw_rect( 90, 160, 60, 40, {fill: true, a: 0.2})
22
+ Nyle.draw_rect(190, 160, 60, 40, {fill: true, a: 0.4})
23
+ Nyle.draw_rect(290, 160, 60, 40, {fill: true, a: 0.6})
24
+ Nyle.draw_rect(390, 160, 60, 40, {fill: true, a: 0.8})
25
+ Nyle.draw_rect(490, 160, 60, 40, {fill: true, a: 1.0})
26
+
27
+ Nyle.draw_rect( 90, 220, 60, 40, {fill: true, a: 0.2, color: :RED})
28
+ Nyle.draw_rect(190, 220, 60, 40, {fill: true, a: 0.4, color: :RED})
29
+ Nyle.draw_rect(290, 220, 60, 40, {fill: true, a: 0.6, color: :RED})
30
+ Nyle.draw_rect(390, 220, 60, 40, {fill: true, a: 0.8, color: :RED})
31
+ Nyle.draw_rect(490, 220, 60, 40, {fill: true, a: 1.0, color: :RED})
32
+
33
+ Nyle.draw_rect( 90, 280, 60, 40, {fill: true, a: 0.2, color: :FOREST_GREEN})
34
+ Nyle.draw_rect(190, 280, 60, 40, {fill: true, a: 0.4, color: :FOREST_GREEN})
35
+ Nyle.draw_rect(290, 280, 60, 40, {fill: true, a: 0.6, color: :FOREST_GREEN})
36
+ Nyle.draw_rect(390, 280, 60, 40, {fill: true, a: 0.8, color: :FOREST_GREEN})
37
+ Nyle.draw_rect(490, 280, 60, 40, {fill: true, a: 1.0, color: :FOREST_GREEN})
38
+
39
+ Nyle.draw_rect( 90, 340, 60, 40, {fill: true, a: 0.2, color: :COBALT})
40
+ Nyle.draw_rect(190, 340, 60, 40, {fill: true, a: 0.4, color: :COBALT})
41
+ Nyle.draw_rect(290, 340, 60, 40, {fill: true, a: 0.6, color: :COBALT})
42
+ Nyle.draw_rect(390, 340, 60, 40, {fill: true, a: 0.8, color: :COBALT})
43
+ Nyle.draw_rect(490, 340, 60, 40, {fill: true, a: 1.0, color: :COBALT})
44
+
45
+ Nyle.draw_rect( 90, 400, 60, 40, {fill: true, a: 0.2, color: :GOLD})
46
+ Nyle.draw_rect(190, 400, 60, 40, {fill: true, a: 0.4, color: :GOLD})
47
+ Nyle.draw_rect(290, 400, 60, 40, {fill: true, a: 0.6, color: :GOLD})
48
+ Nyle.draw_rect(390, 400, 60, 40, {fill: true, a: 0.8, color: :GOLD})
49
+ Nyle.draw_rect(490, 400, 60, 40, {fill: true, a: 1.0, color: :GOLD})
50
+
51
+ Nyle.quit if Nyle.key_press?(KEY_Escape)
52
+ end
53
+ end
54
+
55
+
56
+ Screen.new.show_all
57
+ Gtk.main
58
+
@@ -1,70 +1,70 @@
1
-
2
- require 'nyle'
3
-
4
- module Points
5
- def star(x, y)
6
- [
7
- [x, y - 50],
8
- [x + 14, y - 20],
9
- [x + 47, y - 15],
10
- [x + 23, y + 7],
11
- [x + 29, y + 40],
12
- [x, y + 25],
13
- [x - 29, y + 40],
14
- [x - 23, y + 7],
15
- [x - 47, y - 15],
16
- [x - 14, y - 20]
17
- ]
18
- end
19
-
20
- def para_star(x, y)
21
- rl, rm, rs = 70, 50, 30 # radius(large, middle, small)
22
- count = 10
23
- angle = 360.0 / (count * 4) # central angle of each vertex
24
- deg = Math::PI / 180.0
25
-
26
- points = []
27
- for i in 1..count
28
- points << [x + rs * Math.cos((i * 4 - 3) * angle * deg), y + rs * Math.sin((i * 4 - 3) * angle * deg)]
29
- points << [x + rm * Math.cos((i * 4 - 2) * angle * deg), y + rm * Math.sin((i * 4 - 2) * angle * deg)]
30
- points << [x + rs * Math.cos((i * 4 - 1) * angle * deg), y + rs * Math.sin((i * 4 - 1) * angle * deg)]
31
- points << [x + rl * Math.cos((i * 4 - 0) * angle * deg), y + rl * Math.sin((i * 4 - 0) * angle * deg)]
32
- end
33
- points
34
- end
35
-
36
- def wave(x, y)
37
- points = []
38
- for deg in 0..(360 * 5)
39
- th = -deg * (Math::PI / 180)
40
- points << [deg / 5 + x, Math.sin(th) * 20 + y]
41
- end
42
- points
43
- end
44
- end
45
-
46
-
47
- class Screen < Nyle::Screen
48
- include Points
49
- def initialize
50
- super
51
- end
52
- def draw
53
- Nyle.draw_shape(star(120, 100), {color: :GOLD, weight: 5, close: true})
54
- Nyle.draw_shape(star(280, 100), {color: :GOLD, weight: 5, close: true, fill: true})
55
- Nyle.draw_shape(star(440, 100), {color: :GOLD, a: 0.5, weight: 5, close: true, fill: true})
56
-
57
- Nyle.draw_shape(para_star(120, 240), {color: :BROWN, weight: 3, close: true})
58
- Nyle.draw_shape(para_star(280, 240), {color: :BROWN, weight: 3, close: true, fill: true})
59
- Nyle.draw_shape(para_star(440, 240), {color: :BROWN, a: 0.8, weight: 3, close: true, fill: true})
60
-
61
- Nyle.draw_shape(wave(100, 360), {color: :SKY_BLUE, weight: 5, cap: :ROUND})
62
- Nyle.draw_shape(wave(100, 410), {color: :SKY_BLUE, weight: 5, cap: :ROUND, fill: true})
63
-
64
- Nyle.quit if Nyle.key_press?(KEY_Escape)
65
- end
66
- end
67
-
68
- Screen.new.show_all
69
- Gtk.main
70
-
1
+ require 'nyle'
2
+
3
+ module Points
4
+ def star(x, y)
5
+ [
6
+ [x, y - 50],
7
+ [x + 14, y - 20],
8
+ [x + 47, y - 15],
9
+ [x + 23, y + 7],
10
+ [x + 29, y + 40],
11
+ [x, y + 25],
12
+ [x - 29, y + 40],
13
+ [x - 23, y + 7],
14
+ [x - 47, y - 15],
15
+ [x - 14, y - 20]
16
+ ]
17
+ end
18
+
19
+ def para_star(x, y)
20
+ rl, rm, rs = 70, 50, 30 # radius(large, middle, small)
21
+ count = 10
22
+ angle = 360.0 / (count * 4) # central angle of each vertex
23
+ deg = Math::PI / 180.0
24
+
25
+ points = []
26
+ for i in 1..count
27
+ points << [x + rs * Math.cos((i * 4 - 3) * angle * deg), y + rs * Math.sin((i * 4 - 3) * angle * deg)]
28
+ points << [x + rm * Math.cos((i * 4 - 2) * angle * deg), y + rm * Math.sin((i * 4 - 2) * angle * deg)]
29
+ points << [x + rs * Math.cos((i * 4 - 1) * angle * deg), y + rs * Math.sin((i * 4 - 1) * angle * deg)]
30
+ points << [x + rl * Math.cos((i * 4 - 0) * angle * deg), y + rl * Math.sin((i * 4 - 0) * angle * deg)]
31
+ end
32
+ points
33
+ end
34
+
35
+ def wave(x, y)
36
+ points = []
37
+ for deg in 0..(360 * 6)
38
+ th = -deg * (Math::PI / 180)
39
+ points << [deg / 5 + x, Math.sin(th) * 20 + y]
40
+ end
41
+ points
42
+ end
43
+ end
44
+
45
+
46
+ class Screen < Nyle::Screen
47
+ include Points
48
+ def initialize
49
+ super
50
+ end
51
+ def draw
52
+ Nyle.draw_shape(star(160, 100), {color: :GOLD, weight: 5, close: true})
53
+ Nyle.draw_shape(star(320, 100), {color: :GOLD, weight: 5, close: true, fill: true})
54
+ Nyle.draw_shape(star(480, 100), {color: :GOLD, a: 0.5, weight: 5, close: true, fill: true})
55
+
56
+ Nyle.draw_shape(para_star(160, 240), {color: :BROWN, weight: 3, close: true})
57
+ Nyle.draw_shape(para_star(320, 240), {color: :BROWN, weight: 3, close: true, fill: true})
58
+ Nyle.draw_shape(para_star(480, 240), {color: :BROWN, a: 0.5, weight: 3, close: true, fill: true})
59
+
60
+ Nyle.draw_shape(wave(100, 360), {color: :SKY_BLUE, weight: 5, cap: :ROUND})
61
+ Nyle.draw_shape(wave(100, 410), {color: :SKY_BLUE, weight: 5, cap: :ROUND, fill: true})
62
+
63
+ Nyle.quit if Nyle.key_press?(KEY_Escape)
64
+ end
65
+ end
66
+
67
+
68
+ Screen.new.show_all
69
+ Gtk.main
70
+
@@ -0,0 +1,55 @@
1
+ require 'nyle'
2
+
3
+ class Screen < Nyle::Screen
4
+ def initialize
5
+ super
6
+ end
7
+
8
+ def draw
9
+ Nyle.draw_text( 80, 70, "Nyle", {size: 16})
10
+ Nyle.draw_text(140, 70, "Nyle", {size: 24})
11
+ Nyle.draw_text(220, 70, "Nyle", {size: 32})
12
+ Nyle.draw_text(320, 70, "Nyle", {size: 40})
13
+ Nyle.draw_text(440, 70, "Nyle", {size: 48})
14
+
15
+ Nyle.draw_text( 80, 120, "Nyle", {size: 16, a: 1.0})
16
+ Nyle.draw_text(140, 120, "Nyle", {size: 24, a: 0.8})
17
+ Nyle.draw_text(220, 120, "Nyle", {size: 32, a: 0.6})
18
+ Nyle.draw_text(320, 120, "Nyle", {size: 40, a: 0.4})
19
+ Nyle.draw_text(440, 120, "Nyle", {size: 48, a: 0.2})
20
+
21
+ Nyle.draw_text( 80, 170, "Nyle", {size: 16, color: :RED})
22
+ Nyle.draw_text(140, 170, "Nyle", {size: 24, color: :RED})
23
+ Nyle.draw_text(220, 170, "Nyle", {size: 32, color: :RED})
24
+ Nyle.draw_text(320, 170, "Nyle", {size: 40, color: :RED})
25
+ Nyle.draw_text(440, 170, "Nyle", {size: 48, color: :RED})
26
+
27
+ Nyle.draw_text( 80, 220, "Nyle", {size: 16, color: :FOREST_GREEN})
28
+ Nyle.draw_text(140, 220, "Nyle", {size: 24, color: :FOREST_GREEN})
29
+ Nyle.draw_text(220, 220, "Nyle", {size: 32, color: :FOREST_GREEN})
30
+ Nyle.draw_text(320, 220, "Nyle", {size: 40, color: :FOREST_GREEN})
31
+ Nyle.draw_text(440, 220, "Nyle", {size: 48, color: :FOREST_GREEN})
32
+
33
+ Nyle.draw_text( 80, 270, "Nyle", {size: 16, color: :COBALT})
34
+ Nyle.draw_text(140, 270, "Nyle", {size: 24, color: :COBALT})
35
+ Nyle.draw_text(220, 270, "Nyle", {size: 32, color: :COBALT})
36
+ Nyle.draw_text(320, 270, "Nyle", {size: 40, color: :COBALT})
37
+ Nyle.draw_text(440, 270, "Nyle", {size: 48, color: :COBALT})
38
+
39
+ Nyle.draw_text( 80, 320, "Nyle", {size: 16, color: :GOLD})
40
+ Nyle.draw_text(140, 320, "Nyle", {size: 24, color: :GOLD})
41
+ Nyle.draw_text(220, 320, "Nyle", {size: 32, color: :GOLD})
42
+ Nyle.draw_text(320, 320, "Nyle", {size: 40, color: :GOLD})
43
+ Nyle.draw_text(440, 320, "Nyle", {size: 48, color: :GOLD})
44
+
45
+ Nyle.draw_text( 80, 390, "minimal graphics framework", {size: 24, a: 0.8})
46
+ Nyle.draw_text(110, 420, "using Ruby/GTK3 and rcairo", {size: 24, a: 0.8})
47
+
48
+ Nyle.quit if Nyle.key_press?(KEY_Escape)
49
+ end
50
+ end
51
+
52
+
53
+ Screen.new.show_all
54
+ Gtk.main
55
+
@@ -0,0 +1,33 @@
1
+ require 'nyle'
2
+
3
+ class Screen < Nyle::Screen
4
+ def initialize
5
+ super(480, 320, {bgcolor: :YELLOW_GREEN})
6
+ @image = Nyle.load_image("../image/n_c_mogura.png")
7
+ calc_xy
8
+ end
9
+
10
+ def draw
11
+ Nyle.draw_image(@x, @y, @image)
12
+ calc_xy if clicked?
13
+ Nyle.quit if Nyle.key_press?(KEY_Escape)
14
+ end
15
+
16
+ def calc_xy
17
+ @x = rand(Nyle.screen_width - @image.width)
18
+ @y = rand(Nyle.screen_height - @image.height)
19
+ end
20
+
21
+ def clicked?
22
+ Nyle.mouse_press?(MOUSE_L) and
23
+ Nyle.mouse_x >= @x and
24
+ Nyle.mouse_x <= @x + @image.width and
25
+ Nyle.mouse_y >= @y and
26
+ Nyle.mouse_y <= @y + @image.height
27
+ end
28
+ end
29
+
30
+
31
+ Screen.new.show_all
32
+ Gtk.main
33
+
@@ -0,0 +1,42 @@
1
+ require 'nyle'
2
+
3
+ class Screen < Nyle::Screen
4
+ def initialize
5
+ super
6
+ @image1 = Nyle.load_image("../image/n_b_crocodile.png")
7
+ @th = 0
8
+ end
9
+
10
+ def draw
11
+ # image
12
+ if Nyle.mouse_press?(MOUSE_L) or Nyle.key_press?(KEY_Left)
13
+ @th += Math::PI / 2
14
+ @th = 0 if @th >= Math::PI * 2
15
+ end
16
+ if Nyle.mouse_press?(MOUSE_R) or Nyle.key_press?(KEY_Right)
17
+ @th -= Math::PI / 2
18
+ @th = 0 if @th <= -Math::PI * 2
19
+ end
20
+
21
+ Nyle.save do
22
+ Nyle.translate(320, 150)
23
+ Nyle.rotate(@th)
24
+ Nyle.draw_image(0, 0, @image1, {pos: :CORNER})
25
+ Nyle.draw_circle(0, 0, 2, {color: :RED, fill: true})
26
+ end
27
+
28
+ Nyle.save do
29
+ Nyle.translate(320, 350)
30
+ Nyle.rotate(@th)
31
+ Nyle.draw_image(0, 0, @image1, {pos: :CENTER})
32
+ Nyle.draw_circle(0, 0, 2, {color: :RED, fill: true})
33
+ end
34
+
35
+ Nyle.quit if Nyle.key_press?(KEY_Escape)
36
+ end
37
+ end
38
+
39
+
40
+ Screen.new.show_all
41
+ Gtk.main
42
+
@@ -1,6 +1,7 @@
1
-
2
1
  require 'nyle'
3
2
 
3
+ # Images: (c)2016 NISHIDA Ryota - http://dev.eyln.com (zlib License)
4
+
4
5
  class Character
5
6
  def initialize(x, y, tiles)
6
7
  @x = x
@@ -23,8 +24,8 @@ class Character
23
24
  @tx += 1 # animation to walk
24
25
  @tx = 0 if @tx > 2 # range = (0..2)
25
26
 
26
- @x += dx # drawing position(x)
27
- @y += dy # drawing position(y)
27
+ @x += (dx * 2) # drawing position(x)
28
+ @y += (dy * 2) # drawing position(y)
28
29
 
29
30
  @x = -@tiles[0][0].width if @x > Nyle.screen_width # right end
30
31
  @x = Nyle.screen_width if @x < -@tiles[0][0].width # left end
@@ -36,17 +37,18 @@ end
36
37
  class Screen < Nyle::Screen
37
38
  def initialize
38
39
  super(510, 390)
39
- @image = Nyle.load_image("./image/n_i_bg.jpg", {sx: 0.5, sy: 0.5})
40
- @image_half_right = Nyle.load_image("./image/n_i_bg.jpg", {sx: 0.5, sy: 0.5, cx: 320, cy: 0, cw: 320, ch: 480})
41
- @image_half_low = Nyle.load_image("./image/n_i_bg.jpg", {sx: 0.5, sy: 0.5, cx: 0, cy: 240, cw: 640, ch: 240})
42
- @image_quarter = Nyle.load_image("./image/n_i_bg.jpg", {sx: 0.5, sy: 0.5, cx: 320, cy: 240, cw: 320, ch: 240})
43
40
 
44
- @tiles01 = Nyle.load_image_tiles("./image/n_i_chara.png", 1, 1) # itself
45
- @tiles03 = Nyle.load_image_tiles("./image/n_i_chara.png", 3, 1) # divide into 3 pieces horizontally
46
- @tiles04 = Nyle.load_image_tiles("./image/n_i_chara.png", 1, 4) # divide into 4 pieces vertically
47
- @tiles12 = Nyle.load_image_tiles("./image/n_i_chara.png", 3, 4) # divide into 12 pieces vertically and horizontally
41
+ @image = Nyle.load_image("../image/n_i_bg.jpg", {sx: 0.5, sy: 0.5})
42
+ @image_half_right = Nyle.load_image("../image/n_i_bg.jpg", {sx: 0.5, sy: 0.5, cx: 320, cy: 0, cw: 320, ch: 480})
43
+ @image_half_low = Nyle.load_image("../image/n_i_bg.jpg", {sx: 0.5, sy: 0.5, cx: 0, cy: 240, cw: 640, ch: 240})
44
+ @image_quarter = Nyle.load_image("../image/n_i_bg.jpg", {sx: 0.5, sy: 0.5, cx: 320, cy: 240, cw: 320, ch: 240})
45
+
46
+ @tiles01 = Nyle.load_image_tiles("../image/n_i_chara.png", 1, 1) # itself
47
+ @tiles03 = Nyle.load_image_tiles("../image/n_i_chara.png", 3, 1) # divide into 3 pieces horizontally
48
+ @tiles04 = Nyle.load_image_tiles("../image/n_i_chara.png", 1, 4) # divide into 4 pieces vertically
49
+ @tiles12 = Nyle.load_image_tiles("../image/n_i_chara.png", 3, 4) # divide into 12 pieces vertically and horizontally
48
50
 
49
- @tiles_player = Nyle.load_image_tiles("./image/n_i_chara.png", 3, 4, {sx: 1.25, sy: 1.25}) # divide into 12 pieces and enlarge
51
+ @tiles_player = Nyle.load_image_tiles("../image/n_i_chara.png", 3, 4, {sx: 1.25, sy: 1.25}) # divide into 12 pieces and enlarge
50
52
  @character = Character.new(140, 150, @tiles_player)
51
53
  end
52
54
 
@@ -86,9 +88,7 @@ class Screen < Nyle::Screen
86
88
  end
87
89
 
88
90
  def update
89
- dx = (Nyle.key_down?(KEY_Right) ? 1 : (Nyle.key_down?(KEY_Left) ? -1 : 0))
90
- dy = (Nyle.key_down?(KEY_Down) ? 1 : (Nyle.key_down?(KEY_Up) ? -1 : 0))
91
- @character.move(dx, dy)
91
+ @character.move(Nyle.cursor_x, Nyle.cursor_y)
92
92
  end
93
93
  end
94
94