Skip to content

Instantly share code, notes, and snippets.

@wedesoft
Last active October 19, 2025 21:35
Show Gist options
  • Select an option

  • Save wedesoft/5dba7bd5aa97ecefea500ef133cd5401 to your computer and use it in GitHub Desktop.

Select an option

Save wedesoft/5dba7bd5aa97ecefea500ef133cd5401 to your computer and use it in GitHub Desktop.
Julia fractal using Clojure and dtype-next
{:deps {org.clojure/clojure {:mvn/version "1.12.3"}
org.scicloj/noj {:mvn/version "2-beta18"}}}
(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