Skip to content

Instantly share code, notes, and snippets.



Last active Aug 29, 2015
What would you like to do?
_10 PRINT_ is a book about a one-line Commodore 64 BASIC program, published in November 2012. To paraphrase from _"... a single line of code—the extremely concise BASIC program for the Commodore 64 inscribed in the title—and uses it as a lens through which to consider the phenomenon of creative computing and the way computer…
; 10 PRINT CHR$(205.5+RND(1)); : GOTO 10
(ns big-bang.examples.ten-print
[jayq.core :refer [show]]
[inkspot.color-chart :as cc]
[big-bang.core :refer [big-bang]]
[ :refer [client-coords]]
[enchilada :refer [ctx canvas canvas-size value-of]]
[monet.canvas :refer [begin-path move-to line-to
stroke-width stroke-style stroke-cap stroke
fill-rect fill-style]]))
(def dimensions
(let [[width height] (canvas-size)]
{:x 0 :y 0 :w width :h height}))
(def initial-state
(let [size (value-of :size 20)]
{ :t 0
:size size
:mouse-coords [0 0]
:gradient (cc/ui-gradient
(value-of :gradient :candy)
(/ (:w dimensions) size))}))
; TODO: move into
(defn touch-coords [event]
(when-let [touch-object (.-changedTouches event)]
(client-coords (aget touch-object 0))))
(defn handle-movement [event world-state]
(update-in [:t] inc)
(assoc :mouse-coords (or (touch-coords event)
(client-coords event)))))
(defn determine-coords [mouse-coords x y size]
(if (zero? (mod (apply + mouse-coords) 2))
[x y (+ x size) (+ y size)]
[x (+ y size) (+ x size) y]))
(defn render [{:keys [t mouse-coords gradient size mouse-coords] :as world-state}]
(let [x (* size (mod t (/ (:w dimensions) size)))
y (* size (mod (quot t (/ (:w dimensions) size)) (/ (:h dimensions) size)))
color (nth gradient (/ x size))
[x' y' x'' y''] (determine-coords mouse-coords x y size)]
(fill-style :white)
(fill-rect {:x x :y y :w size :h size})
(stroke-width 4)
;(stroke-cap :square)
(stroke-style color)
(move-to x' y')
(line-to x'' y'')
(show canvas)
:initial-state initial-state
:on-mousemove handle-movement
:on-touchmove handle-movement
:to-draw render)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.