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
new( use_this_runmode = :dna, run_already = true )
click to toggle source
Public Instance Methods
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
increment_counter()
click to toggle source
print_clear()
click to toggle source
#¶ ↑
print_clear
¶ ↑
#¶ ↑
# File lib/ascii_paradise/animations/rotating_dna.rb, line 125 def print_clear print `clear` end
Also aliased as: clear
reset()
click to toggle source
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