quil

dumrat 2022-11-17T15:58:46.701059Z

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])

dumrat 2022-11-17T16:41:34.342669Z

Got it πŸ˜„ I had to wrap the q/line function

dumrat 2022-11-17T16:48:21.105179Z

Any easy way to turn an animation into a gif?

reefersleep 2022-11-22T08:46:16.074279Z

I think I used imagemagick myself

reefersleep 2022-11-22T08:49:30.548989Z

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.

genmeblog 2022-11-22T08:51:51.682829Z

AFAIR ffmpeg can convert .mov to .gif

reefersleep 2022-11-22T08:54:03.152879Z

Ah, well πŸ™‚

reefersleep 2022-11-22T08:54:16.779259Z

I think I’m confusing imagemagick and ffmpeg

genmeblog 2022-11-22T08:58:13.004959Z

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.

reefersleep 2022-11-22T08:59:58.585689Z

Thanks for the tip!

genmeblog 2022-11-17T17:47:51.970659Z

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

πŸ‘ 1
dumrat 2022-11-17T04:46:06.673999Z

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

genmeblog 2022-11-17T06:40:47.946639Z

Create line by chunks using vertex.

πŸ‘ 1