Class: AsciiParadise::Animation
- Inherits:
-
Base
- Object
- Base
- AsciiParadise::Animation
show all
- Defined in:
- lib/ascii_paradise/animation/reset.rb,
lib/ascii_paradise/animation/display.rb,
lib/ascii_paradise/animation/animation.rb
Overview
Direct Known Subclasses
Airbus, AirplaneFight, AirplaneOverForest, AnimatedClock, AnimatedDuck, AnimatedPacman, AnimatedProgressBar, AntiAir, Aquarium, BabyDragon, Backflip, BallBouncesAgainstWall, BallFactory, Basketball, BasketballGame, BikerAndSnail, Bird, BirdAttack, BlockBreaker, BodyBuilders, Boomerang, BouncingBall, BouncyBall, BouncyExplodingBall, BreakingGlass, BubbleDragon, Bunnies, Bunnycat, CanadianFlag, CarProduction, CatchTheBall, Chopper, Cigarette, CircleOfLife, CoinRoll, Counter, DancingGirl, DigitalClock, Diver, DogTriesToCatchTheBall, DotFactory, DrivingCar, Earth, EndlessMonkeyBars, EndlessRunner, ExplodingAlien, ExplodingBubbles, EyeWiggling, Fire, FireworkClock, FireworkLauncher, Fireworks, FlameThrower, FlyingHead, FramerateWalking, FriendlyMonkey, Gargoyle, Genie, GoodMorning, Hadouken, HandOfGod, Hourglass, HumanFactory, Intercourse, Jello, Juggling, JumpRope, JumpingPig, LaserClock, LightningBolt, LoadingDots, Macarena, Moth, NeverendingStaircase, OneDestroyer, ParachuteJump, Phone, PlantingAForest, ProgressBar, PullRope, Raindrop, Raining, Reflection, RidingADuck, RotatingCube, RotatingDNA, RotatingGlobe, RotatingSlash, RubberDuck, RunningMan, SailingBoat, SandClock, Seesaw, ShootingRange, Shotgun, SilentCity, SoccerInFrontOfAHouse, SoccerTwins, Spider, StarTrek, StationTraffic, Steamer, StepperLepper, SwimmingLane, TableTennis, TearsOfIce, Tetris, ThreadAndBall, Trampoline, Turtle, Volcano, Whip, Worker, Worm, WristWatch
Constant Summary
collapse
- RUN_N_TIMES =
#
RUN_N_TIMES
This can be overruled/set via the commandline. It just is a general default in that every animated ASCII component will be run 10 times, aka 10 iterations, by default.
#
10
Class Method Summary
collapse
-
.is_animated? ⇒ Boolean
# === AsciiParadise::Animation.is_animated?.
-
.run ⇒ Object
# === AsciiParadise::Animation.run ========================================================================= #.
Instance Method Summary
collapse
Methods inherited from Base
animation_dir?, #animation_directory?, #clear_screen, #colour_parse_this_string, #debug?, #do_not_run_already, #do_not_use_clear, #do_use_random_colour, #do_wait_for_keypress_event, e, #e, #enable_debug, #initialize, #menu, #project_base_dir?, #register_sigint, #remove_trailing_ansci_escape_code, #report_how_many_animated_components_exist, #return_basename_of_this_file_without_the_extension, #return_random_colour, #rev, #royalblue, #set_use_this_colour, #sfancy, #sfile, #show_available_components, #show_help, #simp, #slategrey, #sort_files, #static_dir?, #steelblue, #swarn, #use_colours?
Class Method Details
.is_animated? ⇒ Boolean
#
AsciiParadise::Animation.is_animated?
This will always be true when people subclass from this class.
#
36
37
38
|
# File 'lib/ascii_paradise/animation/animation.rb', line 36
def self.is_animated?
true
end
|
.run ⇒ Object
#
AsciiParadise::Animation.run
#
558
559
560
|
# File 'lib/ascii_paradise/animation/animation.rb', line 558
def self.run
new
end
|
Instance Method Details
#ascii_files? ⇒ Boolean
68
69
70
|
# File 'lib/ascii_paradise/animation/animation.rb', line 68
def ascii_files?
@ascii_files
end
|
#dataset? ⇒ Boolean
372
373
374
|
# File 'lib/ascii_paradise/animation/animation.rb', line 372
def dataset?
@dataset
end
|
#delay? ⇒ Boolean
Also known as:
sleep_for_n_seconds?
75
76
77
|
# File 'lib/ascii_paradise/animation/animation.rb', line 75
def delay?
@delay
end
|
#display(frame) ⇒ Object
Also known as:
display_this_frame
#
display
This method can display a frame of an animated ASCII class.
It is essentially just an output-method. The method will also optionally allow the user to use a specific colour. This colour must exist as part of the Colours namespace.
#
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/ascii_paradise/animation/display.rb', line 25
def display(frame)
i = frame.dup if @use_colours if @use_rainbow_colours
i = ::Colours::RainbowColours.returnln_plain(i)
elsif @use_this_colour and
::Colours.respond_to?(@use_this_colour.to_sym)
i = ::Colours.send(@use_this_colour, i)
end
end
e i end
|
#display_the_frame(frame = @frame) ⇒ Object
#
display_the_frame
This method will display the individual “frame” of an animated ASCII component.
#
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/ascii_paradise/animation/display.rb', line 44
def display_the_frame(
frame = @frame
)
if debug?
e steelblue('Filename: ')+sfile(guess_filename)
end
display frame
if @wait_for_keypress_on_each_frame == :also_show_red_numbers
e
1.upto(9) {|number| print tomato(number) }
1.upto(9) {|number| print tomato(number) }
1.upto(9) {|number| print tomato(number) }
1.upto(9) {|number| print tomato(number) }
1.upto(9) {|number| print tomato(number) }
1.upto(9) {|number| print tomato(number) }
e
end
if debug?
e
e steelblue('Frame number: ')+
royalblue((@index_position+1).to_s)+
mediumpurple(
' ('+return_filename(@index_position+1)+')'
)
e end
end
|
#do_clear? ⇒ Boolean
170
171
172
|
# File 'lib/ascii_paradise/animation/animation.rb', line 170
def do_clear?
@do_clear
end
|
#do_use_colour_spray ⇒ Object
#
do_use_colour_spray
The colour-spray mode means that after every iteration, a new general colour will be shown for all ASCII frames in that iteration run.
#
136
137
138
|
# File 'lib/ascii_paradise/animation/animation.rb', line 136
def do_use_colour_spray
@use_colour_spray = true
end
|
#do_use_disco_inferno ⇒ Object
#
do_use_disco_inferno
Enable the disco-inferno-mode, also called “disco-mode”.
The disco mode means that we will show a (one) random colour for every new frame. This is not very pretty for the eyes, but feature is feature after all. :)
#
149
150
151
|
# File 'lib/ascii_paradise/animation/animation.rb', line 149
def do_use_disco_inferno
@use_disco_inferno = true
end
|
#do_use_half_colours ⇒ Object
#
do_use_half_colours (half tag)
#
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/ascii_paradise/animation/animation.rb', line 82
def do_use_half_colours
upper_colour = return_random_colour
lower_colour = return_random_colour
loop {
if upper_colour == lower_colour lower_colour = return_random_colour
end
break unless upper_colour == lower_colour
}
upper_colour = remove_trailing_ansci_escape_code(
Colours.send(upper_colour)
)
lower_colour = remove_trailing_ansci_escape_code(
Colours.send(lower_colour)
)
new_dataset = dataset? new_dataset.map! {|string|
string.split("\n")
}
new_dataset.map! {|inner_array|
inner_array[0..inner_array.size / 2] =
inner_array[0..inner_array.size / 2].map {|entry|
upper_colour+entry+rev
}
inner_array[(inner_array.size / 2)..-1] =
inner_array[(inner_array.size / 2)..-1].map {|entry|
lower_colour+entry+rev
}
inner_array
}
new_dataset.map! {|string|
string.join("\n")
}
set_dataset(
new_dataset
)
end
|
#do_use_rainbow_colours ⇒ Object
Also known as:
do_use_rainbow_lines
#
do_use_rainbow_colours
#
163
164
165
|
# File 'lib/ascii_paradise/animation/animation.rb', line 163
def do_use_rainbow_colours
@use_rainbow_colours = true
end
|
#guess_filename ⇒ Object
#
guess_filename
This method will, as its name may imply, attempt to guess the filename.
#
531
532
533
534
|
# File 'lib/ascii_paradise/animation/animation.rb', line 531
def guess_filename
"ascii_paradise/animations/"\
"#{File.basename(@use_ascii_files_from_this_directory)}.rb"
end
|
#load_animated_ascii_files_from_this_directory(i) ⇒ Object
#
load_animated_ascii_files_from_this_directory
#
59
60
61
62
63
|
# File 'lib/ascii_paradise/animation/animation.rb', line 59
def load_animated_ascii_files_from_this_directory(i)
i = return_the_name_to_the_proper_animation_directory_of_this_animated_component(i)
set_use_ascii_files_from_this_directory(i)
load_ascii_files_and_determine_the_dataset
end
|
#load_ascii_files ⇒ Object
#
load_ascii_files
This will only load (and assign) the ascii files - it will NOT read these files into the dataset of the ASCII component at hand.
For the latter you will have to use set_dataset() instead.
#
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
|
# File 'lib/ascii_paradise/animation/animation.rb', line 416
def load_ascii_files
@ascii_files = sort_files(
Dir[
@use_ascii_files_from_this_directory+'*.ascii'
]
)
if @ascii_files.any? {|line|
line.end_with? 'control.ascii'
}
dataset_from_the_file_control_ascii = File.readlines(
@ascii_files.select {|inner_line|
inner_line.end_with? 'control.ascii'
}.first
)
parse_dataset_from_this_control_file(dataset_from_the_file_control_ascii)
@ascii_files.reject! {|line| line.end_with? 'control.ascii' }
end
end
|
#load_ascii_files_and_determine_the_dataset ⇒ Object
#
load_ascii_files_and_determine_the_dataset
#
402
403
404
405
406
|
# File 'lib/ascii_paradise/animation/animation.rb', line 402
def load_ascii_files_and_determine_the_dataset
load_ascii_files
load_dataset
set_dataset
end
|
#load_dataset ⇒ Object
379
380
381
382
383
|
# File 'lib/ascii_paradise/animation/animation.rb', line 379
def load_dataset
set_dataset(
@ascii_files.map {|entry| File.read(entry) }
)
end
|
#mediumpurple(i = '') ⇒ Object
539
540
541
|
# File 'lib/ascii_paradise/animation/animation.rb', line 539
def mediumpurple(i = '')
AsciiParadise.mediumpurple(i)
end
|
#parse_dataset_from_this_control_file(i) ⇒ Object
#
parse_dataset_from_this_control_file
#
510
511
512
513
514
515
516
517
518
519
520
521
522
523
|
# File 'lib/ascii_paradise/animation/animation.rb', line 510
def parse_dataset_from_this_control_file(i)
if i.is_a? Array
i.each {|line|
if line.include? 'delay'
set_delay(
line.split(':').last.strip
)
end
}
end
end
|
#reset ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/ascii_paradise/animation/reset.rb', line 14
def reset
super()
@dataset = nil
set_delay
set_use_this_colour
set_run_n_times
@do_clear = true
@use_rainbow_colours = false
@use_disco_inferno = false
@use_colour_spray = false
end
|
#return_filename(use_this_position = 1) ⇒ Object
546
547
548
549
550
551
552
553
|
# File 'lib/ascii_paradise/animation/animation.rb', line 546
def return_filename(use_this_position = 1)
_ = "ascii_paradise/animations/"\
"#{File.basename(@use_ascii_files_from_this_directory)}/"\
"#{File.basename(@use_ascii_files_from_this_directory)}.ascii".dup
index = _.index('.ascii')
_[index, 0] = '_'+use_this_position.to_s.rjust(2, '0')
return _
end
|
#return_the_name_to_the_proper_animation_directory_of_this_animated_component(i) ⇒ Object
#
return_the_name_to_the_proper_animation_directory_of_this_animated_component
#
50
51
52
53
54
|
# File 'lib/ascii_paradise/animation/animation.rb', line 50
def return_the_name_to_the_proper_animation_directory_of_this_animated_component(i)
animation_directory?+
return_basename_of_this_file_without_the_extension(i)+
'/'
end
|
#run ⇒ Object
247
248
249
|
# File 'lib/ascii_paradise/animation/animation.rb', line 247
def run
run_with_default_dataset
end
|
#run_n_times? ⇒ Boolean
#
run_n_times?
How many times we will run the looped-animation.
#
240
241
242
|
# File 'lib/ascii_paradise/animation/animation.rb', line 240
def run_n_times?
@run_n_times
end
|
#run_with_this_dataset(dataset_holding_all_the_frames = dataset?,
, run_n_times = @run_n_times) ⇒ Object
Also known as:
run_with_default_dataset, start_the_animation, do_animate, animate
#
run_with_this_dataset
This method can be used to “animate” the frames.
Note that this method has some aliases, such as .animate().
#
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
|
# File 'lib/ascii_paradise/animation/animation.rb', line 448
def run_with_this_dataset(
dataset_holding_all_the_frames = dataset?,
run_n_times = @run_n_times
)
@index_position = 0
if @wait_for_keypress_on_each_frame
run_with_this_dataset_while_waiting_for_keypress_events(
dataset_holding_all_the_frames
)
else
run_n_times.times {|iteration_number|
dataset_holding_all_the_frames.each {|this_frame|
clear_screen if @do_clear
if @use_disco_inferno do_use_random_colour
end
@frame = this_frame
display_the_frame
sleep_with_the_default_delay
@index_position += 1
if @index_position >= dataset_holding_all_the_frames.size
@index_position = 0
end
}
}
if @use_colour_spray
do_use_random_colour
end
end
end
|
#run_with_this_dataset_while_waiting_for_keypress_events(dataset_holding_all_the_frames = dataset?
) ⇒ Object
#
run_with_this_dataset_while_waiting_for_keypress_events
To invoke this method, try:
volcano --wait-for-keypress
#
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
# File 'lib/ascii_paradise/animation/animation.rb', line 298
def run_with_this_dataset_while_waiting_for_keypress_events(
dataset_holding_all_the_frames = dataset?
)
loop {
can_we_exit = false
clear_screen if @do_clear
@frame = dataset_holding_all_the_frames[@index_position]
display_the_frame
show_to_the_user_how_to_operate_the_keypress_interface
if @index_position == (dataset_holding_all_the_frames.size - 1)
e "\nThis is the last frame."
end
user_input = STDIN.getch
case user_input when 'p','previous'
e
@index_position -= 1
@index_position = 0 if @index_position < 0 when 'n','next'
@index_position += 1
if @index_position >= dataset_holding_all_the_frames.size @index_position = dataset_holding_all_the_frames.size - 1
end
when 'q'
e
can_we_exit = true
end
if can_we_exit
break
end
}
end
|
#set_dataset(i = @ascii_files.map {|entry| File.read(entry) }) ⇒ Object
#
set_dataset
This method will assign to the dataset of this animated ASCII class.
The dataset is obtained from @ascii_files, and simply reading in the content of these .ascii files.
#
393
394
395
396
397
|
# File 'lib/ascii_paradise/animation/animation.rb', line 393
def set_dataset(
i = @ascii_files.map {|entry| File.read(entry) }
)
@dataset = [i].flatten.compact
end
|
#set_delay(i = SLEEP_FOR_N_SECONDS) ⇒ Object
Also known as:
set_sleep_for_n_seconds
#
set_delay
The default delay is typically set to 0.145.
#
#set_run_n_times(i = RUN_N_TIMES) ⇒ Object
Also known as:
run_n_times
225
226
227
228
229
230
231
232
233
|
# File 'lib/ascii_paradise/animation/animation.rb', line 225
def set_run_n_times(
i = RUN_N_TIMES
)
case i
when :default
i = RUN_N_TIMES
end
@run_n_times = i.to_i
end
|
#set_use_ascii_files_from_this_directory(i) ⇒ Object
Also known as:
set_animation_dir, set_which_dir, set_main_dir
#
set_use_ascii_files_from_this_directory
#
356
357
358
|
# File 'lib/ascii_paradise/animation/animation.rb', line 356
def set_use_ascii_files_from_this_directory(i)
@use_ascii_files_from_this_directory = i
end
|
#show_frame_at_this_position(i) ⇒ Object
#
show_frame_at_this_position
This method can be used to show one individual frame at the given position. For example, if you pass in 3 then we will show frame 3.
The reason as to why this method exists is largely because we may sometimes wish to show just an individual frame on the commandline, perhaps if we wish to colourize it.
See these usage examples:
tetris --show-frame=5 | rainbow_colours
table_tennis --show-frame=4 | rainbow_colours
table_tennis --show-frame=5 | rainbow_colours
table_tennis --show-frames=5-8
table_tennis --show-frames=5-8 | rainbowc
volcano --show-frames=5-8
#
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
# File 'lib/ascii_paradise/animation/animation.rb', line 195
def show_frame_at_this_position(i)
dataset_holding_all_frames = dataset?
i.delete!('(') if i.include? '('
i.delete!(')') if i.include? ')'
if i.include? '-' splitted = i.split('-')
position = (splitted.first.to_i - 1)..(splitted.last.to_i - 1)
else position = (i.to_i - 1) if position > dataset_holding_all_frames.size
position = (dataset_holding_all_frames.size - 1)
end
end
these_frames = dataset_holding_all_frames[position]
these_frames = [these_frames] unless these_frames.is_a? Array
these_frames.each {|this_frame|
e this_frame
}
end
|
#show_to_the_user_how_to_operate_the_keypress_interface ⇒ Object
#
show_to_the_user_how_to_operate_the_keypress_interface
#
276
277
278
279
280
281
282
283
284
285
286
287
288
|
# File 'lib/ascii_paradise/animation/animation.rb', line 276
def show_to_the_user_how_to_operate_the_keypress_interface
e "#{rev}Press "+
slategrey('"')+
simp('n')+
slategrey('"')+
rev+' if you wish to continue and see '\
'the next frame, '+slategrey('"')+
simp('p')+
slategrey('"')
ee "#{rev}for the previous frame and "+
slategrey('"')+simp('q')+slategrey('"')+
"#{rev} if you wish to exit."
end
|
#sleep_with_the_default_delay ⇒ Object
#
sleep_with_the_default_delay
#
365
366
367
|
# File 'lib/ascii_paradise/animation/animation.rb', line 365
def sleep_with_the_default_delay
sleep @delay
end
|
#use_disco_inferno? ⇒ Boolean
156
157
158
|
# File 'lib/ascii_paradise/animation/animation.rb', line 156
def use_disco_inferno?
@use_disco_inferno
end
|