vamp 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +20 -3
- data/lib/vamp/art.rb +189 -0
- data/lib/vamp/graphic/context.rb +142 -0
- data/lib/vamp/graphic/dotter.rb +53 -0
- data/lib/vamp/graphic/text_dotter.rb +35 -0
- data/lib/vamp/graphic/transfer.rb +170 -0
- data/lib/vamp/graphic/transfer5.rb +217 -0
- data/lib/vamp/graphic.rb +17 -0
- data/lib/vamp/version.rb +1 -1
- data/lib/vamp.rb +5 -12
- data/sample/gui.rb +98 -0
- data/spec/art_spec.rb +56 -0
- data/spec/graphic/context_spec.rb +364 -0
- data/spec/graphic/transfer5_spec.rb +179 -0
- data/spec/graphic/transfer_spec.rb +221 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/vamp_spec.rb +1 -0
- metadata +18 -2
@@ -0,0 +1,217 @@
|
|
1
|
+
module Vamp
|
2
|
+
module Graphic
|
3
|
+
# Transfer dotter data into ASCII
|
4
|
+
class Transfer5
|
5
|
+
|
6
|
+
attr_reader :char_width
|
7
|
+
attr_reader :char_height
|
8
|
+
attr_reader :context
|
9
|
+
attr_reader :mapping
|
10
|
+
|
11
|
+
SPACE = <<-'END'
|
12
|
+
_____
|
13
|
+
_____
|
14
|
+
_____
|
15
|
+
_____
|
16
|
+
_____
|
17
|
+
END
|
18
|
+
|
19
|
+
SLASH = <<-'END'
|
20
|
+
___X_
|
21
|
+
__X__
|
22
|
+
_X___
|
23
|
+
X____
|
24
|
+
_____
|
25
|
+
END
|
26
|
+
|
27
|
+
BACKSLASH = <<-'END'
|
28
|
+
X____
|
29
|
+
_X___
|
30
|
+
__X__
|
31
|
+
___X_
|
32
|
+
_____
|
33
|
+
END
|
34
|
+
|
35
|
+
BACKTICK = <<-'END'
|
36
|
+
_X___
|
37
|
+
_____
|
38
|
+
_____
|
39
|
+
_____
|
40
|
+
_____
|
41
|
+
END
|
42
|
+
|
43
|
+
PIPE = <<-'END'
|
44
|
+
__X__
|
45
|
+
__X__
|
46
|
+
__X__
|
47
|
+
__X__
|
48
|
+
_____
|
49
|
+
END
|
50
|
+
|
51
|
+
MINUS = <<-'END'
|
52
|
+
_____
|
53
|
+
_____
|
54
|
+
XXXX_
|
55
|
+
_____
|
56
|
+
_____
|
57
|
+
END
|
58
|
+
|
59
|
+
UNDERSCORE = <<-'END'
|
60
|
+
_____
|
61
|
+
_____
|
62
|
+
_____
|
63
|
+
_____
|
64
|
+
XXXXX
|
65
|
+
END
|
66
|
+
|
67
|
+
FULLSTOP = <<-'END'
|
68
|
+
_____
|
69
|
+
_____
|
70
|
+
_____
|
71
|
+
__X__
|
72
|
+
_____
|
73
|
+
END
|
74
|
+
|
75
|
+
DOUBLEQUOTES = <<-'END'
|
76
|
+
_X_X_
|
77
|
+
_____
|
78
|
+
_____
|
79
|
+
_____
|
80
|
+
_____
|
81
|
+
END
|
82
|
+
|
83
|
+
SINGLEQUOTE = <<-'END'
|
84
|
+
__X__
|
85
|
+
_____
|
86
|
+
_____
|
87
|
+
_____
|
88
|
+
_____
|
89
|
+
END
|
90
|
+
|
91
|
+
STAR = <<-'END'
|
92
|
+
_____
|
93
|
+
__X__
|
94
|
+
_XXX_
|
95
|
+
__X__
|
96
|
+
_____
|
97
|
+
END
|
98
|
+
|
99
|
+
HASH = <<-'END'
|
100
|
+
_____
|
101
|
+
_XXX_
|
102
|
+
_XXX_
|
103
|
+
_XXX_
|
104
|
+
_____
|
105
|
+
END
|
106
|
+
|
107
|
+
def initialize(context)
|
108
|
+
@context = context
|
109
|
+
@char_width = 5
|
110
|
+
@char_height = 5
|
111
|
+
@mapping = {
|
112
|
+
" " => create_pattern(SPACE),
|
113
|
+
"/" => create_pattern(SLASH),
|
114
|
+
"\\" => create_pattern(BACKSLASH),
|
115
|
+
"`" => create_pattern(BACKTICK),
|
116
|
+
"|" => create_pattern(PIPE),
|
117
|
+
"-" => create_pattern(MINUS),
|
118
|
+
"_" => create_pattern(UNDERSCORE),
|
119
|
+
"." => create_pattern(FULLSTOP),
|
120
|
+
"\"" => create_pattern(DOUBLEQUOTES),
|
121
|
+
"'" => create_pattern(SINGLEQUOTE),
|
122
|
+
"*" => create_pattern(STAR),
|
123
|
+
"\#" => create_pattern(HASH),
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
def create_data(pattern)
|
128
|
+
a = pattern.split("\n")
|
129
|
+
fail "pattern has wrong height" if a.size != char_height
|
130
|
+
char_height.times do |dy|
|
131
|
+
fail "pattern has wrong width" if a[dy].size != char_width
|
132
|
+
end
|
133
|
+
a
|
134
|
+
end
|
135
|
+
|
136
|
+
def create_pattern(pattern)
|
137
|
+
char = TextDotter.new(char_width, char_height)
|
138
|
+
a = create_data(pattern)
|
139
|
+
char_height.times do |y|
|
140
|
+
char_width.times do |x|
|
141
|
+
char.dot(x, y) if a[y][x] == "X"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
char
|
145
|
+
end
|
146
|
+
|
147
|
+
def get_pattern(x, y)
|
148
|
+
pattern = ""
|
149
|
+
char_height.times do |dy|
|
150
|
+
char_width.times do |dx|
|
151
|
+
if context.in?(x + dx, y + dy)
|
152
|
+
pattern += (context.dot?(x + dx, y + dy) ? "X" : "_")
|
153
|
+
else
|
154
|
+
pattern += "_"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
pattern += "\n"
|
158
|
+
end
|
159
|
+
create_pattern(pattern.strip)
|
160
|
+
end
|
161
|
+
|
162
|
+
def difference(pattern1, pattern2)
|
163
|
+
m = 0
|
164
|
+
char_width.times do |dx|
|
165
|
+
char_height.times do |dy|
|
166
|
+
m += 1 if pattern1.dot?(dx, dy) != pattern2.dot?(dx, dy)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
m
|
170
|
+
end
|
171
|
+
|
172
|
+
def get_matching(pattern, without_blank = false)
|
173
|
+
ranking = {}
|
174
|
+
mapping.each do |k, v|
|
175
|
+
next if without_blank and v == " "
|
176
|
+
r = difference(pattern, v)
|
177
|
+
ranking[k] = r
|
178
|
+
end
|
179
|
+
match = ranking.min_by{|k, v| v}
|
180
|
+
# require "pp"
|
181
|
+
# pp match
|
182
|
+
match[0..1]
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
def ascii
|
187
|
+
a = ""
|
188
|
+
(context.height / char_height).times do |y|
|
189
|
+
(context.width / char_width).times do |x|
|
190
|
+
m = get_matching(get_pattern(x * char_width, y * char_height))
|
191
|
+
if (m[1] > 0)
|
192
|
+
n = []
|
193
|
+
n << get_matching(get_pattern(x * char_width + 1, y * char_height), true)
|
194
|
+
n << get_matching(get_pattern(x * char_width - 1, y * char_height), true)
|
195
|
+
n << get_matching(get_pattern(x * char_width, y * char_height + 1), true)
|
196
|
+
n << get_matching(get_pattern(x * char_width, y * char_height - 1), true)
|
197
|
+
=begin
|
198
|
+
n << get_matching(get_pattern(x * char_width + 2, y * char_height), true)
|
199
|
+
n << get_matching(get_pattern(x * char_width - 2, y * char_height), true)
|
200
|
+
n << get_matching(get_pattern(x * char_width, y * char_height + 2), true)
|
201
|
+
n << get_matching(get_pattern(x * char_width, y * char_height - 2), true)
|
202
|
+
=end
|
203
|
+
n.each do |v|
|
204
|
+
if v[1] < m[1]
|
205
|
+
m = v
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
a += m[0]
|
210
|
+
end
|
211
|
+
a += "\n"
|
212
|
+
end
|
213
|
+
a.chomp
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
data/lib/vamp/graphic.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative "graphic/context"
|
2
|
+
|
3
|
+
module Vamp
|
4
|
+
module Graphic
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
if __FILE__ == $0
|
9
|
+
g = Vamp::Graphic::Context.new(Vamp::Graphic::TextDotter.new(80, 20))
|
10
|
+
g.dot(10, 10)
|
11
|
+
g.line 1, 2, 70, 9
|
12
|
+
|
13
|
+
g.draw 40, 10, 100, 1
|
14
|
+
puts g.screen
|
15
|
+
puts "now we get an error:"
|
16
|
+
g.line 1, 1, 100, 100
|
17
|
+
end
|
data/lib/vamp/version.rb
CHANGED
data/lib/vamp.rb
CHANGED
@@ -1,21 +1,13 @@
|
|
1
1
|
require_relative "vamp/animator"
|
2
|
+
require_relative "vamp/art"
|
2
3
|
require_relative "vamp/colorize"
|
3
4
|
require_relative "vamp/ply"
|
4
5
|
require_relative "vamp/version"
|
5
6
|
|
6
7
|
module Vamp
|
7
8
|
|
8
|
-
# ascii art vampire
|
9
|
-
|
10
|
-
VAMPIRE = <<-END
|
11
|
-
=/\\ /\\=
|
12
|
-
/ \\'._ (\\_/) _.'/ \\
|
13
|
-
/ .''._'--(o.o)--'_.''. \\
|
14
|
-
/.' _/ |`'=/ " \\='`| \\_ `.\\
|
15
|
-
/` .' `\\;-,'\\___/',-;/` '. '\\
|
16
|
-
/.-' jgs `\\(-V-)/` `-.\\
|
17
|
-
` " " `
|
18
|
-
END
|
9
|
+
# ascii art: vampire
|
10
|
+
VAMPIRE = Vamp::Art::VAMPIRE
|
19
11
|
|
20
12
|
# return random quote
|
21
13
|
def quote
|
@@ -69,7 +61,8 @@ module Vamp
|
|
69
61
|
"Only those prepared to die will find eternal life.",
|
70
62
|
"I remember everything. It's a burden.",
|
71
63
|
"I am teaching you something you don't want to know.",
|
72
|
-
"Death is not the worst. There are things more horrible than death."
|
64
|
+
"Death is not the worst. There are things more horrible than death.",
|
65
|
+
"I'll protect you from the hooded claw; Keep the vampires from your door."
|
73
66
|
].sample
|
74
67
|
end
|
75
68
|
end
|
data/sample/gui.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require "green_shoes"
|
2
|
+
|
3
|
+
=begin
|
4
|
+
Shoes.app do
|
5
|
+
flow do
|
6
|
+
stack :width => 200 do
|
7
|
+
background lavender
|
8
|
+
caption "Column one"
|
9
|
+
para "is 200 pixels wide"
|
10
|
+
end
|
11
|
+
stack :width => -200 do
|
12
|
+
background bisque
|
13
|
+
caption "Column two"
|
14
|
+
para "is 100% minus 200 pixels wide"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
=end
|
19
|
+
|
20
|
+
=begin
|
21
|
+
Shoes.app do
|
22
|
+
fill black.push(0.1)
|
23
|
+
100.times do |i|
|
24
|
+
oval i, i, i * 2 if i > 0
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
=end
|
29
|
+
|
30
|
+
=begin
|
31
|
+
Shoes.app width: 800, height:900, margin: 10, title: "VAMP GUI" do
|
32
|
+
stack width: 800, height: 200, margin: 10 do
|
33
|
+
border black, strokewidth: 2
|
34
|
+
end
|
35
|
+
end
|
36
|
+
=end
|
37
|
+
|
38
|
+
=begin
|
39
|
+
Shoes.app do
|
40
|
+
lb = list_box items: COLORS.keys.map(&:to_s), choose: 'red' do |s|
|
41
|
+
@o.style fill: eval(s.text)
|
42
|
+
@p.text = s.text
|
43
|
+
end.move(300, 0)
|
44
|
+
@p = para
|
45
|
+
nostroke
|
46
|
+
@o = oval 100, 100, 100, 100
|
47
|
+
i = 0
|
48
|
+
button('print'){para lb.text, top: 20*(i+=1)}.move(500, 0)
|
49
|
+
end
|
50
|
+
|
51
|
+
=end
|
52
|
+
|
53
|
+
=begin
|
54
|
+
Shoes.app do
|
55
|
+
background chocolate..black, angle: 130
|
56
|
+
strokewidth 20
|
57
|
+
border deeppink..forestgreen, curve: 30
|
58
|
+
nostroke
|
59
|
+
fill crimson..cyan
|
60
|
+
oval 100, 100, 100, 100, angle: 45
|
61
|
+
nofill
|
62
|
+
strokewidth 50
|
63
|
+
rect 200, 200, 300, 200, stroke: darkblue..ivory, angle: 90
|
64
|
+
end
|
65
|
+
|
66
|
+
=end
|
67
|
+
|
68
|
+
=begin
|
69
|
+
Shoes.app width: 400, height: 400 do
|
70
|
+
cap [:rect, :curve, :project][rand 3]
|
71
|
+
background lightgrey
|
72
|
+
rect 0, 0, 100, 100
|
73
|
+
rect 100, 100, 100, 100
|
74
|
+
rect 200, 200, 100, 100
|
75
|
+
rect 0, 200, 100, 100
|
76
|
+
rect 200, 0, 100, 100
|
77
|
+
stroke File.join(DIR, '../static/gshoes-icon.png')
|
78
|
+
strokewidth 10
|
79
|
+
line 355, 180, 5, 111, strokewidth: 20
|
80
|
+
stroke red
|
81
|
+
line 0, 0, 100, 0
|
82
|
+
line 0, 100, 0, 0
|
83
|
+
line 300, 200, 200, 200
|
84
|
+
line 100, 200, 200, 100
|
85
|
+
stroke white
|
86
|
+
line 200, 200, 200, 300
|
87
|
+
line 300, 200, 200, 100
|
88
|
+
end
|
89
|
+
=end
|
90
|
+
|
91
|
+
Shoes.app width: 800, height: 600 do
|
92
|
+
background lightgrey
|
93
|
+
strokewidth 1
|
94
|
+
stroke black
|
95
|
+
d = 10
|
96
|
+
(height / d + 1).times { |i| line 0, i * d, width, i * d }
|
97
|
+
(width / d + 1).times { |i| line i * d, 0, i * d, height }
|
98
|
+
end
|
data/spec/art_spec.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Vamp::Art do
|
4
|
+
it "has a vampire" do
|
5
|
+
expect(subject::VAMPIRE).not_to be nil
|
6
|
+
puts "\n#{subject::VAMPIRE}"
|
7
|
+
end
|
8
|
+
it "has a colorful hobgoblin" do
|
9
|
+
expect(subject::HOBGOBLIN_COLOR).not_to be nil
|
10
|
+
puts "\n#{subject::HOBGOBLIN_COLOR}"
|
11
|
+
end
|
12
|
+
it "has a hobgoblin" do
|
13
|
+
expect(subject::HOBGOBLIN).not_to be nil
|
14
|
+
puts "\n#{subject::HOBGOBLIN}"
|
15
|
+
end
|
16
|
+
it "has a colorful shark" do
|
17
|
+
expect(subject::SHARK_COLOR).not_to be nil
|
18
|
+
puts "\n#{subject::SHARK_COLOR}"
|
19
|
+
end
|
20
|
+
it "has a shark" do
|
21
|
+
expect(subject::SHARK).not_to be nil
|
22
|
+
puts "\n#{subject::SHARK}"
|
23
|
+
end
|
24
|
+
it "has a colorful skull" do
|
25
|
+
expect(subject::SKULL_COLOR).not_to be nil
|
26
|
+
puts "\n#{subject::SKULL_COLOR}"
|
27
|
+
end
|
28
|
+
it "has a skull" do
|
29
|
+
expect(subject::SKULL).not_to be nil
|
30
|
+
puts "\n#{subject::SKULL}"
|
31
|
+
end
|
32
|
+
it "has a colorful lizard" do
|
33
|
+
expect(subject::LIZARD_COLOR).not_to be nil
|
34
|
+
puts "\n#{subject::LIZARD_COLOR}"
|
35
|
+
end
|
36
|
+
it "has a lizard" do
|
37
|
+
expect(subject::LIZARD).not_to be nil
|
38
|
+
puts "\n#{subject::LIZARD}"
|
39
|
+
end
|
40
|
+
it "has a colorful dragon" do
|
41
|
+
expect(subject::DRAGON_COLOR).not_to be nil
|
42
|
+
puts "\n#{subject::DRAGON_COLOR}"
|
43
|
+
end
|
44
|
+
it "has a dragon" do
|
45
|
+
expect(subject::DRAGON).not_to be nil
|
46
|
+
puts "\n#{subject::DRAGON}"
|
47
|
+
end
|
48
|
+
it "has a running man" do
|
49
|
+
expect(subject::RUNNING).not_to be nil
|
50
|
+
puts "\n#{subject::RUNNING}"
|
51
|
+
end
|
52
|
+
it "has a declaring woman" do
|
53
|
+
expect(subject::DECLARING).not_to be nil
|
54
|
+
puts "\n#{subject::DECLARING}"
|
55
|
+
end
|
56
|
+
end
|