Advertisement
bruhtylerhaveyouseen

Untitled

Dec 19th, 2022
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 8.62 KB | None | 0 0
  1. ;;---------------------------------------------------------------------------
  2. ;; Made a program to generate positive affirmations for your final exam,
  3. ;; attempting to follow the Design Recipe of course.
  4. ;; Manifesting and studying at the same time 😌
  5. ;;
  6. ;; generate one by running the command (affirmation T0 LOI0)
  7. ;;
  8. ;;-------------------------------------------------------------------------
  9.  
  10. (require spd/tags)
  11. (require 2htdp/image)
  12.  
  13. (@htdd AffirmTree ListOfAffirmTree)
  14.  
  15. ;; constants:
  16.  
  17. ;;images
  18. (define CATBOWMAN (scale .75 (bitmap/url "https://i.ibb.co/SDSJxnN/catgirlwilly.jpg")))
  19. (define SRC (scale .50 (bitmap/url "https://i.ibb.co/473WKy5/src.jpg")))
  20. (define LAMBDA
  21.   (bitmap/url "https://i.ibb.co/V2PbpQ2/640px-Racket-logo-svg.png"))
  22. (define GREGOR1 (bitmap/url
  23.  "https://i.ibb.co/6HKZQG6/screen-shot-2018-11-09-at-12-38-51-pm-medium.png"))
  24. (define GREGOR2 (bitmap/url "https://i.ibb.co/CBkH0WP/u32aedl81gv01.png"))
  25. (define PIAZZA (bitmap/url "https://i.ibb.co/Tb2KYPW/p4ioiphj5b661.jpg"))
  26.  
  27. (define LOI0 (list
  28.               CATBOWMAN
  29.               SRC
  30.               LAMBDA
  31.               GREGOR1
  32.               GREGOR2
  33.               PIAZZA))
  34.  
  35. ;;starters
  36. (define B0 "I")
  37. (define B1 "CPSC110")
  38. (define B2 "GREGOR")
  39. (define B3 "BOWMAN")
  40.  
  41. ;;conjoiners
  42. (define C0 "IS")
  43. (define C1 "AM")
  44. (define C2 "DO")
  45. (define C3 "WILL")
  46. (define C4 "NOT")
  47. (define C5 "TAKE")
  48. (define C6 "WOULD MAKE")
  49. (define C7 "HAVE")
  50. (define C8 "MY")
  51. (define C9 "BEST")
  52. (define C10 "TRUST")
  53. (define C11 "HAS")
  54. (define C12 "NO")
  55. (define C13 "TRUSTS")
  56. (define C14 "AFTER")
  57. (define C15 "ON")
  58. (define C16 "SEE")
  59. (define C17 "AT")
  60. (define C18 "THE")
  61.  
  62. ;;cs terms
  63. (define CS2 "SRC")
  64. (define CS3 "DR. RACKET")
  65. (define CS4 "VARIABLES")
  66. (define CS5 "FOLLOW THE RECIPE")
  67. (define CS6 "FUNCTIONAL")
  68. (define CS7 "SEARCH")
  69. (define CS8 "RECURSIVE")
  70. (define CS9 "NATURAL RECURSION")
  71. (define CS10 "FUNCTION")
  72. (define CS11 "INFINITE RECURSIVE LOOP")
  73. (define CS12 "fn-for-exam")
  74. (define CS13 "COMPUTER SCIENTIST")
  75. (define CS14 "CPSC110")
  76. (define CS15 "DESIGN")
  77. (define CS16 "SUBMIT")
  78. (define CS17 "PROGRAMMING")
  79. (define CS18 "PARENTHESES")
  80. (define CS19 "CODE")
  81. (define CS20 "PROBLEM")
  82. (define CS21 "SKILLS")
  83. (define CS22 "GREGOR'S")
  84.  
  85.  
  86. ;;misc
  87. (define M0 "HEALTHY")
  88. (define M1 "UNDERSTAND")
  89. (define M2 "BARRIER")
  90. (define M3 "OMNICRON")
  91. (define M4 "COVID")
  92. (define M5 "PROBLEM")
  93. (define M6 "RELATIONSHIPS")
  94. (define M7 "PASS")
  95. (define M8 "FAIL")
  96. (define M9 "EXAM")
  97. (define M10 "GOD")
  98. (define M11 "SOCIAL OUTCAST")
  99. (define M12 "CATGIRL")
  100. (define M13 "SOMEONE ELSES")
  101. (define M14 "ME")
  102. (define M15 "PROFFESSOR")
  103. (define M16 "SOCKS")
  104. (define M17 "NEED")
  105. (define M18 "GOOD")
  106. (define M19 "ON TIME")
  107. (define M20 "FAVOURITE STUDENT")
  108.  
  109. (define-struct aftr (phrase subs))
  110. ;; AffirmTree is (make-afftree String ListOfAffirmTree)
  111. ;; -interp. Final Exam Affirmation Phrase and Sub-phrases
  112.  
  113. ;; ListOfAffirmTree is one of
  114. ;;   - (cons AffirmTree ListOfAffirmTree)
  115. ;;   - empty
  116. ;; interp. list of sub-trees of an AffirmTree
  117.  
  118. (define B0-C1-SUBS
  119.   (list (make-aftr CS6
  120.                    (list  (make-aftr CS17
  121.                                      (list  (make-aftr M10 empty)))
  122.                           (make-aftr CS19 empty)))
  123.         (make-aftr C17
  124.                    (list  (make-aftr CS2
  125.                                      (list  (make-aftr M19 empty)))))
  126.         (make-aftr CS13 empty)
  127.         (make-aftr CS22 (list (make-aftr M12 empty)
  128.                               (make-aftr M20 empty)))
  129.         (make-aftr C4
  130.                    (list  (make-aftr M11 empty)
  131.                           (make-aftr CS11 empty)))))
  132.  
  133.  
  134. (define B0-C2-SUBS
  135.   (list
  136.    (make-aftr C4
  137.               (list (make-aftr M17
  138.                         (list
  139.                           (make-aftr CS17 (list (make-aftr CS21 empty)))
  140.                           (make-aftr CS4 empty)
  141.  
  142.                           (make-aftr M0
  143.                                  (list (make-aftr M6 empty)))
  144.                           (make-aftr M13
  145.                                   (list
  146.                                     (make-aftr CS19 empty)
  147.                                     (make-aftr CS21 empty)))))))
  148.    (make-aftr C16
  149.               (list
  150.                (make-aftr M18
  151.                           (list (make-aftr CS19 empty)))
  152.                (make-aftr CS18 empty)))
  153.  
  154.    (make-aftr M1
  155.               (list (make-aftr CS9 empty)))))
  156.  
  157.  
  158.  
  159. (define B0-C3-SUBS
  160.   (list  (make-aftr C4
  161.                     (list (make-aftr CS15
  162.                           (list (make-aftr CS11 empty)
  163.                                 (make-aftr CS7
  164.                                 (list (make-aftr C15
  165.                                       (list (make-aftr M9 empty)))))))))
  166.          (make-aftr M7 empty)
  167.          (make-aftr C16
  168.                     (list  (make-aftr M12
  169.                             (list
  170.                              (make-aftr B3
  171.                                (list  (make-aftr C17
  172.                                            (list  (make-aftr CS2 empty)))))
  173.                              (make-aftr CS13
  174.                                     (list (make-aftr C14
  175.                                            (list (make-aftr M9 empty)))))))
  176.                            (make-aftr C12
  177.                                (list (make-aftr CS4 empty)
  178.                                   ))))))
  179.  
  180.  
  181. (define T0 (make-aftr B0
  182.                       (list
  183.                        (make-aftr C10
  184.                                   (list
  185.                                    (make-aftr B2 empty)
  186.                                    (make-aftr B3 empty)
  187.                                    (make-aftr C18 (list
  188.                                                    (make-aftr CS9 empty)))))
  189.                        (make-aftr C1 B0-C1-SUBS)
  190.                        (make-aftr C2 B0-C2-SUBS)
  191.                        (make-aftr C3 B0-C3-SUBS)
  192.                        (make-aftr C7
  193.                                   (list (make-aftr CS17
  194.                                             (list (make-aftr M16 empty)
  195.                                                     (make-aftr CS15
  196.                                                     (list (make-aftr
  197.                                                            CS21 empty))))))))))
  198.  
  199.  
  200.  
  201. (@htdf affirmation)
  202. (@signature AffirmTree (listof Image) -> Image)
  203. ;; produce semi-randomly generated affirmation image
  204. ;;(no idea how to do check-expects for random fns lol)
  205.  
  206. (@template encapsulated Image)
  207.  
  208. (define (affirmation at loi)
  209.   (local [(define font-list (list "modern" "decorative" "default"))
  210.           (define color-list (list "pink" "purple" "red" "blue" "green"))
  211.           (define img (list-ref loi (random (length loi))))
  212.           (define text
  213.             (text/font
  214.              (select-affirm at)
  215.              40
  216.              (list-ref color-list (random (length color-list)))
  217.              #f
  218.              (list-ref font-list (random (length font-list)))
  219.              "normal"
  220.              "bold"
  221.              #f))]
  222.  
  223.     (overlay/align "middle" "top"
  224.                    text            
  225.                    (overlay/align  "middle" "bottom"
  226.                                    (rectangle (max
  227.                                                (+ 10 (image-width img))
  228.                                                (+ 10 (image-width text)))
  229.                                               10 "solid" "black")
  230.                
  231.                                    img
  232.                                    (rectangle (max
  233.                                                (+ 10 (image-width img))
  234.                                                (+ 10 (image-width text)))
  235.                                               (+
  236.                                                (image-height text)
  237.                                                (image-height img))
  238.                                               "solid" "black")))))
  239.  
  240. (@htdf select-affirm)
  241. (@signature AffirmTree -> String)
  242. ;;consumes AffirmTree and combines the phrases of a pseudo-random path
  243. ;;(no idea how to do check-expects for random fns lol)
  244.  
  245. (@template encapsulated AffirmTree ListOfAffirmTree)
  246.  
  247. (define (select-affirm at)
  248.   (local [ (define (fn-for-at at)
  249.              (string-append
  250.               " "
  251.               (aftr-phrase at)
  252.               (fn-for-loat (aftr-subs at))))
  253.  
  254.            (define (fn-for-loat loat)
  255.              (cond [(empty? loat) ". "]
  256.                    [else
  257.                     (if (empty? (rest loat))
  258.                         (fn-for-at (first loat))
  259.                         (fn-for-at (list-ref loat
  260.                                    (random (length loat)))))]))]
  261.     (fn-for-at at)))
  262.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement