Back
| Home
SurfPlot
- Function of Two Variables
This is an advanced Game-Editor Drawing Demo - meaning only the C-scripts are
provided and you should already know the mechanics of starting a canvas actor,
adding scripts, etc. If you are not at this level, please see the Let's
DRAW! Basic Drawing Tutorial.
z=cos(r) | z=exp(-r*r) |
z=sin(r)/r |
cos(x)*cos(y) | The
Monkey Saddle |
This
was another rewarding exercise in converting BASIC code into Game-Editor C-script.
//3D
Surface Builder
//Function of two variables plot
//Adapted from BASIC program
in book
//Fun Mathematics on your Microcomputer
//By Czes Kosniowski - Cambride
University Press - 1983
float
sx = 240;
float sy = 320;
float hy = 0;
float hx = 0;
float ratio
= 0.5;
float s = 0;
float aa = 0;
float bb = 0;
float x1 = 0;
float
y1 = 0;
float a = 0;
float b1 = 0;
float maxx = 0;
float z = 0;
float
v = 0;
float u = 0;
hy=sy/2;
hx=sx/2;
s=sqrt(2)/2;
aa=hx*s;
setpen(255,255,255,0,1);
for(a=
-1*aa; a<aa+5*s; a++)
{
maxx= -1*hy;
bb=aa+a-10*s*floor((a+abs(a))/(10*s));
for(b1
= -1*bb; b1<bb+s*4; b1=b1+(10*s)) //step 10*s
{
x1=s*(a+b1);
y1=s*(b1-a);
z=b1;
r=sqrt(x1*x1+y1*y1);
//Uncomment
the function you wish to use
z=5*cos(r/5)+b1; //Function 1: z=cos(r)
//z=100*exp(-r*r/600)+b1;
//Functio 2: z=exp(-r*r)
//z=125*sin(r/5)/r+b1; //Function 3: z=sin(r)/r
//z=10*cos(x1/10)*cos(y1/10)+b1;
//Function 4: cos(x)*cos(y)
//z=x1*y1*(x1-y1)*(x1+y1)/(8000*r)+b1; //Function
5: The Monkey Saddle
if(z<maxx)break;
maxx=z;
u=hx+a;
v=hy+z*s/ratio;
if(v<0
|| v>sy)break;
putpixel(u,v);
putpixel(100,100);
}
}
Enjoy!
How
many other great old "microcomputer" books are out there just waiting
to be re-coded and re-discovered?

See our new game site