diff options
Diffstat (limited to 'sample/biorhythm.rb')
| -rw-r--r-- | sample/biorhythm.rb | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/sample/biorhythm.rb b/sample/biorhythm.rb index 6465daa29f..f5d189014b 100644 --- a/sample/biorhythm.rb +++ b/sample/biorhythm.rb @@ -1,13 +1,13 @@ #!/usr/local/bin/ruby # -# biorhythm.rb - +# biorhythm.rb - # $Release Version: $ # $Revision$ # by Yasuo OHBA(STAFS Development Room) # # -- # -# +# # # probably based on: @@ -25,22 +25,21 @@ # Environment: basic, dos, os9 include Math -require "date.rb" +require "date" require "optparse" require "optparse/date" -def printHeader(y, m, d, p, w) +def print_header(y, m, d, p, w) print "\n>>> Biorhythm <<<\n" printf "The birthday %04d.%02d.%02d is a %s\n", y, m, d, w printf "Age in days: [%d]\n\n", p end -def getPosition(z) - pi = Math::PI +def get_position(z) z = Integer(z) - phys = (50.0 * (1.0 + sin((z / 23.0 - (z / 23)) * 360.0 * pi / 180.0))).to_i - emot = (50.0 * (1.0 + sin((z / 28.0 - (z / 28)) * 360.0 * pi / 180.0))).to_i - geist =(50.0 * (1.0 + sin((z / 33.0 - (z / 33)) * 360.0 * pi / 180.0))).to_i + phys = (50.0 * (1.0 + sin((z / 23.0 - (z / 23)) * 360.0 * PI / 180.0))).to_i + emot = (50.0 * (1.0 + sin((z / 28.0 - (z / 28)) * 360.0 * PI / 180.0))).to_i + geist =(50.0 * (1.0 + sin((z / 33.0 - (z / 33)) * 360.0 * PI / 180.0))).to_i return phys, emot, geist end @@ -89,25 +88,25 @@ ausgabeart = options[:graph] ? "g" : "v" display_period = options[:days] if ausgabeart == "v" - printHeader(bd.year, bd.month, bd.day, dd - bd, bd.strftime("%a")) + print_header(bd.year, bd.month, bd.day, dd - bd, bd.strftime("%a")) print "\n" - - phys, emot, geist = getPosition(dd - bd) + + phys, emot, geist = get_position(dd - bd) printf "Biorhythm: %04d.%02d.%02d\n", dd.year, dd.month, dd.day printf "Physical: %d%%\n", phys printf "Emotional: %d%%\n", emot printf "Mental: %d%%\n", geist print "\n" else - printHeader(bd.year, bd.month, bd.day, dd - bd, bd.strftime("%a")) + print_header(bd.year, bd.month, bd.day, dd - bd, bd.strftime("%a")) print " P=physical, E=emotional, M=mental\n" print " -------------------------+-------------------------\n" print " Bad Condition | Good Condition\n" print " -------------------------+-------------------------\n" - + (dd - bd).step(dd - bd + display_period) do |z| - phys, emot, geist = getPosition(z) - + phys, emot, geist = get_position(z) + printf "%04d.%02d.%02d : ", dd.year, dd.month, dd.day p = (phys / 2.0 + 0.5).to_i e = (emot / 2.0 + 0.5).to_i |
