diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ef4824f --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# Created by https://www.gitignore.io/api/clojure + +### Clojure ### +pom.xml +pom.xml.asc +*.jar +*.class +/lib/ +/classes/ +/target/ +/checkouts/ +.lein-deps-sum +.lein-repl-history +.lein-plugins/ +.lein-failures +.nrepl-port + +# End of https://www.gitignore.io/api/clojure + +.DS_Store \ No newline at end of file diff --git a/week-3/README.md b/week-3/README.md index 3267d19..4cc7c04 100644 --- a/week-3/README.md +++ b/week-3/README.md @@ -1,3 +1,8 @@ ## Week 3 -Please add instructions for week 3 here. +![Screenshot](http://i.imgur.com/e2OAVUk.gif) + +* a Rectangle + * that follows the mouse + * that changes color with the position of the mouse + * is connected to the edges of the screen by lines diff --git a/week-3/animation/README.md b/week-3/animation/README.md new file mode 100644 index 0000000..4f13b8b --- /dev/null +++ b/week-3/animation/README.md @@ -0,0 +1,10 @@ +# Rainbow Lines&Rectangle + +![](http://i.imgur.com/e2OAVUk.gif) + +following the [ClojureBridge Workshop Material](https://github.com/ClojureBridge/drawing/blob/master/curriculum/first-program.md) and playing around with Quil! + +A project using [Quil](http://quil.info) in which you have: +* a Rectangle + * that changes color with the position of the mouse + * is connected to the edges of the screen by lines diff --git a/week-3/animation/project.clj b/week-3/animation/project.clj new file mode 100644 index 0000000..532d039 --- /dev/null +++ b/week-3/animation/project.clj @@ -0,0 +1,6 @@ +(defproject drawing "0.0.1-SNAPSHOT" + :description "FIXME: write description" + :url "http://example.com/FIXME" + :dependencies [[org.clojure/clojure "1.7.0"] + [quil "2.2.6" :exclusions [org.clojure/clojure]]] + :main drawing.core) diff --git a/week-3/animation/src/drawing/core.clj b/week-3/animation/src/drawing/core.clj new file mode 100644 index 0000000..af08558 --- /dev/null +++ b/week-3/animation/src/drawing/core.clj @@ -0,0 +1,49 @@ +(ns drawing.core + (:require [quil.core :refer :all])) + +(defn setup [] + (frame-rate 30) + (color-mode :rgb) + (stroke 255 0 0)) + +(def my-width 400) +(def my-height 400) + +(defn set-color [mx my] + ; set color according to the mouse position + ; lines + (stroke (abs (- mx 255)) + (abs (- my 255)) + (abs (/ (+ mx my) 2))) + ; rectangle + (fill (abs (- mx 255)) + (abs (- my 255)) + (abs (/ (+ mx my) 2)))) + +(defn size-rect [x y my-size] + (rect (- x (/ my-size 2)) (- y (/ my-size 2)) my-size my-size)) + +(defn perspective-rec [] + ; rectangle connected to the corners of the screen + (let [x (mouse-x) + y (mouse-y) + my-size (/ y 2)] + (line 0 0 (- x (/ my-size 2)) (- y (/ my-size 2))) + (line my-width 0 (+ x (/ my-size 2)) (- y (/ my-size 2))) + (line 0 my-height (- x (/ my-size 2)) (+ y (/ my-size 2))) + (line my-width my-height (+ x (/ my-size 2)) (+ y (/ my-size 2))) + ; rectangle that changes its size according to the mouse position + (size-rect x y my-size))) + +(defn draw [] + (background 0) + (set-color (mouse-x) (mouse-y)) + (perspective-rec)) + + + +(defsketch hello-lines + :title "Responsive-Rainbow-Rectangle" + :size [400 400] + :setup setup + :draw draw)