salamander 0.0.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.
- data/bin/salamander +16 -0
- data/lib/salamander.rb +16 -0
- data/lib/salamander/actor.rb +75 -0
- data/lib/salamander/constants.rb +24 -0
- data/lib/salamander/drawing.rb +6 -0
- data/lib/salamander/drawing/line.rb +16 -0
- data/lib/salamander/drawing/shapes.rb +20 -0
- data/lib/salamander/support.rb +3 -0
- data/lib/salamander/support/radians.rb +12 -0
- data/lib/salamander/version.rb +3 -0
- data/lib/salamander/version.rbc +130 -0
- metadata +104 -0
data/bin/salamander
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'salamander'
|
4
|
+
require 'salamander/support'
|
5
|
+
|
6
|
+
class Sketch < Salamander::Actor
|
7
|
+
include Salamander::Drawing
|
8
|
+
end
|
9
|
+
|
10
|
+
screen = Salamander.setup(512, 512)
|
11
|
+
Sketch.draw(screen, ARGV[0])
|
12
|
+
|
13
|
+
while true
|
14
|
+
event = SDL.WaitEvent
|
15
|
+
break if event.type == SDL::QUIT
|
16
|
+
end
|
data/lib/salamander.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'ruby-sdl-ffi/gfx'
|
2
|
+
|
3
|
+
module Salamander
|
4
|
+
require 'salamander/constants'
|
5
|
+
require 'salamander/actor'
|
6
|
+
require 'salamander/drawing'
|
7
|
+
|
8
|
+
def self.setup (width, height)
|
9
|
+
SDL.Init(SDL::INIT_VIDEO)
|
10
|
+
at_exit { SDL.Quit }
|
11
|
+
|
12
|
+
info = SDL.GetVideoInfo
|
13
|
+
flags = (info.hw_available) ? SDL::HWSURFACE : SDL::SWSURFACE
|
14
|
+
SDL.SetVideoMode(width, height, info.vfmt.BitsPerPixel, flags)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Salamander
|
2
|
+
class Actor
|
3
|
+
def self.draw (screen, filename=nil, &blk)
|
4
|
+
actor = new(screen)
|
5
|
+
if filename
|
6
|
+
actor.instance_eval(File.open(filename).read, filename)
|
7
|
+
else
|
8
|
+
actor.instance_eval(&blk)
|
9
|
+
end
|
10
|
+
SDL.UpdateRect(screen, 0, 0, screen.w, screen.h)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize (surface)
|
14
|
+
@surface = surface
|
15
|
+
|
16
|
+
move_to(surface.w/2, surface.h/2)
|
17
|
+
face :north
|
18
|
+
color "#FFFFFF"
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def position
|
23
|
+
[@x, @y]
|
24
|
+
end
|
25
|
+
|
26
|
+
def move (distance)
|
27
|
+
x = distance * Math.cos(angle) + @x
|
28
|
+
y = distance * Math.sin(angle) + @y
|
29
|
+
move_to(x, y)
|
30
|
+
end
|
31
|
+
|
32
|
+
def move_to (x, y)
|
33
|
+
@x, @y = x, y
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def angle
|
38
|
+
@angle
|
39
|
+
end
|
40
|
+
|
41
|
+
def turn (theta)
|
42
|
+
theta = DIRECTIONS[theta] if theta.is_a? Symbol
|
43
|
+
face(theta + angle)
|
44
|
+
end
|
45
|
+
|
46
|
+
def face (theta)
|
47
|
+
theta = COMPASS[theta] if theta.is_a? Symbol
|
48
|
+
@angle = theta % (2 * Math::PI)
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def rgba
|
53
|
+
@color
|
54
|
+
end
|
55
|
+
|
56
|
+
def color (color=nil)
|
57
|
+
if not color then
|
58
|
+
@color
|
59
|
+
else
|
60
|
+
color = color.to_str
|
61
|
+
if color[0] == ?# and color.length == 7
|
62
|
+
color = color[1..-1].to_i(16)
|
63
|
+
@color = color * (2**8) + 255
|
64
|
+
else
|
65
|
+
raise "color must be a valid string in the format #RRGGBB"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def surface
|
72
|
+
@surface
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Salamander
|
2
|
+
DIRECTIONS = {
|
3
|
+
:right => 90,
|
4
|
+
:left => -90,
|
5
|
+
:around => 180,
|
6
|
+
}
|
7
|
+
DIRECTIONS.each_pair do |k, v|
|
8
|
+
DIRECTIONS[k] = v / 180.0 * Math::PI
|
9
|
+
end
|
10
|
+
|
11
|
+
COMPASS = {
|
12
|
+
:east => 0,
|
13
|
+
:northeast => 315,
|
14
|
+
:north => 270,
|
15
|
+
:northwest => 225,
|
16
|
+
:west => 180,
|
17
|
+
:southwest => 135,
|
18
|
+
:south => 90,
|
19
|
+
:southeast => 45,
|
20
|
+
}
|
21
|
+
COMPASS.each_pair do |k, v|
|
22
|
+
COMPASS[k] = v / 180.0 * Math::PI
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Salamander::Drawing
|
2
|
+
module Line
|
3
|
+
def draw_to (x2, y2)
|
4
|
+
x1, y1 = position
|
5
|
+
move_to(x2, y2)
|
6
|
+
SDL::Gfx.lineColor(surface, x1.round, y1.round, x2.round, y2.round, color)
|
7
|
+
end
|
8
|
+
|
9
|
+
def draw (distance)
|
10
|
+
x1, y1 = position
|
11
|
+
move distance
|
12
|
+
x2, y2 = position
|
13
|
+
SDL::Gfx.lineColor(surface, x1.round, y1.round, x2.round, y2.round, color)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Salamander::Drawing
|
2
|
+
module Shapes
|
3
|
+
include Line
|
4
|
+
|
5
|
+
def star (points, length)
|
6
|
+
raise "The star must have an odd number of points" if points % 2 == 0
|
7
|
+
points.times do
|
8
|
+
draw length
|
9
|
+
turn (720.0/points).degrees
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def polygon (sides, length)
|
14
|
+
sides.times do
|
15
|
+
draw length
|
16
|
+
turn (360.0/sides).degrees
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
!RBIX
|
2
|
+
0
|
3
|
+
x
|
4
|
+
M
|
5
|
+
1
|
6
|
+
n
|
7
|
+
n
|
8
|
+
x
|
9
|
+
10
|
10
|
+
__script__
|
11
|
+
i
|
12
|
+
28
|
13
|
+
99
|
14
|
+
7
|
15
|
+
0
|
16
|
+
65
|
17
|
+
49
|
18
|
+
1
|
19
|
+
2
|
20
|
+
13
|
21
|
+
99
|
22
|
+
12
|
23
|
+
7
|
24
|
+
2
|
25
|
+
12
|
26
|
+
7
|
27
|
+
3
|
28
|
+
12
|
29
|
+
65
|
30
|
+
12
|
31
|
+
49
|
32
|
+
4
|
33
|
+
4
|
34
|
+
15
|
35
|
+
49
|
36
|
+
2
|
37
|
+
0
|
38
|
+
15
|
39
|
+
2
|
40
|
+
11
|
41
|
+
I
|
42
|
+
6
|
43
|
+
I
|
44
|
+
0
|
45
|
+
I
|
46
|
+
0
|
47
|
+
I
|
48
|
+
0
|
49
|
+
n
|
50
|
+
p
|
51
|
+
5
|
52
|
+
x
|
53
|
+
10
|
54
|
+
Salamander
|
55
|
+
x
|
56
|
+
11
|
57
|
+
open_module
|
58
|
+
x
|
59
|
+
15
|
60
|
+
__module_init__
|
61
|
+
M
|
62
|
+
1
|
63
|
+
n
|
64
|
+
n
|
65
|
+
x
|
66
|
+
10
|
67
|
+
Salamander
|
68
|
+
i
|
69
|
+
12
|
70
|
+
5
|
71
|
+
66
|
72
|
+
65
|
73
|
+
7
|
74
|
+
0
|
75
|
+
7
|
76
|
+
1
|
77
|
+
64
|
78
|
+
49
|
79
|
+
2
|
80
|
+
2
|
81
|
+
11
|
82
|
+
I
|
83
|
+
3
|
84
|
+
I
|
85
|
+
0
|
86
|
+
I
|
87
|
+
0
|
88
|
+
I
|
89
|
+
0
|
90
|
+
n
|
91
|
+
p
|
92
|
+
3
|
93
|
+
x
|
94
|
+
7
|
95
|
+
VERSION
|
96
|
+
s
|
97
|
+
5
|
98
|
+
0.0.1
|
99
|
+
x
|
100
|
+
9
|
101
|
+
const_set
|
102
|
+
p
|
103
|
+
3
|
104
|
+
I
|
105
|
+
2
|
106
|
+
I
|
107
|
+
2
|
108
|
+
I
|
109
|
+
c
|
110
|
+
x
|
111
|
+
60
|
112
|
+
/home/jonathan/projects/salamander/lib/salamander/version.rb
|
113
|
+
p
|
114
|
+
0
|
115
|
+
x
|
116
|
+
13
|
117
|
+
attach_method
|
118
|
+
p
|
119
|
+
3
|
120
|
+
I
|
121
|
+
0
|
122
|
+
I
|
123
|
+
1
|
124
|
+
I
|
125
|
+
1c
|
126
|
+
x
|
127
|
+
60
|
128
|
+
/home/jonathan/projects/salamander/lib/salamander/version.rb
|
129
|
+
p
|
130
|
+
0
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: salamander
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Jonathan Castello
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-13 00:00:00 -08:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
- 7
|
32
|
+
version: 1.0.7
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: ruby-sdl-ffi
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
- 3
|
46
|
+
version: "0.3"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: An easy-to-use turtle graphics DSL
|
50
|
+
email: jonathan@jonathan.com
|
51
|
+
executables:
|
52
|
+
- salamander
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- lib/salamander.rb
|
59
|
+
- lib/salamander/support/radians.rb
|
60
|
+
- lib/salamander/constants.rb
|
61
|
+
- lib/salamander/actor.rb
|
62
|
+
- lib/salamander/drawing/line.rb
|
63
|
+
- lib/salamander/drawing/shapes.rb
|
64
|
+
- lib/salamander/version.rbc
|
65
|
+
- lib/salamander/support.rb
|
66
|
+
- lib/salamander/drawing.rb
|
67
|
+
- lib/salamander/version.rb
|
68
|
+
- bin/salamander
|
69
|
+
has_rdoc: true
|
70
|
+
homepage:
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ~>
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 1
|
85
|
+
- 9
|
86
|
+
- 0
|
87
|
+
version: 1.9.0
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.3.7
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: An easy-to-use turtle graphics DSL
|
103
|
+
test_files: []
|
104
|
+
|