Permalink
Browse files

Updated background generators.

  • Loading branch information...
1 parent b0a9d46 commit 87c146ec7febb5ee9a9789478c94ce4f0c78cf6c @pda committed Jan 15, 2012
Showing with 17 additions and 5 deletions.
  1. +17 −5 asc.rb
View
22 asc.rb
@@ -97,15 +97,27 @@ def to_s
end
class Background
- MEDIAN = 233.1
- RANGE = 1.1
- PERIOD = 5
- SPEED = 10
+ PALETTE = [ 16, 232 ]
+ PERIOD = 5.0
+ SPEED = 10.0
+ def pixel x, y, char = ":"
+ Pixel.new char, 0, color(x, y)
+ end
+ def color x, y
+ sin = Math.sin((x + Time.new.to_f * SPEED) / PERIOD + y / PERIOD)
+ PALETTE[(0.5 * sin + 0.5).round]
+ end
+end
+
+class WindowColor
+ PALETTE = [ 16, 60 ]
+ PERIOD = 6.0
def pixel x, y, char = " "
Pixel.new char, 0, color(x, y)
end
def color x, y
- (MEDIAN - RANGE * Math.sin((x + Time.new.to_f * SPEED) / PERIOD + y / PERIOD)).round
+ sin = Math.sin(x / PERIOD + y / (PERIOD * 0.5))
+ PALETTE[(0.256 * sin + 0.256).round]
end
end

0 comments on commit 87c146e

Please sign in to comment.