Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melklein/33bf82d9838d1b2c8c5bb8a7c320da3a to your computer and use it in GitHub Desktop.
Save melklein/33bf82d9838d1b2c8c5bb8a7c320da3a to your computer and use it in GitHub Desktop.
visualisation of gaussian distribution in quil (from The Nature of Code - Daniel Shiffman)
(ns fun-mode-sketch
(:require [quil.core :as q]
[quil.middleware :as m]))
(def win-width 400)
(def win-height 200)
(def sd 60) ;standard deviation
(def center-x (/ win-width 2))
(def center-y (/ win-height 2))
(defn setup []
(q/background 255)
(q/no-stroke)
(q/frame-rate 3))
(defn draw []
(q/fill 228 0 0 20)
(let [num (q/random-gaussian)
x (* num sd)]
(q/push-matrix)
(q/translate center-x center-y)
(q/ellipse x 0 20 20)
(q/pop-matrix)))
(q/defsketch example
:size [win-width win-height]
:setup setup
:draw draw)
(defn -main [& args])
(ns fun-mode-sketch
(:require [quil.core :as q]
[quil.middleware :as m]))
(def win-width 400)
(def win-height 200)
(def sd 60) ;standard deviation
(def mean (/ win-width 2))
(def y (/ win-height 2))
(defn setup []
(q/background 255)
(q/no-stroke)
(q/frame-rate 3))
(defn draw []
(q/fill 228 0 0 20)
(let [num (q/random-gaussian)
x (+ (* num sd) mean)]
(q/ellipse x y 20 20)))
(q/defsketch example
:size [win-width win-height]
:setup setup
:draw draw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment