Julia set: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 12:
=={{header|Ada}}==
{{libheader|SDLAda}}
<langsyntaxhighlight Adalang="ada">with Ada.Numerics.Generic_Complex_Types;
 
with SDL.Video.Windows.Makers;
Line 104:
Window.Finalize;
SDL.Finalise;
end Julia_Set;</langsyntaxhighlight>
 
=={{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.
<langsyntaxhighlight lang="algol68">BEGIN
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</langsyntaxhighlight>
{{out}}
<pre>
Line 177:
The generated file is binary, and the graph can be made with Matlab's "imshow" function.
 
<langsyntaxhighlight lang="basic">
#!/usr/bin/hopper
 
Line 242:
{julia,"julia.dat"}save
exit(0)
</syntaxhighlight>
</lang>
 
=={{header|AWK}}==
{{trans|COBOL}}
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f JULIA_SET.AWK [real imaginary]
BEGIN {
Line 273:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 300:
==={{header|QBasic}}===
{{works with|QBasic}}
<langsyntaxhighlight QBasiclang="qbasic">escala = 1 / 81
zeroX = 160
zeroY = 100
Line 324:
NEXT y
NEXT x
END</langsyntaxhighlight>
 
==={{header|True BASIC}}===
{{trans|QBasic}}
<langsyntaxhighlight lang="qbasic">LIBRARY "GraphLib.tru"
 
LET escala = 1/81
Line 354:
NEXT y
NEXT x
END</langsyntaxhighlight>
 
==={{header|Yabasic}}===
<langsyntaxhighlight lang="yabasic">escala = 1/120
zeroX = 320
zeroY = 240
Line 382:
next y
next x
end</langsyntaxhighlight>
 
==={{header|GW-BASIC}}===
<langsyntaxhighlight lang="gwbasic">10 SCALE# = 1/81 : ZEROX = 160
20 ZEROY = 100 : MAXIT = 32
30 CR# = -.798 : CI# = .1618
Line 402:
160 PSET (X, Y), 1 + (I MOD 3)
170 NEXT Y
180 NEXT X</langsyntaxhighlight>
 
==={{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.)
<langsyntaxhighlight lang="locobasic">1 MODE 3 ' Note the CPCBasic-only screen mode!
2 FOR xp = 0 TO 639
3 FOR yp = 0 TO 399
Line 423:
15 PLOT xp, yp, c MOD 16
16 NEXT
17 NEXT</langsyntaxhighlight>
 
==={{header|Sinclair ZX81 BASIC}}===
Line 429:
 
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.
<langsyntaxhighlight lang="basic"> 10 LET C=-.8
20 LET D=.156
30 FOR V=43 TO 0 STEP -1
Line 444:
140 PLOT H,V
150 NEXT H
160 NEXT V</langsyntaxhighlight>
 
==={{header|ZX Spectrum Basic}}===
{{trans|Sinclair ZX81 BASIC}}
Higher resolution is obtainable, if you have the time to wait for it.
<langsyntaxhighlight lang="zxbasic"> 10 LET creal=-0.8
20 LET cimag=0.156
30 FOR v=-16 TO 16
Line 464:
140 PLOT h+100,150-v
150 NEXT h
160 NEXT v</langsyntaxhighlight>
{{out}}
Screenshot [http://edmundgriffiths.com/spectrumjulia.jpg here].
Line 474:
</pre>
Prints out usage on incorrect invocation. Requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library.
<syntaxhighlight lang="c">
<lang C>
#include<graphics.h>
#include<stdlib.h>
Line 553:
return 0;
}
</syntaxhighlight>
</lang>
 
=={{header|C sharp|C#}}==
{{trans|Python}}
<langsyntaxhighlight lang="csharp">using System.Drawing;
// Note: You have to add the System.Drawing assembly
// (right-click "references," Add Reference, Assemblies, Framework,
Line 605:
}
}
</syntaxhighlight>
</lang>
 
C# also makes it relatively easy to do a multi-threaded version, which should run faster than the above:
 
<langsyntaxhighlight lang="csharp">
public struct CalculatedPoint
{
Line 659:
bitmap.SetPixel(cp.x, cp.y, colors[cp.i]);
bitmap.Save("julia-set-multi.png");
}</langsyntaxhighlight>
 
=={{header|C++}}==
[[File:JuliaSetCpp.png|200px|thumb|right]]
<langsyntaxhighlight lang="cpp">
#include <windows.h>
#include <string>
Line 799:
julia j; j.draw( c ); return 0;
}
</syntaxhighlight>
</lang>
 
=={{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>.
<langsyntaxhighlight lang="cobol">IDENTIFICATION DIVISION.
PROGRAM-ID. JULIA-SET-PROGRAM.
DATA DIVISION.
Line 861:
MOVE SPACE TO WS-PLOT-CHARACTER.
MOVE Z-REAL TO X.
MOVE Z-IMAGINARY TO Y.</langsyntaxhighlight>
{{out}}
<pre>
Line 900:
=={{header|Crystal}}==
{{trans|Ruby}}
<langsyntaxhighlight lang="ruby">require "complex"
 
def julia(c_real, c_imag)
Line 920:
julia(-0.8, 0.156)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 977:
{{libheader| Vcl.Graphics}}
{{Trans|C#}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Julia_set;
 
Line 1,033:
bitmap.Free;
end.
</syntaxhighlight>
</lang>
=={{header|EasyLang}}==
 
[https://easylang.online/apps/julia-set.html Run it]
 
<syntaxhighlight lang="text">cx = -0.7
cy = 0.27015
for y range 300
Line 1,057:
rect 0.4 0.4
.
.</langsyntaxhighlight>
 
=={{header|Elixir}}==
{{trans|AWK}}
<langsyntaxhighlight lang="elixir">defmodule Julia do
def set(c_real, c_imag) do
IO.puts "#{c_real}, #{c_imag}"
Line 1,085:
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)</langsyntaxhighlight>
 
{{out}}
Line 1,145:
 
=={{header|Emacs Lisp}}==
<langsyntaxhighlight lang="lisp">; === Graphical Julia set display in Emacs =====================
 
(setq julia-size (cons 300 200))
Line 1,199:
(insert-image (string-to-image all)))
 
(julia-pic)</langsyntaxhighlight>
 
=={{header|F_Sharp|F#}}==
''' Basic generation code '''
<langsyntaxhighlight lang="fsharp">
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:
loop 0 (initzx x) (initzy y)
[0..height-1] |> List.map(fun y->[0..width-1] |> List.map (calc y))
</syntaxhighlight>
</lang>
 
''' Text display '''
<langsyntaxhighlight lang="fsharp">
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>
</lang>
{{out}}
<pre>
Line 1,252:
 
''' Graphic Display '''
<langsyntaxhighlight lang="fsharp">
open System.Drawing
open System.Windows.Forms
Line 1,273:
 
showGraphic toColor 640 480 -0.7 0.27015 1.0 5000
</syntaxhighlight>
</lang>
 
=={{header|Fortran}}==
Line 1,281:
The procedure calls, on lines 12 and 13, control the display window on the complex plane.
 
<langsyntaxhighlight lang="fortran">C ==================================================================
PROGRAM JULIA
C ------------------------------------------------------------------
Line 1,335:
10 CONTINUE
RETURN
END</langsyntaxhighlight>
{{out}}
<pre>
Line 1,384:
{{works with|Fortran|95 and later}}
[[File:Julia-set-gray.png|480px|thumb|right]]
<langsyntaxhighlight lang="fortran">! ==============================================================================
module julia_mod
! ----------------------------------------------------------------------------
Line 1,498:
call juliaPGM( DEF_FSPC, NUM_ROWS, NUM_COLS, DEF_UL, DEF_LR, DEF_SEED )
 
end program julia</langsyntaxhighlight>
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">
#define pix 1./120
#define zero_x 320
Line 1,556:
while inkey=""
wend
end</langsyntaxhighlight>
 
=={{header|Fōrmulæ}}==
Line 1,568:
=={{header|Go}}==
Using the Goroutines results in a performance improvement of about three times on my four-core machine.
<langsyntaxhighlight Golang="go">package main
 
import (
Line 1,620:
log.Fatal(err)
}
}</langsyntaxhighlight>
=={{header|Haskell}}==
{{trans|AWK}}
<langsyntaxhighlight lang="haskell">import System.Environment (getArgs)
 
plotChar :: Int -> Float -> Float -> Float -> Float -> Char
Line 1,646:
mapM_ putStrLn $ [-100,-96..100] >>= \y ->
[[-280,-276..280] >>= \x -> [plotChar 50 cReal cImag (y/100) (x/200)]]
</syntaxhighlight>
</lang>
{{out}}
<pre style="font-size: 50%;">
Line 1,703:
</pre>
{{trans|F#}}
<langsyntaxhighlight lang="haskell">{-# LANGUAGE LambdaCase #-}
 
getJuliaValues :: Float -> Float -> Float -> Float -> Float -> Int -> [[Int]]
Line 1,719:
 
main :: IO ()
main = mapM_ (putStrLn . fmap (\case 0 -> '#'; _ -> ' ')) (getJuliaValues 140 50 (-0.8) 0.156 1.0 50) </langsyntaxhighlight>
{{out}}
<pre style="font-size: 50%;">
Line 1,776:
=={{header|J}}==
[[File:example-j-julia.png|200px|thumb|right]]
<langsyntaxhighlight lang="j">load '~addons/graphics/fvj4/complex_dynamics.ijs'
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</langsyntaxhighlight>
 
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:
[[File:julia_set_java.png|200px|thumb|right]]
{{works with|Java|8}}
<langsyntaxhighlight lang="java">import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
Line 1,849:
});
}
}</langsyntaxhighlight>
To multi-thread, simply swap the for loop for a parallel IntStream.
<langsyntaxhighlight lang="java">
import javax.swing.*;
import java.awt.*;
Line 1,915:
}
}
</syntaxhighlight>
</lang>
 
=={{header|JavaScript}}==
take a look [http://paulo-jorente.de/tests/juliaset/ here].
<langsyntaxhighlight lang="javascript">
var maxIterations = 450, minX = -.5, maxX = .5,
minY = -.5, maxY = .5, wid, hei, ctx,
Line 1,976:
drawFractal();
}
</syntaxhighlight>
</lang>
 
=={{header|jq}}==
{{trans|awk}}
 
<langsyntaxhighlight lang="jq"># Example values:
# $re : -0.8
# $im : 0.156
Line 1,998:
else .x = .z_real | .y = .z_imag
end )
| .plot ), "\n")</langsyntaxhighlight>
 
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:
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.
 
<langsyntaxhighlight lang="julia">
function iter(z,c)
n = 0
Line 2,029:
writedlm(out, [f(width,height,a,b,i,j) for j = 1:height, i = 1:width], '\n')
end
</syntaxhighlight>
</lang>
 
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:
 
[[File:JuliaSet_julia.png|250px|thumb|right]]
<langsyntaxhighlight lang="julia">using Images
 
@inline function hsv2rgb(h, s, v)
Line 2,092:
end
 
julia_set()</langsyntaxhighlight>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">
import java.awt.*
import java.awt.image.BufferedImage
Line 2,148:
isVisible = true
}
}</langsyntaxhighlight>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">local cmap = { [0]=" ", ".", ":", "-", "=", "+", "*", "#", "%", "$", "@" }
for y = -1.0, 1.0, 0.05 do
for x = -1.5, 1.5, 0.025 do
Line 2,162:
end
print()
end</langsyntaxhighlight>
{{out}}
<pre style="font-size: 50%;">
Line 2,211:
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
<langsyntaxhighlight Mathematicalang="mathematica">JuliaSetPoints[-0.77 + 0.22 I, "ClosenessTolerance" -> 0.01]</langsyntaxhighlight>
Visualize the same Julia set
<langsyntaxhighlight Mathematicalang="mathematica">JuliaSetPlot[-0.77 + 0.22 I]</langsyntaxhighlight>
 
=={{header|Nim}}==
{{trans|C#}}
{{libheader|imageman}}
<langsyntaxhighlight Nimlang="nim">import lenientops
import imageman
 
Line 2,248:
 
# Save into a PNG file.
image.savePNG("julia.png", compression = 9)</langsyntaxhighlight>
 
=={{header|Perl}}==
[[File:JuliaSet.perl.png|250px|thumb|right]]
<langsyntaxhighlight lang="perl">use Imager;
 
my($w, $h, $zoom) = (800, 600, 1);
Line 2,276:
}
 
$img->write(file => 'julia_set.png');</langsyntaxhighlight>
 
=={{header|Phix}}==
{{libheader|Phix/pGUI}}
Interactive gui (zoom/pan incomplete).
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Julia_set.exw
Line 2,438:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
 
=={{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">
<lang PHP>
set_time_limit(300);
header("Content-Type: image/png");
Line 2,525:
 
Julia::start();
</syntaxhighlight>
</lang>
 
=={{header|Processing}}==
<langsyntaxhighlight lang="java">
float cX = -0.7;
float cY = 0.27015;
Line 2,557:
noLoop();
}
</syntaxhighlight>
</lang>
 
==={{header|Processing Python mode}}===
{{trans|Processing}}
 
<langsyntaxhighlight lang="python">from __future__ import division
 
cX = -0.7
Line 2,584:
colorMode(HSB)
c = color(i / maxIter * 255, 255, 255 if i > 1 else 0)
set(x, y, c)</langsyntaxhighlight>
noLoop()
 
Line 2,591:
{{trans|zkl}}
 
<langsyntaxhighlight lang="python">from PIL import Image
 
if __name__ == "__main__":
Line 2,614:
pix[x][y] = (i << 21) + (i << 10) + i*8
bitmap.show()</langsyntaxhighlight>
 
===Vectorized===
Line 2,620:
 
[https://imgur.com/a/o3j9Zzn Example output.]
<langsyntaxhighlight lang="python">"""
Solution from:
https://codereview.stackexchange.com/questions/210271/generating-julia-set
Line 2,695:
origin='lower')
plt.show()
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
[[File:JuliaSet_racket.png|250px|thumb|right]]
<langsyntaxhighlight lang="racket">
;; Based on Mandelbrot code (GPL) from:
;; https://github.com/hebr3/Mandelbrot-Set-Racket/blob/master/Mandelbrot.v6.rkt
Line 2,809:
 
(save-image M-Image "julias.png")
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
Line 2,816:
{{works with|Rakudo|2016.03}}
[[File:Julia-set-perl6.png|250px|thumb|right]]
<syntaxhighlight lang="raku" perl6line>use Image::PNG::Portable;
 
my ($w, $h) = 800, 600;
Line 2,853:
when 5/6..1 { $c, 0, $x }
} ).map: ((*+$m) * 255).Int]
}</langsyntaxhighlight>
 
=={{header|REXX}}==
Line 2,859:
:::: which is a
{{trans|COBOL}}
<langsyntaxhighlight lang="rexx">/*REXX program displays an ASCII plot (character plot) of a Julia set. */
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:
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. */</langsyntaxhighlight>
This REXX program makes use of &nbsp; '''scrsize''' &nbsp; 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:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Julia Set
 
Line 3,121:
}
label1 { setpicture(p1) show() }
</syntaxhighlight>
</lang>
 
=={{header|Ruby}}==
{{trans|AWK}}
<langsyntaxhighlight lang="ruby">def julia(c_real, c_imag)
puts Complex(c_real, c_imag)
-1.0.step(1.0, 0.04) do |v|
Line 3,142:
end
 
julia(-0.8, 0.156)</langsyntaxhighlight>
 
{{out}}
Line 3,199:
{{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
<langsyntaxhighlight lang="ruby">
# frozen_string_literal: true
 
Line 3,227:
no_loop
end
</syntaxhighlight>
</lang>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">extern crate image;
 
use image::{ImageBuffer, Pixel, Rgb};
Line 3,276:
let _ = img.save("output.png");
 
}</langsyntaxhighlight>
 
=={{header|Scala}}==
===Java Swing Interoperability===
<langsyntaxhighlight Scalalang="scala">import java.awt._
import java.awt.image.BufferedImage
 
Line 3,337:
)
 
}</langsyntaxhighlight>
 
=={{header|Sidef}}==
[[File:JuliaSet_sidef.png|250px|thumb|right]]
<langsyntaxhighlight lang="ruby">require('Imager')
 
var (w, h) = (640, 480)
Line 3,361:
}
 
img.write(file => "JuliaSet_sidef.png")</langsyntaxhighlight>
 
This version generates an ASCII representation:
<langsyntaxhighlight lang="ruby">var (w, h) = (141, 50)
 
var maxIter = 40
Line 3,379:
}
print "\n"
}</langsyntaxhighlight>
{{out}}
<pre style="font-size: 50%;"> ##
Line 3,425:
=={{header|Wren}}==
{{libheader|DOME}}
<langsyntaxhighlight lang="ecmascript">import "graphics" for Canvas, Color
import "dome" for Window
 
Line 3,472:
}
 
var Game = JuliaSet.new(800, 600)</langsyntaxhighlight>
 
=={{header|zkl}}==
Line 3,478:
{{trans|Java}}
[[File:JuliaSet.zkl.jpg|250px|thumb|right]]
<langsyntaxhighlight lang="zkl">fcn juliaSet{
w,h,zoom:=800,600, 1;
bitmap:=PPM(w,h,0xFF|FF|FF); // White background
Line 3,500:
 
bitmap.writeJPGFile("juliaSet.jpg",True);
}();</langsyntaxhighlight>
10,333

edits