Skip to content

Instantly share code, notes, and snippets.

@MattS8
Created November 19, 2013 00:41
Show Gist options
  • Save MattS8/7538130 to your computer and use it in GitHub Desktop.
Save MattS8/7538130 to your computer and use it in GitHub Desktop.
Updated file and replaced the old (meh st x y ev) function
world x y ev -> world
;; adds a sound to world if not already in the world
(define (meh st x y ev)
(cond [(string=? ev "button-down")
(cond ;[(in-tone-button x y (length INSTRUMENT BOXES)) (determine-tone-button x y)]
[(in-area-event x y ERASER_CENTER_X ERASER_CENTER_Y (image-width ERASER) (image-height ERASER)) (make-world empty START-IMG)]
[(in-area-event x y CANVAS_CENTER_X CANVAS_CENTER_Y CANVAS_SIZE CANVAS_SIZE) (make-world (addSound (world-lon st) (- x (- CANVAS_CENTER_X (/ CANVAS_SIZE 2))) (- y (- CANVAS_CENTER_Y (/ CANVAS_SIZE 2)))) (addImage (world-bg st) x y))]
[else st])]
[(and (string=? ev "drag")(in-area-event x y CANVAS_CENTER_X CANVAS_CENTER_Y CANVAS_SIZE CANVAS_SIZE))
(make-world (addSound (world-lon st) (- x (- CANVAS_CENTER_X (/ CANVAS_SIZE 2))) (- y (- CANVAS_CENTER_Y (/ CANVAS_SIZE 2)))) (addImage (world-bg st) x y))]
[else st]))
;; x y center_x center_y image_width image_height -> boolean
;; returns whether or not the event occured in one of
;; - tone-button
;; - eraser
;; - canvas
(define (in-area-event x y c_x c_y width height)
(and (> x (- c_x (/ width 2))) (< x (+ c_x (/ width 2)))
(> y (- c_y (/ height 2))) (< y (+ c_y (/ height 2)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment