Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;---------------------------------------------------------------------------
- ;; Made a program to generate positive affirmations for your final exam,
- ;; attempting to follow the Design Recipe of course.
- ;; Manifesting and studying at the same time 😌
- ;;
- ;; generate one by running the command (affirmation T0 LOI0)
- ;;
- ;;-------------------------------------------------------------------------
- (require spd/tags)
- (require 2htdp/image)
- (@htdd AffirmTree ListOfAffirmTree)
- ;; constants:
- ;;images
- (define CATBOWMAN (scale .75 (bitmap/url "https://i.ibb.co/SDSJxnN/catgirlwilly.jpg")))
- (define SRC (scale .50 (bitmap/url "https://i.ibb.co/473WKy5/src.jpg")))
- (define LAMBDA
- (bitmap/url "https://i.ibb.co/V2PbpQ2/640px-Racket-logo-svg.png"))
- (define GREGOR1 (bitmap/url
- "https://i.ibb.co/6HKZQG6/screen-shot-2018-11-09-at-12-38-51-pm-medium.png"))
- (define GREGOR2 (bitmap/url "https://i.ibb.co/CBkH0WP/u32aedl81gv01.png"))
- (define PIAZZA (bitmap/url "https://i.ibb.co/Tb2KYPW/p4ioiphj5b661.jpg"))
- (define LOI0 (list
- CATBOWMAN
- SRC
- LAMBDA
- GREGOR1
- GREGOR2
- PIAZZA))
- ;;starters
- (define B0 "I")
- (define B1 "CPSC110")
- (define B2 "GREGOR")
- (define B3 "BOWMAN")
- ;;conjoiners
- (define C0 "IS")
- (define C1 "AM")
- (define C2 "DO")
- (define C3 "WILL")
- (define C4 "NOT")
- (define C5 "TAKE")
- (define C6 "WOULD MAKE")
- (define C7 "HAVE")
- (define C8 "MY")
- (define C9 "BEST")
- (define C10 "TRUST")
- (define C11 "HAS")
- (define C12 "NO")
- (define C13 "TRUSTS")
- (define C14 "AFTER")
- (define C15 "ON")
- (define C16 "SEE")
- (define C17 "AT")
- (define C18 "THE")
- ;;cs terms
- (define CS2 "SRC")
- (define CS3 "DR. RACKET")
- (define CS4 "VARIABLES")
- (define CS5 "FOLLOW THE RECIPE")
- (define CS6 "FUNCTIONAL")
- (define CS7 "SEARCH")
- (define CS8 "RECURSIVE")
- (define CS9 "NATURAL RECURSION")
- (define CS10 "FUNCTION")
- (define CS11 "INFINITE RECURSIVE LOOP")
- (define CS12 "fn-for-exam")
- (define CS13 "COMPUTER SCIENTIST")
- (define CS14 "CPSC110")
- (define CS15 "DESIGN")
- (define CS16 "SUBMIT")
- (define CS17 "PROGRAMMING")
- (define CS18 "PARENTHESES")
- (define CS19 "CODE")
- (define CS20 "PROBLEM")
- (define CS21 "SKILLS")
- (define CS22 "GREGOR'S")
- ;;misc
- (define M0 "HEALTHY")
- (define M1 "UNDERSTAND")
- (define M2 "BARRIER")
- (define M3 "OMNICRON")
- (define M4 "COVID")
- (define M5 "PROBLEM")
- (define M6 "RELATIONSHIPS")
- (define M7 "PASS")
- (define M8 "FAIL")
- (define M9 "EXAM")
- (define M10 "GOD")
- (define M11 "SOCIAL OUTCAST")
- (define M12 "CATGIRL")
- (define M13 "SOMEONE ELSES")
- (define M14 "ME")
- (define M15 "PROFFESSOR")
- (define M16 "SOCKS")
- (define M17 "NEED")
- (define M18 "GOOD")
- (define M19 "ON TIME")
- (define M20 "FAVOURITE STUDENT")
- (define-struct aftr (phrase subs))
- ;; AffirmTree is (make-afftree String ListOfAffirmTree)
- ;; -interp. Final Exam Affirmation Phrase and Sub-phrases
- ;; ListOfAffirmTree is one of
- ;; - (cons AffirmTree ListOfAffirmTree)
- ;; - empty
- ;; interp. list of sub-trees of an AffirmTree
- (define B0-C1-SUBS
- (list (make-aftr CS6
- (list (make-aftr CS17
- (list (make-aftr M10 empty)))
- (make-aftr CS19 empty)))
- (make-aftr C17
- (list (make-aftr CS2
- (list (make-aftr M19 empty)))))
- (make-aftr CS13 empty)
- (make-aftr CS22 (list (make-aftr M12 empty)
- (make-aftr M20 empty)))
- (make-aftr C4
- (list (make-aftr M11 empty)
- (make-aftr CS11 empty)))))
- (define B0-C2-SUBS
- (list
- (make-aftr C4
- (list (make-aftr M17
- (list
- (make-aftr CS17 (list (make-aftr CS21 empty)))
- (make-aftr CS4 empty)
- (make-aftr M0
- (list (make-aftr M6 empty)))
- (make-aftr M13
- (list
- (make-aftr CS19 empty)
- (make-aftr CS21 empty)))))))
- (make-aftr C16
- (list
- (make-aftr M18
- (list (make-aftr CS19 empty)))
- (make-aftr CS18 empty)))
- (make-aftr M1
- (list (make-aftr CS9 empty)))))
- (define B0-C3-SUBS
- (list (make-aftr C4
- (list (make-aftr CS15
- (list (make-aftr CS11 empty)
- (make-aftr CS7
- (list (make-aftr C15
- (list (make-aftr M9 empty)))))))))
- (make-aftr M7 empty)
- (make-aftr C16
- (list (make-aftr M12
- (list
- (make-aftr B3
- (list (make-aftr C17
- (list (make-aftr CS2 empty)))))
- (make-aftr CS13
- (list (make-aftr C14
- (list (make-aftr M9 empty)))))))
- (make-aftr C12
- (list (make-aftr CS4 empty)
- ))))))
- (define T0 (make-aftr B0
- (list
- (make-aftr C10
- (list
- (make-aftr B2 empty)
- (make-aftr B3 empty)
- (make-aftr C18 (list
- (make-aftr CS9 empty)))))
- (make-aftr C1 B0-C1-SUBS)
- (make-aftr C2 B0-C2-SUBS)
- (make-aftr C3 B0-C3-SUBS)
- (make-aftr C7
- (list (make-aftr CS17
- (list (make-aftr M16 empty)
- (make-aftr CS15
- (list (make-aftr
- CS21 empty))))))))))
- (@htdf affirmation)
- (@signature AffirmTree (listof Image) -> Image)
- ;; produce semi-randomly generated affirmation image
- ;;(no idea how to do check-expects for random fns lol)
- (@template encapsulated Image)
- (define (affirmation at loi)
- (local [(define font-list (list "modern" "decorative" "default"))
- (define color-list (list "pink" "purple" "red" "blue" "green"))
- (define img (list-ref loi (random (length loi))))
- (define text
- (text/font
- (select-affirm at)
- 40
- (list-ref color-list (random (length color-list)))
- #f
- (list-ref font-list (random (length font-list)))
- "normal"
- "bold"
- #f))]
- (overlay/align "middle" "top"
- text
- (overlay/align "middle" "bottom"
- (rectangle (max
- (+ 10 (image-width img))
- (+ 10 (image-width text)))
- 10 "solid" "black")
- img
- (rectangle (max
- (+ 10 (image-width img))
- (+ 10 (image-width text)))
- (+
- (image-height text)
- (image-height img))
- "solid" "black")))))
- (@htdf select-affirm)
- (@signature AffirmTree -> String)
- ;;consumes AffirmTree and combines the phrases of a pseudo-random path
- ;;(no idea how to do check-expects for random fns lol)
- (@template encapsulated AffirmTree ListOfAffirmTree)
- (define (select-affirm at)
- (local [ (define (fn-for-at at)
- (string-append
- " "
- (aftr-phrase at)
- (fn-for-loat (aftr-subs at))))
- (define (fn-for-loat loat)
- (cond [(empty? loat) ". "]
- [else
- (if (empty? (rest loat))
- (fn-for-at (first loat))
- (fn-for-at (list-ref loat
- (random (length loat)))))]))]
- (fn-for-at at)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement