Julia set: Difference between revisions

25,988 bytes added ,  3 months ago
m (syntax highlighting fixup automation)
(→‎{{header|Wren}}: Added image)
 
(32 intermediate revisions by 13 users not shown)
Line 176:
Program made with the Basic-Hopper embedded version, using the tag "#hl {}".
The generated file is binary, and the graph can be made with Matlab's "imshow" function.
 
[[File:Julia_binary_gen_Matlab.png|200px|thumb|Right|Caption]]
 
<syntaxhighlight lang="basic">
Line 242 ⟶ 244:
{julia,"julia.dat"}save
exit(0)
</syntaxhighlight>
 
<pre>Versión 2.
Versión basada en Lua, escrita en Hopper-Jambo:
</pre>
[[File:Captura_de_pantalla_de_2022-10-09_01-36-15.png|200px|thumb|left|Caption]]
 
<syntaxhighlight lang="basic">
#include <jambo.h>
 
Main
Set stack 15
Cls
map = {}
Set '" ", ".", ":", "-", "=", "+", "*", "#", "%", "$", "@"', Apnd list 'map'
 
Loop for ( y= -1.0, Less equal (y,1.0), Let ( y:=Add(y,0.05)) )
Loop for ( x= -1.5, Less equal (x,1.5), Let ( x:=Add(x,0.025)) )
zr = x, zi = y, i = 0, br = 0
Loop
Let ( br := Sqr diff(zr,zi) Minus '0.8' )
Let ( zi := Mul(Mul(zr, zi), 2), Plus '0.156' )
zr = br
Break if ( Greater ( Sqr add (zr, zi), 4 ) )
++i
While ( Less equal (i, 100) )
Colorfore( Int div(i,11) Plus '91' )
Print ( [ Intdiv(i,11) Plus(1)] Get 'map' )
Next
Prnl
Next
Prnl
End
</syntaxhighlight>
 
Line 298 ⟶ 333:
 
=={{header|BASIC}}==
==={{header|BBC BASIC}}===
{{trans|VBScript}}
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> DIM Pix&(11)
$^Pix&(0)="@$%#*+=-:. " : REM Let's inverse :-)
FOR Y=-1.0 TO 1.0 STEP 1/15
FOR X=-1.5 TO 1.5 STEP 3/100
ZR=X
ZI=Y
I%=0
WHILE I% < 100
ZR1=ZR * ZR - ZI * ZI - .79
ZI=ZR * ZI * 2 + .15
ZR=ZR1
I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@@@@@@@@@@@@ # :**=- *=+# = = : . %*+@@@@@@@@@%$ .+=%@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@+.+@@@@@@@@@@@@@@@@@$= += = :.:** =#**-+% +. =:-+@@@@@$% # %%$$#$@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@$+#$@-$ : @@@@@@@@@@$- : : +% +%%%%%%%%%+=+$@@$# -* : +**@@@@@@@@@@@@
@@@@@@@@@@@@@@@$@ .%%$% #= +%$$@@@@@$%+. :=-*** %%%%%%%%%%%%%%#+ $$$ = - =%%%%+ @@=% *@@@@@
@@@@@@@@@@@@@@@$ == * =**-#*##+ +-+$$$$$% - +: *##*:#:%%$$$%%%+ --+##=$$$$%#- #*%%%%% # $- : +$@@@
@@@@@@-$@@@@@@@%- = -%%%%%%%%%%# $$$$$$%##=+ .#%%%$$$$$$%:*# =** %$$$%%- =$$ ##:%%*# $ % $
@@@@@ %- **+$$$* .= **%%%%%%%#=*###*#%$$$$$%%* *%%$$$$$%#*###*=#%%%%%%%** =. *$$$+** -% @@@@@
$ % $ #*%%:## $$= -%%$$$% **= #*:%$$$$$$%%%#. +=##%$$$$$$ #%%%%%%%%%%- = -%@@@@@@@$-@@@@@@
@@@$+ : -$ # %%%%%*# -#%$$$$=##+-- +%%%$$$%%:#:*##* :+ - %$$$$$+-+ +##*#-**= * == $@@@@@@@@@@@@@@@
@@@@@* %=@@ +%%%%= - = $$$ +#%%%%%%%%%%%%%% ***-=: .+%$@@@@@$$%+ =# %$%%. @$@@@@@@@@@@@@@@@
@@@@@@@@@@@@**+ : *- #$@@$+=+%%%%%%%%%+ %+ : : -$@@@@@@@@@@ : $-@$#+$@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@$#$$%% # %$@@@@@+-:= .+ %+-**#= **:.: = =+ =$@@@@@@@@@@@@@@@@@+.+@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@%=+. $%@@@@@@@@@+*% . : = = #+=* -=**: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complex
r as double
i as double
end type
 
operator + (x as complex, y as complex) as complex
dim as complex ret
ret.r = x.r + y.r
ret.i = x.i + y.i
return ret
end operator
 
operator * (x as complex, y as complex) as complex
dim as complex ret
ret.r = x.r*y.r - x.i*y.i
ret.i = x.r*y.i + x.i*y.r
return ret
end operator
 
operator abs ( x as complex ) as double
return sqr(x.r*x.r + x.i*x.i)
end operator
 
dim as complex c, z
dim as integer x, y, iter
 
input "Real part of c? ", c.r
input "Imaginary part of c? ", c.i
 
screen 12
 
for x=0 to 639
for y=0 to 479
z.r = (x-zero_x)*pix
z.i = (y-zero_y)*pix
for iter=0 to maxiter
z = z*z + c
if abs(z)>2 then
pset(x,y),iter mod 16
goto cont
end if
next iter
pset(x,y),1
cont:
next y
next x
 
while inkey=""
wend
end</syntaxhighlight>
 
 
==={{header|GW-BASIC}}===
<syntaxhighlight lang="gwbasic">10 SCALE# = 1/81 : ZEROX = 160
20 ZEROY = 100 : MAXIT = 32
30 CR# = -.798 : CI# = .1618
40 SCREEN 1
50 FOR X = 0 TO 2*ZEROX - 1
60 FOR Y = 0 TO 2*ZEROY - 1
70 ZR# = (X-ZEROX)*SCALE#
80 ZI# = (ZEROY-Y)*SCALE#
90 FOR I = 1 TO MAXIT
100 BR# = CR# + ZR#*ZR# - ZI#*ZI#
110 ZI# = CI# + 2*ZR#*ZI#
120 ZR# = BR#
130 IF ZR#*ZR# + ZI#*ZI# > 4! THEN GOTO 160
140 NEXT I
150 GOTO 170
160 PSET (X, Y), 1 + (I MOD 3)
170 NEXT Y
180 NEXT X</syntaxhighlight>
 
==={{header|Liberty BASIC}}===
{{trans|Locomotive Basic}}
Shades of gray proportional to numbers of iteration are used (differently from the original version).
{{works with|Just BASIC}}
<syntaxhighlight lang="lb">rem Julia set
WindowWidth = 640: WindowHeight = 400
graphicbox #julset.gbox, 0, 0, 639, 399
open "Julia set" for window as #julset
print #julset.gbox, "down"
x0 = -0.512511498387847167 : y0 = 0.521295573094847167
for xp = 0 TO 639
for yp = 0 TO 399
x = xp / 213 - 1.5: y = yp / 200 - 1
iteration = 0
maxIteration = 100
while x * x + y * y <= 4 and iteration < maxIteration
xtemp = x * x - y * y + x0
y = 2 * x * y + y0
x = xtemp
iteration = iteration + 1
wend
if iteration <> maxIteration then c = int(iteration * 255 / maxIteration + .5) else c = 0
print #julset.gbox, "color "; c; " "; c; " "; c
print #julset.gbox, "set "; xp; " "; yp
next yp
next xp
wait
</syntaxhighlight>
 
==={{header|Locomotive Basic}}===
Adapted from the Mandelbrot Locomotive Basic program. This program is meant for use in [https://benchmarko.github.io/CPCBasic/cpcbasic.html CPCBasic] specifically, where it draws a 16-color 640x400 image in less than a minute. (Real CPC hardware would take far longer than that and has lower resolution.)
<syntaxhighlight lang="locobasic">1 MODE 3 ' Note the CPCBasic-only screen mode!
2 FOR xp = 0 TO 639
3 FOR yp = 0 TO 399
4 x0 = -0.512511498387847167 : y0 = 0.521295573094847167
5 x = xp / 213 - 1.5 : y = yp / 200 - 1
6 iteration = 0
7 maxIteration = 100
8 WHILE (x * x + y * y <= (2 * 2) AND iteration < maxIteration)
9 xtemp = x * x - y * y + x0
10 y = 2 * x * y + y0
11 x = xtemp
12 iteration = iteration + 1
13 WEND
14 IF iteration <> maxIteration THEN c = iteration ELSE c = 0
15 PLOT xp, yp, c MOD 16
16 NEXT
17 NEXT</syntaxhighlight>
 
==={{header|QBasic}}===
{{works with|QBasic}}
Line 325 ⟶ 542:
NEXT x
END</syntaxhighlight>
 
==={{header|RapidQ}}===
{{trans|Liberty BASIC}}
<syntaxhighlight lang="rapidq">
'Julia set
DECLARE SUB PaintCanvas
 
CREATE Form AS QForm
ClientWidth = 640
ClientHeight = 400
Caption = "Julia set"
CREATE Canvas AS QCanvas
Height = Form.ClientHeight
Width = Form.ClientWidth
OnPaint = PaintCanvas
END CREATE
END CREATE
 
SUB PaintCanvas
X0 = -0.512511498387847167: Y0 = 0.521295573094847167
FOR XP = 0 TO 639
FOR YP = 0 TO 399
X = XP / 213 - 1.5: Y = YP / 200 - 1
Iteration = 0
MaxIteration = 100
WHILE X * X + Y * Y <= 4 AND Iteration < MaxIteration
XTemp = X * X - Y * Y + X0
Y = 2 * X * Y + Y0
X = XTemp
Iteration = Iteration + 1
WEND
IF Iteration <> MaxIteration THEN C = ROUND(Iteration * 255 / MaxIteration) ELSE C = 0
Canvas.Pset(XP, YP, RGB(C, C, C))
NEXT YP
NEXT XP
END SUB
 
Form.ShowModal
</syntaxhighlight>
 
==={{header|Sinclair ZX81 BASIC}}===
I don't know exactly how long this takes to run; but I left it for about three and a half hours and when I came back it had already finished. If you can't wait to see the results, I've posted a screenshot [http://edmundgriffiths.com/zxjulia.jpg here]. I also haven't tested it with only 1k of RAM—but I suspect it needs at least 2k.
 
You can try changing lines 10 and 20 to run the program with different values of the complex constant <tt>C</tt>+<tt>D</tt><math>i</math>, or lines 50 and 60 to zoom in.
<syntaxhighlight lang="basic"> 10 LET C=-.8
20 LET D=.156
30 FOR V=43 TO 0 STEP -1
40 FOR H=0 TO 63
50 LET X=(H-32)/21
60 LET Y=(V-22)/21
70 FOR A=1 TO 50
80 LET R=X*X-Y*Y+C
90 LET I=2*X*Y+D
100 IF R*R>1000 THEN GOTO 150
110 LET X=R
120 LET Y=I
130 NEXT A
140 PLOT H,V
150 NEXT H
160 NEXT V</syntaxhighlight>
 
==={{header|True BASIC}}===
Line 355 ⟶ 632:
NEXT x
END</syntaxhighlight>
 
==={{header|VBScript}}===
<syntaxhighlight lang="vb">
'ASCII Julia set. Translated from lua. Run with CScript
'Console should be 135x50 to avoid wrapping and scroll
 
cmap=array(" ", ".", ":", "-", "=", "+", "*", "#", "%", "$", "@" )
for y = -1.0 to 1.0 step 0.05
for x = -1.5 to 1.5 step 0.025
zr=x
zi=y
i=0
do while i < 100
zr1 = zr*zr - zi*zi - 0.79
zi=zr * zi * 2 + 0.15
zr=zr1
if (zr*zr + zi*zi) > 4. then exit do
i = i + 1
loop
wscript.stdout.write cmap(i\10)
next
wscript.stdout.write vbcrlf
next
</syntaxhighlight>
{{out}}<small>
<pre>
.:
=@=:.#:
%@=:@%@
..::::#.
:.+=-:+@--%
=+- .#+@@::::@-....--@:.@..$@
.@*:.**=@=::::...=@@@*@@::@-#
:-:::*@@@-:::::--@@%@*+=+::%+:. -@+
%@-=@@@==*@**=*@:%#*@@%@@@@@@@*@@#:-. @:.@@@+:-
- .$-==@%**@@==--*@@@@====@@@-#=@@@%@: -@+:%@@:::.
@@:@. .@ @*:=*@%@@@@*++@%@@@@#-#*-::::=:::*@@#+. .+%@%*@$=+:%%@@=--
$-$-..@@#*:@... + .:=#@@@@@%@@@@@*$#@=:::@::::::::::-+%@.....%@@@@*+##@@=*@@@#
..:@=:::.*@%@=@#%*+:.@. ..:@@$@@@@%**%==+=*$:::::::::::::::::-+@....@@$@#*@+@@:=::::=- +:@=
.::@@#-:%*@=*@@-=@@=*@@@.......@-@+@*@@*+@=--==:::::::::::::@$=*---@=....=@=@@=-*=:::::::-@.-@@*#@.
-+@*@@=+@@@*%::::::::@+*$@......@=+@+@@@@@@--@=@::......:-@@===+*--#@....::@@@@@::...:@=@=+.:@@:::-.%@
: .+. =#@@@@@+#@:::::::::::::-=@-.......:*==*#@@@#@@:::.......:-+=-=+%===@::...:::-#%#@+:...@-:::::##@$.@$-
@@-$=@==@+...-+@@+@==@::::::::-#@@----@=.......::=%@@@@@@@%=::.......=@----@@#-::::::::@==@+@@+-...+@==@=$-@@
-$@.$@##:::::-@...:+@#%#-:::...::@===%+=-=+-:.......:::@@#@@@#*==*:.......-@=-:::::::::::::@#+@@@@@#= .+. :
@%.-:::@@:.+=@=@:...::@@@@@::....@#--*+===@@-:......::@=@--@@@@@@+@+=@......@$*+@::::::::%*@@@+=@@*@+-
.@#*@@-.@-:::::::=*-=@@=@=....=@---*=$@:::::::::::::==--=@+*@@*@+@-@.......@@@*=@@=-@@*=@*%:-#@@::.
=@:+ -=::::=:@@+@*#@$@@....@+-:::::::::::::::::$*=+==%**%@@@@$@@:.. .@.:+*%#@=@%@*.:::=@:..
#@@@*=@@##+*@@@@%.....@%+-::::::::::@:::=@#$*@@@@@%@@@@@#=:. + ...@:*#@@..-$-$
--=@@%%:+=$@*%@%+. .+#@@*:::=::::-*#-#@@@@%@++*@@@@%@*=:*@ @. .@:@@
.:::@@%:+@- :@%@@@=#-@@@====@@@@*--==@@**%@==-$. -
-:+@@@.:@ .-:#@@*@@@@@@@%@@*#%:@*=**@*==@@@=-@%
+@- .:+%::+=+*@%@@--:::::-@@@*:::-:
#-@::@@*@@@=...::::=@=**.:*@.
@$..@.:@--....-@::::@@+#. -+=
%--@+:-=+.:
.#::::..
@%@:=@%
:#.:=@=
:.
 
</pre>
</small>
 
==={{header|Yabasic}}===
Line 383 ⟶ 722:
next x
end</syntaxhighlight>
 
==={{header|GW-BASIC}}===
<syntaxhighlight lang="gwbasic">10 SCALE# = 1/81 : ZEROX = 160
20 ZEROY = 100 : MAXIT = 32
30 CR# = -.798 : CI# = .1618
40 SCREEN 1
50 FOR X = 0 TO 2*ZEROX - 1
60 FOR Y = 0 TO 2*ZEROY - 1
70 ZR# = (X-ZEROX)*SCALE#
80 ZI# = (ZEROY-Y)*SCALE#
90 FOR I = 1 TO MAXIT
100 BR# = CR# + ZR#*ZR# - ZI#*ZI#
110 ZI# = CI# + 2*ZR#*ZI#
120 ZR# = BR#
130 IF ZR#*ZR# + ZI#*ZI# > 4! THEN GOTO 160
140 NEXT I
150 GOTO 170
160 PSET (X, Y), 1 + (I MOD 3)
170 NEXT Y
180 NEXT X</syntaxhighlight>
 
==={{header|Locomotive Basic}}===
 
Adapted from the Mandelbrot Locomotive Basic program. This program is meant for use in [https://benchmarko.github.io/CPCBasic/cpcbasic.html CPCBasic] specifically, where it draws a 16-color 640x400 image in less than a minute. (Real CPC hardware would take far longer than that and has lower resolution.)
<syntaxhighlight lang="locobasic">1 MODE 3 ' Note the CPCBasic-only screen mode!
2 FOR xp = 0 TO 639
3 FOR yp = 0 TO 399
4 x0 = -0.512511498387847167 : y0 = 0.521295573094847167
5 x = xp / 213 - 1.5 : y = yp / 200 - 1
6 iteration = 0
7 maxIteration = 100
8 WHILE (x * x + y * y <= (2 * 2) AND iteration < maxIteration)
9 xtemp = x * x - y * y + x0
10 y = 2 * x * y + y0
11 x = xtemp
12 iteration = iteration + 1
13 WEND
14 IF iteration <> maxIteration THEN c = iteration ELSE c = 0
15 PLOT xp, yp, c MOD 16
16 NEXT
17 NEXT</syntaxhighlight>
 
==={{header|Sinclair ZX81 BASIC}}===
I don't know exactly how long this takes to run; but I left it for about three and a half hours and when I came back it had already finished. If you can't wait to see the results, I've posted a screenshot [http://edmundgriffiths.com/zxjulia.jpg here]. I also haven't tested it with only 1k of RAM—but I suspect it needs at least 2k.
 
You can try changing lines 10 and 20 to run the program with different values of the complex constant <tt>C</tt>+<tt>D</tt><math>i</math>, or lines 50 and 60 to zoom in.
<syntaxhighlight lang="basic"> 10 LET C=-.8
20 LET D=.156
30 FOR V=43 TO 0 STEP -1
40 FOR H=0 TO 63
50 LET X=(H-32)/21
60 LET Y=(V-22)/21
70 FOR A=1 TO 50
80 LET R=X*X-Y*Y+C
90 LET I=2*X*Y+D
100 IF R*R>1000 THEN GOTO 150
110 LET X=R
120 LET Y=I
130 NEXT A
140 PLOT H,V
150 NEXT H
160 NEXT V</syntaxhighlight>
 
==={{header|ZX Spectrum Basic}}===
Line 662 ⟶ 939:
 
=={{header|C++}}==
===Version 1 (<code>windows.h</code>)===
[[File:JuliaSetCpp.png|200px|thumb|right]]
'''Note:''' Will only run on Windows. For the cross-platform version that can be run on different OSes, see [[{{PAGENAME}}#Version 2 (SDL2)|Version 2]].
<syntaxhighlight lang="cpp">
#include <windows.h>
Line 800 ⟶ 1,079:
}
</syntaxhighlight>
 
===Version 2 (SDL2)===
{{libheader|SDL2}}
'''Source:''' https://gist.github.com/KatsumiKougen/74468b3c1c4b9844f6f77a2922f588f9
<syntaxhighlight lang="cpp">
/************************************************************
* JULIA SET IN C++ *
* Library used: SDL2 *
* Written by Katsumi -- https://twitter.com/realKatsumi_vn *
************************************************************/
 
// Standard C++ stuff
#include <iostream>
#include <complex>
#include <vector>
#include <array>
 
// SDL2 stuff
#include "SDL2/SDL.h"
 
// Other crazy stuffs
#define ScreenWidth 800
#define ScreenHeight 600
 
// Compile: g++ -std=c++20 -Wall -Wextra -pedantic julia-set-sdl2.cpp -o julia-set-sdl2 -lSDL2
// Yes, I use the British spelling, it's "colour" not "color". Deal with it.
 
void DrawJuliaSet(SDL_Renderer *r, int width, int height, double real, double imag, int maxiter) {
// Generate colours
std::vector<std::array<int, 3>> colours;
for (int col = 0; col < 256; col++) {
std::array<int, 3> CurrentColour = {(col >> 5) * 36, (col >> 3 & 7) * 36, (col & 3) * 85};
colours.push_back(CurrentColour);
}
std::complex<double> c = {real, imag}, z;
// Actual calculations
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
z.real(1.5 * (x - width / 2) / (0.5 * width));
z.imag((y - height / 2) / (0.5 * height));
int i = maxiter;
while (std::norm(z) < 4 && i > 0) {
z = z * z + c;
i--;
}
// Draw the set on the window, pixel by pixel
SDL_SetRenderDrawColor(r, colours[i][0], colours[i][1], colours[i][2], 0xff);
SDL_RenderDrawPoint(r, x, y);
}
}
}
 
int main(int argc, char *args[]) {
const int MaximumIterations = 256;
SDL_Window *window = NULL; // Define window
SDL_Renderer *renderer = NULL; // Define renderer
// First things first: initialise video
SDL_Init(SDL_INIT_EVERYTHING);
window = SDL_CreateWindow( // Create window
"Julia set - Press any key to exit",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
ScreenWidth, ScreenHeight, // Width and height
SDL_WINDOW_SHOWN // Always show the window
);
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); // Create renderer
SDL_SetRenderDrawColor(renderer, 0xff, 0xff, 0xff, 0xff);
SDL_RenderClear(renderer); // Clear screen
DrawJuliaSet(renderer, ScreenWidth, ScreenHeight, -0.7, 0.27015, MaximumIterations); // Draw the Julia set
SDL_RenderPresent(renderer); // Render it!
// Create an event handler and a "quit" flag
SDL_Event e;
bool KillWindow = false;
while (!KillWindow) { // The window runs until the "quit" flag is set to true
while (SDL_PollEvent(&e) != 0) {
switch (e.type) { // Go through the events in the queue
case SDL_QUIT: case SDL_KEYDOWN: // Event: user hits a key
// Destroy window
KillWindow = true;
break;
}
}
}
SDL_DestroyRenderer(renderer); // Destroy renderer
SDL_DestroyWindow(window); // Destroy window
SDL_Quit();
return 0;
}
</syntaxhighlight>
{{output}}
[[File:Julia set SDL2.png|thumb|center]]
 
=={{header|COBOL}}==
Line 1,036 ⟶ 1,421:
=={{header|EasyLang}}==
 
[https://easylang.onlinedev/apps/julia-set.html Run it]
 
<syntaxhighlight lang="text">cx = -0.7
cx = -0.7
cy = 0.27015
for y range= 3000 to 299
for x range= 3000 to 299
zx = (x - 150) / 100
zy = (y - 150) / 150
color3 0 0 0
for iter range= 1280 to 127
if zx * zx + zy * zy > 4
color3 iter / 16 0 0
Line 1,057 ⟶ 1,443:
rect 0.4 0.4
.
.
.</syntaxhighlight>
</syntaxhighlight>
 
=={{header|Elixir}}==
Line 1,500 ⟶ 1,887:
end program julia</syntaxhighlight>
 
=={{header|FreeBASICFōrmulæ}}==
<syntaxhighlight lang="freebasic">
#define pix 1./120
#define zero_x 320
#define zero_y 240
#define maxiter 250
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Julia_set}}
type complex
r as double
i as double
end type
 
'''Solution'''
operator + (x as complex, y as complex) as complex
dim as complex ret
ret.r = x.r + y.r
ret.i = x.i + y.i
return ret
end operator
 
We need first to generate a color palette, this is, a list of colors:
operator * (x as complex, y as complex) as complex
dim as complex ret
ret.r = x.r*y.r - x.i*y.i
ret.i = x.r*y.i + x.i*y.r
return ret
end operator
 
[[File:Fōrmulæ - Julia set 01.png]]
operator abs ( x as complex ) as double
return sqr(x.r*x.r + x.i*x.i)
end operator
 
[[File:Fōrmulæ - Julia set 02.png]]
dim as complex c, z
dim as integer x, y, iter
 
[[File:Fōrmulæ - Julia set 03.png]]
input "Real part of c? ", c.r
input "Imaginary part of c? ", c.i
 
The following function draw the Julia set:
screen 12
 
[[File:Fōrmulæ - Julia set 04.png]]
for x=0 to 639
for y=0 to 479
z.r = (x-zero_x)*pix
z.i = (y-zero_y)*pix
for iter=0 to maxiter
z = z*z + c
if abs(z)>2 then
pset(x,y),iter mod 16
goto cont
end if
next iter
pset(x,y),1
cont:
next y
next x
 
'''Test Case 1. Grayscale palette'''
while inkey=""
wend
end</syntaxhighlight>
 
=={{header|[[File:Fōrmulæ}}== - Julia set 05.png]]
 
[[File:Fōrmulæ - Julia set 06.png]]
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Test case 2. Black & white palette'''
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
[[File:Fōrmulæ - Julia set 07.png]]
In '''[https://formulae.org/?example=Julia_set this]''' page you can see the program(s) related to this task and their results.
 
[[File:Fōrmulæ - Julia set 08.png]]
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
 
#build CheckArrayBounds NO
output file "Julia Fractal Viewer
include "NSLog.incl"
 
begin record Complex
float real // real component of Complex Number
float imag // imaginary component of Complex Number
end record
 
_window = 1
begin enum output 1
_juliaView
end enum
 
void local fn BuildWindow
CGRect r = fn CGRectMake( 0, 0, 520, 600 )
window _window, @"Rosetta Code Julia Set", r, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable + NSWindowStyleMaskMiniaturizable
r = fn CGRectMake( 10, 10, 500, 580 )
imageview _juliaView, YES,,r, NSImageScaleAxesIndependently, NSImageAlignCenter, NSImageFramePhoto, _window
end fn
 
local fn JuliaPoint( c as Complex, w as long, h as long, xl as float, xr as float, yb as float, yt as float, i as long, j as long ) as long
float ai, ar, cr, ci, t, x, y
long k, value
value = 1
cr = c.real
ci = c.imag
x = ( ( float ) ( w - i - 1 ) * xl + ( float ) ( i ) * xr ) / ( float ) ( w - 1 )
y = ( ( float ) ( h - j - 1 ) * yb + ( float ) ( j ) * yt ) / ( float ) ( h - 1 )
ar = x
ai = y
for k = 0 to 199
t = ar * ar - ai * ai + cr
ai = ar * ai + ai * ar + ci
ar = t
if ( 1000 < ar * ar + ai * ai )
value = 0
exit fn
end if
next k
end fn = value
 
void local fn JuliaRGB( c as Complex, w as long, h as long, xl as float, xr as float, yb as float, yt as float, rgb(0) as unsigned char )
long i, j, juliaValue, k
k = 0
for j = 0 to h - 1
for i = 0 to w - 1
juliaValue = fn JuliaPoint( c, w, h, xl, xr, yb, yt, i, j )
rgb(k) = 255 * (1-juliaValue)
rgb(k+1) = 255 * (1-juliaValue)
rgb(k+2) = 255
k += 3
next i
next j
end fn
 
void local fn TGAWrite( w as long, h as long, rgb(0) as ^unsigned char, url as CFURLRef )
CFMutableDataRef dta
unsigned char header1(11), header2(5)
BlockZero( @header1(0), 12 * sizeof(unsigned char) )
header1(2) = 2
header2(0) = w mod 256
header2(1) = w/256
header2(2) = h mod 256
header2(3) = h/256
header2(4) = 24
header2(5) = 0
dta = fn MutableDataWithCapacity(0)
MutableDataAppendBytes( dta, @header1(0), 12 * sizeof(unsigned char) )
MutableDataAppendBytes( dta, @header2(0), 6 * sizeof(unsigned char) )
MutableDataAppendBytes( dta, @rgb(0), w * h * 3 * sizeof(unsigned char) )
fn DataWriteToURL( dta, url, NSDataWritingAtomic, NULL )
ImageRef image = fn ImageWithData( dta )
ImageViewSetImage( _juliaView, image )
end fn
 
void local fn BuildJuliaSet( c as Complex )
long h, w
float xl, xr, yb, yt
ptr p
CFURLRef url
// Create 1000x1000-pixel canvas for image
h = 1000
w = 1000
// Locate image on canvas
xl = -1.5
xr = 1.5
yb = -1.5
yt = 1.5
p = fn malloc( w * h * 3 * sizeof(unsigned char) )
xref rgb(1) as unsigned char
rgb = p
// Create image data
fn JuliaRGB( c, w, h, xl, xr, yb, yt, @rgb(0) )
// Create path to final image
url = fn URLFileURLWithPath( fn StringByExpandingTildeInPath( @"~/Desktop/julia_set.png" ) )
// Write image data to file
fn TGAWrite( w, h, @rgb(0), url )
free(p)
end fn
 
dim as Complex c
 
c.real = 0.355534
c.imag = -0.337292
 
// c.real = -0.8
// c.imag = 0.156
 
// c.real = 0.26
// c.imag = 0.0016
 
// c.real = 0.355
// c.imag = 0.355
 
// c.real = -0.4
// c.imag = -0.59
 
// c.real = -0.54
// c.imag = 0.54
 
fn BuildWindow
fn BuildJuliaSet( c )
 
HandleEvents
</syntaxhighlight>
{{output}}
[[File:Julia Set.png]]
 
=={{header|Go}}==
Line 1,621 ⟶ 2,122:
}
}</syntaxhighlight>
 
 
=={{header|Haskell}}==
{{trans|AWK}}
Line 2,214 ⟶ 2,717:
Visualize the same Julia set
<syntaxhighlight lang="mathematica">JuliaSetPlot[-0.77 + 0.22 I]</syntaxhighlight>
 
=={{header|Maxima}}==
Using autoloaded package plotdf
<syntaxhighlight lang="maxima">
julia (-0.786, 0.147, [iterations, 255], [x, -1.5, 1.5],
[y, -1, 1], [grid, 320, 320])$
</syntaxhighlight>
[[File:JuliaMaxima.png|thumb|center]]
 
=={{header|Nim}}==
Line 3,422 ⟶ 3,933:
##
##</pre>
 
=={{header|Transact-SQL}}==
This is a Transact-SQL version of SQL Server to generate Julia set. Export the final result to a .ppm file to view the image.
<syntaxhighlight lang="Transact-SQL">
-- Juila Set
-- SQL Server 2017 and above
SET NOCOUNT ON
GO
 
-- Plot area 800 X 600
DECLARE @width INT = 800
DECLARE @height INT = 600
 
DECLARE @r_min DECIMAL (10, 8) = -1.5;
DECLARE @r_max DECIMAL (10, 8) = 1.5;
DECLARE @i_min DECIMAL (10, 8) = -1;
DECLARE @i_max DECIMAL (10, 8) = 1;
 
DECLARE @zoom INT = 1,
@moveX INT = 0,
@moveY INT = 0;
 
DECLARE @iter INT = 255; -- Iteration
 
DROP TABLE IF EXISTS dbo.Numbers
DROP TABLE IF EXISTS dbo.julia_set;
 
CREATE TABLE dbo.Numbers (n INT);
 
-- Generate a number table of 1000 rows
;WITH N1(n) AS
(
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1
), -- 10
N2(n) AS (SELECT 1 FROM N1 CROSS JOIN N1 AS b), -- 10*10
N3(n) AS (SELECT 1 FROM N1 CROSS JOIN N2) -- 10*100
INSERT INTO dbo.Numbers (n)
SELECT n = ROW_NUMBER() OVER (ORDER BY n)
FROM N3 ORDER BY n;
/*
-- If the version is SQL Server 2022 and above
INSERT INTO dbo.Numbers (n)
SELECT value FROM GENERATE_SERIES(0, 1000);
*/
 
CREATE TABLE dbo.julia_set
(
a INT,
b INT,
c_re DECIMAL (10, 8),
c_im DECIMAL (10, 8),
z_re DECIMAL (10, 8) DEFAULT 0,
z_im DECIMAL (10, 8) DEFAULT 0,
znew_re DECIMAL (10, 8) DEFAULT 0,
znew_im DECIMAL (10, 8) DEFAULT 0,
steps INT DEFAULT 0,
active BIT DEFAULT 1,
)
 
-- Store all the z_re, z_im with constant c_re, c_im corresponding to each point in the plot area
-- Generate 480,000 rows (800 X 600)
INSERT INTO dbo.julia_set (a, b, c_re, c_im, z_re, z_im, steps)
SELECT a.n as a, b.n as b
,-0.7 AS c_re
,0.27015 AS c_im
,@r_max * (a.n - @width / 2) / (0.5 * @zoom * @width) + @moveX AS z_re
,@i_max * (b.n - @height / 2) / (0.5 * @zoom * @height) + @moveY AS z_im
,@iter as steps
FROM
(
SELECT n - 1 as n FROM dbo.Numbers WHERE n <= @width
) as a
CROSS JOIN
(
SELECT n - 1 as n FROM dbo.Numbers WHERE n <= @height
) as b;
 
-- Iteration
WHILE (@iter > 1)
BEGIN
 
UPDATE dbo.julia_set
SET
znew_re = POWER(z_re,2)-POWER(z_im,2)+c_re,
znew_im = 2*z_re*z_im+c_im,
steps = steps-1
WHERE active=1;
 
UPDATE dbo.julia_set
SET
z_re=znew_re,
z_im=znew_im,
active= CASE
WHEN POWER(znew_re,2)+POWER(znew_im,2)>4 THEN 0
ELSE 1
END
WHERE active=1;
 
SET @iter = @iter - 1;
END
 
-- Generating PPM File
-- Save the below query results to a file with extension .ppm
-- NOTE : All the unwanted info like 'rows affected', 'completed time' etc. needs to be
-- removed from the file. Most of the image editing softwares and online viewers can display the .ppm file
SELECT 'P3' UNION ALL
SELECT CAST(@width AS VARCHAR(5)) + ' ' + CAST(@height AS VARCHAR(5)) UNION ALL
SELECT '255' UNION ALL
SELECT
STRING_AGG(CAST(CASE WHEN active = 1 THEN 0 ELSE 55 + steps % 200 END AS VARCHAR(MAX)) + ' ' -- R
+ CAST(CASE WHEN active = 1 THEN 0 ELSE 55+POWER(steps,3) % 200 END AS VARCHAR(MAX)) + ' ' -- G
+ CAST(CASE WHEN active = 1 THEN 0 ELSE 55+ POWER(steps,2) % 200 END AS VARCHAR(MAX)) -- B
, ' ') WITHIN GROUP (ORDER BY a, b)
FROM dbo.julia_set
GROUP BY a, b
</syntaxhighlight>
 
'''OUTPUT'''
[[File:Julia set transact sql.png|thumb|Julia set in Transact-SQL]]
 
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
'ASCII Julia set. Translated from lua. Run with CScript
'Console should be 135x50 to avoid wrapping and scroll
sub pause() wscript.stdout.write "Press Enter to Continue":wscript.stdin.readline: end sub
cmap=array(" ", ".", ":", "-", "=", "+", "*", "#", "%", "$", "@" )
for y = -1.0 to 1.0 step 0.05
for x = -1.5 to 1.5 step 0.025
zr=x
zi=y
i=0
do while i < 100
zr1 = zr*zr - zi*zi - 0.79
zi=zr * zi * 2 + 0.15
zr=zr1
if (zr*zr + zi*zi) > 4. then exit do
i = i + 1
loop
wscript.stdout.write cmap(i\10)
next
wscript.stdout.write vbcrlf
Next
pause
</syntaxhighlight>
{{out}}
<small>
<pre>
.:
=@=:.#:
%@=:@%@
..::::#.
:.+=-:+@--%
=+- .#+@@::::@-....--@:.@..$@
.@*:.**=@=::::...=@@@*@@::@-#
:-:::*@@@-:::::--@@%@*+=+::%+:. -@+
%@-=@@@==*@**=*@:%#*@@%@@@@@@@*@@#:-. @:.@@@+:-
- .$-==@%**@@==--*@@@@====@@@-#=@@@%@: -@+:%@@:::.
@@:@. .@ @*:=*@%@@@@*++@%@@@@#-#*-::::=:::*@@#+. .+%@%*@$=+:%%@@=--
$-$-..@@#*:@... + .:=#@@@@@%@@@@@*$#@=:::@::::::::::-+%@.....%@@@@*+##@@=*@@@#
..:@=:::.*@%@=@#%*+:.@. ..:@@$@@@@%**%==+=*$:::::::::::::::::-+@....@@$@#*@+@@:=::::=- +:@=
.::@@#-:%*@=*@@-=@@=*@@@.......@-@+@*@@*+@=--==:::::::::::::@$=*---@=....=@=@@=-*=:::::::-@.-@@*#@.
-+@*@@=+@@@*%::::::::@+*$@......@=+@+@@@@@@--@=@::......:-@@===+*--#@....::@@@@@::...:@=@=+.:@@:::-.%@
: .+. =#@@@@@+#@:::::::::::::-=@-.......:*==*#@@@#@@:::.......:-+=-=+%===@::...:::-#%#@+:...@-:::::##@$.@$-
@@-$=@==@+...-+@@+@==@::::::::-#@@----@=.......::=%@@@@@@@%=::.......=@----@@#-::::::::@==@+@@+-...+@==@=$-@@
-$@.$@##:::::-@...:+@#%#-:::...::@===%+=-=+-:.......:::@@#@@@#*==*:.......-@=-:::::::::::::@#+@@@@@#= .+. :
@%.-:::@@:.+=@=@:...::@@@@@::....@#--*+===@@-:......::@=@--@@@@@@+@+=@......@$*+@::::::::%*@@@+=@@*@+-
.@#*@@-.@-:::::::=*-=@@=@=....=@---*=$@:::::::::::::==--=@+*@@*@+@-@.......@@@*=@@=-@@*=@*%:-#@@::.
=@:+ -=::::=:@@+@*#@$@@....@+-:::::::::::::::::$*=+==%**%@@@@$@@:.. .@.:+*%#@=@%@*.:::=@:..
#@@@*=@@##+*@@@@%.....@%+-::::::::::@:::=@#$*@@@@@%@@@@@#=:. + ...@:*#@@..-$-$
--=@@%%:+=$@*%@%+. .+#@@*:::=::::-*#-#@@@@%@++*@@@@%@*=:*@ @. .@:@@
.:::@@%:+@- :@%@@@=#-@@@====@@@@*--==@@**%@==-$. -
-:+@@@.:@ .-:#@@*@@@@@@@%@@*#%:@*=**@*==@@@=-@%
+@- .:+%::+=+*@%@@--:::::-@@@*:::-:
#-@::@@*@@@=...::::=@=**.:*@.
@$..@.:@--....-@::::@@+#. -+=
%--@+:-=+.:
.#::::..
@%@:=@%
:#.:=@=
:.
</pre>
</small>
 
=={{header|Wren}}==
{{libheader|DOME}}
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color
import "dome" for Window
 
Line 3,473 ⟶ 4,168:
 
var Game = JuliaSet.new(800, 600)</syntaxhighlight>
 
{{out}}
[[File:Wren-Julia_set.png|400px]]
 
=={{header|XPL0}}==
[[File:JuliaSetXPL0.png|200px|thumb|right]]
<syntaxhighlight lang "XPL0">def Cx = -0.72, Cy = 0.27;
def ScrW=800, ScrH=600;
int X, Y, Iter;
real Zx, Zy, T;
[SetVid($115);
for Y:= 0 to ScrH-1 do
for X:= 0 to ScrW-1 do
[Iter:= 0;
Zx:= 3.2 * float(X-ScrW/2) / float(ScrW);
Zy:= 2.4 * float(ScrH/2-Y) / float(ScrH);
while Zx*Zx + Zy*Zy < 4.0 and Iter < 300 do
[T:= Zx*Zx - Zy*Zy + Cx;
Zy:= 2.0*Zx*Zy + Cy;
Zx:= T;
Iter:= Iter+1;
];
Point(X, Y, Iter<<21+Iter<<8+Iter<<3);
];
]</syntaxhighlight>
 
 
=={{header|zkl}}==
9,476

edits