class AsciiParadise::RotatingDNA

Constants

DNA_X_Y_MOVEMENT_SPEED
#

DNA_X_Y_MOVEMENT_SPEED

The higher this number is, the faster the DNA will “rotate”. 2 is my default.

#
THRESHOLD_N_RUNS_ALLOWED
#

THRESHOLD_N_RUNS_ALLOWED

#
UPDATE_SPEED
#

UPDATE_SPEED

How fast the DNA will rotate, at each interval.

#

Public Class Methods

[](runmode = :dna) click to toggle source
#

AsciiParadise::RotatingDNA[]

The runmodes can be:

AsciiParadise::RotatingDNA[:dna]
AsciiParadise::RotatingDNA[:star]
#
# File lib/ascii_paradise/animations/rotating_dna.rb, line 171
def self.[](runmode = :dna)
  new(runmode)
end
new( use_this_runmode = :dna, run_already = true ) click to toggle source
#

initialize

#
Calls superclass method
# File lib/ascii_paradise/animations/rotating_dna.rb, line 36
def initialize(
    use_this_runmode = :dna,
    run_already      = true
  )
  super()
  reset
  register_sigint
  set_runmode(use_this_runmode)
  run if run_already
end

Public Instance Methods

clear()
Alias for: print_clear
draw_dna_frame( time_scale, horiz_scale, vert_scale, curve_length, pair_space, pair_offset = pair_space/2, char = '*' ) click to toggle source
#

draw_dna_frame

Draw the DNA frame. This is the main powerhorse of this class.

#
# File lib/ascii_paradise/animations/rotating_dna.rb, line 91
def draw_dna_frame(
    time_scale,   horiz_scale, vert_scale, 
    curve_length, pair_space, 
    pair_offset = pair_space/2, char = '*'
  )
  frame = Array.new(vert_scale) { Array.new(curve_length, ' ') }
  time_now  = Time.now.to_f # Get the start-time.
  sin_start = time_scale * time_now
  half_vs   = vert_scale/2
  (0...curve_length).each { |i|
    v = half_vs * Math.sin(sin_start+horiz_scale*i)
    p1 = half_vs + v
    p2 = half_vs - v
    frame[p1][i] = char
    frame[p2][i] = char
    if (i + pair_offset) % pair_space < 1
      p1,p2 = [p1, p2].sort
      (p1.ceil...p2.ceil).each { |y| frame[y][i] = char }
    end
  }
  clear
  e frame.map {|line| line.join }
end
draw_star_frame( clear, time_scale, horiz_scale, vert_scale, curve_length, pair_space, pair_offset = pair_space / 2, char = '*' ) click to toggle source
#

draw_star_frame

#
# File lib/ascii_paradise/animations/rotating_dna.rb, line 59
def draw_star_frame(
    clear,
    time_scale,
    horiz_scale,
    vert_scale,
    curve_length,
    pair_space,
    pair_offset = pair_space / 2,
    char = '*'
  )
  frame = Array.new(vert_scale){Array.new(curve_length, ' ')}
  t = Time.now.to_f
  sin_start = time_scale*t
  half_vs = vert_scale / 2
  (0...curve_length).each{|i| 
    if (i+pair_offset) % pair_space < 1
      v = half_vs * Math.sin(sin_start+horiz_scale*i)
      p1 = (half_vs + v)
      p2 = (half_vs - v)
      frame[p1][i] = char
      frame[p2][i] = char
    end
  }
  print_clear
  e frame.map {|line| line.join }
end
draw_what?()
Alias for: runmode?
increment_counter() click to toggle source
#

increment_counter

#
# File lib/ascii_paradise/animations/rotating_dna.rb, line 118
def increment_counter
  @n_runs += 1
end
print_clear() click to toggle source
#

print_clear

#
Also aliased as: clear
reset() click to toggle source
#

reset

#
Calls superclass method AsciiParadise::Animation#reset
# File lib/ascii_paradise/animations/rotating_dna.rb, line 50
def reset
  super()
  set_runmode # Default mode is :dna. The other mode is :star
  @n_runs = 0
end
run() click to toggle source
#

run

#
# File lib/ascii_paradise/animations/rotating_dna.rb, line 132
def run
  loop {
    case runmode?
    when :dna, :default
      draw_dna_frame(DNA_X_Y_MOVEMENT_SPEED, 0.1, 11, 60, 8, 4)
    else
      draw_star_frame(`clear`,2,0.1,11,60,4,2)
    end
    sleep UPDATE_SPEED
    increment_counter
    exit if @n_runs > THRESHOLD_N_RUNS_ALLOWED
  }
end
runmode?() click to toggle source
#

runmode?

@runmode right now can be :dna, or :star. :star will be the default.

#
# File lib/ascii_paradise/animations/rotating_dna.rb, line 158
def runmode?
  @runmode
end
Also aliased as: draw_what?
set_runmode(use_this_runmode = :dna) click to toggle source
#

set_runmode

#
# File lib/ascii_paradise/animations/rotating_dna.rb, line 149
def set_runmode(use_this_runmode = :dna)
  @runmode = use_this_runmode
end