📄 democode.pas
字号:
glRotate(DemoTime/20, 0, 1, 0);
glRotate(DemoTime/10, 0, 0, 1);
C :=DemoTime/1000;
for i := 0 to numVertices-1 do
begin
Y := 1 + 0.1*((1 - cos(LU[i].X + C*5)) +
(1 - cos(LU[i].Y + C*7)) +
(1 - cos(LU[i].Z + C*8)));
blob.vertex[i].x := sphere.vertex[i].x * Y;
blob.vertex[i].y := sphere.vertex[i].y * Y;
blob.vertex[i].z := sphere.vertex[i].z * Y;
end;
glPushMatrix();
glScale(0.015, 0.015, 0.015);
glRotate(-DemoTime/50, 0, 0, 1);
glBindTexture(GL_TEXTURE_2D, ColorsTex);
renderBlob(blob);
glPopMatrix();
end;
{------------------------------------------------------------------}
{ Draw a tentacle }
{------------------------------------------------------------------}
procedure DrawTentacle(const Step : Integer; const Angle, TwistAngle : glFloat);
begin
if Step = 19 then exit;
glTranslate(2.25, 0, 0);
glRotatef(Angle, 0, 1, 0);
glRotatef(TwistAngle, 1, 0, 0);
glCallList(CubeDL);
glScale(0.9, 0.9, 0.9);
DrawTentacle(Step+1, Angle, TwistAngle);
end;
{------------------------------------------------------------------}
{ Draw the entire tentacle object }
{------------------------------------------------------------------}
procedure DrawObject(const DemoTime : Integer);
var Angle, TwistAngle : glFloat;
begin
glCallList(CubeDL);
glScale(0.9, 0.9, 0.9);
Angle :=25*sin(DemoTime/600);
TwistAngle :=25*sin(DemoTime/800);
glPushMatrix();
DrawTentacle(0, Angle, TwistAngle);
glPopMatrix();
Angle :=25*cos(DemoTime/500);
TwistAngle :=25*sin(DemoTime/800);
glRotate(90, 0, 1, 0);
glPushMatrix();
DrawTentacle(0, Angle, -TwistAngle);
glPopMatrix();
Angle :=25*sin(DemoTime/500);
TwistAngle :=25*cos(DemoTime/600);
glRotate(90, 0, 1, 0);
glPushMatrix();
DrawTentacle(0, Angle, TwistAngle);
glPopMatrix();
Angle :=25*sin(DemoTime/600);
TwistAngle :=25*sin(DemoTime/400);
glRotate(90, 0, 1, 0);
glPushMatrix();
DrawTentacle(0, Angle, -TwistAngle);
glPopMatrix();
Angle :=25*sin(DemoTime/600);
TwistAngle :=25*cos(DemoTime/400);
glRotate(90, 0, 0, 1);
glPushMatrix();
DrawTentacle(0, Angle, TwistAngle);
glPopMatrix();
Angle :=25*sin(DemoTime/400);
TwistAngle :=25*cos(DemoTime/800);
glRotate(180, 0, 0, 1);
glPushMatrix();
DrawTentacle(0, -Angle, -TwistAngle);
glPopMatrix();
end;
{------------------------------------------------------------------}
{ Draw the tentacle scene }
{------------------------------------------------------------------}
procedure drawTentacles;
var X : glFloat;
DemoTime : Integer;
begin
DemoTime :=ElapsedTime - 22000;
glTranslate(0, -0.05, -3);
X :=DemoTime/10000;
if X > 0.1 then X :=0.1;
glScale(X, X, X);
// Rectangle (blob frame)
glDisable(GL_TEXTURE_2D);
glLineWidth(3);
glBegin(GL_LINE_LOOP);
glVertex3f(-9, -9, 0.0);
glVertex3f( 9, -9, 0.0);
glVertex3f( 9, 9, 0.0);
glVertex3f(-9, 9, 0.0);
glEnd;
glEnable(GL_TEXTURE_2D);
// Draw the blue tentacles
glPushMatrix();
// wobly movement
if ELapsedTime > 29200 then
glTranslate(4*cos(ElapsedTime/200), 3*cos(ElapsedTime/230), 0);
glRotatef(DemoTime/10, 1, 0, 0);
glRotatef(DemoTime/15, 0, 1, 0);
glBindTexture(GL_TEXTURE_2D, colorsTex); // Bind the Texture to the object
DrawObject(DemoTime);
glPopMatrix;
end;
procedure ShowScroller;
var DemoTime : Integer;
X, Y, C : glFloat;
T, I : Integer;
begin
DemoTime :=ElapsedTime - 44000;
// --- Drawing the Blob and Rectangle --- //
glPushMatrix();
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glColor3f(1.0, 1.0, 1.0);
glScale(2, 2, 1);
glTranslate(0, 0, -2);
// Rectangle (blob frame)
glDisable(GL_TEXTURE_2D);
glLineWidth(3);
glBegin(GL_LINE_LOOP);
glVertex3f(-0.32, -0.28, 0.0);
glVertex3f( 0.32, -0.28, 0.0);
glVertex3f( 0.32, 0.28, 0.0);
glVertex3f(-0.32, 0.28, 0.0);
glEnd;
glEnable(GL_TEXTURE_2D);
// Blob
glRotate(DemoTime/20, 0, 1, 0);
glRotate(DemoTime/10, 0, 0, 1);
C :=DemoTime/1000;
for i := 0 to numVertices-1 do
begin
Y := 1 + 0.1*((1 - cos(LU[i].X + C*5)) +
(1 - cos(LU[i].Y + C*7)) +
(1 - cos(LU[i].Z + C*8)));
blob.vertex[i].x := sphere.vertex[i].x * Y;
blob.vertex[i].y := sphere.vertex[i].y * Y;
blob.vertex[i].z := sphere.vertex[i].z * Y;
end;
glScale(0.015, 0.015, 0.015);
glRotate(-DemoTime/50, 0, 0, 1);
glBindTexture(GL_TEXTURE_2D, ColorsTex);
renderBlob(blob);
glPopMatrix();
T :=Round(DemoTime/15);
glWrite(350, 10+T, 'A 64K Demo by Jan Horn');
glWrite(300, -60+T, 'Well that is all there is to this 64K demo');
glWrite(300, -100+T, 'I started it on the morning Optimize 2001');
glWrite(300, -140+T, 'and just didnt have enough time to finish');
glWrite(300, -180+T, 'it. I also wasted to much time trying to get');
glWrite(300, -220+T, 'a midi file in the app resource and playing');
glWrite(300, -260+T, 'it from there.');
glWrite(300, -320+T, 'Total coding time = 2 hours.');
glWrite(300, -380+T, 'The demo has to submited now and I still');
glWrite(300, -420+T, 'have a few KB left. Guess I wont finish it now');
glWrite(300, -480+T, 'The demo and source will be available on ');
glWrite(300, -520+T, 'my site as usual.');
glWrite(300, -580+T, ' www.sulaco.co.za');
end;
procedure drawDemo;
var I, J : Integer;
C, J1, J2 : glFloat;
X, Y : glFloat;
Angle : glFloat;
A1, A2, A3, A4 : glFloat;
DemoTime : Integer;
begin
DemoTime :=ElapsedTime;
// --- Drawing the tunnel --- //
glDisable(GL_BLEND);
glPushMatrix();
glTranslatef(0.0,0.0,-2);
Angle := DemoTime/14;
//--- Outside tunnel ---//
// setup tunnel coordinates
A1 := sin(Angle/27);
A2 := cos(Angle/25);
A3 := cos(Angle/13);
A4 := sin(Angle/17);
for I :=0 to 16 do
begin
X :=cos(PI_8*I);
Y :=sin(PI_8*I);
for J :=0 to 32 do
begin
Tunnels[I, J].X :=(3 - J/12)*X + 2.0*sin((Angle+2*j)/27) + cos((Angle+2*j)/13) - 2*A1 - A3;
Tunnels[I, J].Y :=(3 - J/12)*Y + 2.5*cos((Angle+2*j)/25) + sin((Angle+2*j)/17) - 2*A2 - A4;
Tunnels[I, J].Z :=-J;
end;
end;
// draw tunnel and fade out last few
glBindTexture(GL_TEXTURE_2D, BlueTex);
For J :=0 to 31 do
begin
J1 :=J/32 + Angle*TUNNEL_SPEED; // precalculate texture v coords for speed
J2 :=(J+1)/32 + Angle*TUNNEL_SPEED;
// near the end of the tunnel, fade the effect away
if J > 24 then
C :=1.0-(J-24)/10
else
C :=1.0;
// fade in tunnel
if DemoTime < 500 then
C :=C*DemoTime/500;
glColor3f(C, C, C);
glBegin(GL_QUADS);
For I :=0 to 15 do
begin
glTexCoord2f((I-1)/8, J1); glVertex3f(Tunnels[ I, J ].X, Tunnels[ I, J ].Y, Tunnels[ I, J ].Z);
glTexCoord2f(( I )/8, J1); glVertex3f(Tunnels[I+1, J ].X, Tunnels[I+1, J ].Y, Tunnels[I+1, J ].Z);
glTexCoord2f(( I )/8, J2); glVertex3f(Tunnels[I+1, J+1].X, Tunnels[I+1, J+1].Y, Tunnels[I+1, J+1].Z);
glTexCoord2f((I-1)/8, J2); glVertex3f(Tunnels[ I, J+1].X, Tunnels[ I, J+1].Y, Tunnels[ I, J+1].Z);
end;
glEnd();
end;
glColor3f(1, 1, 1);
glPopMatrix;
if (DemoTime > 4000) AND (DemoTime < 22000) then drawBlob;
if (DemoTime > 22000) AND (DemoTime < 42000) then drawTentacles;
if (DemoTime > 44000) then
ShowScroller;
end;
procedure initData;
var I : Integer;
begin
LoadTexture('Colors.bmp', ColorsTex, TRUE); // Load the Texture
LoadTexture('Blue.bmp', BlueTex, TRUE); // Load the Texture
CreateSphere(blob);
Sphere :=Blob;
for I :=0 to numVertices-1 do
begin
LU[i].X := ArcTan(sphere.vertex[i].x, sphere.vertex[i].y) * 5;
LU[i].Y := ArcTan(sphere.vertex[i].x, sphere.vertex[i].z) * 6;
LU[i].Z := ArcTan(sphere.vertex[i].y, sphere.vertex[i].z) * 8;
end;
// Initialise tentacles
CubeDL :=glGenLists(1);
glNewList(CubeDL, GL_COMPILE);
glBegin(GL_QUADS);
// Front Face
glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, 1.0);
glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0, 1.0);
glTexCoord2f(1.0, 1.0); glVertex3f( 1.0, 1.0, 1.0);
glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, 1.0);
// Back Face
glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, -1.0, -1.0);
glTexCoord2f(1.0, 1.0); glVertex3f(-1.0, 1.0, -1.0);
glTexCoord2f(0.0, 1.0); glVertex3f( 1.0, 1.0, -1.0);
glTexCoord2f(0.0, 0.0); glVertex3f( 1.0, -1.0, -1.0);
// Top Face
glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, -1.0);
glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, 1.0, 1.0);
glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, 1.0, 1.0);
glTexCoord2f(1.0, 1.0); glVertex3f( 1.0, 1.0, -1.0);
// Bottom Face
glTexCoord2f(1.0, 1.0); glVertex3f(-1.0, -1.0, -1.0);
glTexCoord2f(0.0, 1.0); glVertex3f( 1.0, -1.0, -1.0);
glTexCoord2f(0.0, 0.0); glVertex3f( 1.0, -1.0, 1.0);
glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, -1.0, 1.0);
// Right face
glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0, -1.0);
glTexCoord2f(1.0, 1.0); glVertex3f( 1.0, 1.0, -1.0);
glTexCoord2f(0.0, 1.0); glVertex3f( 1.0, 1.0, 1.0);
glTexCoord2f(0.0, 0.0); glVertex3f( 1.0, -1.0, 1.0);
// Left Face
glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, -1.0);
glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, -1.0, 1.0);
glTexCoord2f(1.0, 1.0); glVertex3f(-1.0, 1.0, 1.0);
glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, -1.0);
glEnd();
glEndList();
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -