Julia set: Difference between revisions
→{{header|Wren}}: Added image
(→{{header|Wren}}: Added image) |
|||
(33 intermediate revisions by 14 users not shown) | |||
Line 12:
=={{header|Ada}}==
{{libheader|SDLAda}}
<
with SDL.Video.Windows.Makers;
Line 104:
Window.Finalize;
SDL.Finalise;
end Julia_Set;</
=={{header|ALGOL 68}}==
Line 111:
<br>
Uses the Algol 68G specific argc and argv procedures. Note argv( 1 ) is the path of the Algol 68G interpreter and argv( 2 ) is the source being executed.
<
REAL c real, c imaginary;
STRING real and imaginary := IF argc < 3 THEN "-0.8" ELSE argv( 3 ) FI
Line 145:
print( ( newline ) )
OD
END</
{{out}}
<pre>
Line 177:
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">
#!/usr/bin/hopper
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>
=={{header|AWK}}==
{{trans|COBOL}}
<syntaxhighlight lang="awk">
# syntax: GAWK -f JULIA_SET.AWK [real imaginary]
BEGIN {
Line 273 ⟶ 308:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
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
IF ZR * ZR + ZI * ZI > 4 EXIT WHILE
I%+=1
ENDWHILE
VDU Pix&(I% / 10)
NEXT
PRINT
NEXT</syntaxhighlight>
{{out}}
<pre>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@$*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%-*= %*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@$$%% #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%+ #%++#:@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*% $ = %%%%%$$$#+*#* **%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@:%%%. +%%%%%% :* %$$$@@@@@@@@@@@@@@@@@@%@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ # :**=- *=+# = = : . %*+@@@@@@@@@%$ .+=%@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@+.+@@@@@@@@@@@@@@@@@$= += = :.:** =#**-+% +. =:-+@@@@@$% # %%$$#$@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@$+#$@-$ : @@@@@@@@@@$- : : +% +%%%%%%%%%+=+$@@$# -* : +**@@@@@@@@@@@@
@@@@@@@@@@@@@@@$@ .%%$% #= +%$$@@@@@$%+. :=-*** %%%%%%%%%%%%%%#+ $$$ = - =%%%%+ @@=% *@@@@@
@@@@@@@@@@@@@@@$ == * =**-#*##+ +-+$$$$$% - +: *##*:#:%%$$$%%%+ --+##=$$$$%#- #*%%%%% # $- : +$@@@
@@@@@@-$@@@@@@@%- = -%%%%%%%%%%# $$$$$$%##=+ .#%%%$$$$$$%:*# =** %$$$%%- =$$ ##:%%*# $ % $
@@@@@ %- **+$$$* .= **%%%%%%%#=*###*#%$$$$$%%* *%%$$$$$%#*###*=#%%%%%%%** =. *$$$+** -% @@@@@
$ % $ #*%%:## $$= -%%$$$% **= #*:%$$$$$$%%%#. +=##%$$$$$$ #%%%%%%%%%%- = -%@@@@@@@$-@@@@@@
@@@$+ : -$ # %%%%%*# -#%$$$$=##+-- +%%%$$$%%:#:*##* :+ - %$$$$$+-+ +##*#-**= * == $@@@@@@@@@@@@@@@
@@@@@* %=@@ +%%%%= - = $$$ +#%%%%%%%%%%%%%% ***-=: .+%$@@@@@$$%+ =# %$%%. @$@@@@@@@@@@@@@@@
@@@@@@@@@@@@**+ : *- #$@@$+=+%%%%%%%%%+ %+ : : -$@@@@@@@@@@ : $-@$#+$@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@$#$$%% # %$@@@@@+-:= .+ %+-**#= **:.: = =+ =$@@@@@@@@@@@@@@@@@+.+@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@%=+. $%@@@@@@@@@+*% . : = = #+=* -=**: # @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@%@@@@@@@@@@@@@@@@@@$$$% *: %%%%%%+ .%%%:@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%%** *#*+#$$$%%%%% = $ %*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@:#++%# +%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# %%$$@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*% =*-%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*$@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@</pre>
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">
#define pix 1./120
#define zero_x 320
#define zero_y 240
#define maxiter 250
type 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}}
<
zeroX = 160
zeroY = 100
Line 324 ⟶ 541:
NEXT y
NEXT x
END</
==={{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}}===
{{trans|QBasic}}
<
LET escala = 1/81
Line 354 ⟶ 631:
NEXT y
NEXT x
END</
==={{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}}===
<
zeroX = 320
zeroY = 240
Line 382 ⟶ 721:
next y
next x
end</
==={{header|ZX Spectrum Basic}}===
{{trans|Sinclair ZX81 BASIC}}
Higher resolution is obtainable, if you have the time to wait for it.
<
20 LET cimag=0.156
30 FOR v=-16 TO 16
Line 464 ⟶ 741:
140 PLOT h+100,150-v
150 NEXT h
160 NEXT v</
{{out}}
Screenshot [http://edmundgriffiths.com/spectrumjulia.jpg here].
Line 474 ⟶ 751:
</pre>
Prints out usage on incorrect invocation. Requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library.
<syntaxhighlight lang="c">
#include<graphics.h>
#include<stdlib.h>
Line 553 ⟶ 830:
return 0;
}
</syntaxhighlight>
=={{header|C sharp|C#}}==
{{trans|Python}}
<
// Note: You have to add the System.Drawing assembly
// (right-click "references," Add Reference, Assemblies, Framework,
Line 605 ⟶ 882:
}
}
</syntaxhighlight>
C# also makes it relatively easy to do a multi-threaded version, which should run faster than the above:
<
public struct CalculatedPoint
{
Line 659 ⟶ 936:
bitmap.SetPixel(cp.x, cp.y, colors[cp.i]);
bitmap.Save("julia-set-multi.png");
}</
=={{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>
#include <string>
Line 799 ⟶ 1,078:
julia j; j.draw( c ); return 0;
}
</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}}==
Plots—in ASCII or EBCDIC art—a Julia set for the function <i>f</i>(<i>z</i>) = <i>z</i><sup>2</sup> + <i>c</i>, based on a value of <i>c</i> input by the user (real part then imaginary part, pressing the carriage return key after each). The sample output is for the inputs <tt>-0.8</tt> and <tt>0.156</tt>.
<
PROGRAM-ID. JULIA-SET-PROGRAM.
DATA DIVISION.
Line 861 ⟶ 1,246:
MOVE SPACE TO WS-PLOT-CHARACTER.
MOVE Z-REAL TO X.
MOVE Z-IMAGINARY TO Y.</
{{out}}
<pre>
Line 900 ⟶ 1,285:
=={{header|Crystal}}==
{{trans|Ruby}}
<
def julia(c_real, c_imag)
Line 920 ⟶ 1,305:
julia(-0.8, 0.156)
</syntaxhighlight>
{{out}}
<pre>
Line 977 ⟶ 1,362:
{{libheader| Vcl.Graphics}}
{{Trans|C#}}
<syntaxhighlight lang="delphi">
program Julia_set;
Line 1,033 ⟶ 1,418:
bitmap.Free;
end.
</syntaxhighlight>
=={{header|EasyLang}}==
[https://easylang.
<syntaxhighlight lang="text">
cx = -0.7
cy = 0.27015
for y
for x
zx = (x - 150) / 100
zy = (y - 150) / 150
color3 0 0 0
for iter
if zx * zx + zy * zy > 4
color3 iter / 16 0 0
Line 1,057 ⟶ 1,443:
rect 0.4 0.4
.
.
</syntaxhighlight>
=={{header|Elixir}}==
{{trans|AWK}}
<
def set(c_real, c_imag) do
IO.puts "#{c_real}, #{c_imag}"
Line 1,085 ⟶ 1,472:
c_real = if r=Enum.at(System.argv, 0), do: Float.parse(r) |> elem(0), else: -0.8
c_imag = if c=Enum.at(System.argv, 1), do: Float.parse(c) |> elem(0), else: 0.156
Julia.set(c_real, c_imag)</
{{out}}
Line 1,145 ⟶ 1,532:
=={{header|Emacs Lisp}}==
<
(setq julia-size (cons 300 200))
Line 1,199 ⟶ 1,586:
(insert-image (string-to-image all)))
(julia-pic)</
=={{header|F_Sharp|F#}}==
''' Basic generation code '''
<
let getJuliaValues width height centerX centerY zoom maxIter =
let initzx x = 1.5 * float(x - width/2) / (0.5 * zoom * float(width))
Line 1,214 ⟶ 1,601:
loop 0 (initzx x) (initzy y)
[0..height-1] |> List.map(fun y->[0..width-1] |> List.map (calc y))
</syntaxhighlight>
''' Text display '''
<
getJuliaValues 80 25 -0.7 0.27015 1.0 50
|> List.map(fun row-> row |> List.map (function | 0 ->" " |_->".") |> String.concat "")
|> List.iter (printfn "%s")
</syntaxhighlight>
{{out}}
<pre>
Line 1,252 ⟶ 1,639:
''' Graphic Display '''
<
open System.Drawing
open System.Windows.Forms
Line 1,273 ⟶ 1,660:
showGraphic toColor 640 480 -0.7 0.27015 1.0 5000
</syntaxhighlight>
=={{header|Fortran}}==
Line 1,281 ⟶ 1,668:
The procedure calls, on lines 12 and 13, control the display window on the complex plane.
<
PROGRAM JULIA
C ------------------------------------------------------------------
Line 1,335 ⟶ 1,722:
10 CONTINUE
RETURN
END</
{{out}}
<pre>
Line 1,384 ⟶ 1,771:
{{works with|Fortran|95 and later}}
[[File:Julia-set-gray.png|480px|thumb|right]]
<
module julia_mod
! ----------------------------------------------------------------------------
Line 1,498 ⟶ 1,885:
call juliaPGM( DEF_FSPC, NUM_ROWS, NUM_COLS, DEF_UL, DEF_LR, DEF_SEED )
end program julia</
=={{header|
{{FormulaeEntry|page=https://formulae.org/?script=examples/Julia_set}}
'''Solution'''
We need first to generate a color palette, this is, a list of colors:
[[File:Fōrmulæ - Julia set 01.png]]
[[File:Fōrmulæ - Julia set 02.png]]
[[File:Fōrmulæ - Julia set 03.png]]
The following function draw the Julia set:
[[File:Fōrmulæ - Julia set 04.png]]
'''Test Case 1. Grayscale palette'''
[[File:Fōrmulæ - Julia set 06.png]]
'''Test case 2. Black & white palette'''
[[File:Fōrmulæ - Julia set 07.png]]
[[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}}==
Using the Goroutines results in a performance improvement of about three times on my four-core machine.
<
import (
Line 1,620 ⟶ 2,121:
log.Fatal(err)
}
}</
=={{header|Haskell}}==
{{trans|AWK}}
<
plotChar :: Int -> Float -> Float -> Float -> Float -> Char
Line 1,646 ⟶ 2,149:
mapM_ putStrLn $ [-100,-96..100] >>= \y ->
[[-280,-276..280] >>= \x -> [plotChar 50 cReal cImag (y/100) (x/200)]]
</syntaxhighlight>
{{out}}
<pre style="font-size: 50%;">
Line 1,703 ⟶ 2,206:
</pre>
{{trans|F#}}
<
getJuliaValues :: Float -> Float -> Float -> Float -> Float -> Int -> [[Int]]
Line 1,719 ⟶ 2,222:
main :: IO ()
main = mapM_ (putStrLn . fmap (\case 0 -> '#'; _ -> ' ')) (getJuliaValues 140 50 (-0.8) 0.156 1.0 50) </
{{out}}
<pre style="font-size: 50%;">
Line 1,776 ⟶ 2,279:
=={{header|J}}==
[[File:example-j-julia.png|200px|thumb|right]]
<
pal2=: 255,~0,<.(254$1 0.8 0.6)*Hue 5r6*(i.%<:)254
g=: [: %: 0.3746j0.102863 0.132565j0.389103 _0.373935j_0.353777 1&p.
view_image pal2;b=:g escapetc (10 255) 500 zl_clur _1.5 1.5j1.5</
See also: [http://webbox.lafayette.edu/~reiterc/j/fvj4/index.html Fractals Visualization and J, 4th edition, Part 1] (by Clifford A. Reiter), Chapter 6
Line 1,788 ⟶ 2,291:
[[File:julia_set_java.png|200px|thumb|right]]
{{works with|Java|8}}
<
import java.awt.*;
import java.awt.image.BufferedImage;
Line 1,849 ⟶ 2,352:
});
}
}</
To multi-thread, simply swap the for loop for a parallel IntStream.
<
import javax.swing.*;
import java.awt.*;
Line 1,915 ⟶ 2,418:
}
}
</syntaxhighlight>
=={{header|JavaScript}}==
take a look [http://paulo-jorente.de/tests/juliaset/ here].
<
var maxIterations = 450, minX = -.5, maxX = .5,
minY = -.5, maxY = .5, wid, hei, ctx,
Line 1,976 ⟶ 2,479:
drawFractal();
}
</syntaxhighlight>
=={{header|jq}}==
{{trans|awk}}
<
# $re : -0.8
# $im : 0.156
Line 1,998 ⟶ 2,501:
else .x = .z_real | .y = .z_imag
end )
| .plot ), "\n")</
With the above program in a file called julia.jq, the following invocation of jq 1.5 produces the same output as shown in the awk entry on this page:
Line 2,011 ⟶ 2,514:
The following code creates the fractal as a ppm file named julia.ppm. There is no need of an external library to create this image since the ppm format is straightforward to generate.
<
function iter(z,c)
n = 0
Line 2,029 ⟶ 2,532:
writedlm(out, [f(width,height,a,b,i,j) for j = 1:height, i = 1:width], '\n')
end
</syntaxhighlight>
We can then produce a 600x300 ppm image of the Julia set associated to the parameter ''-0.786+0.147i'' as follows.
Line 2,038 ⟶ 2,541:
[[File:JuliaSet_julia.png|250px|thumb|right]]
<
@inline function hsv2rgb(h, s, v)
Line 2,092 ⟶ 2,595:
end
julia_set()</
=={{header|Kotlin}}==
<
import java.awt.*
import java.awt.image.BufferedImage
Line 2,148 ⟶ 2,651:
isVisible = true
}
}</
=={{header|Lua}}==
<
for y = -1.0, 1.0, 0.05 do
for x = -1.5, 1.5, 0.025 do
Line 2,162 ⟶ 2,665:
end
print()
end</
{{out}}
<pre style="font-size: 50%;">
Line 2,211 ⟶ 2,714:
Mathematica provides built-in functions for Julia sets.
Generate the set of points for the -0.77 +0.22 I Julia set with step sizes of 0.01
<
Visualize the same Julia set
<
=={{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}}==
{{trans|C#}}
{{libheader|imageman}}
<
import imageman
Line 2,248 ⟶ 2,759:
# Save into a PNG file.
image.savePNG("julia.png", compression = 9)</
=={{header|Perl}}==
[[File:JuliaSet.perl.png|250px|thumb|right]]
<
my($w, $h, $zoom) = (800, 600, 1);
Line 2,276 ⟶ 2,787:
}
$img->write(file => 'julia_set.png');</
=={{header|Phix}}==
{{libheader|Phix/pGUI}}
Interactive gui (zoom/pan incomplete).
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Julia_set.exw
Line 2,438 ⟶ 2,949:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</
=={{header|PHP}}==
[https://drive.google.com/file/d/1DYfWyRBW_prZPcTNgfe29kCmRZKzgGDw/view?usp=sharing Click here to see a sample image created using this script.]
<syntaxhighlight lang="php">
set_time_limit(300);
header("Content-Type: image/png");
Line 2,525 ⟶ 3,036:
Julia::start();
</syntaxhighlight>
=={{header|Processing}}==
<
float cX = -0.7;
float cY = 0.27015;
Line 2,557 ⟶ 3,068:
noLoop();
}
</syntaxhighlight>
==={{header|Processing Python mode}}===
{{trans|Processing}}
<
cX = -0.7
Line 2,584 ⟶ 3,095:
colorMode(HSB)
c = color(i / maxIter * 255, 255, 255 if i > 1 else 0)
set(x, y, c)</
noLoop()
Line 2,591 ⟶ 3,102:
{{trans|zkl}}
<
if __name__ == "__main__":
Line 2,614 ⟶ 3,125:
pix[x][y] = (i << 21) + (i << 10) + i*8
bitmap.show()</
===Vectorized===
Line 2,620 ⟶ 3,131:
[https://imgur.com/a/o3j9Zzn Example output.]
<
Solution from:
https://codereview.stackexchange.com/questions/210271/generating-julia-set
Line 2,695 ⟶ 3,206:
origin='lower')
plt.show()
</syntaxhighlight>
=={{header|Racket}}==
[[File:JuliaSet_racket.png|250px|thumb|right]]
<
;; Based on Mandelbrot code (GPL) from:
;; https://github.com/hebr3/Mandelbrot-Set-Racket/blob/master/Mandelbrot.v6.rkt
Line 2,809 ⟶ 3,320:
(save-image M-Image "julias.png")
</syntaxhighlight>
=={{header|Raku}}==
Line 2,816 ⟶ 3,327:
{{works with|Rakudo|2016.03}}
[[File:Julia-set-perl6.png|250px|thumb|right]]
<syntaxhighlight lang="raku"
my ($w, $h) = 800, 600;
Line 2,853 ⟶ 3,364:
when 5/6..1 { $c, 0, $x }
} ).map: ((*+$m) * 255).Int]
}</
=={{header|REXX}}==
Line 2,859 ⟶ 3,370:
:::: which is a
{{trans|COBOL}}
<
parse arg real imag fine . /*obtain optional arguments from the CL*/
if real=='' | real=="," then real= -0.8 /*Not specified? Then use the default.*/
Line 2,879 ⟶ 3,390:
end /*h*/
if $\='' then say strip($, 'T') /*only display a plot line if non-blank*/
end /*v*/ /*stick a fork in it, we're all done. */</
This REXX program makes use of '''scrsize''' REXX program (or BIF) which is used to determine the screen size of the terminal (console),
<br>and the plot size is adjusted according.
Line 3,062 ⟶ 3,573:
=={{header|Ring}}==
<
# Project : Julia Set
Line 3,121 ⟶ 3,632:
}
label1 { setpicture(p1) show() }
</syntaxhighlight>
=={{header|Ruby}}==
{{trans|AWK}}
<
puts Complex(c_real, c_imag)
-1.0.step(1.0, 0.04) do |v|
Line 3,142 ⟶ 3,653:
end
julia(-0.8, 0.156)</
{{out}}
Line 3,199 ⟶ 3,710:
{{libheader|JRubyArt}}
JRubyArt is a port of Processing to the ruby language, here we target same Julia Set as Processing for comparison, produces a colored output
<
# frozen_string_literal: true
Line 3,227 ⟶ 3,738:
no_loop
end
</syntaxhighlight>
=={{header|Rust}}==
<
use image::{ImageBuffer, Pixel, Rgb};
Line 3,276 ⟶ 3,787:
let _ = img.save("output.png");
}</
=={{header|Scala}}==
===Java Swing Interoperability===
<
import java.awt.image.BufferedImage
Line 3,337 ⟶ 3,848:
)
}</
=={{header|Sidef}}==
[[File:JuliaSet_sidef.png|250px|thumb|right]]
<
var (w, h) = (640, 480)
Line 3,361 ⟶ 3,872:
}
img.write(file => "JuliaSet_sidef.png")</
This version generates an ASCII representation:
<
var maxIter = 40
Line 3,379 ⟶ 3,890:
}
print "\n"
}</
{{out}}
<pre style="font-size: 50%;"> ##
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}}
<
import "dome" for Window
Line 3,472 ⟶ 4,167:
}
var Game = JuliaSet.new(800, 600)</
{{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}}==
Line 3,478 ⟶ 4,199:
{{trans|Java}}
[[File:JuliaSet.zkl.jpg|250px|thumb|right]]
<
w,h,zoom:=800,600, 1;
bitmap:=PPM(w,h,0xFF|FF|FF); // White background
Line 3,500 ⟶ 4,221:
bitmap.writeJPGFile("juliaSet.jpg",True);
}();</
|