This section is meant for programmers using Delphi. A visual file is a dynamic link library (.dll) file.
Calenz is written in Delphi 3 and to compile a visual, you will need Delphi 3 or
newer. A visual example is shown below and you can copy and paste the code into
a new file and call it CalenzVis.dpr or you can download it from Calenz's web
site. Open the project file (.dpr) from Delphi and compile it. The output will
be 'calenzvis.dll' and copy it as '<filename>.v' into the 'vis' directory
of Calenz. Load the visual file from Calenz and use a skin with a visual area to
see the result.
There is a pointer to a mask array (ppicmask) which defines the shape of the visual area. This can
be used as a boundary for your visuals that may involve particles, for example,
the 'fireworks.v' and 'fireball.v' visuals. The 'mousex' and 'mousey' in the Vis
procedure can be used to add some user interaction to your visuals like creating
water ripples over the mouse cursor in the 'water.v' visual or changing pictures
in the PhotoDisplay visual.
/// StarDust.v example
library CalenzVis;
uses
SysUtils,Classes,Math;
type
pictypeptr=^pictype;
pictype=array[0..400*400-1] of integer; ///array for main window size
ctype=array[0..100] of integer; // array for indexed colour entries
ycalctypeptr=^ycalctype;
ycalctype=array[0..400-1] of integer; //array for pre-calculated y values
var
pycalc: ycalctypeptr;
ppicmask: pictypeptr;
vxx,vyy,vxpos,vypos,fheight: integer;
vptr: pictypeptr;
///Calenz will initialize the visual using this procedure when a visual is
loaded
///mxpos,mypos: visual area position on main form
///mxx,myy: width and height of visual area
///mpicmask: mask of visual area
///mycalc: pre-calculated y values (calcauted by each y value multiplied by mxx)
procedure VisInit(mxpos,mypos,mxx,myy: integer; mpicmask:
pictype;mycalc:ycalctype);stdcall;
begin
randomize;
/// use local variables to reference variables in main Calenz program
pycalc:= @mycalc; ppicmask:= @mpicmask;
vxpos:= mxpos; vypos:= mypos; vxx:= mxx; vyy:= myy;
vptr:= nil; new(vptr);
fillchar(vptr^,sizeof(pictype),0); /// initialize virtual buffer
///Stardust startup code
if myy div 50<2 then fheight:= 1
else
if myy div 50>=2 then fheight:= 2
else if myy div 50>=4 then fheight:= 3;
end;
///Calenz will run this procedure at a specified frame rate.
///mpic: array of colour bits for the display of rendered visual
///mc: colour palette of entries 0..100 from Calenz main program
///where 0..9 is a gradient from black to colour1
///and 10..90 is a gradient from colour1 to colour2
///and where 90..100 is a gradient from colour2 to white
///mousex,mousey: position of mouse cursor with respect to the main Calenz window
procedure Vis(var mpic: pictype;mc:ctype;mousex,mousey: integer)stdcall;
var
/// Stardust variables
i,j,tmpint,tmpint2,tmpint3,ccolor: integer;
begin
///put pixels in virtual buffer
for i:= 0 to vxx do
begin
tmpint:= random(50)+50;
tmpint2:= i+pycalc^[random(3)+1];
if tmpint2<=vxx*vyy-1 then vptr^[tmpint2]:= tmpint;
end;
/// Check that mouse position is within visual area and displays pixels on that
point
if (((mousex>=vxpos) and (mousex<=vxpos+vxx)) and ((mousey>=vypos)
and (mousey<=vypos+vyy))) then
begin
for i:= -3 to 3 do
for j:= -3 to 3 do
begin
tmpint:= random(90)+10;
tmpint2:= mousex-vxpos+i+pycalc^[vypos+vyy-mousey+j];
if tmpint2<=vxx*vyy-1 then vptr^[tmpint2]:= tmpint;
end;
end;
/// rendering code
for j:= vyy-1-1 downto 1 do
for i:= 1 to vxx-1 do
begin
tmpint:= i+pycalc^[j];
ccolor:= vptr^[tmpint]-random(5-fheight);
if ccolor<0 then ccolor:= 0;
if ccolor>100 then ccolor:= 100; /// set colour limits
tmpint2:= tmpint+vxx*(fheight+random(1));
/// check that the new pixel position does not exceed array
if tmpint2<=vxx*vyy-1 then vptr^[tmpint2]:= ccolor;
mpic[tmpint]:= mc[ccolor];
/// get RGB colour from Calenz palette
/// if you want to use RGB colours, use
/// 'mpic[tmpint]:= ccolor;'
/// where ccolor:= ((r shl 8) shl 8) or (g shl 8) or b;
end;
end;
///Calenz will do any clean up code for the visual using this procedure
procedure VisClose;stdcall;
begin
/// release memory
try
if vptr<> nil then dispose(vptr);
except
end;
end;
exports
VisInit index 1,
Vis index 2,
VisClose index 3;
begin
end.