aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2023-11-18 14:58:24 +0530
committerAkshay Nair <phenax5@gmail.com>2023-11-18 14:58:24 +0530
commite81c764bd50ba3e0b34b3138078af0a372242988 (patch)
tree62dd513f46260c4ef7e2cda18526805d8c1e7bf6
parentdcd918162dcb4d70b905cc562ae92d98a10045ce (diff)
downloadcreative-coding-playground-e81c764bd50ba3e0b34b3138078af0a372242988.tar.gz
creative-coding-playground-e81c764bd50ba3e0b34b3138078af0a372242988.zip
feat: dragon fractal
-rw-r--r--TODO.norg13
-rw-r--r--flake.nix1
-rw-r--r--justfile10
-rw-r--r--sketches/05/dragon.rkt60
4 files changed, 75 insertions, 9 deletions
diff --git a/TODO.norg b/TODO.norg
index 28d69d4..c514b0f 100644
--- a/TODO.norg
+++ b/TODO.norg
@@ -2,22 +2,25 @@
- (x) Mandelbrot | BQN + Glsl
- (x) Newton's fractals | Glsl
- ( ) Flow | Glsl
- - ( ) {http://quil.info/sketches/local/04058d1f6e2628d8c71b4fd7c850b8937c0d12b8c48cfb2383b24fbdf41ae8c1} | Glsl
+ - (x) polka | Glsl
+ - ( ) Dragon deez nuts | Racket
* Ideas
- - Flow fields on image
+ - Dragon fractal
- Newton's fractals
- - Iterate over messytones
- - Spinning poin
- Mandelbrot
- - Buddhabrot
+ - Flow fields on image
+ - Iterate over messytones
+ - Spinning poin (Future me note: what?)
- Siperski triangle
- 3d game of life
- Webcam effects
- Hilbert curve
+ - Polynomial fractals? {https://frankwang95.github.io/2018/02/polynomial-roots-are-beautiful}
* Tools
- HTML5 canvas
+ - Sketching racket {https://docs.racket-lang.org/manual-sketching/Reference.html#%28part._loop%29}
- p5.js
- Uiua
- {https://github.com/sleexyz/hylogen}
diff --git a/flake.nix b/flake.nix
index 50d3c9a..256d081 100644
--- a/flake.nix
+++ b/flake.nix
@@ -18,6 +18,7 @@
uiua
glslviewer
nodePackages.live-server
+ racket
# cbqn
];
};
diff --git a/justfile b/justfile
index 2d1f299..915a277 100644
--- a/justfile
+++ b/justfile
@@ -3,12 +3,14 @@ sketch name *args:
s1: (sketch "01" "glslViewer" "mandelbrot.frag")
s1_bqn: (sketch "01" "live-server" "--port=3000" "--no-browser" ".")
+
s2: (sketch "02" "glslViewer" "newton.frag")
-s3: (sketch "03" "glslViewer" "flow.frag" "-testImage" "test.png")
-s4: (sketch "04" "glslViewer" "polka.frag")
+s3: (sketch "03" "glslViewer" "flow.frag" "-testImage" "test.png")
-# week1:
-# npx nodemon -e ua -x 'clear && just sketch week1 uiua run --no-format'
+s4: (sketch "04" "glslViewer" "polka.frag")
+s5_run: (sketch "05" "racket" "dragon.rkt")
+s5:
+ npx nodemon -e rkt -x 'clear && just s5_run'
diff --git a/sketches/05/dragon.rkt b/sketches/05/dragon.rkt
new file mode 100644
index 0000000..9cca295
--- /dev/null
+++ b/sketches/05/dragon.rkt
@@ -0,0 +1,60 @@
+#lang sketching
+
+(define (setup)
+ (size 200 200)
+ (frame-rate 1)
+ (loop))
+
+(define iterations 14)
+(define init-segment 400)
+
+(define Line cons)
+(define ->0 car)
+(define ->1 cdr)
+(define Point cons)
+(define ->x car)
+(define ->y cdr)
+
+(define (draw/line my-line)
+ (let [ (p1 (->0 my-line)) (p2 (->1 my-line)) ]
+ (line (->x p1) (->y p1) (->x p2) (->y p2))))
+
+(define (split-line my-line dir)
+ (let* [
+ (x1 (->x (->0 my-line)))
+ (y1 (->y (->0 my-line)))
+ (x2 (->x (->1 my-line)))
+ (y2 (->y (->1 my-line)))
+ (len (dist x1 y1 x2 y2))
+ (sidelen (sqrt (/ (* len len) 2)))
+ (theta (atan2 (- y2 y1) (- x2 x1)))
+ (slope (+ theta (* (/ pi 4) dir)))
+ (p3 (Point
+ (+ x1 (* sidelen (cos slope)))
+ (+ y1 (* sidelen (sin slope)))))
+ ]
+ (cons (Line (->0 my-line) p3) (Line p3 (->1 my-line)))))
+
+(define (dragon-curve my-line dir iteration)
+ (let [ (lines (split-line my-line dir)) ]
+ (if (<= iteration 0)
+ (list (->0 lines) (->1 lines))
+ (append
+ (dragon-curve (->0 lines) 1 (- iteration 1))
+ (dragon-curve (->1 lines) -1 (- iteration 1))))))
+
+(define current-iteration 0)
+(define (draw)
+ (background 150)
+ (let* [
+ (p1 (Point (- (/ width 2) (/ init-segment 2)) (/ height 2)))
+ (l1 (Line p1 (Point (+ (->x p1) init-segment) (->y p1))))
+ (lines (dragon-curve l1 1 current-iteration))
+ ]
+ (stroke-weight 2)
+ (stroke 0 0 0)
+ (for-each draw/line lines)
+ (if (= current-iteration iterations)
+ (no-loop)
+ (set! current-iteration (+ current-iteration 1)))))
+