vamp 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/files/vampire.txt +1860 -0
- data/lib/vamp/animator.rb +29 -17
- data/lib/vamp/colorize.rb +47 -0
- data/lib/vamp/ply/cube.rb +37 -0
- data/lib/vamp/ply/ply_object.rb +61 -0
- data/lib/vamp/ply/vampire.rb +43 -0
- data/lib/vamp/ply.rb +8 -0
- data/lib/vamp/version.rb +1 -1
- data/lib/vamp.rb +17 -10
- data/sample/vampire.rb +10 -0
- metadata +10 -3
data/lib/vamp/animator.rb
CHANGED
@@ -1,22 +1,32 @@
|
|
1
|
+
require_relative "colorize"
|
2
|
+
|
1
3
|
module Vamp
|
2
4
|
# play animation on console
|
3
5
|
class Animator
|
4
|
-
attr_accessor :data
|
5
|
-
attr_accessor :number
|
6
|
+
attr_accessor :data # complete animation lines
|
7
|
+
attr_accessor :number # animation source height
|
8
|
+
attr_accessor :width # animation width
|
9
|
+
attr_accessor :height # animation height
|
10
|
+
attr_accessor :scroll # running text
|
6
11
|
|
7
|
-
def initialize(file, number = 31)
|
12
|
+
def initialize(file, number = 31, height = number, scroll)
|
8
13
|
@data = []
|
9
14
|
@number = number
|
15
|
+
@width = 80
|
16
|
+
@height = height
|
17
|
+
@scroll = scroll
|
18
|
+
@offset = 0
|
10
19
|
lines = IO.readlines(file)
|
11
20
|
lines.each_slice(number) do |block|
|
12
21
|
d = []
|
13
|
-
block.
|
22
|
+
block.each_with_index do |line, index|
|
14
23
|
# puts line.class
|
15
24
|
# puts printf("%-40s", line)
|
16
25
|
# d << line
|
17
26
|
d << (line.rstrip + (" " * 80))[0..80]
|
18
27
|
# d << sprintf("%80s", line)
|
19
28
|
# puts block.length
|
29
|
+
break if index >= height
|
20
30
|
end
|
21
31
|
# puts lines
|
22
32
|
@data << d
|
@@ -28,16 +38,16 @@ module Vamp
|
|
28
38
|
end
|
29
39
|
|
30
40
|
def home
|
31
|
-
print "\e[H\e[#{
|
41
|
+
print "\e[H\e[#{height}F"
|
32
42
|
end
|
33
43
|
|
34
44
|
def home
|
35
|
-
print "\e[H\e[#{
|
45
|
+
print "\e[H\e[#{height}F"
|
36
46
|
end
|
37
47
|
|
38
|
-
def down
|
48
|
+
def down(lines = @height)
|
39
49
|
# number.times { puts }
|
40
|
-
print "\e[H\e[#{
|
50
|
+
print "\e[H\e[#{lines}E"
|
41
51
|
end
|
42
52
|
|
43
53
|
def flush
|
@@ -46,7 +56,8 @@ module Vamp
|
|
46
56
|
|
47
57
|
def animate(msg)
|
48
58
|
home
|
49
|
-
|
59
|
+
puts Vamp::Colorize.colorize("red", msg)
|
60
|
+
puts Vamp::Colorize.colorize("blue", animate_line) if scroll
|
50
61
|
flush
|
51
62
|
sleep(1.0/48.0)
|
52
63
|
end
|
@@ -59,23 +70,24 @@ module Vamp
|
|
59
70
|
print "\e[H\e[?25h"
|
60
71
|
end
|
61
72
|
|
73
|
+
def animate_line
|
74
|
+
@offset += 1
|
75
|
+
"#{@scroll[(@offset / 2)..(@offset / 2 + @width - 1)]}"
|
76
|
+
end
|
77
|
+
|
62
78
|
def play
|
63
79
|
if $stdout.isatty
|
64
80
|
begin
|
65
81
|
cursor_off
|
66
82
|
clear
|
67
|
-
data.each
|
83
|
+
data.each do
|
84
|
+
|lines| animate(lines.join("\n"))
|
85
|
+
end
|
68
86
|
ensure
|
69
87
|
cursor_on
|
70
|
-
down
|
88
|
+
down(@height + 2)
|
71
89
|
end
|
72
90
|
end
|
73
91
|
end
|
74
92
|
end
|
75
93
|
end
|
76
|
-
|
77
|
-
if __FILE__ == $0
|
78
|
-
# get root directory of this gem
|
79
|
-
animator = Vamp::Animator.new(File.join(Gem.loaded_specs["vamp"].gem_dir, "files", "pyramid.txt"))
|
80
|
-
animator.play
|
81
|
-
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Vamp
|
2
|
+
module Colorize
|
3
|
+
module Colors
|
4
|
+
NOTHING = '0;0'
|
5
|
+
BLACK = '0;30'
|
6
|
+
DARK_RED = '0;31'
|
7
|
+
DARK_GREEN = '0;32'
|
8
|
+
BROWN = '0;33'
|
9
|
+
BLUE = '0;34'
|
10
|
+
PURPLE = '0;35'
|
11
|
+
CYAN = '0;36'
|
12
|
+
GRAY = '0;37'
|
13
|
+
LIGHT_GRAY = '0;37'
|
14
|
+
DARK_GRAY = '1;30'
|
15
|
+
RED = '1;31'
|
16
|
+
GREEN = '1;32'
|
17
|
+
YELLOW = '1;33'
|
18
|
+
LIGHT_BLUE = '1;34'
|
19
|
+
LIGHT_PURPLE = '1;35'
|
20
|
+
LIGHT_CYAN = '1;36'
|
21
|
+
WHITE = '1;37'
|
22
|
+
end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
def colorize(color, text)
|
26
|
+
color = Colorize::Colors.const_get(color.to_s.upcase)
|
27
|
+
color ? colorful_text(color, text) : text
|
28
|
+
rescue
|
29
|
+
text
|
30
|
+
end
|
31
|
+
|
32
|
+
def method_missing(symbol, *args)
|
33
|
+
color = Colorize::Colors.const_get(color.to_s.upcase)
|
34
|
+
return colorful_text(color, *args) if color
|
35
|
+
super
|
36
|
+
rescue
|
37
|
+
super
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def colorful_text(color, text)
|
43
|
+
"\e[#{color}m#{text}\e[0;0m"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "stringio"
|
2
|
+
|
3
|
+
require_relative "ply_object"
|
4
|
+
|
5
|
+
module Vamp
|
6
|
+
module Ply
|
7
|
+
class Cube < PlyObject
|
8
|
+
|
9
|
+
def initialize(file, number = 31)
|
10
|
+
super()
|
11
|
+
@file = file
|
12
|
+
@number = number
|
13
|
+
add_vertex(1, 1, 1)
|
14
|
+
add_vertex(-1, 1, 1)
|
15
|
+
add_vertex(1, -1, 1)
|
16
|
+
add_vertex(1, 1, -1)
|
17
|
+
add_vertex(1, -1, -1)
|
18
|
+
add_vertex(-1, -1, 1)
|
19
|
+
add_vertex(-1, 1, -1)
|
20
|
+
add_vertex(-1, -1, -1)
|
21
|
+
add_polygon(0, 1, 5, 2)
|
22
|
+
add_polygon(0, 1, 6, 3)
|
23
|
+
add_polygon(0, 3, 4, 2)
|
24
|
+
add_polygon(2, 5, 7, 4)
|
25
|
+
add_polygon(1, 6, 7, 5)
|
26
|
+
add_polygon(3, 6, 7, 4)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
if __FILE__ == $0
|
34
|
+
# get root directory of this gem
|
35
|
+
creator = Vamp::Ply::Cube.new(File.join("vampire.txt"))
|
36
|
+
puts creator
|
37
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "stringio"
|
2
|
+
|
3
|
+
module Vamp
|
4
|
+
module Ply
|
5
|
+
class PlyObject
|
6
|
+
attr_reader :vertices
|
7
|
+
attr_reader :polygons
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@vertices = []
|
11
|
+
@polygons = []
|
12
|
+
@output = StringIO.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_vertex(x, y, z)
|
16
|
+
vertices << ([x.to_f, y.to_f, z.to_f])
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_polygon(*vertexes)
|
20
|
+
vertexes.each do |v|
|
21
|
+
fail "unknown vertex #{v}" unless vertices[v.to_i]
|
22
|
+
end
|
23
|
+
polygons << vertexes.map(&:to_i)
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
@output = StringIO.new
|
28
|
+
print_header
|
29
|
+
print_vertices
|
30
|
+
print_polygons
|
31
|
+
output.string
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
attr_accessor :output
|
37
|
+
|
38
|
+
def print_header
|
39
|
+
output.puts("# ply file to describe a 3D model")
|
40
|
+
output.puts("#")
|
41
|
+
end
|
42
|
+
|
43
|
+
def print_vertices
|
44
|
+
output.puts("# list of vertices (3 float values, coordinates)")
|
45
|
+
output.puts("# x y z")
|
46
|
+
vertices.each do |v|
|
47
|
+
output.puts("#{v[0].to_f} #{v[1].to_f} #{v[2].to_f}")
|
48
|
+
end
|
49
|
+
output.puts
|
50
|
+
end
|
51
|
+
|
52
|
+
def print_polygons
|
53
|
+
output.puts("# list of polygons (3, 4, .. integer values, vertex indices)")
|
54
|
+
polygons.each do |p|
|
55
|
+
output.puts("#{p.join(' ')}")
|
56
|
+
end
|
57
|
+
output.puts
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "stringio"
|
2
|
+
|
3
|
+
require_relative "ply_object"
|
4
|
+
|
5
|
+
module Vamp
|
6
|
+
module Ply
|
7
|
+
class Vampire < PlyObject
|
8
|
+
|
9
|
+
def initialize(file, number = 31)
|
10
|
+
super()
|
11
|
+
@file = file
|
12
|
+
@number = number
|
13
|
+
d = 0.2
|
14
|
+
add_vertex(d, 1, 1) # 0
|
15
|
+
add_vertex(d, 0.4, 1) # 1
|
16
|
+
add_vertex(d, -1, 0) # 2
|
17
|
+
add_vertex(d, 0.4, -1) # 3
|
18
|
+
add_vertex(d, 1, -1) # 4
|
19
|
+
add_vertex(d, -0.4, 0) # 5
|
20
|
+
add_vertex(-d, 1, 1) # 6
|
21
|
+
add_vertex(-d, 0.4, 1) # 7
|
22
|
+
add_vertex(-d, -1, 0) # 8
|
23
|
+
add_vertex(-d, 0.4, -1) # 9
|
24
|
+
add_vertex(-d, 1, -1) # 10
|
25
|
+
add_vertex(-d, -0.4, 0) # 11
|
26
|
+
add_polygon(0, 1, 2, 3, 4, 5)
|
27
|
+
add_polygon(6, 7, 8, 9, 10, 11)
|
28
|
+
add_polygon(0, 1, 7, 6)
|
29
|
+
add_polygon(1, 2, 8, 7)
|
30
|
+
add_polygon(2, 3, 9, 8)
|
31
|
+
add_polygon(3, 4, 10, 9)
|
32
|
+
add_polygon(4, 5, 11, 10)
|
33
|
+
add_polygon(5, 0, 6, 11)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
if __FILE__ == $0
|
40
|
+
# get root directory of this gem
|
41
|
+
creator = Vamp::Ply::Vampire.new(File.join("vampire.txt"))
|
42
|
+
puts creator
|
43
|
+
end
|
data/lib/vamp/ply.rb
ADDED
data/lib/vamp/version.rb
CHANGED
data/lib/vamp.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative "vamp/animator"
|
2
|
+
require_relative "vamp/colorize"
|
3
|
+
require_relative "vamp/ply"
|
4
|
+
require_relative "vamp/version"
|
3
5
|
|
4
6
|
module Vamp
|
5
7
|
|
@@ -25,13 +27,13 @@ module Vamp
|
|
25
27
|
"Hey, what's your blood type?",
|
26
28
|
"The strength of the vampire is that people will not believe in him.",
|
27
29
|
"Death is Peaceful, Life is Harder.",
|
28
|
-
"You
|
30
|
+
"You're still waiting for the running and the screaming, aren't you?",
|
29
31
|
"Your number was up the first time I met you.",
|
30
32
|
"You really should stay away from me.",
|
31
33
|
"Thats the beautiful thing about being human: Things change.",
|
32
|
-
"I
|
34
|
+
"I've never tried to keep a specific person alive before, and it's much more troublesome" \
|
33
35
|
" than I would have believed.",
|
34
|
-
"Hasn
|
36
|
+
"Hasn't anyone ever told you? Life isn't fair.",
|
35
37
|
"No blood, no foul.",
|
36
38
|
"Go sit down and look pale.",
|
37
39
|
"It's not the end. It's the beginning.",
|
@@ -39,13 +41,13 @@ module Vamp
|
|
39
41
|
"Don't be offended, but you seem to be one of those people who just attract accidents like a magnet.",
|
40
42
|
"Without the dark, we'd never see the stars.",
|
41
43
|
"I warned you that you didn't want to know everything I was thinking.",
|
42
|
-
"Our relationship couldn
|
43
|
-
"Why do people always assume that volume will succeed when logic won
|
44
|
+
"Our relationship couldn't continue to balance, as it did, on the point of a knife.",
|
45
|
+
"Why do people always assume that volume will succeed when logic won't?",
|
44
46
|
"I hope you enjoyed your visit. You never know. You may want to join forever.",
|
45
47
|
"If you are a vampire, then a vampire is not the creature of the legends.",
|
46
48
|
"Not all vampires are created equal.",
|
47
49
|
"According to my research, in a vampire-werewolf love triangle, the vampire always gets the girl.",
|
48
|
-
"Some things aren
|
50
|
+
"Some things aren't meant for sunlight. The only place for them is in the shadows.",
|
49
51
|
"Is that all I was to you, a one-bite stand?",
|
50
52
|
"Though I cannot predict the future, the consequences of this night will reverberate through the halls" \
|
51
53
|
" of both great covens for many years to come",
|
@@ -61,8 +63,13 @@ module Vamp
|
|
61
63
|
"One thing vampire children are taught is, never run with a wooden stake.",
|
62
64
|
"The unknown is now my reality, for I do not yet understand what I have become." \
|
63
65
|
" The future brings so many questions, so many fears. But the first step, the first day, has arrived.",
|
64
|
-
"Please forgive me, but I desperately need your guidance. I apologise for breaking the Chain and awakening you
|
65
|
-
" a head of schedule, but I fear we may all be in grave danger."
|
66
|
+
"Please forgive me, but I desperately need your guidance. I apologise for breaking the Chain and awakening you" \
|
67
|
+
" a head of schedule, but I fear we may all be in grave danger.",
|
68
|
+
"I just feel like all the sand is at the bottom of the hour glass or something.",
|
69
|
+
"Only those prepared to die will find eternal life.",
|
70
|
+
"I remember everything. It's a burden.",
|
71
|
+
"I am teaching you something you don't want to know.",
|
72
|
+
"Death is not the worst. There are things more horrible than death."
|
66
73
|
].sample
|
67
74
|
end
|
68
75
|
end
|
data/sample/vampire.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "vamp"
|
2
|
+
|
3
|
+
animator = Vamp::Animator.new(File.join(Gem.loaded_specs["vamp"].gem_dir, "files", "vampire.txt"), 31, 24,
|
4
|
+
" " * 80 +
|
5
|
+
"No man knows till he has suffered from the night how sweet and how dear to his heart and eye the morning can be." \
|
6
|
+
" When the sun grew so high this morning that it struck the top of the great gateway opposite my window," \
|
7
|
+
" the high spot which it touched seemed to me as if the dove from the ark had lighted there. My fear fell from me" \
|
8
|
+
" as if it had been a vaporous garment which dissolved in the warmth." +
|
9
|
+
" " * 80)
|
10
|
+
16.times { animator.play }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vamp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Meyling
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -52,10 +52,17 @@ files:
|
|
52
52
|
- README.md
|
53
53
|
- Rakefile
|
54
54
|
- files/pyramid.txt
|
55
|
+
- files/vampire.txt
|
55
56
|
- lib/vamp.rb
|
56
57
|
- lib/vamp/animator.rb
|
58
|
+
- lib/vamp/colorize.rb
|
59
|
+
- lib/vamp/ply.rb
|
60
|
+
- lib/vamp/ply/cube.rb
|
61
|
+
- lib/vamp/ply/ply_object.rb
|
62
|
+
- lib/vamp/ply/vampire.rb
|
57
63
|
- lib/vamp/version.rb
|
58
64
|
- sample/cli.rb
|
65
|
+
- sample/vampire.rb
|
59
66
|
- spec/spec_helper.rb
|
60
67
|
- spec/vamp_spec.rb
|
61
68
|
- vamp.gemspec
|
@@ -79,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
86
|
version: '0'
|
80
87
|
requirements: []
|
81
88
|
rubyforge_project:
|
82
|
-
rubygems_version: 2.4.
|
89
|
+
rubygems_version: 2.4.6
|
83
90
|
signing_key:
|
84
91
|
specification_version: 4
|
85
92
|
summary: vampire quotes
|