Kronecker product based fractals: Difference between revisions

Added FreeBASIC
imported>Maxima enthusiast
(Added FreeBASIC)
 
(3 intermediate revisions by 3 users not shown)
Line 335:
SDL.Finalise;
end Kronecker_Fractals;</syntaxhighlight>
 
=={{header|ALGOL 68}}==
<syntaxhighlight lang="algol68">
BEGIN # Kronecker product based fractals - translated from the Kotlin sample #
 
MODE MATRIX = FLEX[ 1 : 0, 1 : 0 ]INT;
 
PROC kronecker product = ( MATRIX a in, b in )MATRIX:
BEGIN
MATRIX a = a in[ AT 0, AT 0 ], b = b in[ AT 0, AT 0 ];
INT m = 1 UPB a + 1, n = 2 UPB a + 1;
INT p = 1 UPB b + 1, q = 2 UPB b + 1;
INT rtn = m * p, ctn = n * q;
[ 0 : rtn - 1, 0 : ctn - 1 ]INT r;
FOR i FROM 0 TO rtn - 1 DO FOR j FROM 0 TO ctn - 1 DO r[ i, j ] := 0 OD OD;
FOR i FROM 0 TO m - 1 DO
FOR j FROM 0 TO n - 1 DO
FOR k FROM 0 TO p - 1 DO
FOR l FROM 0 TO q - 1 DO
r[ p * i + k, q * j + l ] := a[ i, j ] * b[ k, l ]
OD
OD
OD
OD;
r
END # kronecker product # ;
 
PROC kronecker power = ( MATRIX a, INT n )MATRIX:
BEGIN
MATRIX pow := a;
FOR i TO n - 1 DO pow := kronecker product( pow, a ) OD;
pow
END # kronecker power # ;
 
PROC print matrix = ( STRING text, MATRIX m )VOID:
BEGIN
print( ( text, " fractal :", newline ) );
FOR i FROM 1 LWB m TO 1 UPB m DO
FOR j FROM 2 LWB m TO 2 UPB m DO
print( ( IF m[ i, j ] = 1 THEN "*" ELSE " " FI ) )
OD;
print( ( newline ) )
OD;
print( ( newline ) )
END # print matrix # ;
 
MATRIX a := MATRIX( ( 0, 1, 0 )
, ( 1, 1, 1 )
, ( 0, 1, 0 )
);
print matrix( "Vicsek", kronecker power( a, 4 ) );
 
a := MATRIX( ( 1, 1, 1 )
, ( 1, 0, 1 )
, ( 1, 1, 1 )
);
print matrix( "Sierpinski carpet", kronecker power( a, 4 ) )
END
</syntaxhighlight>
{{out}}
Same as the Kotlin sample.
 
=={{header|C}}==
Line 1,370 ⟶ 1,431:
 
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vbnet">Type Matrix
As Integer x
As Integer y
As Integer Ptr Dato
End Type
 
Function kroneckerProduct(a As Matrix, b As Matrix) As Matrix
Dim As Integer m = a.x, n = a.y
Dim As Integer p = b.x, q = b.y
Dim As Matrix r
r.x = m * p
r.y = n * q
r.dato = Callocate(r.x * r.y, Sizeof(Integer))
Dim As Integer i, j, k, l
For i = 0 To m - 1
For j = 0 To n - 1
For k = 0 To p - 1
For l = 0 To q - 1
r.dato[(p * i + k) * r.y + (q * j + l)] = a.dato[i * a.y + j] * b.dato[k * b.y + l]
Next
Next
Next
Next
Return r
End Function
 
Function kroneckerPower(a As Matrix, n As Integer) As Matrix
Dim As Matrix pow = a
For i As Integer = 1 To n - 1
pow = kroneckerProduct(pow, a)
Next
Return pow
End Function
 
Sub printMatrix(text As String, m As Matrix)
Dim As Integer i, j
Print text & " fractal:"
For i = 0 To m.x - 1
For j = 0 To m.y - 1
Print Iif(m.dato[i * m.y + j] = 1, "*", " ");
Next
Print
Next
Print
End Sub
 
Dim As Matrix a = Type(3, 3, Callocate(9, Sizeof(Integer)))
a.dato[0] = 0: a.dato[1] = 1: a.dato[2] = 0
a.dato[3] = 1: a.dato[4] = 1: a.dato[5] = 1
a.dato[6] = 0: a.dato[7] = 1: a.dato[8] = 0
printMatrix("Vicsek", kroneckerPower(a, 4))
 
a.dato[0] = 1: a.dato[1] = 1: a.dato[2] = 1
a.dato[3] = 1: a.dato[4] = 0: a.dato[5] = 1
a.dato[6] = 1: a.dato[7] = 1: a.dato[8] = 1
printMatrix("Sierpinski carpet", kroneckerPower(a, 4))
 
Sleep</syntaxhighlight>
{{out}}
<pre>Same as Kotlin entry.</pre>
 
=={{header|gnuplot}}==
Line 1,453 ⟶ 1,576:
[[File:Fōrmulæ - Kronecker product based fractals 14.png]]
 
(click or tap to enlargesee in real size)
 
[[File:Fōrmulæ - Kronecker product based fractals 15.png|250px|link=https://static.wikiforge.net/rosettacodewikitide/5/55/F%C5%8Drmul%C3%A6_-_Kronecker_product_based_fractals_15.png256px]]
 
=={{header|Go}}==
Line 3,780 ⟶ 3,903:
{{trans|Kotlin}}
{{libheader|Wren-matrix}}
<syntaxhighlight lang="ecmascriptwren">import "./matrix" for Matrix
 
var kroneckerPower = Fn.new { |m, n|
2,122

edits