Last active
August 29, 2015 14:19
-
-
Save epitron/0e4543a206799e32b126 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'paint' | |
include Math | |
class Waves | |
BLOCKS = [ "█", "▓", "▒", "░" ] | |
attr_reader :width, :height | |
def initialize | |
@width, @height = 60, 40 | |
@t = 1 | |
end | |
def clear | |
puts "\e[2J" | |
end | |
def home | |
puts "\e[H" | |
end | |
def draw | |
i = @t / 1000.0 | |
height.times do |y| | |
line = (0...width).map do |x| | |
val = (sin(x * i) * tan(y * i)) * i | |
val = [[0.0, val].max, 1.0].min | |
val = (val * 255).to_i | |
Paint[BLOCKS.first, [val, val, val]] | |
end | |
puts line.join('') | |
end | |
@t += 1 | |
end | |
def run | |
clear | |
loop do | |
home | |
draw | |
sleep 0.01 | |
end | |
end | |
end | |
Waves.new.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment