Advertisement
GoldenKela

analogue clock

Oct 27th, 2021
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1.  
  2. CLOCK_MULTIPLIER = pi / 30;
  3. TOTAL_COUNT = 120;
  4. ONE_COUNT = 36;
  5. ONE_THIRD = ONE_COUNT / TOTAL_COUNT;
  6.  
  7. FACE_SIZE = 120;
  8. SEC_LENGTH = 370;
  9. MIN_LENGTH = 280;
  10. HOUR_LENGTH = 200;
  11.  
  12. second = time % 60;
  13. second_circum = second * CLOCK_MULTIPLIER;
  14.  
  15. minute = time / 60;
  16. minute_circum = minute * CLOCK_MULTIPLIER;
  17.  
  18. hour = time / 3600;
  19. hour_circum = (hour / 12) * 60 * CLOCK_MULTIPLIER;
  20.  
  21. #clockhand
  22.  
  23. #seconds
  24. is_second = floor(index / ONE_COUNT) == 0;
  25. sin_sec = sin(second_circum);
  26. cos_sec = cos(second_circum);
  27.  
  28. #set to origin (hand for seconds):
  29. sec_x = 0;
  30. sec_y = (fraction - 0.03) * is_second * SEC_LENGTH;
  31.  
  32. sec_tx = sec_x * cos_sec + sec_y * sin_sec;
  33. sec_ty = sec_y * cos_sec + sec_x * sin_sec;
  34.  
  35. #minutes
  36. is_minute = floor((index - ONE_COUNT) / ONE_COUNT) == 0;
  37. sin_min = sin(minute_circum);
  38. cos_min = cos(minute_circum);
  39.  
  40. #set to origin (hands for minutes):
  41. min_x = 0;
  42. min_y = (fraction - ONE_THIRD - 0.04) * is_minute * MIN_LENGTH;
  43.  
  44. min_tx = min_x * cos_min + min_y * sin_min;
  45. min_ty = min_y * cos_min + min_x * sin_min;
  46.  
  47.  
  48. #hours
  49. is_hour = floor((index - ONE_COUNT * 2) / ONE_COUNT) == 0;
  50. sin_hour = sin(hour_circum);
  51. cos_hour = cos(hour_circum);
  52.  
  53. #set to origin (hands for hours):
  54. hour_x = 0;
  55. hour_y = (fraction - ONE_THIRD * 2 - 0.05) * is_hour * HOUR_LENGTH;
  56.  
  57. hour_tx = hour_x * cos_hour + hour_y * sin_hour;
  58. hour_ty = hour_y * cos_hour + hour_x * sin_hour;
  59.  
  60.  
  61. #CLOCKFACE
  62.  
  63. face_index = (index - ONE_COUNT * 3) / (TOTAL_COUNT - ONE_COUNT * 3);
  64. is_clockface = (floor(face_index) == 0) * FACE_SIZE;
  65. face_rotation = face_index * tau;
  66. face_x = sin(face_rotation) * is_clockface;
  67. face_y = cos(face_rotation) * is_clockface;
  68.  
  69. #if its second, it will only be affected by seconds.
  70. #if its minute, it will only be affected by minutes
  71.  
  72. x' = sec_tx + min_tx + hour_tx + face_x;
  73. y' = sec_ty + min_ty + hour_ty + face_y;
  74.  
  75. h = 0;
  76. s = 0;
  77. v = 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement