Skip to content

Instantly share code, notes, and snippets.

@nevyn
Created July 22, 2009 15:38
Show Gist options
  • Save nevyn/152050 to your computer and use it in GitHub Desktop.
Save nevyn/152050 to your computer and use it in GitHub Desktop.
Google wave ASCII art
#!/usr/bin/env ruby
# http://gist.github.com/152050
# thanks http://www.ascii-art.de/ascii/uvw/wave.txt
class Sprite
attr_accessor :data, :w, :h
def initialize w = 80, h = 23
@w = w
@h = h
clear
end
def self.fromBuf buf
s = Sprite.new buf[0].length, buf.length
s.data = buf
s
end
def clear
@data = (0...@h).map {' '*@w}
end
def blit to, destx = 0, desty = 0
(0...@h).each { |y|
(0...@w).each { |x|
dx = destx + x
dy = desty + y
next if dx >= to.w or dx < 0
next if dy >= to.h or dy < 0
next if @data[y][x] == ' '[0]
to.data[dy][dx] = @data[y][x]
}
}
end
def to_s
@data
end
end
class Animation
def initialize sprites # = [[duration, sprite], [dur, spr], ...]
@sprites = sprites
@idx = -1
@remaining = 1
end
def blit to, destx = 0, desty = 0
@remaining -= 1
if @remaining == 0 then
@idx += 1
@idx = 0 if @idx == @sprites.length
@remaining = @sprites[@idx][0]
@sprite = @sprites[@idx][1]
end
@sprite.blit to, destx, desty
end
end
$screen = Sprite.new
$wave1 = Sprite.fromBuf [
" )."*40,
"`-' "*40
]
$bigwave = Sprite.fromBuf [
" _.====.._ ",
" ,:._ ~-_ ",
" `\\ ~-_ ",
" | `. ",
" ,/ ~-_ ",
" -..__..-'' ~~--..__...----..."
]
$surfer1 = Sprite.fromBuf [
' \O ',
' |\ ',
' / \ ',
' J \ ',
'==========='
]
$surfer2 = Sprite.fromBuf [
' O/ ',
' /| ',
' / \ ',
' / \ ',
'==========='
]
$W = Sprite.fromBuf [
' ',
' | | ',
' \ / ',
' \/^\/ '
]
$A = Sprite.fromBuf [
' ___ ',
' / \ ',
' |_____| ',
' | | '
]
$V = Sprite.fromBuf [
' ',
' | | ',
' \ / ',
' \/ '
]
$E = Sprite.fromBuf [
' ',
' +----- ',
' |----- ',
' |_____ '
]
$RO = Sprite.fromBuf [
'ROFL:ROFL:LOL: ',
' A ',
' L /-------- ',
' O === []\ ',
' L \ \ ',
' \________] ',
' | | ' ,
' ------------/ '
]
$FL = Sprite.fromBuf [
' :LOL:ROFL:ROFL',
' A ',
' /-------- ',
' LOL=== []\ ',
' \ \ ',
' \________] ',
' | | ' ,
' ------------/ '
]
$ohyeah1 = Sprite.fromBuf ["Revvin' up your engine / Listen to her howlin' roar / Metal under tension / Beggin' you to touch and go / Highway to the Danger Zone / Ride into the Danger Zone / Headin' into twilight / Spreadin' out her wings tonight / She got you jumpin' off the track / And shovin' into overdrive / Highway to the Danger Zone / I'll take you / Right into the Danger Zone / You'll never say hello to you / Until you get it on the red line overload / You'll never know what you can do / Until you get it up as high as you can go / Out along the edges / Always where I burn to be / The further on the edge / The hotter the intensity / Highway to the Danger Zone / Gonna take you / Right into the Danger Zone / Highway to the Danger Zone"]
$ohyeah2 = Sprite.fromBuf ["We're no strangers to love / You know the rules and so do I / A full commitment's what I'm thinking of / You wouldn't get this from any other guy / / I just wanna tell you how I'm feeling / Gotta make you understand / / Never gonna give you up / Never gonna let you down / Never gonna run around and desert you / Never gonna make you cry / Never gonna say goodbye / Never gonna tell a lie and hurt you / / We've known each other for so long / Your heart's been aching, but / You're too shy to say it / Inside we both know what's been going on / We know the game and we're gonna play it / / And if you ask me how I'm feeling / Don't tell me you're too blind to see / / Never gonna give you up / Never gonna let you down / Never gonna run around and desert you / Never gonna make you cry / Never gonna say goodbye / Never gonna tell a lie and hurt you / / Never gonna give you up / Never gonna let you down / Never gonna run around and desert you / Never gonna make you cry / Never gonna say goodbye / Never gonna tell a lie and hurt you / / (Oooooooh, Give you up) / (Oooooooh, Give you UP) / Never gonna give, never gonna give / (Give you up) / Never gonna give, never gonna give / (Give you up) / / We've known each other for so long / Your heart's been aching, but / You're too shy to say it / Inside we both know what's been going on / We know the game and we're gonna play it / / I just wanna tell you how I'm feeling / Gotta make you understand / / Never gonna give you up / Never gonna let you down / Never gonna run around and desert you / Never gonna make you cry / Never gonna say goodbye / Never gonna tell a lie and hurt you / / Never gonna give you up / Never gonna let you down / Never gonna run around and desert you / Never gonna make you cry / Never gonna say goodbye / Never gonna tell a lie and hurt you / / Never gonna give you up / Never gonna let you down / Never gonna run around and desert you / Never gonna make you cry / Never gonna say goodbye / Never gonna tell a lie and hurt you"]
$ohyeah = rand(2)==1 ? $ohyeah1 : $ohyeah2
$surfer = Animation.new [[10, $surfer1], [10, $surfer2]]
$roflcoptr = Animation.new [[1, $RO], [1, $FL]]
t = 0
while true
$screen.clear
`clear`
Sprite.fromBuf(["#{Time.now}"]).blit $screen
Sprite.fromBuf(["GOOGLE"]).blit $screen, 34, 2
$W.blit $screen, 36, 3 + ((t+0)/16)%2
$A.blit $screen, 47, 3 + ((t+4)/16)%2
$V.blit $screen, 56, 3 + ((t+8)/16)%2
$E.blit $screen, 66, 3 + ((t+12)/16)%2
(15...24).step(2) {|y|
$wave1.blit $screen, -10+(t%5)-y, y
}
$bigwave.blit $screen, 28, 11
$surfer.blit $screen, 21 - (t/12)%2, 12 - (t/23)%2
$roflcoptr.blit $screen, (t%300) - 200, 3
$ohyeah.blit $screen, 80+200-40-(t % ($ohyeah.data[0].length + 80+200-40)), 22
puts $screen.to_s
t += 1
sleep 0.1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment