BioChart — File Browser

BioChartv1.2 / BioChartv1.2 / biochart.mrc

biochart.mrc — 11.71 KB — Download this file

;================================ BioChart  V1.2  [ Script For mIRC 5.31 ]   ===============================
;-------------------------------------------------------------------- by KiloVolt,  1998 --------------------------------------------------------------------

;********************************************************* Credits ****************************************************************
;The date conversion routines (Gregorian to Julian, etc.) are based on an article by T. W. Edwards in the 1991 Aug./Sept.
;issue of  "Campus Computing Newsletter" published by the University of Missouri-Columbia.  This aritcle can be found at
;http://www.missouri.edu/cc/pubs/news/1991-08/index.html#julian.  It contains some interesting information about
;the Gregorian calendar and Julian numbers, etc.
***********************************************************************************************************************************

on 1:load:{
  echo 4 -s ------ This script adds the entry "BioRythm"  to the Status Window popup menu.
  echo 4 -s ------ Select Birthdate and enter the birthdate for which you want plots.
  echo 4 -s ------ Select Chart for plots.  It takes about 10 seconds or so for plots to complete.
  echo 4 -s ----------This is due to the resolution chosen for the sin wave functions.
  echo 4 -s ----------Reducing the resolution will speed up the plot, but curve lines become jagged.
  echo 4 -s ------ Close the plot window with the X in upper right corner.
  echo 4 -s ------ All variables except birthdate are cleared after plotting.
  echo 4 -s >
  echo 6 -s ***** For information about the Gregorian calendar and Julian numbers see the
  echo 6 -s ***** article by T. W. Edwards in the 1991, Aug./Sept. issue of  "Campus Computing Newsletter"
  echo 6 -s ***** at http://www.missouri.edu/cc/pubs/news/1991-08/index.html#julian
  echo 6 -s ***** The Gregorian date to Julian number (and Julian to Gregorian) routines in this script
  echo 6 -s ***** are based on that article.
}


on 1:start:{
  if ($version < 5.31) { echo 4 -a ******* The script (BioChart V1.2) requires Mirc ver. 5.31 or later ********* | beep 2 200 }
}


menu status {
  BioRythm
  .Chart: Biorythm
  .BirthDate: BioGetBirth
}  

;Gets birthdate for plotting.  Does some format error checking for user input.  Determines if date entered is a valid date
;and if so sets the birtdate variable BioBirthDStr

alias BioGetBirth {
  set %Bio.BirthD $$?="Enter Birth Date in format mm/dd/yyyy"
  if ( $count(%Bio.BirthD,$chr(47)) != 2) { echo 4 -s Improper date format, check number of slashes. | beep 2 200 | unset %Bio.* BP.* | halt }
  elseif ( $gettok(%Bio.BirthD,3,47) >= $gettok($fulldate,5,32)) { echo 4 -s Year of birth must be earlier than current year! | beep 2 200 | unset %Bio.* BP.* | halt }
  elseif ( $len( $gettok(%Bio.BirthD,1,47)) > 2) { echo 4 -s You have entered an improper month format. Use 1 or 2 places (i.e. 5, 05, 11, etc.). | beep 2 200 | unset %Bio.* BP.* | halt }
  elseif ( $len( $gettok(%Bio.BirthD,2,47)) > 2) { echo 4 -s You have entered an improper day format. Use 1 or 2 places (i.e. 5, 05, 15, etc). | beep 2 200 | unset %Bio.* BP.* | halt }
  elseif ( $len( $gettok(%Bio.BirthD,3,47)) < 4) { echo 4 -s You have entered an improper year format. Use four places (i.e. 1975). | beep 2 200 | unset %Bio.* BP.* | halt }
  set %BioBirthDStr $calc($gettok(%Bio.BirthD,1,47) + 0) $+ $chr(32) $+ $calc($gettok(%Bio.BirthD,2,47) + 0) $+ $chr(32) $+ $gettok(%Bio.BirthD,3,47)
  if ( $BioDatValid(%BioBirthDStr) == 0) { echo 4 -s You have entered an invalid date, please check! | beep 2 200 | unset %Bio.* BP.* %BioBirthDStr | halt }
  echo 4 -s Birthdate has been set to: %Bio.BirthD
}

;Converts Gregorian dates to Julian numbers so dates can be added, subtracted, etc.; accounts for leap years.
;A non-century year (1973, etc.) is a leap year if evenly divisible by 4.  Century years (1900, 2000, etc.) are leap years if evenly
;divisible by 400.
;$1 = mm, $2 = dd, $3 = yyyy

alias Biodat2Julian {
  unset %Bio.dat2J.*
  %Bio.dat2J.d1 = $calc( $1 - 14 )
  %Bio.dat2J.d2 = $int( $calc( %Bio.dat2J.d1 / 12 ))
  %Bio.dat2J.d3 = $int( $calc( %Bio.dat2J.d2 * 12 ))
  %Bio.dat2J.ky = $calc( $3 + 4800 + %Bio.dat2J.d2 )
  %Bio.dat2J.km = $calc( $1 - 2 - %Bio.dat2J.d3 )
  %Bio.dat2J.j1 = $int( $calc((1461 * %Bio.dat2J.ky ) / 4))
  %Bio.dat2J.j2 = $int( $calc(( 367 * %Bio.dat2J.km ) / 12))
  %Bio.dat2J.j3 = $int( $calc( %Bio.dat2J.ky + 100 ))
  %Bio.dat2J.j4 = $int( $calc( %Bio.dat2J.j3 / 100 ))
  %Bio.dat2J.j5 = $int( $calc( 3 * %Bio.dat2J.j4 / 4 ))
  %Bio.dat2J.jd = $int( $calc( $2 - 32075 + %Bio.dat2J.j1 + %Bio.dat2J.j2 - %Bio.dat2J.j5 ))
  return %Bio.dat2J.jd
}

;Converts a Julian number to a Gregorian calendar date string in format mm dd yyyy
;$1 = Julian number

alias BioJulian2dat {
  unset %Bio.J2dat.*
  %Bio.J2dat.v1 = $calc( $1 + 68569)
  %Bio.J2dat.v2 = $int( $calc(4 * %Bio.J2dat.v1 / 146097))
  %Bio.J2dat.v3 = $int( $calc(((146097 * %Bio.J2dat.v2) + 3) / 4))
  %Bio.J2dat.ld = $calc( %Bio.J2dat.v1 - %Bio.J2dat.v3)
  %Bio.J2dat.ly = $int( $calc(4000 * (%Bio.J2dat.ld + 1) / 1461001))
  %Bio.J2dat.v4 = $int( $calc((1461 * %Bio.J2dat.ly) / 4))
  %Bio.J2dat.kd = $calc( %Bio.J2dat.ld - %Bio.J2dat.v4 + 31)
  %Bio.J2dat.km = $int( $calc((80 * %Bio.J2dat.kd) / 2447))
  %Bio.J2dat.id = $calc( %Bio.J2dat.kd - $int($calc(( 2447 * %Bio.J2dat.km) / 80)))
  %Bio.J2dat.im = $calc( %Bio.J2dat.km + 2 - 12 * $int( $calc(%Bio.J2dat.km / 11)))
  %Bio.J2dat.iy = $calc(( 100 * (%Bio.J2dat.v2 - 49)) + %Bio.J2dat.ly + $int( $calc( %Bio.J2dat.km / 11)))
  return %Bio.J2dat.im %Bio.J2dat.id %Bio.J2dat.iy
}

;Checks for a valid date by converting a Gregorian date string to a Julian number then converting that number back to
;a Gregorian date.  If the final date thus obtained is the same as the date started with, it is a valid.  This is used
;to check that the user has not entered numbers like 32 for a day, 29 for Feb in a non-leap year, 13 for month, etc.
;$1- = date string

alias BioDatValid {
  set %Bio.DatValid.dat $1-
  set %Bio.DatValid.temp1 $Biodat2Julian(%Bio.DatValid.dat)
  set %Bio.DatValid.temp2 $Biojulian2dat(%Bio.DatValid.temp1)
  if ( %Bio.DatValid.temp2 == %Bio.DatValid.dat ) { return 1 }
  else { return 0 }
}

;Determines the day of week from a Julian number
;$1= Julian number

alias BioDayofWk {
  %Bio.daywk = $int($calc((($1 + 1) % 7) + 1))
  if %Bio.daywk == 1 return Su
  elseif %Bio.daywk == 2 return M
  elseif %Bio.daywk == 3 return T
  elseif %Bio.daywk == 4 return W
  elseif %Bio.daywk == 5 return Th
  elseif %Bio.daywk == 6 return F
  elseif %Bio.daywk == 7 return Sa
}

;Starting point for chart. Calculates number of days lived then divides by 23, 28, and 33 day periods. The remainder
;after division is used to determine the point on the sin curve to start plots.

alias BioRythm {
  if (%BioBirthDStr == $null) { echo 4 -s Must enter birthdate before plotting. | beep 2 200 | unset %Bio.* BP.* | halt }
  set %Bio.BirthJ $Biodat2Julian(%BioBirthDStr)
  set %Bio.datStr  $gettok($date,2,47) $+ $chr(32) $+ $gettok($date,1,47) $+ $chr(32) $+ $gettok($fulldate,5,32)
  %Bio.TodayJ = $Biodat2Julian( %Bio.datStr )
  %Bio.DaysLived  =  $calc(%Bio.TodayJ - %Bio.BirthJ)
  %Bio.PhyFraction = $calc(%Bio.DaysLived % 23)
  %Bio.EmoFraction = $calc(%Bio.DaysLived % 28)
  %Bio.IntFraction = $calc(%Bio.DaysLived % 33)
  BioPlot
}

;Charts the three biorythm curves.
;Change variables VertScale, HorzScale, VertOffset, and HorzOffset to change spread and position of plots.
;VertOffset is the location of the x axis from the top of the window; HorzOffset is the location of the y axis from the left of window.
;This code could be improved but these variables give some control to change the look of the chart.
;Keep VertOffset in the range of 1.5 times VertScale.

alias BioPlot {
  set %BP.VertOffset 150 | set %BP.HorzOffset 20
  set %BP.VertScale 100 | set %BP.HorzScale 18
  set %BP.HorzMax $calc((%BP.HorzScale * 30) + %BP.HorzOffset + 20))
  window -c @Biorythm
  window -p @Biorythm 50 50  $int($calc(%BP.HorzMax + 50)) $int($calc((%BP.VertScale * 2) + %BP.VertOffset))
  drawrect -f  @Biorythm 2 1 2 2 $int($calc(%BP.HorzMax + 45)) $int($calc((%BP.VertScale * 2) + %BP.VertOffset - 5))
  titlebar @Biorythm Plot for birthdate of %BioBirthDStr
  drawline @Biorythm 14 3 $calc(%BP.HorzOffset - 10) %BP.VertOffset %BP.HorzMax %BP.VertOffset
  drawline @Biorythm 14 3 %BP.HorzOffset $calc(%BP.VertOffset - %BP.VertScale - 20)  %BP.HorzOffset $calc(%BP.VertOffset +%BP.VertScale + 20)
  drawline @Biorythm 14 3 %BP.HorzOffset $calc(%BP.VertOffset  - %BP.VertScale) $calc(%BP.HorzOffset + 10) $calc(%BP.VertOffset  - %BP.VertScale)
  drawline @Biorythm 14 3 %BP.HorzOffset $calc(%BP.VertScale + %BP.VertOffset) $calc(%BP.HorzOffset + 10) $calc(%BP.VertScale + %BP.VertOffset)
  BioCurves
  BioScale
  BioText
  unset %BP.* %Bio.*
}

;Plots the three biorythm sin curves. 
;Note that pi is added to each sin wave function, to flip it, since mIRC screen coordinates are from top to bottom.

alias BioCurves {
  set %Bio.Pi 3.14159
  set %Bio.i 0
  :BioFunc
  if (%Bio.i >= 31 ) { goto BioFuncEnd }
  set %Bio.EmoFunc $calc(2 * %Bio.Pi * $calc(%Bio.i + %Bio.EmoFraction) / 28 + %Bio.Pi)
  set %Bio.PhyFunc $calc(2 * %Bio.Pi * $calc(%Bio.i + %Bio.PhyFraction) / 23 + %Bio.Pi ))
  set %Bio.IntFunc $calc(2 * %Bio.Pi * $calc(%Bio.i + %Bio.IntFraction) / 33 + %Bio.Pi ))
  drawdot @Biorythm 3 1 $calc((%Bio.i * %BP.HorzScale) + %BP.HorzOffset) $calc(($sin(%Bio.EmoFunc) * %BP.VertScale) + %BP.VertOffset)
  drawdot @Biorythm 12 1 $calc((%Bio.i * %BP.HorzScale + %BP.HorzOffset)) $calc(($sin(%Bio.PhyFunc) * %BP.VertScale) + %BP.VertOffset)
  drawdot @Biorythm 4 1 $calc((%Bio.i * %BP.HorzScale) + %BP.HorzOffset) $calc(($sin(%Bio.IntFunc) * %BP.VertScale) + %BP.VertOffset)
  inc %Bio.i .02 | goto BioFunc
  :BioFuncEnd
}

;Adds various text to the chart.

alias BioText {
  drawtext  @Biorythm 14 fixedsys 10 $calc(%BP.HorzOffset ) $calc(%BP.VertOffset - %BP.VertScale - 40) Left Axis = Today $adate 
  drawtext  @Biorythm 14 fixedsys 10 $calc(%BP.HorzMax - 150 ) $calc(%BP.VertOffset - %BP.VertScale - 40) Days Lived: %Bio.DaysLived 
  drawtext  @Biorythm 14 fixedsys 10 $calc(%BP.HorzOffset + 5) $calc(%BP.VertScale + %BP.VertOffset + 10)  Min
  drawtext  @Biorythm 14 fixedsys 10 $calc(%BP.HorzOffset + 5) $calc(%BP.VertOffset - %BP.VertScale - 20) Max
  drawtext  -b @Biorythm 1 3 fixedsys 10 $calc(%BP.HorzOffset + 80) $calc((%BP.VertScale * 2) + %BP.VertOffset - 50) «Emotional»
  drawtext  -b @Biorythm 1 12 fixedsys 10 $calc(%BP.HorzOffset + 200) $calc((%BP.VertScale * 2) + %BP.VertOffset - 50) «Physical»
  drawtext  -b @Biorythm 1 4 fixedsys 10 $calc(%BP.HorzOffset + 300) $calc((%BP.VertScale * 2) + %BP.VertOffset - 50) «Intellectual»
}

;Scales the X axis with one vertical line for each of 31 days.  Lables each line with the date and day of week.
;Uses a colored line for Saturdays and Sundays.

alias BioScale {
  set %Bio.x 0
  :Bioxaxis
  if ( %Bio.x >= 32 ) { goto Bioxaxisend }
  if ($BioDayofWk(%Bio.TodayJ) == Sa) { %Bio.Linecol = 7 }
  elseif ($BioDayofWk(%Bio.TodayJ) == Su) { %Bio.Linecol = 13 }
  else %Bio.Linecol = 14
  drawline @Biorythm %Bio.Linecol 0 $calc((%BP.HorzScale * %Bio.x) + %BP.HorzOffset) $calc(%BP.VertOffset - %BP.VertScale - 20)  $calc((%BP.HorzScale * %Bio.x) + %BP.HorzOffset) $calc(%BP.VertOffset +%BP.VertScale + 20)
  drawtext @Biorythm 15 arial 12 $calc((%BP.HorzScale * %Bio.x) + %BP.HorzOffset + 2) $calc(%BP.VertOffset + 15) $BioDayofWk(%Bio.TodayJ)
  drawtext @Biorythm 15 arial 12 $calc((%BP.HorzScale * %Bio.x) + %BP.HorzOffset + 2) $calc(%BP.VertOffset + 5) $gettok($BioJulian2dat(%Bio.TodayJ),2,32)
  inc %Bio.x | inc %Bio.TodayJ | goto Bioxaxis
  :Bioxaxisend
}