Skip to content

Instantly share code, notes, and snippets.

@melklein
Created July 10, 2016 16:28
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/b61246f4891075d33dc420a216fe1337 to your computer and use it in GitHub Desktop.
Save melklein/b61246f4891075d33dc420a216fe1337 to your computer and use it in GitHub Desktop.
draw lines following the mouse in rainbow colours; base stroke thickness on mouse speed
(ns mouse-interactivity.core
(:require [quil.core :refer :all]))
(def max-stroke-weight 40)
(defn setup []
(background 255)
(color-mode :hsb)
(smooth))
(defn draw []
(stroke (mod (frame-count) 360) 255 255)
(let [speed-x (abs (- (mouse-x) (pmouse-x)))
speed-y (abs (- (mouse-y) (pmouse-y)))
new-weight (mod (+ speed-x speed-y) max-stroke-weight)]
(stroke-weight new-weight)
(line (mouse-x) (mouse-y) (pmouse-x) (pmouse-y))))
(defsketch example
:title "Example"
:setup setup
:draw draw
:size [400 400])
(defn -main [& args])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment