|
유영인.Chris 님이 쓰신 글 :
: 저두 잘 모르고.. 찾아보니 소스가 있어서.. 올려드립니다. 아마도 C++ Builder 소스라서 차이가 좀 있을껍니다.. 그대로 쓰시기에는 무리같구.. 여기에 있는 계산등의 이론을 분석하시는건 어떻까요..?
:
:
:
: #!/usr/bin/env python
: #
: # Biorhythm calculator. Easier to program than to spell.
: #
: # Re-use of this code for any purpose is permitted, so long as this notice
: # and the __author__ attribution are retained in the source file.
: #
:
: __author__ = "Steve Purcell (stephen_purcell at yahoo dot com)"
:
: import string
: import time
: import math
:
: SECS_IN_DAY = 24 * 60 * 60
:
: class BiorhythmCalculator:
: EMOT_PERIOD = 28.0 * SECS_IN_DAY
: PHYS_PERIOD = 23.0 * SECS_IN_DAY
: INTL_PERIOD = 33.0 * SECS_IN_DAY
:
: def __init__(self, birthtime):
: self.birthtime = birthtime
:
: def calculateFor(self, theTime):
: """Return tuple of percentages, (emotional,physical,intellectual)"""
: if theTime < self.birthtime:
: raise ValueError("that time is before the birthtime!")
: timeDiff = theTime - self.birthtime
: twoPi = math.pi * 2.0
: return (math.sin(twoPi * (timeDiff / self.EMOT_PERIOD)),
: math.sin(twoPi * (timeDiff / self.PHYS_PERIOD)),
: math.sin(twoPi * (timeDiff / self.INTL_PERIOD)))
:
: def makeTimeFromDate(day, month, year):
: if day < 1 or month < 1 or year < 1:
: raise ValueError('negative day/month/year not allowed')
: return time.mktime((year,month,day,0,0,0,-1,-1,-1))
:
: if __debug__: # Test code
: birthtime = makeTimeFromDate(1,7,1974)
: calc = BiorhythmCalculator(birthtime)
: assert calc.calculateFor(birthtime) == (0,0,0)
: assert calc.calculateFor(birthtime + 28*SECS_IN_DAY)[0] < 0.001
: assert calc.calculateFor(birthtime + 23*SECS_IN_DAY)[1] < 0.001
: assert calc.calculateFor(birthtime + 33*SECS_IN_DAY)[2] < 0.001
:
: if __name__ == '__main__':
: import sys
: args = sys.argv[1:]
: if len(args) != 3:
: print """\
: Biorhythm calculator
:
: usage: biorhythm.py day month year
:
: Calculates today's biorhythms for the person born on the given day. """
: sys.exit(2)
:
: day, month, year = map(string.atoi, args)
: birthtime = makeTimeFromDate(day,month,year)
: thistime = time.mktime(time.localtime(time.time())[0:3] +
: (0,0,0,-1,-1,-1))
: calc = BiorhythmCalculator(birthtime)
: emot,phys,intl = calc.calculateFor(thistime)
: print "Emotional: %7.1f %%" % (emot*100)
: print "Physical : %7.1f %%" % (phys*100)
: print "Mental : %7.1f %%" % (intl*100)
:
: width = 60
: halfwidth = width / 2
: solidline = '=' * (width+10)
: print solidline
: print "Day(s) |-100%" + (' ' * (width - 10)) + "+100%|"
: print solidline
: for dayDiff in range(-20,20):
: thatTime = thistime + dayDiff * SECS_IN_DAY
: emot,phys,intl = calc.calculateFor(thatTime)
: bar = [' -'[dayDiff==0]] * width
: bar[halfwidth - 1] = bar[halfwidth] = '.'
: bar[halfwidth - 1 + int(emot * halfwidth)] = 'E'
: bar[halfwidth - 1 + int(phys * halfwidth)] = 'P'
: bar[halfwidth - 1 + int(intl * halfwidth)] = 'M'
: print "%4d |%s|" % (dayDiff,string.join(bar,''))
: print solidline
:
:
: sado1028 님이 쓰신 글 :
: : 님들 중에 아시는 분 있음 그 알고리즘 좀 갈쳐 주세요....
: : 소스를 짤려구 하는데 그 알고리즘을 모르니까 짜증만 나구 밥맛두 없구 살맛도 안나구....
: : 제가 씨빌더를 시작한지 별루 안되서 잘 모르는 왕초보여서요....
|