Advertisement
Guest User

moon phases 2020 (jgs ascii art)

a guest
Oct 17th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <unistd.h>
  3. #include <time.h>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. void phase_newmoon()
  9. {
  10. cout << "   _..._   " << endl;
  11. cout << " .:::::::. " << endl;
  12. cout << ":::::::::::" << endl;
  13. cout << ":::::::::::" << endl;
  14. cout << "`:::::::::'" << endl;
  15. cout << "  `':::''  " << endl;
  16. cout << "N E W  M O O N" << endl;
  17. }
  18.  
  19. void phase_waxingcrescent()
  20. {
  21. cout << "   _..._   " << endl;
  22. cout << " .::::. `. " << endl;
  23. cout << ":::::::.  :" << endl;
  24. cout << "::::::::  :" << endl;
  25. cout << "`::::::' .'" << endl;
  26. cout << "  `'::'-'  " << endl;
  27. cout << "W A X I N G  C R E S C E N T" << endl;
  28. }
  29.  
  30. void phase_firstquarter()
  31. {
  32. cout << "   _..._   " << endl;
  33. cout << " .::::  `. " << endl;
  34. cout << "::::::    :" << endl;
  35. cout << "::::::    :" << endl;
  36. cout << "`:::::   .'" << endl;
  37. cout << "  `'::.-'  " << endl;
  38. cout << "F I R S T  Q U A R T E R" << endl;
  39. }
  40.  
  41. void phase_waxinggibbous()
  42. {
  43. cout << "   _..._   " << endl;
  44. cout << " .::'   `. " << endl;
  45. cout << ":::       :" << endl;
  46. cout << ":::       :" << endl;
  47. cout << "`::.     .'" << endl;
  48. cout << "  `':..-'  " << endl;
  49. cout << "W A X I N G  G I B B O U S" << endl;
  50. }
  51.  
  52. void phase_fullmoon()
  53. {
  54. cout << "   _..._   " << endl;
  55. cout << " .'     `. " << endl;
  56. cout << ":         :" << endl;
  57. cout << ":         :" << endl;
  58. cout << "`.       .'" << endl;
  59. cout << "  `-...-'  " << endl;
  60. cout << "F U L L  M O O N" << endl;
  61. }
  62.  
  63. void phase_waninggibbous()
  64. {
  65. cout << "   _..._   " << endl;
  66. cout << " .'   `::. " << endl;
  67. cout << ":       :::" << endl;
  68. cout << ":       :::" << endl;
  69. cout << "`.     .::'" << endl;
  70. cout << "  `-..:''  " << endl;
  71. cout << "W A N I N G  G I B B O U S" << endl;
  72. }
  73.  
  74. void phase_lastquarter()
  75. {
  76. cout << "   _..._   " << endl;
  77. cout << " .'  ::::. " << endl;
  78. cout << ":    ::::::" << endl;
  79. cout << ":    ::::::" << endl;
  80. cout << "`.   :::::'" << endl;
  81. cout << "  `-.::''  " << endl;
  82. cout << "L A S T  Q U A R T E R" << endl;
  83. }
  84.  
  85. void phase_waningcrescent()
  86. {
  87. cout << "   _..._   " << endl;
  88. cout << " .' .::::. " << endl;
  89. cout << ":  ::::::::" << endl;
  90. cout << ":  ::::::::" << endl;
  91. cout << "`. '::::::'" << endl;
  92. cout << "  `-.::''  " << endl;
  93. cout << "W A N I N G  C R E S C E N T" << endl;
  94. }
  95.  
  96. void phase_cycleall()
  97. {
  98. while (true)
  99.     {
  100.     phase_newmoon(); usleep(370000);
  101.     phase_waxingcrescent(); usleep(370000);
  102.     phase_firstquarter(); usleep(370000);
  103.     phase_waxinggibbous(); usleep(370000);
  104.     phase_fullmoon(); usleep(370000);
  105.     phase_waninggibbous(); usleep(370000);
  106.     phase_lastquarter(); usleep(370000);
  107.     phase_waningcrescent(); usleep(370000);
  108.     }
  109. }
  110.  
  111. // *****************************************************************************
  112. // *****************************************************************************
  113.  
  114. int main()
  115. {
  116.  
  117. // decorative cycling function
  118. //phase_cycleall();
  119. // decorative cycling function
  120.  
  121. // get the current date
  122. time_t theTime = time(NULL);
  123. struct tm *aTime = localtime(&theTime);
  124. int day = aTime->tm_mday;
  125. int month = aTime->tm_mon + 1;
  126. int year = aTime->tm_year + 1900;
  127. // get the current date
  128.  
  129. // set up the previous date
  130. int prev_day = --aTime->tm_mday;
  131. int prev_month = aTime->tm_mon + 1;
  132. int prev_year = aTime->tm_year +1900;
  133. // set up the previous date
  134.  
  135. // open the file for the year
  136. fstream inFile;
  137. if (year == 2017)
  138. {
  139. inFile.open("percent2017.txt");
  140. }
  141. if (year == 2018)
  142. {
  143. inFile.open("percent2018.txt");
  144. }
  145. if (year == 2019)
  146. {
  147. inFile.open("percent2019.txt");
  148. }
  149. if (year == 2020)
  150. {
  151. inFile.open("percent2020.txt");
  152. }
  153. // open the file for the year
  154.  
  155.  
  156. // variable for tracking the percentage
  157. float percentagevar;
  158. float yest_percentagevar;
  159. // variable for tracking the percentage
  160.  
  161. // locate the correct percentage
  162. for (int i = 0; i < (day-1)*13+2+(month-1); i++)
  163. {
  164.     inFile >> percentagevar;
  165. }
  166. // locate the correct percentage
  167.  
  168. // close the file and clear the stream
  169. inFile.close();
  170. inFile.clear();
  171. // close the file and clear the stream
  172.  
  173. // open the file for reading #2
  174. if (prev_year == 2017)
  175. {
  176. inFile.open("percent2017.txt");
  177. }
  178. if (prev_year == 2018)
  179. {
  180. inFile.open("percent2018.txt");
  181. }
  182. if (prev_year == 2019)
  183. {
  184. inFile.open("percent2019.txt");
  185. }
  186. if (prev_year == 2020)
  187. {
  188. inFile.open("percent2020.txt");
  189. }
  190.  
  191. // locate the correct percentage, yesterday
  192. for (int i = 0; i < (prev_day-1)*13+2+(prev_month-1); i++)
  193. {
  194.     inFile >> yest_percentagevar;
  195. }
  196. // locate the correct percentage, yesterday
  197.  
  198. // close the file
  199. inFile.close();
  200. // close the file
  201.  
  202. // determine if the moon is waxing
  203. int waxing_binary;
  204. if (yest_percentagevar > percentagevar) waxing_binary = 0;
  205. else waxing_binary = 1;
  206. // determine if the moon is waxing
  207.  
  208. // UP TO THIS POINT WE HAVE READ THE FILE AND GOTTEN THE PERCENTAGE, STORED AS percentagevar.
  209. // AS WELL AS THE PERCENTAGE YESTERDAY. WE USED THIS TO DETERMINE waxing_binary
  210. // THE GOAL IS NOW TO CONVERT THIS PERCENTAGE TO AN ACTUAL MOON PHASE
  211.  
  212. cout << "* * " << percentagevar*100 << "% ILLUMINTATED * *" << endl;
  213.  
  214. if (percentagevar >= 0 && percentagevar < .08) // NEW MOON
  215.     {
  216.     phase_newmoon();
  217.     }
  218. if (percentagevar >= .08 && percentagevar < .25 && waxing_binary == 1) // WAXING CRESCENT
  219.     {
  220.     phase_waxingcrescent();
  221.     }
  222. if (percentagevar >= .25 && percentagevar <.6 && waxing_binary == 1) // FIRST QUARTER
  223.     {
  224.     phase_firstquarter();
  225.     }
  226. if (percentagevar >= .6 && percentagevar < .9 && waxing_binary == 1) // WAXING GIBBOUS
  227.     {
  228.     phase_waxinggibbous();
  229.     }
  230. if (percentagevar >= .9 && percentagevar < 1) // FULL MOON
  231.     {
  232.     phase_fullmoon();
  233.     }
  234. if (percentagevar >= .6 && percentagevar < .9 && waxing_binary == 0) // WANING GIBBOUS
  235.     {
  236.     phase_waninggibbous();
  237.     }
  238. if (percentagevar >= .25 && percentagevar < .6 && waxing_binary == 0) //LAST QUARTER
  239.     {
  240.     phase_lastquarter();
  241.     }
  242. if (percentagevar >= .08 && percentagevar < .25 && waxing_binary == 0) //WANING CRESCENT
  243.     {
  244.     phase_waningcrescent();
  245.     }
  246.  
  247.     return 0;
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement