バイオリズム

なんか気分が乗らないなーと思ってバイオリズムを調べたりしていた。
ついでに計算&表示するプログラムを作った。

点で描画しているから縮小したらかなり暗い。

require 'dxruby'
require 'date'

birthday = Date.new(2010, 1, 1) # ここに誕生日を入れる
start = (Date.today - birthday - 15).to_i
image = Image.new(640, 480)
image.line(0,240,639,240,[255,255,255]).line(320,0,320,479,[255,255,255])

for x in 0..640
  p = Math.sin(((x / (640.0 / 30) + start) % 23) / 23.0 * Math::PI * 2) # 身体
  e = Math.sin(((x / (640.0 / 30) + start) % 28) / 28.0 * Math::PI * 2) # 感情
  i = Math.sin(((x / (640.0 / 30) + start) % 33) / 33.0 * Math::PI * 2) # 知性

  image[x, -p * 240 + 240] = [255,255,0]
  image[x, -e * 240 + 240] = [255,0,255]
  image[x, -i * 240 + 240] = [0,255,255]
end

Window.loop do
  break if Input.keyPush?(K_ESCAPE)
  Window.draw(0,0,image)
end