Fork me on GitHub
#quil
<
2022-11-17
>
dumrat04:11:06

hi, how do I add some randomness/noise to a black horizontal line for example? To make it look less artificial?

genmeblog06:11:47

Create line by chunks using vertex.

👍 1
dumrat15:11:46

Hi, perhaps a stupid question, but I'm stumped. How can I "wrap around" the animation here? (I mean how do I make it look like it's a infinite strip scrolling right?)

(ns depata_lanuwa
  (:require [quil.core :as q]
            [quil.helpers.drawing :refer [line-join-points]]
            [quil.helpers.seqs :refer [range-incl]]))

(defn rand-walk-coords
  [seed]
  (lazy-seq (cons seed (rand-walk-coords (+ seed (/ (- (rand 5) 1) 20))))))

(defn slightly-natural-horizontal-line
  [x-start x-end y]
  (let [step      2
        xs        (range-incl x-start x-end step)
        ys        (rand-walk-coords y)
        line-args (line-join-points xs ys)]
    (dorun (map #(apply q/line %) line-args))))

(defn slightly-natural-vertical-line
  [y-start y-end x]
  (let [step      2
        ys        (range-incl y-start y-end step)
        xs        (rand-walk-coords x)
        line-args (line-join-points xs ys)]
    (dorun (map #(apply q/line %) line-args))))

(defn n-natural-horizontal-lines
  [x-start x-end y-start n y-dist]
  (doseq [y
      (->> (range-incl n)
           (map (comp (partial + y-start) (partial * y-dist))))]  
    (slightly-natural-horizontal-line x-start x-end y)))

(defn n-natural-vertical-lines
  [y-start y-end x-start n x-dist]
  (doseq [x
      (->> (range-incl n)
           (map (comp (partial + x-start) (partial * x-dist))))]  
    (slightly-natural-vertical-line y-start y-end x)))

(defn single-block [weight stroke x n d]
  (q/stroke-weight weight)
  (q/smooth 8)
  (apply q/stroke stroke)
  (let [nd (* n d)]
    (n-natural-horizontal-lines x (+ x nd) 10 n d)
    (n-natural-vertical-lines 10 (+ 10 nd) (+ x nd) n d)
    (n-natural-vertical-lines (+ 10 nd) (+ 10 (* 2 nd)) x n d)
    (n-natural-horizontal-lines (+ x nd) (+ x (* 2 nd)) (+ 10 nd) n d))
  )

(def x-offset (atom 0))
(reset! x-offset 0)

(defn draw []
  (q/background 255)
  (q/stroke 0 0 0)
  
  ; Top border
  (q/stroke-weight 3)
  (q/stroke 0 0 0)
  (q/line [0 10] [600 10])
  
  ; Bottom border
  (q/stroke-weight 3)
  (q/stroke 0 0 0)
  (q/line [0 110] [600 110])

  (q/frame-rate 30)

  (doseq [x (range-incl 0 500 100)]
    (single-block 1 [0 0 0] (+ @x-offset x) 5 10))

  (swap! x-offset inc)
  )

(q/defsketch depata_lanuwa
  :title ""
  :settings #(q/smooth 2)
  ;;:setup draw
  :draw draw 
  :size [600 120])

dumrat16:11:34

Got it 😄 I had to wrap the q/line function

dumrat16:11:21

Any easy way to turn an animation into a gif?

genmeblog17:11:51

Just save individual frames and use external tool to combine them into gif.

👍 1
reefersleep08:11:16

I think I used imagemagick myself

reefersleep08:11:30

I’ve pondered whether there are easier solutions. For just recording a .mov video, I use Quicktime Player on Mac, it has a great screen recorder where you can select part of the screen. And no install - it comes with the OS 🙂 I wonder if there’s some good .mov->gif tool. Maybe imagemagick can do it.

genmeblog08:11:51

AFAIR ffmpeg can convert .mov to .gif

reefersleep08:11:03

Ah, well 🙂

reefersleep08:11:16

I think I’m confusing imagemagick and ffmpeg

genmeblog08:11:13

For the best quality and infinite loops ImageMagicks's convert with saved individual frames is the option I use most. Saving to .mov adds another lossy compression step.

reefersleep08:11:58

Thanks for the tip!