quil / quil-site

Source code of quil.info
http://quil.info
Eclipse Public License 1.0
7 stars 13 forks source link

10 Print Example #19

Closed ampersanda closed 6 years ago

ampersanda commented 6 years ago

http://quil.info/sketches/show/-KzO2S1X6sg1ce9WkPRE

It's not pretty good but maybe I can submit this

(ns my.core
  (:require [quil.core :as q :include-macros true]
            [quil.middleware :as m]))

(defn setup []
  (q/background 0)
  (q/frame-rate 30)
  (q/color-mode :hsb)
  {:x 0
   :y 0
:scale 20})

(defn update-state [{:keys [x y scale] :as state}]
  {:x (if (>= x (q/width)) 0 (+ x scale))
   :y (if (>= x (q/width)) (+ y scale) y)
   :scale scale})

(defn draw-state [{:keys [x y scale] :as state}]
  (q/stroke (* 255 (rand)) (* 255 (rand)) (* 255 (rand)))

  (if (>= y  (q/height))
    (q/no-loop)
    (if (> (rand) 0.5)
      (q/line x y (+ x scale) (+ y scale))
(q/line x (+ y scale) (+ x scale) y))))

(q/defsketch my
  :host "host"
  :size [500 500]
  :setup setup
  :update update-state
  :draw draw-state
  :middleware [m/fun-mode])
nbeloglazov commented 6 years ago

Thanks. It looks nice! I'm going to add it later (next week). Could you also update it so that it automatically starts over when it reaches last line? Currently after it reaches the last line it stops changing. Or instead of starting over do some other way to make it infinite.

ampersanda commented 6 years ago

I am currently read this, sorry. I just add some maybe "infinite" thing

(ns my.core
  (:require [quil.core :as q :include-macros true]
            [quil.middleware :as m]))

(defn setup []
  (q/background 0)
  (q/frame-rate 300)
  (q/color-mode :hsb)
  {:x 0
   :y 0
   :scale 20
   :once false})

(defn update-state [{:keys [x y scale once] :as state}]
  {:x (if (>= x (q/width)) 0 (+ x scale))
   :y (if (>= x (q/width)) (+ y scale) y)
   :scale scale
   :once once})

(defn draw-state [{:keys [x y scale once] :as state}]
  (q/stroke (* 255 (rand)) (* 255 (rand)) (* 255 (rand)))

  (if (true? once)
    (do 
      (q/no-stroke)
      (q/fill 0)
      (q/rect 0 y (q/width) scale)))

  (if (>= y  (q/height))
    (swap! (q/state-atom) assoc :y 0 :once (not once))
    (if (> (rand) 0.5)
      (q/line x y (+ x scale) (+ y scale))
      (q/line x (+ y scale) (+ x scale) y))))

(q/defsketch my
  :host "host"
  :size [500 500]
  :setup setup
  :update update-state
  :draw draw-state
  :middleware [m/fun-mode])
nbeloglazov commented 6 years ago

Thank you @ampersanda for the sketch! I added your sketch and now it's available on quil.info: http://quil.info/?example=ten%20print

ampersanda commented 6 years ago

Thank you very much. I learn some of your code and that's amazing