kame 0.4.0 → 0.5.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.
- data/CHANGE_LOG.txt +15 -0
- data/README.md +26 -13
- data/VERSION +1 -1
- data/kame.gemspec +3 -2
- data/lib/kame.rb +12 -3
- data/lib/kame/kame_colours.rb +9 -1
- data/lib/kame/kame_window.rb +20 -1
- metadata +4 -3
data/CHANGE_LOG.txt
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
0.5.0
|
2
|
+
|
3
|
+
* Added more colours as selected by my 6yo daughter.
|
4
|
+
* Added an optional colour param to pen_down.
|
5
|
+
* Added defensive check for valid colour names.
|
6
|
+
* Added grid. See options, off by default.
|
7
|
+
|
8
|
+
0.4.0
|
9
|
+
|
10
|
+
* Fixed bug when on Windows. The gosu draw method was called before update on the first time round and so the time variable wasn't available. Now works on Windows.
|
11
|
+
* Changed the default pen to black as the default paper is white.
|
12
|
+
|
13
|
+
0.3.0
|
14
|
+
|
15
|
+
* Initial public release
|
data/README.md
CHANGED
@@ -18,10 +18,10 @@ Each command is on a new line and they are executed in order.
|
|
18
18
|
|
19
19
|
As this is using Ruby, you also have access to Ruby constructs such as loops and functions.
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
Platforms
|
22
|
+
---------
|
23
23
|
|
24
|
-
I've tested this on OSX and
|
24
|
+
I've tested this on OSX Snow Leopard and also Windows 7. Both work fine :o) It should also work on OSX Lion and Linux in theory, but I haven't tested this yet. Please let me know if you try it.
|
25
25
|
|
26
26
|
Install
|
27
27
|
-------
|
@@ -74,9 +74,14 @@ To move the turtle backward by 75 pixels from it's current position, you can use
|
|
74
74
|
|
75
75
|
backward 75
|
76
76
|
|
77
|
-
|
77
|
+
You can change the colour of the turtle's pen at any time (on the paper or not) with the `colour` command:
|
78
|
+
|
79
|
+
colour :pink
|
80
|
+
|
81
|
+
To tell the turtle to put his pen down onto the paper use the `pen_down` command. There is an optional parameter for the pen colour to switch to, if not supplied the pen is not changed:
|
78
82
|
|
79
83
|
pen_down
|
84
|
+
pen_down :red
|
80
85
|
|
81
86
|
To tell the turtle to pick his pen up again, use the `pen_up` command:
|
82
87
|
|
@@ -89,10 +94,6 @@ You can ask the turtle to rotate 90 degrees to the left (anti-clockwise) on the
|
|
89
94
|
You can ask the turtle to rotate 90 degrees to the right (clockwise) on the spot without moving by using the `turn_right` command:
|
90
95
|
|
91
96
|
turn_right 90
|
92
|
-
|
93
|
-
You can change the colour of the turtle's pen at any time (on the paper or not) with the `colour` command:
|
94
|
-
|
95
|
-
colour :pink
|
96
97
|
|
97
98
|
Colours
|
98
99
|
-------
|
@@ -107,6 +108,14 @@ Here is a list of the available colours:
|
|
107
108
|
:yellow
|
108
109
|
:pink
|
109
110
|
:grey
|
111
|
+
:orange
|
112
|
+
:purple
|
113
|
+
:brown
|
114
|
+
:peach
|
115
|
+
:turquoise
|
116
|
+
:silver
|
117
|
+
:gold
|
118
|
+
:violet
|
110
119
|
|
111
120
|
Options
|
112
121
|
-------
|
@@ -119,11 +128,15 @@ In addition to commanding the turtle, there are some options you can specify. Yo
|
|
119
128
|
|
120
129
|
Here is a list of all options with their default values (all are optional):
|
121
130
|
|
122
|
-
:width => 640
|
123
|
-
:height => 480
|
124
|
-
:paper => :white
|
125
|
-
:title => 'Kame'
|
126
|
-
:speed => 10
|
131
|
+
:width => 640 # The width of the paper in pixels
|
132
|
+
:height => 480 # The height of the paper in pixels
|
133
|
+
:paper => :white # The colour of the paper (from the list above)
|
134
|
+
:title => 'Kame' # The window title
|
135
|
+
:speed => 10 # The speed that the turtle draws. This is how many lines per second should be drawn
|
136
|
+
:grid => false # Should the help grid be displayed (true | false)?
|
137
|
+
:grid_size => 8 # If the help grid is displayed, this is how many rows and columns should be drawn
|
138
|
+
:grid_colour => :silver # If the help grid is displayed, this is the colour for the grid (from the list above)
|
139
|
+
|
127
140
|
|
128
141
|
|
129
142
|
Contributing to kame
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/kame.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "kame"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andy Pike"]
|
12
|
-
s.date = "2011-11-
|
12
|
+
s.date = "2011-11-13"
|
13
13
|
s.description = "Kame (Japanese for turtle) is an implementation of the Logo programming language built as a challenge to myself. I wanted a simple way to introduce programming in Ruby to my daughter and thought this would be fun. With Kame, you control the movement of a turtle around the screen by programming commands. With these simple commands your turtle will draw you a picture. It's a nice introduction to programming for kids and will also help their maths :o)"
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
]
|
18
18
|
s.files = [
|
19
19
|
".document",
|
20
|
+
"CHANGE_LOG.txt",
|
20
21
|
"Gemfile",
|
21
22
|
"Gemfile.lock",
|
22
23
|
"LICENSE.txt",
|
data/lib/kame.rb
CHANGED
@@ -17,7 +17,10 @@ class Kame
|
|
17
17
|
:height => 480,
|
18
18
|
:paper => :white,
|
19
19
|
:title => 'Kame',
|
20
|
-
:speed => 10
|
20
|
+
:speed => 10,
|
21
|
+
:grid_size => 8,
|
22
|
+
:grid_colour => :silver,
|
23
|
+
:grid => false
|
21
24
|
}.merge(options)
|
22
25
|
|
23
26
|
instance_eval(&block)
|
@@ -29,8 +32,9 @@ class Kame
|
|
29
32
|
@state[:pen_down] = false
|
30
33
|
end
|
31
34
|
|
32
|
-
def pen_down
|
35
|
+
def pen_down(colour = nil)
|
33
36
|
@state[:pen_down] = true
|
37
|
+
colour(colour) unless colour.nil?
|
34
38
|
end
|
35
39
|
|
36
40
|
def pen_down?
|
@@ -46,7 +50,12 @@ class Kame
|
|
46
50
|
end
|
47
51
|
|
48
52
|
def colour(colour)
|
49
|
-
|
53
|
+
new_colour = KameColours::lookup[colour]
|
54
|
+
if new_colour.nil?
|
55
|
+
new_colour = KameColours::lookup[:black]
|
56
|
+
puts "Can't find the colour '#{colour.to_s}', using black instead."
|
57
|
+
end
|
58
|
+
@state[:line_colour] = new_colour
|
50
59
|
end
|
51
60
|
|
52
61
|
def forward(distance)
|
data/lib/kame/kame_colours.rb
CHANGED
@@ -8,7 +8,15 @@ class KameColours
|
|
8
8
|
:blue => 0xff0000ff,
|
9
9
|
:yellow => 0xffffff00,
|
10
10
|
:pink => 0xffff00ff,
|
11
|
-
:grey => 0xff808080
|
11
|
+
:grey => 0xff808080,
|
12
|
+
:orange => 0xffff9900,
|
13
|
+
:purple => 0xff9900ff,
|
14
|
+
:brown => 0xff6b4e01,
|
15
|
+
:peach => 0xffffcb7a,
|
16
|
+
:turquoise => 0xff5edfbf,
|
17
|
+
:silver => 0xffcccccc,
|
18
|
+
:gold => 0xffffd700,
|
19
|
+
:violet => 0xffbe75ea
|
12
20
|
}
|
13
21
|
end
|
14
22
|
end
|
data/lib/kame/kame_window.rb
CHANGED
@@ -6,6 +6,9 @@ class KameWindow < Gosu::Window
|
|
6
6
|
@height = options[:height]
|
7
7
|
@background_colour = Gosu::Color.argb(KameColours::lookup[options[:paper]])
|
8
8
|
@speed = options[:speed]
|
9
|
+
@grid = options[:grid]
|
10
|
+
@grid_size = options[:grid_size]
|
11
|
+
@grid_colour = Gosu::Color.argb(KameColours::lookup[options[:grid_colour]])
|
9
12
|
@lines = lines
|
10
13
|
@first_frame = Gosu::milliseconds
|
11
14
|
|
@@ -21,6 +24,21 @@ class KameWindow < Gosu::Window
|
|
21
24
|
0)
|
22
25
|
end
|
23
26
|
|
27
|
+
def grid
|
28
|
+
@grid_font ||= Gosu::Font.new(self, "Arial", 10)
|
29
|
+
@grid_size.times do |i|
|
30
|
+
c = (@width / @grid_size) * (i + 1)
|
31
|
+
r = (@height / @grid_size) * (i + 1)
|
32
|
+
|
33
|
+
draw_line(0, r, @grid_colour, @width, r, @grid_colour, 1)
|
34
|
+
@grid_font.draw(r.to_s, 2, r - 11, 1, 1, 1, @grid_colour)
|
35
|
+
|
36
|
+
draw_line(c, 0, @grid_colour, c, @height, @grid_colour, 1)
|
37
|
+
c_width = @grid_font.text_width(c.to_s)
|
38
|
+
@grid_font.draw(c.to_s, c - c_width - 2, @height - 13, 1, 1, 1, @grid_colour)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
24
42
|
def update
|
25
43
|
@this_frame = Gosu::milliseconds
|
26
44
|
@seconds_since_last_frame = (@this_frame - @first_frame) / 1000.0
|
@@ -28,6 +46,7 @@ class KameWindow < Gosu::Window
|
|
28
46
|
|
29
47
|
def draw
|
30
48
|
self.draw_background
|
49
|
+
self.grid if @grid
|
31
50
|
return if @lines.nil? || @lines.count == 0 || @seconds_since_last_frame.nil?
|
32
51
|
|
33
52
|
max = (@seconds_since_last_frame * @speed).round
|
@@ -38,7 +57,7 @@ class KameWindow < Gosu::Window
|
|
38
57
|
0.upto(max).each do |i|
|
39
58
|
line = @lines[i]
|
40
59
|
line_colour = Gosu::Color.argb(line[:colour])
|
41
|
-
draw_line(line[:from][:x], line[:from][:y], line_colour, line[:to][:x], line[:to][:y], line_colour,
|
60
|
+
draw_line(line[:from][:x], line[:from][:y], line_colour, line[:to][:x], line[:to][:y], line_colour, 10)
|
42
61
|
end
|
43
62
|
end
|
44
63
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: kame
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.5.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Andy Pike
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-11-
|
13
|
+
date: 2011-11-13 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: gosu
|
@@ -56,6 +56,7 @@ extra_rdoc_files:
|
|
56
56
|
- README.md
|
57
57
|
files:
|
58
58
|
- .document
|
59
|
+
- CHANGE_LOG.txt
|
59
60
|
- Gemfile
|
60
61
|
- Gemfile.lock
|
61
62
|
- LICENSE.txt
|
@@ -79,7 +80,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
80
|
requirements:
|
80
81
|
- - ">="
|
81
82
|
- !ruby/object:Gem::Version
|
82
|
-
hash:
|
83
|
+
hash: 2769029216864616128
|
83
84
|
segments:
|
84
85
|
- 0
|
85
86
|
version: "0"
|