Class: AsciiParadise::RotatingSlash

Inherits:
Animation show all
Defined in:
lib/ascii_paradise/animations/rotating_slash.rb

Constant Summary collapse

DEFAULT_DELAY =
#

DEFAULT_DELAY

#
0.15
ARRAY =
#

ARRAY

This constant is an Array that keeps the different tokens which will be displayed on the commandline.

Note that the last character in that array, the ‘/’, will be the token that we will keep displayed.

There are six entries in this Array.

#
%w(
  | / - \\ '  /'
)
BACKSPACE =
#

BACKSPACE

#
"\b"

Constants inherited from Animation

Animation::RUN_N_TIMES

Instance Method Summary collapse

Methods inherited from Animation

#ascii_files?, #dataset?, #display, #display_the_frame, #do_clear?, #do_use_colour_spray, #do_use_disco_inferno, #do_use_half_colours, #do_use_rainbow_colours, #guess_filename, #is_animated?, is_animated?, #load_animated_ascii_files_from_this_directory, #load_ascii_files, #load_ascii_files_and_determine_the_dataset, #load_dataset, #mediumpurple, #parse_dataset_from_this_control_file, #return_filename, #return_the_name_to_the_proper_animation_directory_of_this_animated_component, run, #run_n_times?, #run_with_this_dataset, #run_with_this_dataset_while_waiting_for_keypress_events, #set_dataset, #set_delay, #set_run_n_times, #set_use_ascii_files_from_this_directory, #show_frame_at_this_position, #show_to_the_user_how_to_operate_the_keypress_interface, #sleep_with_the_default_delay, #use_disco_inferno?

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, #is_animated?, #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, run, #set_use_this_colour, #sfancy, #sfile, #show_available_components, #show_help, #simp, #slategrey, #sort_files, #static_dir?, #steelblue, #swarn, #use_colours?

Constructor Details

#initialize(run_already = true) ⇒ RotatingSlash

#

initialize

#


39
40
41
42
43
44
45
# File 'lib/ascii_paradise/animations/rotating_slash.rb', line 39

def initialize(
    run_already = true
  )
  register_sigint
  reset
  run if run_already
end

Instance Method Details

#can_we_finish?Boolean

#

can_we_finish?

#

Returns:

  • (Boolean)


57
58
59
# File 'lib/ascii_paradise/animations/rotating_slash.rb', line 57

def can_we_finish?
  rand(300) == 0
end

#delay?Boolean

#

delay?

#

Returns:

  • (Boolean)


71
72
73
# File 'lib/ascii_paradise/animations/rotating_slash.rb', line 71

def delay?
  @delay
end

#resetObject

#

reset

#


50
51
52
# File 'lib/ascii_paradise/animations/rotating_slash.rb', line 50

def reset
  @delay = DEFAULT_DELAY # We use this default.
end

#runObject

#

run

#


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ascii_paradise/animations/rotating_slash.rb', line 78

def run
  # ======================================================================= #
  # The tokens are those that will appear to "dance".
  # ======================================================================= #
  $stdout.sync = true # must be true else we won't see a thing.
  loop {
    print ARRAY.unshift(ARRAY.pop).last
    sleep delay?
    print BACKSPACE
    if can_we_finish? # Randomly finish here, via a message.
      show_finish_message
      break
    end
  }
end

#show_finish_messageObject

#

finish

#


64
65
66
# File 'lib/ascii_paradise/animations/rotating_slash.rb', line 64

def show_finish_message # finish and end here.
  puts 'Finished!'
end