114 lines
2.5 KiB
Plaintext
114 lines
2.5 KiB
Plaintext
//Practice tracing circles
|
|
|
|
I1 ct_buf[128];
|
|
double score=0,rad;
|
|
|
|
void SongEndTsk()
|
|
{
|
|
Sound(0);
|
|
Exit;
|
|
}
|
|
|
|
void SongTsk()
|
|
{
|
|
Fs->end_task_cb=&SongEndTsk;
|
|
ResetMusicSettings;
|
|
while (TRUE)
|
|
Play("hEDCARCDECR");
|
|
}
|
|
|
|
void DrawIt(TssStruct *tss)
|
|
{
|
|
ClearWinText(tss);
|
|
PlotWinStr(tss,ct_buf,BLACK<<4+WHITE,0,0);
|
|
}
|
|
|
|
#define cir_radius 100
|
|
|
|
|
|
void CTPlot(GrBitMap *base,I8 x,I8 y,I8 z)
|
|
{
|
|
nounusedwarn z;
|
|
GrPlot(base,x,y);
|
|
rad=Sqrt(Sqr(x-cir_radius-25)+Sqr(y-cir_radius-25));
|
|
score+=Abs(rad-cir_radius);
|
|
}
|
|
|
|
|
|
void CircleTrace()
|
|
{
|
|
I8 cmd,p1,p2,x1,y1;
|
|
void *old_update=Fs->update_win;
|
|
BoolU4 old_ip_double=Bts(&Fs->crt_flags,CRTf_NO_DOUBLE_CLICK);
|
|
BoolU4 old_inhibit=ip_inhibit_win_operations;
|
|
U8 start_time;
|
|
GrBitMap *base=GrAlias(Gs->grbase,Fs);
|
|
TssStruct *song_tss=Spawn(&SongTsk,"Circle Trace Song",Fs);
|
|
ip_inhibit_win_operations=TRUE;
|
|
WinMax;
|
|
*ct_buf=0;
|
|
Fs->update_win=&DrawIt;
|
|
GrClear;
|
|
base->color=ROP_XOR+(BLACK ^ WHITE);
|
|
GrCircle(base,cir_radius+25,cir_radius+25,cir_radius);
|
|
FlushMsgs;
|
|
do {
|
|
cmd=GetMsg(&p1,&p2,
|
|
(1<<MSG_KEY_DOWN)+(1<<MSG_IP_L_DOWN));
|
|
switch (cmd) {
|
|
case MSG_KEY_DOWN:
|
|
break;
|
|
case MSG_IP_L_DOWN:
|
|
GrClear;
|
|
base->color=ROP_XOR+(BLACK ^ WHITE);
|
|
GrCircle(base,cir_radius+25,cir_radius+25,cir_radius);
|
|
base->color=ROP_XOR+(RED ^ WHITE);
|
|
score=0;
|
|
start_time=BootTime;
|
|
x1=p1; y1=p2;
|
|
do {
|
|
cmd=ScanMsg(&p1,&p2,
|
|
(1<<MSG_IP_L_UP)+(1<<MSG_IP_MOVE));
|
|
switch (cmd) {
|
|
case MSG_IP_L_UP:
|
|
break;
|
|
case MSG_IP_MOVE:
|
|
if (x1!=p1 || y1!=p2) {
|
|
Line(base,x1,y1,0,p1,p2,0,&CTPlot);
|
|
x1=p1;y1=p2;
|
|
//undo overlapping pixels on segments
|
|
GrPlot(base,x1,y1);
|
|
rad=Sqrt(Sqr(x1-cir_radius-25)+Sqr(y1-cir_radius-25));
|
|
score-=Abs(rad-cir_radius);
|
|
}
|
|
break;
|
|
}
|
|
SPrintF(ct_buf,"Score:%9.2f Time:%h17T",score/(pi2*cir_radius),BootTime-start_time);
|
|
|
|
//This $LK,"Sleep","MN:Sleep"$()s until the next time the
|
|
//window manager task runs. The
|
|
//window manager calls the $FG,4$DrawIt$FG$() routine
|
|
//and places messages in the queue, so there's
|
|
//no need to do anything until the window manager runs.
|
|
WinSync;
|
|
|
|
} while (cmd!=MSG_IP_L_UP);
|
|
break;
|
|
}
|
|
} while (cmd!=MSG_KEY_DOWN);
|
|
Fs->update_win=old_update;
|
|
GrClear;
|
|
AssignBit(&Fs->crt_flags,CRTf_NO_DOUBLE_CLICK,old_ip_double);
|
|
ip_inhibit_win_operations=old_inhibit;
|
|
GrDel(base);
|
|
Kill(song_tss);
|
|
}
|
|
|
|
CircleTrace; //Execute when #included
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|