1#!/usr/local/bin/ruby 2# 3# biorhythm.rb - 4# $Release Version: $ 5# $Revision: 31573 $ 6# by Yasuo OHBA(STAFS Development Room) 7# 8# -- 9# 10# 11# 12 13# probably based on: 14# 15# Newsgroups: comp.sources.misc,de.comp.sources.os9 16# From: fkk@stasys.sta.sub.org (Frank Kaefer) 17# Subject: v41i126: br - Biorhythm v3.0, Part01/01 18# Message-ID: <1994Feb1.070616.15982@sparky.sterling.com> 19# Sender: kent@sparky.sterling.com (Kent Landfield) 20# Organization: Sterling Software 21# Date: Tue, 1 Feb 1994 07:06:16 GMT 22# 23# Posting-number: Volume 41, Issue 126 24# Archive-name: br/part01 25# Environment: basic, dos, os9 26 27include Math 28require "date.rb" 29require "optparse" 30require "optparse/date" 31 32def print_header(y, m, d, p, w) 33 print "\n>>> Biorhythm <<<\n" 34 printf "The birthday %04d.%02d.%02d is a %s\n", y, m, d, w 35 printf "Age in days: [%d]\n\n", p 36end 37 38def get_position(z) 39 pi = Math::PI 40 z = Integer(z) 41 phys = (50.0 * (1.0 + sin((z / 23.0 - (z / 23)) * 360.0 * pi / 180.0))).to_i 42 emot = (50.0 * (1.0 + sin((z / 28.0 - (z / 28)) * 360.0 * pi / 180.0))).to_i 43 geist =(50.0 * (1.0 + sin((z / 33.0 - (z / 33)) * 360.0 * pi / 180.0))).to_i 44 return phys, emot, geist 45end 46 47def prompt(msg) 48 $stderr.print msg 49 return gets.chomp 50end 51 52# 53# main program 54# 55options = { 56 :graph => true, 57 :date => Date.today, 58 :days => 9, 59} 60ARGV.options do |opts| 61 opts.on("-b", "--birthday=DATE", Date, "specify your birthday"){|v| 62 options[:birthday] = v 63 } 64 opts.on("--date=DATE", Date, "specify date to show"){|v| 65 options[:date] = v 66 } 67 opts.on("-g", "--show-graph", TrueClass, "show graph (default)"){|v| 68 options[:graph] = v 69 } 70 opts.on("-v", "--show-values", TrueClass, "show values"){|v| 71 options[:graph] = !v 72 } 73 opts.on("--days=DAYS", Integer, "graph range (only in effect for graph)"){|v| 74 options[:days] = v - 1 75 } 76 opts.on_tail("-h", "--help", "show this message"){puts opts; exit} 77 begin 78 opts.parse! 79 rescue => ex 80 puts "Error: #{ex.message}" 81 puts opts 82 exit 83 end 84end 85 86bd = options[:birthday] || Date.parse(prompt("Your birthday (YYYYMMDD): ")) 87dd = options[:date] || Date.today 88ausgabeart = options[:graph] ? "g" : "v" 89display_period = options[:days] 90 91if ausgabeart == "v" 92 print_header(bd.year, bd.month, bd.day, dd - bd, bd.strftime("%a")) 93 print "\n" 94 95 phys, emot, geist = get_position(dd - bd) 96 printf "Biorhythm: %04d.%02d.%02d\n", dd.year, dd.month, dd.day 97 printf "Physical: %d%%\n", phys 98 printf "Emotional: %d%%\n", emot 99 printf "Mental: %d%%\n", geist 100 print "\n" 101else 102 print_header(bd.year, bd.month, bd.day, dd - bd, bd.strftime("%a")) 103 print " P=physical, E=emotional, M=mental\n" 104 print " -------------------------+-------------------------\n" 105 print " Bad Condition | Good Condition\n" 106 print " -------------------------+-------------------------\n" 107 108 (dd - bd).step(dd - bd + display_period) do |z| 109 phys, emot, geist = get_position(z) 110 111 printf "%04d.%02d.%02d : ", dd.year, dd.month, dd.day 112 p = (phys / 2.0 + 0.5).to_i 113 e = (emot / 2.0 + 0.5).to_i 114 g = (geist / 2.0 + 0.5).to_i 115 graph = "." * 51 116 graph[25] = ?| 117 graph[p] = ?P 118 graph[e] = ?E 119 graph[g] = ?M 120 print graph, "\n" 121 dd = dd + 1 122 end 123 print " -------------------------+-------------------------\n\n" 124end 125