[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: matlab m-file
From: |
Adam Majewski |
Subject: |
Re: matlab m-file |
Date: |
Fri, 28 Oct 2011 19:50:50 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110921 Thunderbird/3.1.15 |
Hi,
I have made code that works in my Octave ( see below).
Can I improve it ?
TIA
Adam
#----------code start -------------------
# http://www.dhushara.com/DarkHeart/DarkHeart.htm
# it is Octave m-file
# converted from matlab m-file by Chris King
# http://www.dhushara.com/DarkHeart/Viewers/source/siegel.m
#
# ------------- load packages ------------------------
pkg load image;
pkg load miscellaneous; # waitbar
# --------- definitions ------------------------------
function [potential myfl] = Mlevel(zx,zy,c,maxiter)
z = complex(zx,zy);
ang=0;
iter = 0;
while (iter < maxiter)&&(abs(z) > 0.001)&&(abs(z)<20)
h=z;
z=z*z+c;
hh=abs(z-h)*(z-h);
if iter>maxiter/2
ang=ang+hh;
end
iter = iter+1;
end
if iter < maxiter
potential = iter;
if abs(z)>=20 myfl=0;
else myfl=1;
end
else
potential=abs(ang);
myfl=2;
end
endfunction; # Mlevel
# ------------- const ------------------------------
# function siegel();
# integer ( screen ) coordinate
nx = 480;
ny = 480;
# image as a 2D matrix of 24 bit colors
MyImage = zeros(nx,ny,3); # matrix filled with 0
# world ( float) coordinate - dynamical (Z) plane
magc=0.65;
dSide=1/magc;
Zxmin = -dSide;
Zxmax = dSide;
Zymin = -dSide;
Zymax = dSide;
stepy = (Zymax - Zymin)/(ny - 1); # pixel height
stepx = (Zxmax - Zxmin)/(nx - 1); # pixel width
maxiter = 1200;
# fc(z) = z*z + c
th=pi*(-1+sqrt(5)); # rotation number or internal angle
d=exp(complex(0,th)); #
c =d/2-d*d/4; # point on boundary of main cardioid
# a=4;
pi4=pi/4;
# --------------- main ---------------------
waitbar(0,'Please wait...'); # info
# scan all pixels of image and comput color
for iy = 1:ny
Zy = Zymin + iy*stepy; # map from screen to world coordinate
for ix= 1:nx
Zx = Zxmin + ix*stepx;
[k myfl] = Mlevel(Zy,Zx,c, maxiter);
if myfl==2 MyImage(ix,iy,2) = abs(sin(5*k/10 + pi4));
else if myfl==1 MyImage(ix,iy,1) = abs(sin(2*k/10));
else MyImage(ix,iy,3) = abs(cos(2*k/10)); # myfl==0
end # else
end # else
end # for ix
waitbar(iy/ny);
end # for iy
# image
image(MyImage); # display image
imwrite(MyImage,'si2.jpg'); # save image to file
# this requires the ImageMagick "convert" utility.
#---------------- code end ----------
On 27.10.2011 17:49, Adam Majewski wrote:
Hi,
I woould like to run Matlab m-file :
http://www.dhushara.com/DarkHeart/Viewers/source/siegel.m
using GNU Octave, version 3.2.3
I have packages :
octave-3.2.3:2> pkg list
Package Name | Version | Installation directory
-------------------+---------+-----------------------
ftp *| 1.0.2 | /usr/share/octave/packages/3.2/ftp-1.0.2
general *| 1.1.3 | /usr/share/octave/packages/3.2/general-1.1.3
image *| 1.0.10 | /usr/share/octave/packages/3.2/image-1.0.10
io *| 1.0.9 | /usr/share/octave/packages/3.2/io-1.0.9
miscellaneous *| 1.0.9 | .../share/octave/packages/3.2/miscellaneous-1.0.9
missing-functions *| 1.0.2 |
.../octave/packages/3.2/missing-functions-1.0.2
plot *| 1.0.7 | /usr/share/octave/packages/3.2/plot-1.0.7
Program "works" without error codes but it does not creates image file.
What can I do to create image ?
TIA
Adam
- matlab m-file, Adam Majewski, 2011/10/27
- Re: matlab m-file,
Adam Majewski <=