Created
October 4, 2013 23:27
-
-
Save jbclements/6834497 to your computer and use it in GitHub Desktop.
a simple big-bang program that plays notes depending on the x-position of the mouse
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
(require 2htdp/image) | |
(require 2htdp/universe) | |
(require rsound) | |
;; a world is an integer. | |
;; rep. the "x" position of the mouse | |
(define SCREENWIDTH 400) | |
;; draw the world | |
(define (draw-world st) | |
(rectangle SCREENWIDTH 100 "solid" "purple")) | |
;; should draw a blank rectangle | |
;(draw-world 1) | |
;; take two things, return the second | |
(define (both a b) | |
b) | |
;; map an x position to a midi note number | |
;; from 0 to 127 | |
(define (x-to-note-num st) | |
(* 127 (/ st 550))) | |
;; should play a note | |
(define (play-it st) | |
(both (play (synth-note "vgame" 49 (x-to-note-num st) 22010)) | |
st)) | |
(check-expect (play-it 3) 3) | |
;; given a state, an x and y coordinate, and a mouse event, | |
;; return the x coordinate (the new state) | |
(define (mousehandler st x y ev) | |
x) | |
;; start the world | |
(big-bang 0 | |
[on-mouse mousehandler] | |
[on-tick play-it 1/4] | |
[to-draw draw-world]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment