Last active
September 28, 2018 15:49
-
-
Save bennuttall/1d0fddf26e4132b68c2cbbf466be7395 to your computer and use it in GitHub Desktop.
Rich Wareham's Julia set code
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
| # Copyright (c) 2017: Rich Wareham, Simon Byrne | |
| # Available under the MIT "Expat" license. | |
| using Colors | |
| using SenseHat | |
| const LED = led_matrix() | |
| function julia(z, c) | |
| maxit = 50 | |
| cols = [RGB(HSV(360*h, 1, sqrt(h))) for h in linspace(0, 1, maxit)] | |
| for it in 1:maxit | |
| z = z^2 + c | |
| if abs(z) > 2 | |
| return cols[it] | |
| end | |
| end | |
| cols[end] | |
| end | |
| function julia_render(n) | |
| for a in linspace(0, n*2*pi, 200*n) | |
| r = sin(0.5 + a/2) | |
| cx = sin(a) * r | |
| cy = cos(a/3) * r | |
| LED[:] = [julia(zx + im*zy, cx+im*cy) for zx in linspace(-1, 1, 8), zy in linspace(-1, 1, 8)] | |
| end | |
| end | |
| julia_render(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment