Last active
April 11, 2021 06:58
-
-
Save saikyun/412fcfb7509be356685845c5b1a7d7ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use ./build/jaylib) | |
(set-config-flags | |
:msaa-4x-hint) | |
(init-window 800 600 "Chart") | |
(init-audio-device) | |
(set-target-fps 60) | |
(def current-animations @{}) | |
(def big 50) | |
(def small 30) | |
(def frames 30) | |
(def rects | |
(seq [x :range [20 (+ 40 (get-screen-width)) 40] | |
y :range [20 (+ 40 (get-screen-height)) 40] | |
:let [r @[x y small small]]] | |
r)) | |
(defn bigger-anim | |
[r] | |
(def w 2) | |
(def h 3) | |
(loop [i :range [0 frames] | |
:let [p (/ i frames) | |
v (+ small (* (- big small) p))]] # here's the tweening | |
(put r w v) | |
(put r h v) | |
(yield)) | |
(put current-animations r nil)) | |
(defn smaller-anim | |
[r] | |
(def w 2) | |
(def h 3) | |
(loop [i :range [0 frames] | |
:let [p (/ i frames) | |
v (- big (* (- big small) p))]] # here's the tweening | |
(put r w v) | |
(put r h v) | |
(yield)) | |
(put current-animations r nil)) | |
(defn make-bigger | |
[r] | |
(when (and (not (current-animations r)) | |
(< (r 2) (inc small))) | |
(def anim (fiber/new |(bigger-anim r))) | |
(put current-animations r anim))) | |
(defn make-smaller | |
[r] | |
(when (and (not (current-animations r)) | |
(> (r 2) (dec big))) | |
(def anim (fiber/new |(smaller-anim r))) | |
(put current-animations r anim))) | |
(while (not (window-should-close)) | |
(begin-drawing) | |
(clear-background [0 0 0]) | |
(def [mx my] (get-mouse-position)) | |
(def mr [(- mx 15) (- my 15) small small]) | |
(draw-rectangle-rec mr :blue) | |
(loop [a :in current-animations] | |
(resume a)) | |
(loop [r :in rects | |
:let [coll (check-collision-recs | |
r | |
mr)]] | |
(when coll | |
(make-bigger r)) | |
(when (not coll) | |
(make-smaller r)) | |
(draw-rectangle-rec r (if coll :yellow :green))) | |
(end-drawing)) | |
(close-window) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment