11-12-2017, 03:59 PM
cas + pixels cmds
Example with standard CAS notation.
fract1( 320, 240, 10 ); [enter]
As function xcas compatibility
fract2( 320, 240, 10 ); [enter]
deltalist(time(fract2(320,240,10))); // only for Xcas to determine the execution time
using symmetry
With Python syntax.
fract3( 320, 240, 10 ); [enter]
XCAS only
deltalist(time(fract2(320,240,10))); [enter]
XCAS only
Example with standard CAS notation.
PHP Code:
#cas
fract1( X_, Y_, Nmax ):=
begin
// Mandelbrot fractal, not using symmetry.
local x, y, z, c, j, w, h, res1;
//freeze;
w := 2.7/X_;
h := -1.87/Y_;
res1 := [];
Y_ := Y_-1;
for y from 0 to Y_ do
c := -2.1 + i*(h*y+0.935);
for x from 0 to X_-1 do
z := 0;
for j from 0 to Nmax-1 do
if abs( z := z^2+c )>2 then break; end;
end;
res1.append( pixon_p( x, y, 126*j+2079 ));
c := c+w;
end;
end;
wait(0);
return "Done"; //return res1;
end;
#end
As function xcas compatibility
PHP Code:
#cas
function fract2( X_, Y_, Nmax )
// Mandelbrot fractal, not using symmetry.
local x, y, z, c, j, w, h, res1;
w := 2.7/X_;
h := -1.87/Y_;
res1 := [];
Y_ := Y_-1;
for y from 0 to Y_ do
c := -2.1 + i*(h*y+0.935);
for x from 0 to X_-1 do
z := 0;
for j from 0 to Nmax-1 do
if abs( z := z^2+c )>2 then break; end;
end;
res1.append( pixon_p( x, y, 126*j+2079 )); // Xcas pixon_p -> pixon
c := c+w;
end;
end;
wait(0); // Xcas: comment on this line
return "Done" ;
end;
#end
deltalist(time(fract2(320,240,10))); // only for Xcas to determine the execution time
using symmetry
PHP Code:
#cas
function fract2a( X_, Y_, Nmax )
// Mandelbrot fractal, using symmetry.
local x, y, z, c, j, w, h, res1, res2;
//freeze;
w := 2.7/X_;
h := -1.87/Y_;
res1:=makelist(-ceiling( X_*Y_/2 )-1);
res2 := res1;
Y_ := Y_-1;
for y from 0 to Y_/2 do
c := -2.1 + i*(h*y+0.935);
for x from 0 to X_-1 do
z := 0;
for j from 0 to Nmax-1 do
if abs( z := z^2+c )>2 then break; end;
end;
res1.append( pixon_p( x, y, 126*j+2079 ));
res2.append( pixon_p( x, Y_-y, 126*j+2079 ));
c := c+w;
end;
end;
wait(0);
return "Done"; // return res1,res2;
end;
#end
With Python syntax.
PHP Code:
#cas
def fract3( X_, Y_, Nmax ):
local x, y, z, c, j
for x in range( X_ ):
for y in range( Y_ ):
z = 0
c = 2.7*x / X_-2.1 + i*( -1.87*y/Y_ + .935)
for j in range( Nmax ):
z = z*z + c
if abs( z ) > 2: # abs(z = z*z+c)>2:
break
pixon_p( x, y, 255*20*j + 256 )
wait(0)
return "Done"
#end
XCAS only
PHP Code:
function fract2( X_, Y_, Nmax )
local x, y, z, c, j, w, h, res1;
w := 2.7/X_;
h := -1.87/Y_;
res1 := [];
Y_ := Y_-1;
for y from 0 to Y_ do
c := -2.1+i*(h*y+0.935);
for x from 0 to X_-1 do
z := 0;
for j from 0 to Nmax-1 do
if abs( z := z^2+c )>2 then break; end;
end;
res1.append( pixon( x, y, 126*j+2079 )); // hpprime pixon -> pixon_p
c := c+w;
end;
end;
return res1;
end
XCAS only
PHP Code:
function fract2a( X_, Y_, Nmax )
// Mandelbrot fractal, using symmetry.
local x, y, z, c, j, w, h, res1, res2;
w := 2.7/X_;
h := -1.87/Y_;
res1:=makelist(-ceiling( X_*Y_/2 )-1);
res2 := res1;
Y_ := Y_-1;
for y from 0 to Y_/2 do
c := -2.1 + i*(h*y+0.935);
for x from 0 to X_-1 do
z := 0;
for j from 0 to Nmax-1 do
if abs( z := z^2+c )>2 then break; end;
end;
res1.append( pixon( x, y, 126*j+2079 ));
res2.append( pixon( x, Y_-y, 126*j+2079 ));
c := c+w;
end;
end;
return res1,res2;
end