Last active
October 19, 2025 21:35
-
-
Save wedesoft/5dba7bd5aa97ecefea500ef133cd5401 to your computer and use it in GitHub Desktop.
Julia fractal using Clojure and dtype-next
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {:deps {org.clojure/clojure {:mvn/version "1.12.3"} | |
| org.scicloj/noj {:mvn/version "2-beta18"}}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns fractals.julia | |
| (:require [tech.v3.tensor :as dtt] | |
| [tech.v3.libs.buffered-image :as bufimg]) | |
| (:import [javax.imageio ImageIO] | |
| [java.io File])) | |
| (defn sq [x] (* x x)) | |
| (def w 1920) | |
| (def h (quot (* w 9) 16)) | |
| (def t (dtt/compute-tensor | |
| [h w] | |
| (fn [y x] | |
| (loop [zr (+ -1.5 (* x (/ 3.0 w))) | |
| zi (+ -0.9 (* y (/ 1.8 h))) | |
| i 0] | |
| (if (or (>= i 200) (> (+ (sq zr) (sq zi)) 4)) | |
| (- 255 (quot (* i 255) 200)) | |
| (recur (- (sq zr) (sq zi) 0.79) | |
| (+ (* zr zi 2) 0.15) | |
| (inc i))))) | |
| :uint8)) | |
| (def image (bufimg/tensor->image t)) | |
| (ImageIO/write image "png" (File. "julia.png")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment