Created
October 18, 2021 22:22
-
-
Save a11ce/11e2fd9f8af5c7ad4143d6c6e195ea47 to your computer and use it in GitHub Desktop.
julia fractals with shading.rkt
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
#lang racket | |
(require (except-in "shading.rkt" | |
; we need magnitude from racket | |
; for complex numbers | |
magnitude)) | |
; creates a procedure f_c(z) = z^2 + c | |
; given a constant c | |
(define (julia-fc c) | |
(lambda (z) | |
(+ c | |
(* z z)))) | |
(define julia-f | |
; you can modify this parameter for different results | |
; see here for examples: | |
; https://en.wikipedia.org/wiki/Julia_set#Quadratic_polynomials | |
(julia-fc -0.4+0.6i)) | |
(define (julia-iterations p) | |
; this is a local definition within julia-iterations | |
(define (j-aux p idx) | |
; this is a local definition within j-aux | |
(define next-p (julia-f p)) | |
; the actual color value is determined by how many iterations | |
; [ as in, f(f(f(f(x)))) ] | |
; it takes to get over 2 | |
; with a max cutoff of 255 | |
(if (or (= idx 255) | |
(> (magnitude | |
next-p) | |
2)) | |
idx | |
(j-aux next-p | |
(+ 1 idx)))) | |
(j-aux p 0)) | |
; applies translation and reflection | |
; to center the image and scaling | |
; for a better view | |
(define (point->complex-coords p) | |
; make-rectangular converts x y to x+yi | |
( * (make-rectangular (- (- (point-x p) 150)) | |
(- (point-y p) 150)) | |
0.01)) | |
(render (lambda (p) | |
(julia-iterations | |
(point->complex-coords p)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment