Class: Background

Inherits:
Object
  • Object
show all
Defined in:
lib/roflbalt.rb

Constant Summary collapse

PALETTE =
[ 16, 232, 233 ]
PERIOD =
16.0
SPEED =
0.5
BLOCKINESS =
10.0

Instance Method Summary collapse

Constructor Details

#initialize(world) ⇒ Background

Returns a new instance of Background.



118
119
120
# File 'lib/roflbalt.rb', line 118

def initialize world
  @world = world
end

Instance Method Details

#color(x, y) ⇒ Object



124
125
126
127
128
# File 'lib/roflbalt.rb', line 124

def color x, y
  y = (y / BLOCKINESS).round * BLOCKINESS
  sin = Math.sin((x + @world.distance.to_f * SPEED) / PERIOD + y / PERIOD)
  PALETTE[(0.9 * sin + 0.9).round]
end

#pixel(x, y, char = " ") ⇒ Object



121
122
123
# File 'lib/roflbalt.rb', line 121

def pixel x, y, char = " "
  Pixel.new char, 0, color(x, y)
end