Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animated Lorenz Attractor #38

Open
eliashauksson opened this issue Nov 23, 2021 · 0 comments
Open

Animated Lorenz Attractor #38

eliashauksson opened this issue Nov 23, 2021 · 0 comments

Comments

@eliashauksson
Copy link

eliashauksson commented Nov 23, 2021

An animation of the famous lorenz attractor.

(ns chaos.core
  (:require [quil.core :as q]))

(def screen [1200 800])
(def unit [5 5])
(def n-points 10)
(def max-rand-n 50)

(def sigma 28)
(def rho 46.92)
(def beta 4)
(def dt 0.0003)

(def points (atom (mapv #(into (vector) %)
                        (for [i (range n-points)
                              :let [x (- (rand-int (* 2 max-rand-n)) max-rand-n)
                                    y (- (rand-int (* 2 max-rand-n)) max-rand-n)
                                    z (- (rand-int (* 2 max-rand-n)) max-rand-n)]]
                          [x y z]))))

(defn lorenz-attractor [[x y z]]
  [(+ x (* dt (* sigma (- y x))))
   (+ y (* dt (- (* x (- rho z)) y)))
   (+ z (* dt (- (* x y) (* beta z))))])

(defn setup []
  (q/frame-rate 800)
  (q/background 20))

(defn draw []
  (q/stroke-weight 0.1)
  (q/stroke 255 255 0)
  (reset! points (mapv lorenz-attractor @points))
  (mapv #(q/point (+ (/ (get screen 0) 2) (* (get % 0) (get unit 0)))
                  (+ (/ (get screen 1) 2) (* (get % 1) (get unit 1)))) @points))

(q/defsketch chaos
  :title "Chaos Attractor"
  :setup setup
  :draw draw
  :size [(get screen 0) (get screen 1)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant