Julia set: Difference between revisions

(Move FutureBasic out of BASIC group)
(→‎{{header|Wren}}: Added image)
 
(9 intermediate revisions by 6 users not shown)
Line 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>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@$*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%-*= %*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@$$%% #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%+ #%++#:@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*% $ = %%%%%$$$#+*#* **%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@:%%%. +%%%%%% :* %$$$@@@@@@@@@@@@@@@@@@%@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ # :**=- *=+# = = : . %*+@@@@@@@@@%$ .+=%@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@+.+@@@@@@@@@@@@@@@@@$= += = :.:** =#**-+% +. =:-+@@@@@$% # %%$$#$@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@$+#$@-$ : @@@@@@@@@@$- : : +% +%%%%%%%%%+=+$@@$# -* : +**@@@@@@@@@@@@
@@@@@@@@@@@@@@@$@ .%%$% #= +%$$@@@@@$%+. :=-*** %%%%%%%%%%%%%%#+ $$$ = - =%%%%+ @@=% *@@@@@
@@@@@@@@@@@@@@@$ == * =**-#*##+ +-+$$$$$% - +: *##*:#:%%$$$%%%+ --+##=$$$$%#- #*%%%%% # $- : +$@@@
@@@@@@-$@@@@@@@%- = -%%%%%%%%%%# $$$$$$%##=+ .#%%%$$$$$$%:*# =** %$$$%%- =$$ ##:%%*# $ % $
@@@@@ %- **+$$$* .= **%%%%%%%#=*###*#%$$$$$%%* *%%$$$$$%#*###*=#%%%%%%%** =. *$$$+** -% @@@@@
$ % $ #*%%:## $$= -%%$$$% **= #*:%$$$$$$%%%#. +=##%$$$$$$ #%%%%%%%%%%- = -%@@@@@@@$-@@@@@@
@@@$+ : -$ # %%%%%*# -#%$$$$=##+-- +%%%$$$%%:#:*##* :+ - %$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@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@</pre>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">
Line 1,367 ⟶ 1,421:
=={{header|EasyLang}}==
 
[https://easylang.onlinedev/apps/julia-set.html Run it]
 
<syntaxhighlight lang="text">
Line 1,836 ⟶ 1,890:
 
{{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 05.png]]
 
[[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}}==
Line 1,892 ⟶ 2,122:
}
}</syntaxhighlight>
 
 
=={{header|Haskell}}==
{{trans|AWK}}
Line 2,485 ⟶ 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,880 ⟶ 4,120:
=={{header|Wren}}==
{{libheader|DOME}}
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color
import "dome" for Window
 
Line 3,928 ⟶ 4,168:
 
var Game = JuliaSet.new(800, 600)</syntaxhighlight>
 
{{out}}
[[File:Wren-Julia_set.png|400px]]
 
=={{header|XPL0}}==
9,486

edits