SparrowOSTS_121127.ISO
This commit is contained in:
1 parent
0e9364ff4c
commit
e57428affb
1218 files changed
+247142
-165507
No files matched your search
@@ -0,0 +1,117 @@
|
||||
U0 Main()
|
||||
{
|
||||
F64 é=0,č=0,ę=0;
|
||||
CD3I32 poly[4];
|
||||
CDC *dc=DCAlias;
|
||||
DCAllocDepthBuf(dc);
|
||||
dc->flags|=DCF_TRANSFORMATION|DCF_SYMMETRY;
|
||||
try {
|
||||
while (!ScanChar) {
|
||||
DCDepthBufRst(dc);
|
||||
GrSetSymmetry(dc,Fs->win_pixel_width/2,Fs->win_pixel_height/2,
|
||||
ipx-Fs->win_pixel_left-Fs->win_scroll_x,
|
||||
ipy-Fs->win_pixel_top-Fs->win_scroll_y);
|
||||
dc->color=LTBLUE;
|
||||
GrLine(dc,Fs->win_pixel_width/2,Fs->win_pixel_height/2,
|
||||
ipx-Fs->win_pixel_left-Fs->win_scroll_x,
|
||||
ipy-Fs->win_pixel_top-Fs->win_scroll_y);
|
||||
|
||||
GrIdentEqu(dc->r);
|
||||
GrRotXEqu(dc->r,ę);
|
||||
GrRotYEqu(dc->r,č);
|
||||
GrRotZEqu(dc->r,é);
|
||||
GrSetRotMat(dc,dc->r);
|
||||
|
||||
dc->x=Fs->win_pixel_width/2;
|
||||
dc->y=Fs->win_pixel_height/2;
|
||||
dc->z=500;
|
||||
|
||||
dc->color=GREEN;
|
||||
poly[0].x=50;
|
||||
poly[0].y=150;
|
||||
poly[0].z=0;
|
||||
poly[1].x=275;
|
||||
poly[1].y=100;
|
||||
poly[1].z=0;
|
||||
poly[2].x=155;
|
||||
poly[2].y=200;
|
||||
poly[2].z=0;
|
||||
poly[3].x=100;
|
||||
poly[3].y=200;
|
||||
poly[3].z=0;
|
||||
GrFillPoly3(dc,4,poly);
|
||||
|
||||
dc->color=RED;
|
||||
poly[0].x=50;
|
||||
poly[0].y=150;
|
||||
poly[0].z=50;
|
||||
poly[1].x=275;
|
||||
poly[1].y=100;
|
||||
poly[1].z=50;
|
||||
poly[2].x=155;
|
||||
poly[2].y=200;
|
||||
poly[2].z=50;
|
||||
poly[3].x=100;
|
||||
poly[3].y=200;
|
||||
poly[3].z=50;
|
||||
GrFillPoly3(dc,4,poly);
|
||||
|
||||
dc->color=BLUE;
|
||||
poly[0].x=50;
|
||||
poly[0].y=150;
|
||||
poly[0].z=-50;
|
||||
poly[1].x=275;
|
||||
poly[1].y=100;
|
||||
poly[1].z=-50;
|
||||
poly[2].x=155;
|
||||
poly[2].y=200;
|
||||
poly[2].z=-50;
|
||||
poly[3].x=100;
|
||||
poly[3].y=200;
|
||||
poly[3].z=-50;
|
||||
GrFillPoly3(dc,4,poly);
|
||||
|
||||
dc->color=RED+GREEN<<16+ROPF_DITHER;
|
||||
poly[0].x=50;
|
||||
poly[0].y=150;
|
||||
poly[0].z=50;
|
||||
poly[1].x=275;
|
||||
poly[1].y=100;
|
||||
poly[1].z=50;
|
||||
poly[2].x=275;
|
||||
poly[2].y=100;
|
||||
poly[2].z=0;
|
||||
poly[3].x=50;
|
||||
poly[3].y=150;
|
||||
poly[3].z=0;
|
||||
GrFillPoly3(dc,4,poly);
|
||||
|
||||
dc->color=BLUE+GREEN<<16+ROPF_DITHER;
|
||||
poly[0].x=100;
|
||||
poly[0].y=200;
|
||||
poly[0].z=-50;
|
||||
poly[1].x=155;
|
||||
poly[1].y=200;
|
||||
poly[1].z=-50;
|
||||
poly[2].x=155;
|
||||
poly[2].y=200;
|
||||
poly[2].z=0;
|
||||
poly[3].x=100;
|
||||
poly[3].y=200;
|
||||
poly[3].z=0;
|
||||
GrFillPoly3(dc,4,poly);
|
||||
|
||||
WinMgrSync;
|
||||
DCFill;
|
||||
é+=2.1*ă/180.0;
|
||||
č+=1.1*ă/180.0;
|
||||
ę+=0.5*ă/180.0;
|
||||
}
|
||||
} catch
|
||||
CatchAll;
|
||||
|
||||
DCFill;
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
Main;
|
||||
@@ -0,0 +1,32 @@
|
||||
U0 BSplineDemo()
|
||||
{
|
||||
CDC *dc=DCAlias;
|
||||
I64 p1,p2,i=0,msg_code;
|
||||
CD3I32 c[64];
|
||||
|
||||
SettingsPush;
|
||||
Fs->win_inhibit=WIF_ALL-WIF_BORDER;
|
||||
|
||||
"$$CL$$Select ctrl points with left mouse. Right when finished.\n";
|
||||
DCFill;
|
||||
do {
|
||||
msg_code=GetMsg(&p1,&p2,1<<MSG_IP_L_UP+1<<MSG_IP_R_UP);
|
||||
if (msg_code==MSG_IP_L_UP) {
|
||||
c[i].x=p1; c[i].y=p2; c[i].z=0;
|
||||
dc->color=GREEN;
|
||||
GrCircle(dc,p1,p2,10);
|
||||
i++;
|
||||
}
|
||||
} while (msg_code!=MSG_IP_R_UP);
|
||||
dc->color=RED;
|
||||
Gr2BSpline(dc,c,i,TRUE);
|
||||
dc->color=BLUE;
|
||||
Gr3BSpline(dc,c,i,TRUE);
|
||||
DCDel(dc);
|
||||
SettingsPop;
|
||||
|
||||
PressAKey;
|
||||
DCFill;
|
||||
}
|
||||
|
||||
BSplineDemo;
|
||||
@@ -0,0 +1,242 @@
|
||||
Bool chged;
|
||||
|
||||
#define DAWG_SETTINGS_SPACING 16
|
||||
#define DAWG_SETTINGS_RANGE 60
|
||||
#define DAWG_SETTINGS_BORDER 2
|
||||
|
||||
class DawgSettingsState
|
||||
{
|
||||
I64 cnt,n2_amp,color_scale;
|
||||
} glbl_state;
|
||||
|
||||
U0 DrawDawgSettingsCtrl(CDC *dc,CCtrl *c)
|
||||
{
|
||||
DawgSettingsState *s=c->state;
|
||||
|
||||
dc->color=LTRED;
|
||||
GrRect(dc, c->left,c->top,DAWG_SETTINGS_SPACING*4+3,DAWG_SETTINGS_SPACING*2+DAWG_SETTINGS_RANGE);
|
||||
dc->color=BLUE;
|
||||
GrRect(dc, c->left+DAWG_SETTINGS_BORDER,c->top+DAWG_SETTINGS_BORDER,
|
||||
DAWG_SETTINGS_SPACING*4+3-2*DAWG_SETTINGS_BORDER,DAWG_SETTINGS_SPACING*2+DAWG_SETTINGS_RANGE-2*DAWG_SETTINGS_BORDER);
|
||||
dc->color=BLACK;
|
||||
GrLine(dc,c->left+DAWG_SETTINGS_SPACING,c->top+DAWG_SETTINGS_SPACING,
|
||||
c->left+DAWG_SETTINGS_SPACING,c->top+DAWG_SETTINGS_SPACING+DAWG_SETTINGS_RANGE-1);
|
||||
GrLine(dc,c->left+2*DAWG_SETTINGS_SPACING+1,c->top+DAWG_SETTINGS_SPACING,
|
||||
c->left+2*DAWG_SETTINGS_SPACING+1,c->top+DAWG_SETTINGS_SPACING+DAWG_SETTINGS_RANGE-1);
|
||||
GrLine(dc,c->left+3*DAWG_SETTINGS_SPACING+1,c->top+DAWG_SETTINGS_SPACING,
|
||||
c->left+3*DAWG_SETTINGS_SPACING+1,c->top+DAWG_SETTINGS_SPACING+DAWG_SETTINGS_RANGE-1);
|
||||
|
||||
dc->color=LTRED;
|
||||
GrPrintF(dc,c->left+DAWG_SETTINGS_SPACING-FONT_WIDTH/2,
|
||||
c->top+DAWG_SETTINGS_SPACING+DAWG_SETTINGS_RANGE+3,
|
||||
"%d",s->cnt*10/DAWG_SETTINGS_RANGE);
|
||||
GrPrintF(dc,c->left+2*DAWG_SETTINGS_SPACING+1-FONT_WIDTH/2,
|
||||
c->top+DAWG_SETTINGS_SPACING+DAWG_SETTINGS_RANGE+3,
|
||||
"%d",s->n2_amp*10/DAWG_SETTINGS_RANGE);
|
||||
GrPrintF(dc,c->left+3*DAWG_SETTINGS_SPACING+2-FONT_WIDTH/2,
|
||||
c->top+DAWG_SETTINGS_SPACING+DAWG_SETTINGS_RANGE+3,
|
||||
"%d",s->color_scale*10/DAWG_SETTINGS_RANGE);
|
||||
GrRect(dc,c->left+DAWG_SETTINGS_SPACING-3, c->top+DAWG_SETTINGS_SPACING+DAWG_SETTINGS_RANGE-1-s->cnt-2 ,7,5);
|
||||
GrRect(dc,c->left+2*DAWG_SETTINGS_SPACING+1-3,c->top+DAWG_SETTINGS_SPACING+DAWG_SETTINGS_RANGE-1-s->n2_amp-2,7,5);
|
||||
GrRect(dc,c->left+3*DAWG_SETTINGS_SPACING+2-3,c->top+DAWG_SETTINGS_SPACING+DAWG_SETTINGS_RANGE-1-s->color_scale-2,7,5);
|
||||
dc->color=YELLOW;
|
||||
GrRect(dc,c->left+DAWG_SETTINGS_SPACING-2, c->top+DAWG_SETTINGS_SPACING+DAWG_SETTINGS_RANGE-1-s->cnt-1 ,5,3);
|
||||
GrRect(dc,c->left+2*DAWG_SETTINGS_SPACING+1-2,c->top+DAWG_SETTINGS_SPACING+DAWG_SETTINGS_RANGE-1-s->n2_amp-1,5,3);
|
||||
GrRect(dc,c->left+3*DAWG_SETTINGS_SPACING+2-2,c->top+DAWG_SETTINGS_SPACING+DAWG_SETTINGS_RANGE-1-s->color_scale-1,5,3);
|
||||
}
|
||||
|
||||
U0 UpdateDerivedDawgSettingsCtrl(CCtrl *c)
|
||||
{
|
||||
DawgSettingsState *s=c->state;
|
||||
c->left=c->win_task->win_pixel_width-(DAWG_SETTINGS_SPACING*4+3);
|
||||
c->right=c->left+DAWG_SETTINGS_SPACING*4+3;
|
||||
c->top=c->win_task->win_pixel_height-(DAWG_SETTINGS_SPACING*2+DAWG_SETTINGS_RANGE);
|
||||
c->bottom=c->top+DAWG_SETTINGS_SPACING*2+DAWG_SETTINGS_RANGE;
|
||||
s->cnt =LimitI64(s->cnt,0,DAWG_SETTINGS_RANGE-1);
|
||||
s->n2_amp=LimitI64(s->n2_amp,0,DAWG_SETTINGS_RANGE-1);
|
||||
s->color_scale=LimitI64(s->color_scale,0,DAWG_SETTINGS_RANGE-1);
|
||||
}
|
||||
|
||||
U0 LeftClickDawgSettings(CCtrl *c,I64 x,I64 y,Bool down)
|
||||
{
|
||||
DawgSettingsState *s=c->state;
|
||||
if (x<c->left+(c->right-c->left)/3)
|
||||
s->cnt=DAWG_SETTINGS_RANGE-1-(y-(c->top+DAWG_SETTINGS_SPACING));
|
||||
else if (x<c->left+2*(c->right-c->left)/3)
|
||||
s->n2_amp=DAWG_SETTINGS_RANGE-1-(y-(c->top+DAWG_SETTINGS_SPACING));
|
||||
else
|
||||
s->color_scale=DAWG_SETTINGS_RANGE-1-(y-(c->top+DAWG_SETTINGS_SPACING));
|
||||
if (c->update_derived_vals)
|
||||
(*c->update_derived_vals)(c);
|
||||
if (!down) chged=TRUE;
|
||||
}
|
||||
|
||||
CCtrl *DawgSettingsNew()
|
||||
{
|
||||
Bool old_preempt;
|
||||
CCtrl *c=CAlloc(sizeof(CCtrl));
|
||||
c->win_task=Fs;
|
||||
c->flags=CTRLF_SHOW|CTRLF_CAPTURE_LEFT_IP;
|
||||
c->type=CTRLT_GENERIC;
|
||||
// c->state=CAlloc(sizeof(DawgSettingsState));
|
||||
c->state=&glbl_state;
|
||||
glbl_state.cnt=DAWG_SETTINGS_RANGE/2;
|
||||
glbl_state.n2_amp=DAWG_SETTINGS_RANGE/2;
|
||||
glbl_state.color_scale=DAWG_SETTINGS_RANGE/2;
|
||||
c->draw_it=&DrawDawgSettingsCtrl;
|
||||
c->left_click=&LeftClickDawgSettings;
|
||||
c->update_derived_vals=&UpdateDerivedDawgSettingsCtrl;
|
||||
old_preempt=Preempt(OFF);
|
||||
QueIns(c,Fs->last_ctrl);
|
||||
TaskDerivedValsUpdate;
|
||||
Preempt(old_preempt);
|
||||
return c;
|
||||
}
|
||||
|
||||
U0 DawgSettingsDel(CCtrl *c)
|
||||
{
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
QueRem(c);
|
||||
Preempt(old_preempt);
|
||||
// Free(c->state);
|
||||
Free(c);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//This program does a fractel-like thing with
|
||||
//integer arithmetic.
|
||||
|
||||
class Simplex //This is something I made-up. It's not standard math.
|
||||
{
|
||||
I64 x,y;
|
||||
};
|
||||
|
||||
I64 Norm(Simplex *n1)
|
||||
{
|
||||
return AbsI64(n1->x)+AbsI64(n1->y);
|
||||
}
|
||||
|
||||
Simplex *CopySimplex(Simplex *dst, Simplex *src)
|
||||
{
|
||||
Simplex *result;
|
||||
MemCpy(dst,src,sizeof(Simplex));
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
Simplex *Mix(Simplex *result,Simplex *n1,Simplex *n2)
|
||||
{ //This is something I made-up. It's not standard math.
|
||||
result->x=n1->x*n2->x;
|
||||
result->y=n1->y*n2->y;
|
||||
return result;
|
||||
}
|
||||
|
||||
Simplex *Mangle(Simplex *result,Simplex *n1,Simplex *n2)
|
||||
{ //This is something I made-up. It's not standard math.
|
||||
result->x=n1->x*n2->y;
|
||||
result->y=n1->y*n2->x;
|
||||
return result;
|
||||
}
|
||||
|
||||
Simplex *Add(Simplex *result,Simplex *n1,Simplex *n2)
|
||||
{
|
||||
result->x=n1->x+n2->x;
|
||||
result->y=n1->y+n2->y;
|
||||
return result;
|
||||
}
|
||||
|
||||
Simplex *Sub(Simplex *result,Simplex *n1,Simplex *n2)
|
||||
{
|
||||
result->x=n1->x-n2->x;
|
||||
result->y=n1->y-n2->y;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
U0 Bling()
|
||||
{
|
||||
I64 ch;
|
||||
I64 x,y,cnt;
|
||||
I64 d;
|
||||
F64 color,color_scale;
|
||||
Simplex n1,n2,n3,n4,n5,n6,n7,n8;
|
||||
F64 timeout_time;
|
||||
CCtrl *c=DawgSettingsNew;
|
||||
CDC *dc=DCAlias;
|
||||
F64 e=Exp(1);
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
DocCursor;
|
||||
DocClear;
|
||||
Fs->win_inhibit=WIF_ALL-WIF_BORDER-WIF_CTRLS;
|
||||
|
||||
chged=FALSE;
|
||||
WordStat;
|
||||
WinMax;
|
||||
while (TRUE) {
|
||||
next_dotel:
|
||||
ch=0;
|
||||
cnt =2e9*(RandU32+0x1000)/MAX_U32*((Exp(ToF64(glbl_state.cnt +10)/DAWG_SETTINGS_RANGE)-1)/e);
|
||||
n2.x=2e9*Sign(RandI32)*(RandU32+0x1000)/MAX_U32*((Exp(ToF64(glbl_state.n2_amp)/DAWG_SETTINGS_RANGE)-1)/e);
|
||||
n2.y=2e9*Sign(RandI32)*(RandU32+0x1000)/MAX_U32*((Exp(ToF64(glbl_state.n2_amp)/DAWG_SETTINGS_RANGE)-1)/e);
|
||||
n8.x=RandI32;
|
||||
n8.y=RandI32;
|
||||
color_scale=4.0*(glbl_state.color_scale+1.0)/DAWG_SETTINGS_RANGE+0.5;
|
||||
timeout_time=tNP+0.1;
|
||||
for (y=0;y<GR_HEIGHT;y++) {
|
||||
if (y<20)
|
||||
if (tNP>timeout_time)
|
||||
goto next_dotel;
|
||||
if (ScanKey(&ch))
|
||||
goto next_dotel;
|
||||
for (x=0;x<GR_WIDTH;x++) {
|
||||
if (y<20)
|
||||
if (tNP>timeout_time)
|
||||
goto next_dotel;
|
||||
|
||||
n1.x=x; n1.y=y;
|
||||
CopySimplex(&n3,&n1);
|
||||
|
||||
color=0;
|
||||
d=Norm(&n3);
|
||||
|
||||
//This doesn't make mathematical sense, but it makes nice results.
|
||||
while (d.u32[0]<cnt && color<65536) {
|
||||
if (y<20)
|
||||
if (tNP>timeout_time)
|
||||
goto next_dotel;
|
||||
Mangle(&n7,Mix(&n4,&n3,&n1),
|
||||
Add(&n5,&n3,&n2));
|
||||
color++;
|
||||
d=Norm(Add(&n3,&n7,Mangle(&n6,&n3,&n8)));
|
||||
}
|
||||
color-=(cnt-d.u32[0])/cnt;
|
||||
dc->color=ROP_EQU+
|
||||
color=gr_rainbow_10[LimitI64(color_scale*(Ln(color)),0,9)];
|
||||
GrPlot(dc,x,y);
|
||||
}
|
||||
}
|
||||
dc->color=COLOR_TRANSPARENT;
|
||||
GrRect(dc,c->left,c->top,c->right-c->left,c->bottom-c->top);
|
||||
while (TRUE) {
|
||||
if (chged) {
|
||||
chged=FALSE;
|
||||
break;
|
||||
}
|
||||
if (ch=ScanChar)
|
||||
if (ch==CH_SPACE||ch==CH_NEW_LINE)
|
||||
break;
|
||||
else
|
||||
goto bling_done;
|
||||
WinMgrSync;
|
||||
}
|
||||
}
|
||||
bling_done:
|
||||
SettingsPop;
|
||||
DCDel(dc);
|
||||
DCFill;
|
||||
DawgSettingsDel(c);
|
||||
}
|
||||
|
||||
Bling; //Start when included
|
||||
@@ -0,0 +1,34 @@
|
||||
U0 DrawIt(CTask *task,CDC *dc)
|
||||
{ //This routine is called by the window mgr task.
|
||||
GrPrintF(dc,0,0*FONT_HEIGHT,"tNP:%4.3f tP:%4.3f",tNP,tP(task));
|
||||
|
||||
//default 2.5Hz
|
||||
if (Blink)
|
||||
GrPutS(dc,0,1*FONT_HEIGHT,"Blink");
|
||||
|
||||
//10 Hz
|
||||
if (Blink(10))
|
||||
GrPutS(dc,0,2*FONT_HEIGHT,"Blink(10)");
|
||||
|
||||
//$LK,"tNP","MN:tNP"$ is a float var with time in seconds, function actually.
|
||||
//You can skip arguments if they have defaults.
|
||||
if (Blink(,tNP))
|
||||
GrPutS(dc,0,3*FONT_HEIGHT,"Blink(,tNP)");
|
||||
|
||||
//$LK,"tP","MN:tP"$ is a pausable function.
|
||||
if (Blink(,tP(task)))
|
||||
GrPutS(dc,0,4*FONT_HEIGHT,"Blink(,tP(task))");
|
||||
}
|
||||
|
||||
U0 BlinkDemo()
|
||||
{
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
Fs->draw_it=&DrawIt;
|
||||
DocClear;
|
||||
NewLine(10);
|
||||
"Pause and unpause task with $$FG,GREEN$$<CTRL-ALT-P>$$FG$$\n";
|
||||
PressAKey;
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
BlinkDemo;
|
||||
@@ -0,0 +1,41 @@
|
||||
CDC *dc=DCAlias;
|
||||
CDC *img1=DCNew(DCT_COLOR8,64,64);
|
||||
CDC *img2=DCNew(DCT_COLOR8,512,512);
|
||||
|
||||
img1->color=COLOR_MONO;
|
||||
img1->pen_width=3;
|
||||
GrCircle(img1,30,30,20);
|
||||
GrFloodFill3(img1,30,30,0,TRUE);
|
||||
GrLine3(img1,60,0,0,0,60,0);
|
||||
|
||||
DCFill(img2);
|
||||
img2->color=ROP_EQU+RED;
|
||||
img2->brush=img1;
|
||||
GrCircle(img2,256-30,256-30,128,67);
|
||||
img2->color=BLUE;
|
||||
img2->pen_width=6;
|
||||
img2->brush=NULL;
|
||||
GrLine3(img2,128,128,0,256+128,256+128,0);
|
||||
GrLine3(img2,256+128,128,0,128,256+128,0);
|
||||
|
||||
img2->color=YELLOW;
|
||||
GrRect(img2,256-20,256-20,40,40);
|
||||
|
||||
I64 i;
|
||||
for (i=0;i<256;i+=4) {
|
||||
WinMgrSync;
|
||||
DCFill;
|
||||
GrBlot(dc,i-256,i-256,img2);
|
||||
Sleep(10);
|
||||
}
|
||||
U8 *tempg=DC2Sprite(img1);
|
||||
PutSprite(tempg);
|
||||
Free(tempg);
|
||||
NewLine(9);
|
||||
|
||||
DCDel(img1);
|
||||
DCDel(img2);
|
||||
DCDel(dc);
|
||||
|
||||
PressAKey;
|
||||
DCFill;
|
||||
@@ -0,0 +1,57 @@
|
||||
//This uses $LK,"fixed-point-arithmetic","FI:::/SparrowOS/Demo/Lectures/FixedPoint.CPP.Z"$.
|
||||
|
||||
I64 x[16],y[16],dx[16],dy[16];
|
||||
|
||||
U0 Init()
|
||||
{
|
||||
I64 i;
|
||||
F64 é;
|
||||
MemSet(x,0,sizeof(x));
|
||||
MemSet(y,0,sizeof(y));
|
||||
for (i=0;i<16;i++) {
|
||||
é=Rand*2*ã;
|
||||
dx[i]=MAX_I32*Cos(é);
|
||||
dy[i]=MAX_I32*Sin(é);
|
||||
}
|
||||
}
|
||||
|
||||
U0 Bounce()
|
||||
{
|
||||
CDC *dc=DCAlias;
|
||||
I64 i,msg_code,p1,update;
|
||||
Init;
|
||||
try { //Catch <CTRL-ALT-C>
|
||||
while (TRUE) {
|
||||
update=win_updates;
|
||||
do for (i=0;i<16;i++) {
|
||||
dc->color=i;
|
||||
GrPlot(dc,x[i].i32[1],y[i].i32[1]);
|
||||
x[i]+=dx[i];
|
||||
y[i]+=dy[i];
|
||||
if (!(0<=x[i]<Fs->win_pixel_width<<32)) {
|
||||
x[i]-=dx[i];
|
||||
dx[i]=-dx[i];
|
||||
}
|
||||
if (!(0<=y[i]<Fs->win_pixel_height<<32)) {
|
||||
y[i]-=dy[i];
|
||||
dy[i]=-dy[i];
|
||||
}
|
||||
}
|
||||
while (update==win_updates);
|
||||
while (msg_code=ScanMsg(&p1,NULL,1<<MSG_KEY_DOWN|1<<MSG_RESIZE|1<<MSG_MOVE))
|
||||
if (msg_code==MSG_KEY_DOWN) {
|
||||
if (p1==CH_SHIFT_ESC || p1==CH_ESC)
|
||||
goto bc_done;
|
||||
else
|
||||
Init;
|
||||
} else
|
||||
DCFill(dc);
|
||||
}
|
||||
bc_done:
|
||||
} catch
|
||||
CatchAll;
|
||||
DCFill(dc);
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
Bounce;
|
||||
@@ -0,0 +1,53 @@
|
||||
CDC *dc;
|
||||
|
||||
U0 DrawIt(CTask *,CDC *)
|
||||
{
|
||||
dc->pen_width=2;
|
||||
dc->color=RED;
|
||||
GrLine3(dc,-100,-100,-100, -100, 100,-100);
|
||||
GrLine3(dc,-100, 100,-100, 100, 100,-100);
|
||||
GrLine3(dc, 100, 100,-100, 100,-100,-100);
|
||||
GrLine3(dc, 100,-100,-100, -100,-100,-100);
|
||||
GrLine3(dc,-100,-100, 100, -100, 100, 100);
|
||||
GrLine3(dc,-100, 100, 100, 100, 100, 100);
|
||||
GrLine3(dc, 100, 100, 100, 100,-100, 100);
|
||||
GrLine3(dc, 100,-100, 100, -100,-100, 100);
|
||||
GrLine3(dc,-100,-100, 100, -100,-100,-100);
|
||||
GrLine3(dc,-100, 100, 100, -100, 100,-100);
|
||||
GrLine3(dc, 100, 100, 100, 100, 100,-100);
|
||||
GrLine3(dc, 100,-100, 100, 100,-100,-100);
|
||||
}
|
||||
|
||||
U0 Box()
|
||||
{
|
||||
F64 é=0,è=0,ê=0,s=1,s1=1.05;
|
||||
dc=DCAlias(gr_dc,Fs);
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
DocClear;
|
||||
Fs->draw_it=&DrawIt;
|
||||
Preempt(OFF); //We don't want matrix used while we're changing it.
|
||||
|
||||
dc->x=200;
|
||||
dc->y=200;
|
||||
dc->flags|=DCF_TRANSFORMATION;
|
||||
while (!ScanChar) {
|
||||
GrIdentEqu(dc->r);
|
||||
GrRotZEqu(dc->r,é);
|
||||
GrRotXEqu(dc->r,è);
|
||||
GrRotZEqu(dc->r,ê);
|
||||
GrScaleMatEqu(dc->r,s);
|
||||
GrSetRotMat(dc,dc->r);
|
||||
|
||||
Sleep(20);
|
||||
é+=2*ã/70;
|
||||
è +=2*ã/90;
|
||||
ê +=2*ã/110;
|
||||
s *=s1;
|
||||
if ( !(0.2<s<1.4) ) s1=1/s1;
|
||||
}
|
||||
SettingsPop;
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
Box;
|
||||
@@ -0,0 +1,64 @@
|
||||
#define NUM_DATA_PTS 256
|
||||
|
||||
F64 CPU_idle[MP_MAX_PROCESSORS][NUM_DATA_PTS];
|
||||
F64 mem[NUM_DATA_PTS];
|
||||
F64 refresh[NUM_DATA_PTS];
|
||||
|
||||
U0 DrawIt(CTask *task,CDC *dc)
|
||||
{
|
||||
I64 i,j,x1,y1,x2,y2;
|
||||
U8 buf[32];
|
||||
for (i=1;i<NUM_DATA_PTS;i++) {
|
||||
x1=(i-1)*task->win_pixel_width/(NUM_DATA_PTS-1);
|
||||
x2=i*task->win_pixel_width/(NUM_DATA_PTS-1);
|
||||
for (j=0;j<mp_cnt;j++) {
|
||||
dc->color=gr_rainbow_10[j];
|
||||
y1=task->win_pixel_height*CPU_idle[j][i-1];
|
||||
y2=task->win_pixel_height*CPU_idle[j][i];
|
||||
GrLine(dc,x1,y1,x2,y2);
|
||||
}
|
||||
dc->color=LTCYAN;
|
||||
y1=task->win_pixel_height*mem[i-1];
|
||||
y2=task->win_pixel_height*mem[i];
|
||||
GrLine(dc,x1,y1,x2,y2);
|
||||
|
||||
dc->color=LTPURPLE;
|
||||
y1=task->win_pixel_height*refresh[i-1];
|
||||
y2=task->win_pixel_height*refresh[i];
|
||||
GrLine(dc,x1,y1,x2,y2);
|
||||
}
|
||||
for (j=0;j<mp_cnt;j++) {
|
||||
SPrintF(buf,"CPU%d",j);
|
||||
PlotWinStr(task,buf,gr_rainbow_10[j]+WHITE<<4,0,task->win_height-4-j);
|
||||
}
|
||||
PlotWinStr(task,"Mem %",LTCYAN+WHITE<<4,0,task->win_height-3);
|
||||
PlotWinStr(task,"Refresh Hz",LTPURPLE+WHITE<<4,0,task->win_height-2);
|
||||
}
|
||||
|
||||
U0 CPUPlot()
|
||||
{
|
||||
I64 cur_pt=0,j;
|
||||
MemSet(CPU_idle,0,sizeof(CPU_idle));
|
||||
MemSet(mem,0,sizeof(F64)*NUM_DATA_PTS);
|
||||
MemSet(refresh,0,sizeof(F64)*NUM_DATA_PTS);
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
DocCursor;
|
||||
DocClear;
|
||||
Fs->draw_it=&DrawIt;
|
||||
|
||||
while (!ScanChar) {
|
||||
for (j=0;j<mp_cnt;j++)
|
||||
CPU_idle[j][cur_pt]=cpu_structs[j].idle_factor;
|
||||
mem[cur_pt]=ToF64(UnusedSysMem)/(sys_heap_limit-sys_heap_base+1);
|
||||
refresh[cur_pt]=1.0-win_actual_refresh/100.0; //This plots on a scale of 0-100 Hz
|
||||
Sleep(25);
|
||||
cur_pt= ++cur_pt % NUM_DATA_PTS;
|
||||
}
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
CPUPlot; //start when #included
|
||||
|
||||
//Study $LK,"::/SparrowOS/Adam/MemRep.CPP.Z","FI:::/SparrowOS/Adam/MemRep.CPP.Z"$ and $LK,"WallPaper","MN:WallPaper"$() to learn more about
|
||||
//how the system resources are put together.
|
||||
Binary file not shown.
@@ -0,0 +1,27 @@
|
||||
//See $LK,"::/SparrowOS/Demo/GameStarters/Stadium/StadiumGen.CPP.Z","FI:::/SparrowOS/Demo/GameStarters/Stadium/StadiumGen.CPP.Z"$.
|
||||
|
||||
U0 ViewScreenCapture(U8 *filename)
|
||||
{
|
||||
CDC *dc=DCAlias(gr_dc2,Fs),
|
||||
*dc2=GRARead(filename);
|
||||
GrBlot(dc,0,0,dc2);
|
||||
DCDel(dc2);
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
|
||||
U0 Main()
|
||||
{
|
||||
"Capture screen...\n";
|
||||
PressAKey;
|
||||
GRACaptureScreen("HOME/ScreenShot.GRA.Z");
|
||||
|
||||
"View captured screen...\n";
|
||||
PressAKey;
|
||||
ViewScreenCapture("HOME/ScreenShot.GRA.Z");
|
||||
|
||||
PressAKey;
|
||||
DCFill;
|
||||
}
|
||||
|
||||
Main;
|
||||
@@ -0,0 +1,48 @@
|
||||
//x must be global.
|
||||
//Might as well make y global.
|
||||
|
||||
F64 x,y,y_last;
|
||||
|
||||
U0 Cartesian()
|
||||
{
|
||||
U8 *st;
|
||||
I64 ch=0,h,v;
|
||||
Bool first;
|
||||
CDC *dc=DCAlias;
|
||||
do {
|
||||
DocClear;
|
||||
"Enter algebraic equation to graph.\n"
|
||||
"Example: y=2*x\n"
|
||||
"y=";
|
||||
if (st=MGetS) {
|
||||
if (*st) {
|
||||
h=Fs->win_pixel_width/2;
|
||||
v=Fs->win_pixel_height/2;
|
||||
dc->color=RED;
|
||||
GrLine(dc,h,0,h,2*v+1);
|
||||
GrLine(dc,0,v,2*h+1,v);
|
||||
first=TRUE;
|
||||
dc->color=BLACK;
|
||||
for (x=-h;x<=h;x++) {
|
||||
y=-ExePrintF("ToF64(%s);",st)(F64);
|
||||
if (!first)
|
||||
GrLine(dc,x-1+h,y_last+v,x+h,y+v);
|
||||
y_last=y;
|
||||
first=FALSE;
|
||||
}
|
||||
ch=GetChar;
|
||||
} else
|
||||
ch=CH_SHIFT_ESC;
|
||||
Free(st);
|
||||
} else
|
||||
ch=CH_SHIFT_ESC;
|
||||
DCFill;
|
||||
} while (ch!=CH_SHIFT_ESC && ch!=CH_ESC);
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
Cartesian;
|
||||
|
||||
/*$WW,1$
|
||||
For better performance, compile the expression entered by the user one time with $LK,"CmpExpression","MN:CmpExpression"$() and use $LK,"Call","MN:Call"$(). See $LK,"::/SparrowOS/Demo/CompileDemo.CPP.Z","FI:::/SparrowOS/Demo/CompileDemo.CPP.Z"$.
|
||||
*/
|
||||
@@ -0,0 +1,35 @@
|
||||
U8 *old_font=gr_font;
|
||||
|
||||
// See $LK,"::/SparrowOS/OSMain/Font8x8.CPP.Z","FI:::/SparrowOS/OSMain/Font8x8.CPP.Z"$.
|
||||
// See $LK,"::/SparrowOS/Demo/ScreenCodes.CPP.Z","FI:::/SparrowOS/Demo/ScreenCodes.CPP.Z"$.
|
||||
// See $LK,"::/SparrowOS/Demo/ExtendedChars.CPP.Z","FI:::/SparrowOS/Demo/ExtendedChars.CPP.Z"$.
|
||||
// See $LK,"::/SparrowOS/Demo/Graphics/FontEd.CPP.Z","FI:::/SparrowOS/Demo/Graphics/FontEd.CPP.Z"$.
|
||||
|
||||
U8 waves[8*4]={
|
||||
0x00,0x11,0xAA,0x44,0x00,0x11,0xAA,0x44,
|
||||
0x00,0x22,0x55,0x88,0x00,0x22,0x55,0x88,
|
||||
0x00,0x44,0xAA,0x11,0x00,0x44,0xAA,0x11,
|
||||
0x00,0x88,0x55,0x22,0x00,0x88,0x55,0x22};
|
||||
|
||||
U0 AnimateEndCB()
|
||||
{
|
||||
gr_font=old_font;
|
||||
Exit;
|
||||
}
|
||||
|
||||
U0 AnimateTask(I64)
|
||||
{
|
||||
I64 i;
|
||||
U8 *font=MAlloc(256*8);
|
||||
Fs->task_end_cb=&AnimateEndCB;
|
||||
MemCpy(font,gr_font,256*8);
|
||||
gr_font=font;
|
||||
while (TRUE) {
|
||||
MemCpy(font+CH_SPACE*FONT_HEIGHT,waves+8*(i++&0x3),8);
|
||||
Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Spawn(&AnimateTask,NULL,"Animate",Fs);
|
||||
TaskRep;
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,119 @@
|
||||
#define N 32
|
||||
|
||||
class Node
|
||||
{
|
||||
Node *left,*right;
|
||||
I64 n;
|
||||
};
|
||||
|
||||
I64 n1,n2,common_ancestor;
|
||||
Node *root;
|
||||
|
||||
#define X_SPACING 16
|
||||
#define Y_SPACING 45
|
||||
#define ARROW_SPACING 3
|
||||
|
||||
U0 ShowTree(CDC *dc,Node *tempn,I64 *_node_x,I64 *_tree_x,I64 y)
|
||||
{
|
||||
I64 node_x;
|
||||
if (tempn) {
|
||||
if (tempn->left) {
|
||||
ShowTree(dc,tempn->left,&node_x,_tree_x,y+Y_SPACING);
|
||||
dc->color=BLUE;
|
||||
GrArrow3(dc,*_tree_x,y,0,node_x+ARROW_SPACING,y+Y_SPACING-ARROW_SPACING,0);
|
||||
}
|
||||
if (tempn->n==n1 || tempn->n==n2) {
|
||||
if (tempn->n==common_ancestor)
|
||||
dc->color=YELLOW;
|
||||
else
|
||||
dc->color=RED;
|
||||
} else if (tempn->n==common_ancestor)
|
||||
dc->color=GREEN;
|
||||
else
|
||||
dc->color=BLUE;
|
||||
|
||||
*_node_x=*_tree_x;
|
||||
GrPrintF(dc,*_node_x,y,"%d",tempn->n);
|
||||
*_tree_x+=X_SPACING;
|
||||
|
||||
if (tempn->right) {
|
||||
ShowTree(dc,tempn->right,&node_x,_tree_x,y+Y_SPACING);
|
||||
dc->color=BLUE;
|
||||
GrArrow3(dc,*_node_x,y,0,node_x-ARROW_SPACING,y+Y_SPACING-ARROW_SPACING,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 DrawIt(CTask *,CDC *dc)
|
||||
{
|
||||
I64 node_x=0,tree_x=0;
|
||||
ShowTree(dc,root,&node_x,&tree_x,20);
|
||||
}
|
||||
|
||||
U0 TreeAdd(Node **_root,Node *tempn)
|
||||
{
|
||||
Node *root=*_root;
|
||||
if (!root)
|
||||
*_root=tempn;
|
||||
else if (tempn->n==root->n)
|
||||
Free(tempn);
|
||||
else if (tempn->n<root->n)
|
||||
TreeAdd(&root->left,tempn);
|
||||
else
|
||||
TreeAdd(&root->right,tempn);
|
||||
}
|
||||
|
||||
U0 TreeNew()
|
||||
{
|
||||
I64 i;
|
||||
Node *tempn;
|
||||
for (i=0;i<N;i++) {
|
||||
tempn=CAlloc(sizeof(Node));
|
||||
tempn->n=RandU16%N;
|
||||
|
||||
if (i==N-1)
|
||||
n1=tempn->n;
|
||||
else if (i==N-2)
|
||||
n2=tempn->n;
|
||||
|
||||
TreeAdd(&root,tempn);
|
||||
Sleep(50);
|
||||
}
|
||||
}
|
||||
|
||||
U0 TreeCommonAncestorFind(Node *root)
|
||||
{
|
||||
if (root && root->n!=n1 && root->n!=n2) {
|
||||
common_ancestor=root->n;
|
||||
if (n1<root->n && n2<root->n)
|
||||
TreeCommonAncestorFind(root->left);
|
||||
else if (n1>root->n && n2>root->n)
|
||||
TreeCommonAncestorFind(root->right);
|
||||
}
|
||||
}
|
||||
|
||||
U0 TreeCommonAncestor()
|
||||
{ //Make tree and find common ancestor to n1 & n2.
|
||||
root=NULL;
|
||||
n1=n2=common_ancestor=0;
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
Fs->draw_it=&DrawIt;
|
||||
DocClear;
|
||||
"Scroll with {CTRL-Left Grab}.\n";
|
||||
try {
|
||||
TreeNew;
|
||||
TreeCommonAncestorFind(root);
|
||||
PressAKey;
|
||||
} catch
|
||||
CatchAll;
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
TreeCommonAncestor;
|
||||
/*
|
||||
Be careful with recursive routines in SparrowOS
|
||||
because the stack does not grow and will overflow.
|
||||
|
||||
See $LK,"::/SparrowOS/Demo/StkGrow.CPP.Z","FI:::/SparrowOS/Demo/StkGrow.CPP.Z"$.
|
||||
*/
|
||||
@@ -0,0 +1,16 @@
|
||||
U0 Main()
|
||||
{
|
||||
CDC *dc=DCAlias;
|
||||
dc->color=RED+BLACK<<16+ROPF_DITHER;
|
||||
GrCircle(dc,100,100,50);
|
||||
GrLine(dc,10,10,280,70);
|
||||
dc->color=RED+BLUE<<16+ROPF_DITHER;
|
||||
GrFloodFill(dc,100,100);
|
||||
dc->color=PURPLE+BLUE<<16+ROPF_DITHER;
|
||||
GrRect(dc,20,20,100,100);
|
||||
PressAKey;
|
||||
DCFill;
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
Main;
|
||||
@@ -0,0 +1,48 @@
|
||||
//This is a drawing program
|
||||
|
||||
U0 Doodle()
|
||||
{
|
||||
I64 msg_code,i,x1,y1,x2,y2,p1,p2,color=BLACK;
|
||||
CDC *dc=DCAlias;
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
Fs->win_inhibit=WIF_ALL-WIF_BORDER;
|
||||
|
||||
WinMax;
|
||||
WordStat;
|
||||
|
||||
DCFill;
|
||||
"$$CL$$"; //$LK,"DocClear","MN:DocClear"$() is better
|
||||
do {
|
||||
msg_code=GetMsg(&p1,&p2,
|
||||
1<<MSG_KEY_DOWN+1<<MSG_IP_L_DOWN+
|
||||
1<<MSG_IP_R_UP);
|
||||
switch (msg_code) {
|
||||
case MSG_IP_R_UP:
|
||||
i=PopUpColor;
|
||||
if (i>=0) color=i;
|
||||
break;
|
||||
case MSG_IP_L_DOWN:
|
||||
x1=p1; y1=p2;
|
||||
x2=p1; y2=p2;
|
||||
dc->color=ROP_XOR+color^COLOR_TRANSPARENT;
|
||||
dc->pen_width=1;
|
||||
while (msg_code!=MSG_IP_L_UP) {
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
msg_code=GetMsg(&p1,&p2,
|
||||
1<<MSG_IP_L_UP+1<<MSG_IP_MOVE);
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
x2=p1; y2=p2;
|
||||
}
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
break;
|
||||
case MSG_KEY_DOWN:
|
||||
break;
|
||||
}
|
||||
} while (msg_code!=MSG_KEY_DOWN || !p1);
|
||||
DCFill;
|
||||
DCDel(dc);
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
Doodle; //Execute when #included
|
||||
@@ -0,0 +1,14 @@
|
||||
U0 DotNet()
|
||||
{
|
||||
I64 i;
|
||||
CDC *dc=DCAlias;
|
||||
DocClear; //Clear text
|
||||
dc->color=RED;
|
||||
for (i=0;i<480;i+=20)
|
||||
GrLine(dc,i,0,0,480-i,3);
|
||||
DCDel(dc);
|
||||
PressAKey;
|
||||
DCFill;
|
||||
}
|
||||
|
||||
DotNet; //Run when #included
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,142 @@
|
||||
//After making a font, you can save it as a binary
|
||||
//file with:
|
||||
// FileWrite("filename.BIN.Z",gr_font,256*FONT_HEIGHT);
|
||||
//You can load it with:
|
||||
// U8 *myfont=FileRead("filename.BIN.Z");
|
||||
// gr_font=myfont; //preserve gr_font if you want to go back.
|
||||
|
||||
//If you want to change the system font permanently,
|
||||
//save to a file with this font editor program
|
||||
//and cut and paste the code into $LK,"::/SparrowOS/OSMain/Font8x8.CPP.Z","FI:::/SparrowOS/OSMain/Font8x8.CPP.Z"$.
|
||||
//You will need to recompile OSMain by calling $LK,"InstallBoot","MN:InstallBoot"$().
|
||||
|
||||
//See $LK,"::/SparrowOS/Demo/ExtendedChars.CPP.Z","FI:::/SparrowOS/Demo/ExtendedChars.CPP.Z"$ and
|
||||
//$LK,"::/SparrowOS/Demo/ScreenCodes.CPP.Z","FI:::/SparrowOS/Demo/ScreenCodes.CPP.Z"$.
|
||||
|
||||
#define BLOW_UP_CHAR_X (18*FONT_WIDTH)
|
||||
#define BLOW_UP_CHAR_Y (2*FONT_HEIGHT)
|
||||
|
||||
U8 cur_ch;
|
||||
|
||||
U0 DrawIt(CTask *task,CDC *dc)
|
||||
{
|
||||
I64 i,j,k,c;
|
||||
k=0;
|
||||
for (i=0;i<16;i++)
|
||||
for (j=0;j<16;j++) {
|
||||
if (k==cur_ch) {
|
||||
if (Blink(,tP(task)))
|
||||
c=(BLUE<<4+YELLOW)<<8 + k++;
|
||||
else
|
||||
c=(YELLOW<<4+BLUE)<<8 + k++;
|
||||
} else
|
||||
c=(BLUE<<4+WHITE)<<8 + k++;
|
||||
PlotWinU8(task,c,j,i);
|
||||
}
|
||||
|
||||
k=0;
|
||||
for (i=0;i<FONT_HEIGHT;i++)
|
||||
for (j=0;j<FONT_WIDTH;j++) {
|
||||
if (Bt(&gr_font[FONT_HEIGHT*cur_ch],k++))
|
||||
dc->color=YELLOW;
|
||||
else
|
||||
dc->color=BLUE;
|
||||
GrRect(dc,BLOW_UP_CHAR_X+j*FONT_WIDTH,
|
||||
BLOW_UP_CHAR_Y+i*FONT_HEIGHT,
|
||||
FONT_WIDTH,FONT_HEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
U0 FESave(Bool pmt)
|
||||
{
|
||||
U8 old_draw_it=Fs->draw_it;
|
||||
CDoc *doc=DocNew;
|
||||
I64 i,j,k=0;
|
||||
for (i=0;i<256;i++) {
|
||||
for (j=0;j<FONT_HEIGHT;j++)
|
||||
DocPrintF(doc,"0x%02X,",gr_font[k++]);
|
||||
DocPutS(doc,"\n");
|
||||
}
|
||||
Fs->draw_it=NULL;
|
||||
DocWrite(doc,pmt);
|
||||
Fs->draw_it=old_draw_it;
|
||||
DocDel(doc);
|
||||
}
|
||||
|
||||
U0 FontEd()
|
||||
{
|
||||
I64 msg_code,p1,p2,k;
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
MenuPush(
|
||||
"File {"
|
||||
" SaveAs(,CH_CTRLA);"
|
||||
" Abort(,CH_SHIFT_ESC);"
|
||||
" Exit(,CH_ESC);"
|
||||
"}");
|
||||
WordStat;
|
||||
DocClear;
|
||||
DocCursor;
|
||||
Fs->win_inhibit|=WIF_DBL_CLICK;
|
||||
cur_ch=0;
|
||||
try {
|
||||
Fs->draw_it=&DrawIt;
|
||||
while (TRUE) {
|
||||
switch (msg_code=GetMsg(&p1,&p2,1<<MSG_KEY_DOWN|1<<MSG_IP_L_DOWN|1<<MSG_IP_R_DOWN|1<<MSG_IP_MOVE)) {
|
||||
case MSG_KEY_DOWN:
|
||||
switch (p1) {
|
||||
case 0:
|
||||
switch (p2.u8[0]) {
|
||||
case SC_CURSOR_LEFT:
|
||||
cur_ch--;
|
||||
break;
|
||||
case SC_CURSOR_RIGHT:
|
||||
cur_ch++;
|
||||
break;
|
||||
case SC_CURSOR_UP:
|
||||
cur_ch-=16;
|
||||
break;
|
||||
case SC_CURSOR_DOWN:
|
||||
cur_ch+=16;
|
||||
break;
|
||||
|
||||
}
|
||||
break;
|
||||
goto fe_done;
|
||||
case CH_CTRLA:
|
||||
FESave(TRUE);
|
||||
break;
|
||||
case CH_ESC:
|
||||
FESave(FALSE);
|
||||
case CH_SHIFT_ESC:
|
||||
goto fe_done;
|
||||
default:
|
||||
cur_ch=p1;
|
||||
}
|
||||
break;
|
||||
case MSG_IP_L_DOWN:
|
||||
case MSG_IP_R_DOWN:
|
||||
if (0<=p1<FONT_WIDTH*16 &&
|
||||
0<=p2<FONT_HEIGHT*16) {
|
||||
cur_ch=(p2/FONT_HEIGHT)*16+p1/FONT_WIDTH;
|
||||
break;
|
||||
} //fall through
|
||||
case MSG_IP_MOVE:
|
||||
k=((p2-BLOW_UP_CHAR_Y)/FONT_HEIGHT)*FONT_WIDTH+
|
||||
(p1-BLOW_UP_CHAR_X)/FONT_WIDTH;
|
||||
if (0<=k<FONT_WIDTH*FONT_HEIGHT) {
|
||||
if (ip_lb||msg_code==MSG_IP_L_DOWN)
|
||||
Bts(&gr_font[FONT_HEIGHT*cur_ch],k);
|
||||
if (ip_rb||msg_code==MSG_IP_R_DOWN)
|
||||
Btr(&gr_font[FONT_HEIGHT*cur_ch],k);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
fe_done:
|
||||
} catch
|
||||
CatchAll;
|
||||
MenuPop;
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
FontEd;
|
||||
Binary file not shown.
@@ -0,0 +1,141 @@
|
||||
#define NUM_DISKS 6
|
||||
#define PEDESTAL_HEIGHT 20
|
||||
#define DISK_HEIGHT 7
|
||||
#define DISK_UNIT_WIDTH 5
|
||||
|
||||
I64 poles_x[3];
|
||||
I64 disks_x[NUM_DISKS],disks_y[NUM_DISKS],disks_pole[NUM_DISKS];
|
||||
|
||||
I64 OtherPole(I64 pole1,I64 pole2)
|
||||
{
|
||||
return 3-pole1-pole2;
|
||||
}
|
||||
|
||||
I64 TopDisk(I64 pole)
|
||||
{
|
||||
I64 i;
|
||||
for (i=0;i<NUM_DISKS;i++)
|
||||
if (disks_pole[i]==pole)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
I64 PosInStk(I64 pole,I64 disk)
|
||||
{
|
||||
I64 result=0,i;
|
||||
for (i=NUM_DISKS-1;i>disk;i--)
|
||||
if (disks_pole[i]==pole)
|
||||
result++;
|
||||
return result;
|
||||
}
|
||||
|
||||
U0 SetDisksRestXY()
|
||||
{
|
||||
I64 i;
|
||||
for (i=0;i<NUM_DISKS;i++) {
|
||||
disks_x[i]=poles_x[disks_pole[i]];
|
||||
disks_y[i]=Fs->win_pixel_height-PEDESTAL_HEIGHT-(DISK_HEIGHT+1)/2-1-(DISK_HEIGHT+1)*PosInStk(disks_pole[i],i);
|
||||
}
|
||||
}
|
||||
|
||||
U0 DrawIt(CTask *task,CDC *dc)
|
||||
{
|
||||
I64 i;
|
||||
|
||||
for (i=0;i<3;i++)
|
||||
poles_x[i]=(1+i)*task->win_pixel_width/4;
|
||||
|
||||
dc->color=BLACK;
|
||||
GrRect(dc,poles_x[0]-50,task->win_pixel_height-PEDESTAL_HEIGHT,poles_x[2]-poles_x[0]+100,PEDESTAL_HEIGHT-FONT_HEIGHT);
|
||||
dc->color=DKGRAY;
|
||||
GrRect(dc,poles_x[0]-49,task->win_pixel_height-PEDESTAL_HEIGHT+1,poles_x[2]-poles_x[0]+98,PEDESTAL_HEIGHT-FONT_HEIGHT-2);
|
||||
|
||||
for (i=0;i<3;i++) {
|
||||
dc->color=BLACK;
|
||||
GrRect(dc,poles_x[i]-3,task->win_pixel_height-PEDESTAL_HEIGHT-(NUM_DISKS+1)*(DISK_HEIGHT+1),7,(NUM_DISKS+1)*(DISK_HEIGHT+1));
|
||||
dc->color=YELLOW;
|
||||
GrRect(dc,poles_x[i]-2,task->win_pixel_height-PEDESTAL_HEIGHT+1-(NUM_DISKS+1)*(DISK_HEIGHT+1),5,(NUM_DISKS+1)*(DISK_HEIGHT+1)-1);
|
||||
}
|
||||
|
||||
for (i=0;i<NUM_DISKS;i++) {
|
||||
dc->color=BLACK;
|
||||
GrRect(dc,disks_x[i]-(i+1)*DISK_UNIT_WIDTH,disks_y[i]-DISK_HEIGHT/2,(i+1)*(DISK_UNIT_WIDTH*2)+1,DISK_HEIGHT);
|
||||
dc->color=gr_rainbow_10[i];
|
||||
GrRect(dc,disks_x[i]-(i+1)*DISK_UNIT_WIDTH+1,disks_y[i]-DISK_HEIGHT/2+1,(i+1)*(DISK_UNIT_WIDTH*2)-1,DISK_HEIGHT-2);
|
||||
}
|
||||
}
|
||||
|
||||
U0 MySleep()
|
||||
{
|
||||
if (ScanChar)
|
||||
ThrowBreak;
|
||||
Sleep(3);
|
||||
}
|
||||
|
||||
U0 MoveDisks(I64 src_pole,I64 dst_pole,I64 num)
|
||||
{
|
||||
I64 top,x,y;
|
||||
if (num>1)
|
||||
MoveDisks(src_pole,OtherPole(src_pole,dst_pole),num-1);
|
||||
DocClear;
|
||||
"$$CM+BY,0,0$$Disk:%d from %d to %d\n",TopDisk(src_pole),src_pole,dst_pole;
|
||||
|
||||
top=TopDisk(src_pole);
|
||||
for (y=disks_y[top];y>Fs->win_pixel_height-PEDESTAL_HEIGHT-(DISK_HEIGHT+1)/2-(DISK_HEIGHT+1)*(NUM_DISKS+2);y--) {
|
||||
disks_y[top]=y;
|
||||
MySleep;
|
||||
}
|
||||
if (src_pole<dst_pole)
|
||||
for (x=poles_x[src_pole];x<=poles_x[dst_pole];x++) {
|
||||
disks_x[top]=x;
|
||||
MySleep;
|
||||
}
|
||||
else
|
||||
for (x=poles_x[src_pole];x>=poles_x[dst_pole];x--) {
|
||||
disks_x[top]=x;
|
||||
MySleep;
|
||||
}
|
||||
|
||||
disks_pole[top]=dst_pole;
|
||||
for (y=disks_y[top];y<Fs->win_pixel_height-PEDESTAL_HEIGHT-(DISK_HEIGHT+1)/2-1-(DISK_HEIGHT+1)*PosInStk(dst_pole,top);y++) {
|
||||
disks_y[top]=y;
|
||||
MySleep;
|
||||
}
|
||||
SetDisksRestXY;
|
||||
if (num>1)
|
||||
MoveDisks(OtherPole(src_pole,dst_pole),dst_pole,num-1);
|
||||
}
|
||||
|
||||
U0 Init()
|
||||
{
|
||||
I64 i;
|
||||
for (i=0;i<3;i++)
|
||||
poles_x[i]=(1+i)*Fs->win_pixel_width/4;
|
||||
|
||||
for (i=0;i<NUM_DISKS;i++)
|
||||
disks_pole[i]=0;
|
||||
|
||||
SetDisksRestXY;
|
||||
}
|
||||
|
||||
U0 Hanoi()
|
||||
{
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
Init;
|
||||
DocClear;
|
||||
Fs->draw_it=&DrawIt;
|
||||
|
||||
Sleep(1000);
|
||||
try {
|
||||
MoveDisks(0,2,NUM_DISKS);
|
||||
Beep; Beep;
|
||||
DocClear;
|
||||
"$$CM+BY,0,0$$";
|
||||
PressAKey;
|
||||
} catch
|
||||
CatchAll;
|
||||
SettingsPop;
|
||||
DocClear;
|
||||
}
|
||||
|
||||
Hanoi;
|
||||
@@ -0,0 +1,97 @@
|
||||
CDC *dc[2]; //dbl buf
|
||||
I64 cur_dc,;
|
||||
Bool restart;
|
||||
|
||||
U0 DrawIt(CTask *,CDC *dc2)
|
||||
{
|
||||
dc[cur_dc]->flags|=DCF_NO_TRANSPARENTS;
|
||||
GrBlot(dc2,0,0,dc[cur_dc]);
|
||||
}
|
||||
|
||||
U0 AnimateTask(I64)
|
||||
{
|
||||
I64 x,y,x1,y1,cnt,next_dc;
|
||||
while (TRUE) {
|
||||
next_dc=cur_dc^1;
|
||||
start_over:
|
||||
restart=FALSE;
|
||||
DCClear(dc[next_dc]);
|
||||
for (y=1;y<Fs->parent_task->win_pixel_height-1;y++) {
|
||||
for (x=1;x<Fs->parent_task->win_pixel_width-1;x++) {
|
||||
cnt=0;
|
||||
for (y1=y-1;y1<=y+1;y1++)
|
||||
for (x1=x-1;x1<=x+1;x1++)
|
||||
if (GrPeek(dc[cur_dc],x1,y1)==GREEN)
|
||||
cnt++;
|
||||
if (restart) goto start_over;
|
||||
if (GrPeek(dc[cur_dc],x,y)==GREEN) {
|
||||
if (cnt==3) {
|
||||
dc[next_dc]->color=GREEN;
|
||||
GrPlot(dc[next_dc],x,y);
|
||||
}
|
||||
} else {
|
||||
// if (cnt==3) { //Use this for the classic rules
|
||||
if (cnt==2) {
|
||||
dc[next_dc]->color=GREEN;
|
||||
GrPlot(dc[next_dc],x,y);
|
||||
}
|
||||
}
|
||||
}
|
||||
Yield;
|
||||
}
|
||||
Sleep(50);
|
||||
cur_dc=next_dc;
|
||||
}
|
||||
}
|
||||
|
||||
public U0 Life()
|
||||
{
|
||||
I64 msg_code,cnt,x1,y1,x2,y2,p1,p2;
|
||||
|
||||
dc[0]=DCNew(DCT_COLOR8,GR_WIDTH,GR_HEIGHT);
|
||||
dc[1]=DCNew(DCT_COLOR8,GR_WIDTH,GR_HEIGHT);
|
||||
cur_dc=0;
|
||||
restart=FALSE;
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
WinMax;
|
||||
DCFill;
|
||||
"$$CL$$";
|
||||
|
||||
Fs->animate_task=Spawn(&AnimateTask,NULL,"Animate",Fs);
|
||||
WordStat;
|
||||
Fs->draw_it=&DrawIt;
|
||||
Fs->win_inhibit=WIF_ALL-WIF_BORDER;
|
||||
|
||||
do {
|
||||
msg_code=GetMsg(&p1,&p2,
|
||||
1<<MSG_KEY_DOWN+1<<MSG_IP_L_DOWN);
|
||||
switch (msg_code) {
|
||||
case MSG_IP_L_DOWN:
|
||||
x1=p1; y1=p2;
|
||||
x2=p1; y2=p2;
|
||||
cnt=0;
|
||||
while (msg_code!=MSG_IP_L_UP) {
|
||||
restart=TRUE;
|
||||
dc[cur_dc]->color=ROP_EQU+GREEN;
|
||||
dc[cur_dc]->pen_width=0.04*ip_speed;
|
||||
GrLine3(dc[cur_dc],x1,y1,0,x2,y2,0);
|
||||
restart=TRUE;
|
||||
msg_code=GetMsg(&p1,&p2,
|
||||
1<<MSG_IP_L_UP+1<<MSG_IP_MOVE);
|
||||
x1=x2; y1=y2;
|
||||
x2=p1; y2=p2;
|
||||
}
|
||||
GrLine3(dc[cur_dc],x1,y1,0,x2,y2,0);
|
||||
break;
|
||||
case MSG_KEY_DOWN:
|
||||
break;
|
||||
}
|
||||
} while (msg_code!=MSG_KEY_DOWN || !p1);
|
||||
SettingsPop;
|
||||
DCFill;
|
||||
DCDel(dc[0]);
|
||||
DCDel(dc[1]);
|
||||
}
|
||||
|
||||
Life;
|
||||
@@ -0,0 +1,26 @@
|
||||
U0 Main()
|
||||
{
|
||||
I64 x1=0,y1=0,x2=0,y2=0,i=1,c=0;
|
||||
I64 vx1=0,vy1=0,vx2=0,vy2=0;
|
||||
CDC *dc=DCAlias;
|
||||
while (!ScanChar) {
|
||||
if (!--i) {
|
||||
i=1000;
|
||||
dc->color=c++&15;
|
||||
}
|
||||
GrLine(dc,x1,y1,x2,y2);
|
||||
vx1=LimitI64(vx1+SignI64(RandI16),-5,5);
|
||||
vy1=LimitI64(vy1+SignI64(RandI16),-5,5);
|
||||
vx2=LimitI64(vx2+SignI64(RandI16),-5,5);
|
||||
vy2=LimitI64(vy2+SignI64(RandI16),-5,5);
|
||||
x1=LimitI64(x1+vx1,0,Fs->win_pixel_width-1);
|
||||
y1=LimitI64(y1+vy1,0,Fs->win_pixel_height-1);
|
||||
x2=LimitI64(x2+vx2,0,Fs->win_pixel_width-1);
|
||||
y2=LimitI64(y2+vy2,0,Fs->win_pixel_height-1);
|
||||
Sleep(1); //Take this out and see what happens!
|
||||
}
|
||||
DCFill(dc);
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
Main;
|
||||
Binary file not shown.
@@ -0,0 +1,82 @@
|
||||
#define STEP_SIZE 400
|
||||
|
||||
U0 LowPassFilterDemo()
|
||||
{
|
||||
F64 y,y1,t,dt;
|
||||
CDC *dc=DCAlias;
|
||||
|
||||
WinMax;
|
||||
DocClear;
|
||||
|
||||
dc->color=BLUE;
|
||||
GrLine(dc,0,0,0,STEP_SIZE);
|
||||
GrLine(dc,0,STEP_SIZE,GR_WIDTH/2,STEP_SIZE);
|
||||
GrLine(dc,GR_WIDTH/2,STEP_SIZE,GR_WIDTH/2,0);
|
||||
GrLine(dc,GR_WIDTH/2,0,GR_WIDTH,0);
|
||||
PressAKey;
|
||||
|
||||
dc->color=CYAN;
|
||||
t=0;
|
||||
y=0.0;
|
||||
while (t<GR_WIDTH) {
|
||||
dt=1.0;
|
||||
if (t<GR_WIDTH/2)
|
||||
y1=STEP_SIZE-STEP_SIZE*Exp(-0.01*t);
|
||||
else
|
||||
y1=STEP_SIZE*Exp(-0.01*(t-GR_WIDTH/2));
|
||||
GrLine(dc,t,y,t+dt,y1);
|
||||
y=y1;
|
||||
t+=dt;
|
||||
}
|
||||
PressAKey;
|
||||
|
||||
dc->color=BLACK;
|
||||
t=0;
|
||||
y=0.0;
|
||||
while (t<GR_WIDTH) {
|
||||
dt=1.0;
|
||||
if (t<GR_WIDTH/2)
|
||||
y1=0.99*y+.01*STEP_SIZE;
|
||||
else
|
||||
y1=0.99*y;
|
||||
GrLine(dc,t,y,t+dt,y1);
|
||||
y=y1;
|
||||
t+=dt;
|
||||
}
|
||||
PressAKey;
|
||||
|
||||
dc->color=RED;
|
||||
t=0;
|
||||
y=0.0;
|
||||
while (t<GR_WIDTH) {
|
||||
dt=Rand/10;
|
||||
if (t<GR_WIDTH/2)
|
||||
y1=LowPass1(.01,y,STEP_SIZE,dt);
|
||||
else
|
||||
y1=LowPass1(.01,y,0,dt);
|
||||
GrLine(dc,t,y,t+dt,y1);
|
||||
y=y1;
|
||||
t+=dt;
|
||||
}
|
||||
PressAKey;
|
||||
|
||||
dc->color=GREEN;
|
||||
t=0;
|
||||
y=0.0;
|
||||
while (t<GR_WIDTH) {
|
||||
dt=Rand/10;
|
||||
if (t<GR_WIDTH/2)
|
||||
y1=LowPass1(.1,y,STEP_SIZE,dt);
|
||||
else
|
||||
y1=LowPass1(.1,y,0,dt);
|
||||
GrLine(dc,t,y,t+dt,y1);
|
||||
y=y1;
|
||||
t+=dt;
|
||||
}
|
||||
PressAKey;
|
||||
|
||||
DCDel(dc);
|
||||
DCFill;
|
||||
}
|
||||
|
||||
LowPassFilterDemo;
|
||||
@@ -0,0 +1,100 @@
|
||||
F64 MySin(F64 d)
|
||||
{
|
||||
return Sin(d);
|
||||
}
|
||||
|
||||
F64 MyCos(F64 d)
|
||||
{
|
||||
return Cos(d);
|
||||
}
|
||||
|
||||
U0 FunDraw1(CDC *dc,F64 (*f)(F64 t))
|
||||
{
|
||||
I64 i,w=Fs->win_pixel_width,h=Fs->win_pixel_height;
|
||||
F64 scale=h/5.0;
|
||||
for (i=-w/2;i<=w/2;i++)
|
||||
GrLine(dc,w/2+i,h/2-scale*f(i/scale*2*ã),w/2+i+1,h/2-scale*f((i+1)/scale*2*ã));
|
||||
}
|
||||
|
||||
U0 FunDraw2(CDC *dc,F64 (*f)(F64 t,F64 p),F64 T)
|
||||
{
|
||||
I64 i,w=Fs->win_pixel_width,h=Fs->win_pixel_height;
|
||||
F64 scale=h/5.0;
|
||||
for (i=-w/2;i<=w/2;i++)
|
||||
GrLine(dc,w/2+i,h/2-scale*f(i/scale,T),w/2+i+1,h/2-scale*f((i+1)/scale,T));
|
||||
}
|
||||
|
||||
U0 Init(CDC *dc)
|
||||
{
|
||||
I64 i,w=Fs->win_pixel_width,h=Fs->win_pixel_height;
|
||||
F64 scale=h/5.0;
|
||||
DocClear;
|
||||
DCFill(dc);
|
||||
dc->color=BLACK;
|
||||
GrLine(dc,0,h/2,w-1,h/2);
|
||||
GrLine(dc,w/2,0,w/2,h-1);
|
||||
for (i=-2;i<=2;i++) {
|
||||
dc->color=BLACK;
|
||||
GrLine(dc,w/2-3,h/2-scale*i,w/2+3,h/2-scale*i);
|
||||
if (i) {
|
||||
dc->color=DKGRAY;
|
||||
GrPrintF(dc,w/2+5,h/2-scale*i-FONT_HEIGHT/2,"%5.1f",ToF64(i));
|
||||
}
|
||||
}
|
||||
for (i=-4;i<=4;i++) {
|
||||
dc->color=BLACK;
|
||||
GrLine(dc,w/2+scale*i,h/2-3,w/2+scale*i,h/2+3);
|
||||
if (i) {
|
||||
dc->color=DKGRAY;
|
||||
GrPrintF(dc,w/2+scale*i-7*FONT_WIDTH/2,h/2+5+FONT_HEIGHT,"%5.1f*T",ToF64(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 SndMathDemo()
|
||||
{
|
||||
CDC *dc=DCAlias;
|
||||
|
||||
Init(dc);
|
||||
dc->color=RED;
|
||||
FunDraw1(dc,&MySin);
|
||||
"$$FG,RED$$Sin$$FG$$\n";
|
||||
PressAKey;
|
||||
dc->color=BLUE;
|
||||
FunDraw2(dc,&Saw,1.0);
|
||||
"$$FG,BLUE$$Saw$$FG$$\n";
|
||||
PressAKey;
|
||||
|
||||
Init(dc);
|
||||
dc->color=RED;
|
||||
FunDraw1(dc,&MyCos);
|
||||
"$$FG,RED$$Cos$$FG$$\n";
|
||||
PressAKey;
|
||||
dc->color=BLUE;
|
||||
FunDraw2(dc,&Caw,1.0);
|
||||
"$$FG,BLUE$$Caw$$FG$$\n";
|
||||
PressAKey;
|
||||
dc->color=GREEN;
|
||||
FunDraw2(dc,&FullCaw,1.0);
|
||||
"$$FG,GREEN$$FullCaw$$FG$$\n";
|
||||
PressAKey;
|
||||
|
||||
Init(dc);
|
||||
dc->color=RED;
|
||||
FunDraw1(dc,&MySin);
|
||||
"$$FG,RED$$Sin$$FG$$\n";
|
||||
PressAKey;
|
||||
dc->color=BLUE;
|
||||
FunDraw2(dc,&Tri,1.0);
|
||||
"$$FG,BLUE$$Tri$$FG$$\n";
|
||||
PressAKey;
|
||||
dc->color=GREEN;
|
||||
FunDraw2(dc,&FullTri,1.0);
|
||||
"$$FG,GREEN$$FullTri$$FG$$\n";
|
||||
PressAKey;
|
||||
|
||||
DCFill(dc);
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
SndMathDemo;
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,21 @@
|
||||
U0 DrawIt(CTask *task,CDC *)
|
||||
{
|
||||
if (win_updates&1)
|
||||
PlotWinStr(task,"test",RED+WHITE*16,10,3);
|
||||
else
|
||||
PlotWinStr(task,"test",PURPLE+WHITE*16,10,3);
|
||||
PlotWinStr(task,"test",RED+WHITE*16,10,2);
|
||||
PlotWinStr(task,"test",PURPLE+WHITE*16,10,4);
|
||||
}
|
||||
|
||||
U0 Main()
|
||||
{
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
DocClear;
|
||||
Fs->draw_it=&DrawIt;
|
||||
|
||||
GetChar;
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
Main;
|
||||
@@ -0,0 +1,27 @@
|
||||
U0 PaletteDemo()
|
||||
{
|
||||
I64 i,j;
|
||||
CBGR bgr;
|
||||
for (i=0;i<16;i++)
|
||||
"$$FG,BLACK$$$$BG,%d$$__%-8Z__$$FG$$$$BG$$\n",i,i,"ST_COLORS";
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
//Alternatively, use $LK,"SetVGAPalette4","MN:SetVGAPalette4"$(vga_palette4_gray);
|
||||
for (i=0;i<16;i++) {
|
||||
j=0xFF*i/15;
|
||||
bgr.b=j;
|
||||
bgr.g=j;
|
||||
bgr.r=j;
|
||||
SetVGAPaletteColor(i,bgr);
|
||||
}
|
||||
PressAKey;
|
||||
|
||||
//You can do it this way, too.
|
||||
SetVGAPaletteColor(WHITE,0xFFFF00);
|
||||
PressAKey;
|
||||
|
||||
//$LK,"SettingsPop","MN:SettingsPop"$() restores original palette
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
PaletteDemo;
|
||||
@@ -0,0 +1,101 @@
|
||||
U0 Convert()
|
||||
{
|
||||
I64 *ptr;
|
||||
|
||||
//Normally, allocate large objects on the heap
|
||||
//because stk size can't grow. 256 bytes, however,
|
||||
//is not that bad.
|
||||
U8 byte_bit_cnts[256];
|
||||
|
||||
I64 i,j,row,col,ch,best_ch,score,best_score,cur_char_image,diff_image;
|
||||
CDC *dc=DCAlias;
|
||||
|
||||
//Set-up a table telling how many 1 bits in a val.
|
||||
MemSet(byte_bit_cnts,0,sizeof(byte_bit_cnts));
|
||||
for (i=0;i<256;i++)
|
||||
for (j=0;j<7;j++)
|
||||
if (Bt(&i,j))
|
||||
byte_bit_cnts[i]++;
|
||||
|
||||
for (row=0;row<Fs->win_height;row++) {
|
||||
for (col=0;col<Fs->win_width;col++) {
|
||||
|
||||
|
||||
//The size of one character is 8x8 pixels
|
||||
//which fits in a 64-bit var. We'll
|
||||
//fetch the pixels from the screen using $LK,"GrPeek","MN:GrPeek"$().
|
||||
cur_char_image=0;
|
||||
for (i=0;i<FONT_HEIGHT;i++)
|
||||
for (j=0;j<FONT_WIDTH;j++)
|
||||
//$LK,"GrPeek","MN:GrPeek"$() returns color or -1 if covered or off-screen.
|
||||
if (GrPeek(dc,col*FONT_WIDTH+j,row*FONT_HEIGHT+i)!=COLOR_TRANSPARENT)
|
||||
LBts(&cur_char_image,i*8+j);
|
||||
|
||||
best_score=MAX_I64;
|
||||
best_ch=0;
|
||||
ptr=&gr_font[32*FONT_HEIGHT];
|
||||
for (ch=32;ch<127;ch++) {
|
||||
diff_image=*ptr++ ^ cur_char_image;
|
||||
score=0;
|
||||
for (i=0;i<8;i++)
|
||||
score+=byte_bit_cnts[diff_image.u8[i]];
|
||||
if (score<best_score) {
|
||||
best_score=score;
|
||||
best_ch=ch;
|
||||
}
|
||||
}
|
||||
if (best_ch=='$$')
|
||||
"$$$$";
|
||||
else
|
||||
'' best_ch;
|
||||
}
|
||||
NewLine;
|
||||
}
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
public U0 Pic2ASCII()
|
||||
{
|
||||
I64 msg_code,cnt,x1,y1,x2,y2,p1,p2;
|
||||
CDC *dc=DCAlias;
|
||||
dc->color=ROP_EQU+BLACK;
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
Fs->win_inhibit=WIF_ALL-WIF_BORDER;
|
||||
|
||||
WinMax;
|
||||
DCFill;
|
||||
"$$CL$$Draw a picture and hit\na key to convert to ASCII.\n";
|
||||
do {
|
||||
msg_code=GetMsg(&p1,&p2,
|
||||
1<<MSG_KEY_DOWN+1<<MSG_IP_L_DOWN);
|
||||
switch (msg_code) {
|
||||
case MSG_IP_L_DOWN:
|
||||
x1=p1; y1=p2;
|
||||
x2=p1; y2=p2;
|
||||
cnt=0;
|
||||
while (msg_code!=MSG_IP_L_UP) {
|
||||
dc->pen_width=0.04*ip_speed;
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
msg_code=GetMsg(&p1,&p2,
|
||||
1<<MSG_IP_L_UP+1<<MSG_IP_MOVE);
|
||||
x1=x2; y1=y2;
|
||||
x2=p1; y2=p2;
|
||||
}
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
break;
|
||||
case MSG_KEY_DOWN:
|
||||
break;
|
||||
}
|
||||
} while (msg_code!=MSG_KEY_DOWN || !p1);
|
||||
|
||||
//We clear the screen text and turn-off word-wrap
|
||||
"$$CL$$$$WW,0$$";
|
||||
|
||||
Convert;
|
||||
DCFill;
|
||||
DCDel(dc);
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
Pic2ASCII; //Execute when #included
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,171 @@
|
||||
#define NUM_ZEROS 2
|
||||
Complex zeros[NUM_ZEROS]={{10.0,0},{-30,0}};
|
||||
#define NUM_POLES 2
|
||||
Complex poles[NUM_POLES]={{-20.0,-15.0},{-20.0,15.0}};
|
||||
|
||||
F64 scale;
|
||||
|
||||
Complex *PoleZeroFind(I64 x,I64 y)
|
||||
{
|
||||
I64 i;
|
||||
F64 d,best_d=MAX_F64;
|
||||
Complex *result=NULL;
|
||||
for (i=0;i<NUM_POLES;i++) {
|
||||
d=Sqr(poles[i].x-x)+Sqr(poles[i].y-y);
|
||||
if (d<best_d) {
|
||||
best_d=d;
|
||||
result=&poles[i];
|
||||
}
|
||||
}
|
||||
for (i=0;i<NUM_ZEROS;i++) {
|
||||
d=Sqr(zeros[i].x-x)+Sqr(zeros[i].y-y);
|
||||
if (d<best_d) {
|
||||
best_d=d;
|
||||
result=&zeros[i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
F64 F(Complex *x)
|
||||
{
|
||||
F64 m,a;
|
||||
Complex num,denom,n1;
|
||||
|
||||
CPoly(&num, x,zeros,NUM_ZEROS);
|
||||
CPoly(&denom,x,poles,NUM_POLES);
|
||||
CDiv(&num,&denom,&n1);
|
||||
|
||||
R2P(&m,&a,n1.x,n1.y);
|
||||
if (ip_rb)
|
||||
return ã+a;
|
||||
else
|
||||
return m;
|
||||
}
|
||||
|
||||
F64 MPDraw(CTask *task)
|
||||
{
|
||||
Complex xx;
|
||||
I64 x,y,w=task->win_pixel_width,h=task->win_pixel_height,cx=w/2,cy=h/2,
|
||||
lo=Gs->num*h/mp_cnt,hi=(Gs->num+1)*h/mp_cnt;
|
||||
F64 yy,y_total=0;
|
||||
CDC *dc=DCAlias(gr_dc2,task);
|
||||
for (y=lo;y<hi;y++) {
|
||||
for (x=0;x<w;x++) {
|
||||
CEqu(&xx,x-cx,cy-y);
|
||||
yy=scale*F(&xx);
|
||||
dc->color=Limit(yy,0,14);
|
||||
y_total+=Limit(yy,-14,14);
|
||||
GrPlot(dc,x,y);
|
||||
}
|
||||
}
|
||||
DCDel(dc);
|
||||
return y_total;
|
||||
}
|
||||
|
||||
U0 Draw()
|
||||
{
|
||||
CMPCmd *tempm[MP_MAX_PROCESSORS];
|
||||
F64 y_total,old_y_total=MAX_F64;
|
||||
I64 i,w=Fs->win_pixel_width,h=Fs->win_pixel_height,cx=w/2,cy=h/2;
|
||||
CDC *dc=DCAlias;
|
||||
while (TRUE) {
|
||||
|
||||
for (i=1;i<mp_cnt;i++)
|
||||
tempm[i]=MPJob(&MPDraw,Fs,i,0);
|
||||
y_total=MPDraw(Fs);
|
||||
for (i=1;i<mp_cnt;i++)
|
||||
y_total+=MPJobResult(tempm[i])(F64);
|
||||
|
||||
if (!y_total) break;
|
||||
scale*=7*GR_WIDTH*GR_HEIGHT/y_total;
|
||||
if (Abs(y_total-old_y_total)<1.0*GR_WIDTH*GR_HEIGHT)
|
||||
break;
|
||||
old_y_total=y_total;
|
||||
}
|
||||
dc->color=15;
|
||||
GrLine(dc,0,cy,w,cy);
|
||||
GrLine(dc,cx,0,cx,h);
|
||||
for (i=0;i<NUM_ZEROS;i++)
|
||||
GrPutS(dc,cx+zeros[i].x-FONT_WIDTH/2,cy-zeros[i].y-FONT_HEIGHT/2,"o");
|
||||
for (i=0;i<NUM_POLES;i++)
|
||||
GrPutS(dc,cx+poles[i].x-FONT_WIDTH/2,cy-poles[i].y-FONT_HEIGHT/2,"x");
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
U0 PoleZeros()
|
||||
{
|
||||
I64 msg_code,p1,p2,p11,p22,cx,cy;
|
||||
Complex *tempc=NULL;
|
||||
|
||||
PopUpOk(
|
||||
"Drag the poles and zeros with left mouse.\n"
|
||||
"Hold right mouse for phase plot.\n"
|
||||
);
|
||||
WinMgrSync;
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
Fs->win_inhibit=WIF_ALL-WIF_BORDER;
|
||||
SetVGAPalette4(vga_palette4_gray);
|
||||
SetVGAPaletteColor(15,0xFF0000); //White is red
|
||||
|
||||
WinMax;
|
||||
WordStat;
|
||||
WinBorder;
|
||||
|
||||
DCFill;
|
||||
DocClear;
|
||||
scale=1.0;
|
||||
|
||||
try {
|
||||
Draw;
|
||||
while (TRUE) {
|
||||
msg_code=GetMsg(&p1,&p2,1<<MSG_KEY_DOWN+1<<MSG_IP_L_DOWN+1<<MSG_IP_L_UP+1<<MSG_IP_R_DOWN+1<<MSG_IP_R_UP+1<<MSG_IP_MOVE);
|
||||
pz_msg:
|
||||
cx=Fs->win_pixel_width/2;
|
||||
cy=Fs->win_pixel_height/2;
|
||||
switch (msg_code) {
|
||||
case MSG_IP_L_DOWN:
|
||||
tempc=PoleZeroFind(p1-cx,cy-p2);
|
||||
break;
|
||||
case MSG_IP_MOVE:
|
||||
if (tempc) {
|
||||
p11=p1;p22=p2;
|
||||
//get to last mouse move
|
||||
while (msg_code=ScanMsg(&p1,&p2,1<<MSG_KEY_DOWN+1<<MSG_IP_L_DOWN+1<<MSG_IP_L_UP+1<<MSG_IP_R_DOWN+1<<MSG_IP_R_UP+1<<MSG_IP_MOVE))
|
||||
if (msg_code==MSG_IP_MOVE) {
|
||||
p11=p1;p22=p2;
|
||||
} else
|
||||
goto pz_msg;
|
||||
|
||||
tempc->x=p11-cx;
|
||||
tempc->y=cy-p22;
|
||||
Draw;
|
||||
}
|
||||
break;
|
||||
case MSG_IP_L_UP:
|
||||
if (tempc) {
|
||||
tempc->x=p1-cx;
|
||||
tempc->y=cy-p2;
|
||||
tempc=NULL;
|
||||
Draw;
|
||||
}
|
||||
break;
|
||||
case MSG_IP_R_DOWN:
|
||||
case MSG_IP_R_UP:
|
||||
Draw;
|
||||
break;
|
||||
case MSG_KEY_DOWN:
|
||||
if (p1==CH_SHIFT_ESC||p1==CH_ESC)
|
||||
goto pz_done;
|
||||
}
|
||||
WinMgrSync;
|
||||
}
|
||||
pz_done:
|
||||
} catch
|
||||
CatchAll;
|
||||
SettingsPop;
|
||||
DCFill;
|
||||
}
|
||||
|
||||
PoleZeros;
|
||||
@@ -0,0 +1,82 @@
|
||||
//This is a classic 2nd order nonlinear ordinary differential equation
|
||||
|
||||
I64 mp_done_flags;
|
||||
|
||||
#define OX 10
|
||||
#define OY GR_HEIGHT/2-FONT_HEIGHT
|
||||
|
||||
#define MICRO_STEP 0.000001
|
||||
|
||||
class State
|
||||
{
|
||||
F64 wabbits,hawks,
|
||||
d_wabbits,d_hawks; //Technically, these are not part of the state.
|
||||
};
|
||||
|
||||
U0 Steps(State *s)
|
||||
{
|
||||
I64 i;
|
||||
for (i=0;i<10000;i++) {
|
||||
s->d_wabbits=s->wabbits*(1.0-0.10*s->hawks);
|
||||
s->d_hawks =-s->hawks *(1.0-0.01*s->wabbits);
|
||||
s->hawks +=s->d_hawks *MICRO_STEP;
|
||||
s->wabbits+=s->d_wabbits*MICRO_STEP;
|
||||
}
|
||||
}
|
||||
|
||||
U0 PlotTrajectory(CTask *parent)
|
||||
{
|
||||
I64 i;
|
||||
CDC *dc=DCAlias(gr_dc2,parent);
|
||||
State s;
|
||||
|
||||
MemSet(&s,0,sizeof(State));
|
||||
s.wabbits=RandU16%100 +10;
|
||||
s.hawks =RandU16%10 +1;
|
||||
|
||||
for (i=0;i<1000;i++) {
|
||||
dc->color=LTGREEN;
|
||||
GrPlot(dc,s.wabbits+OX,OY-s.d_wabbits);
|
||||
dc->color=LTRED;
|
||||
GrPlot(dc,s.hawks +OX,OY-s.d_hawks);
|
||||
Steps(&s);
|
||||
}
|
||||
DCDel(dc);
|
||||
LBts(&mp_done_flags,Gs->num);
|
||||
}
|
||||
|
||||
U0 PredatorPrey()
|
||||
{
|
||||
I64 i;
|
||||
CDC *dc=DCAlias;
|
||||
|
||||
PopUpOk("This will plot multiple predator-prey\n"
|
||||
"trajectories. It restarts many times\n"
|
||||
"with different, random, initial populations.\n");
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
try {
|
||||
DocClear;
|
||||
WinMax;
|
||||
WinBorder;
|
||||
WinMgrSync;
|
||||
WordStat;
|
||||
|
||||
dc->color=BLACK;
|
||||
GrLine(dc,OX,0,OX,GR_HEIGHT-FONT_HEIGHT-1);
|
||||
GrLine(dc,0,OY,GR_WIDTH-1,OY);
|
||||
while (!ScanChar) {
|
||||
mp_done_flags=0;
|
||||
for (i=1;i<mp_cnt;i++)
|
||||
MPJob(&PlotTrajectory,Fs,i);
|
||||
PlotTrajectory(Fs);
|
||||
while (mp_done_flags!=1<<mp_cnt-1)
|
||||
Yield;
|
||||
}
|
||||
} catch
|
||||
CatchAll;
|
||||
SettingsPop;
|
||||
DCFill(dc);
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
PredatorPrey;
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,180 @@
|
||||
//"ls" is light source.
|
||||
|
||||
U0 Lighting(CDC *dc,CD3I32 *ls,CD3I32 *poly,I64 color)
|
||||
{ //color is a color from 0-7
|
||||
CD3I32 v1,v2;
|
||||
I64 *r=dc->r,i,vn_x,vn_y,vn_z;
|
||||
F64 d;
|
||||
|
||||
v1.x=poly[0].x-poly[1].x;
|
||||
v1.y=poly[0].y-poly[1].y;
|
||||
v1.z=poly[0].z-poly[1].z;
|
||||
|
||||
v2.x=poly[2].x-poly[1].x;
|
||||
v2.y=poly[2].y-poly[1].y;
|
||||
v2.z=poly[2].z-poly[1].z;
|
||||
|
||||
//V1 and V2 are vects along two sides
|
||||
//of the polygon joined at point[1].
|
||||
|
||||
vn_x=v1.y*v2.z-v1.z*v2.y;
|
||||
vn_y=v1.z*v2.x-v1.x*v2.z;
|
||||
vn_z=v1.x*v2.y-v1.y*v2.x;
|
||||
|
||||
if (d=Sqrt(SqrI64(vn_x)+SqrI64(vn_y)+SqrI64(vn_z)))
|
||||
d=1<<16/d;
|
||||
vn_x*=d;
|
||||
vn_y*=d;
|
||||
vn_z*=d;
|
||||
//Vn is the cross product of V1 and V3
|
||||
//which means it is perpendicular. It
|
||||
//is the normal vect to the surface.
|
||||
//It has been scaled to length 65536.
|
||||
GrRot(r,&vn_x,&vn_y,&vn_z);
|
||||
i=(vn_x*ls->x+vn_y*ls->y+vn_z*ls->z)>>16;
|
||||
//The dot product of the light source
|
||||
//vect and the surface normal
|
||||
//gives an illumination number.
|
||||
|
||||
|
||||
//SparrowOS will generate a random U16
|
||||
//and compare to dither_probability and
|
||||
//will pick from two colors.
|
||||
//Probability dithering does not work with pen_width>1 at this time.
|
||||
if (i<0) {
|
||||
dc->color=ROPF_PROBABILITY_DITHER+BLACK<<16+color;
|
||||
dc->dither_probability=-i;
|
||||
} else {
|
||||
dc->color=ROPF_PROBABILITY_DITHER+(color^8)<<16+color;
|
||||
dc->dither_probability=i;
|
||||
}
|
||||
}
|
||||
|
||||
#define RINGS 8
|
||||
#define FACES 32
|
||||
#define SLOP 0.03 //Gaps appear without this.
|
||||
|
||||
U0 DrawIt(CTask *task,CDC *dc)
|
||||
{
|
||||
CCtrl *c=CtrlFindUnique(task,CTRLT_VIEWING_ANGLES);
|
||||
CViewAngles *s=c->state;
|
||||
F64 tt=0.5*(Sin(ã*2*(tP(task)%10.0)/10.0)+2.0),
|
||||
é,é2,è,è2,radius,d;
|
||||
I64 i,j,cx=task->win_pixel_width/2,cy=task->win_pixel_height/2;
|
||||
CD3I32 poly[3],ls;
|
||||
|
||||
dc->flags|=DCF_TRANSFORMATION;
|
||||
DCAllocDepthBuf(dc);
|
||||
|
||||
GrIdentEqu(dc->r);
|
||||
GrRotZEqu(dc->r,s->az);
|
||||
GrRotYEqu(dc->r,s->ay);
|
||||
GrRotXEqu(dc->r,s->ax+ã);
|
||||
GrScaleMatEqu(dc->r,tt);
|
||||
GrSetRotMat(dc,dc->r);
|
||||
|
||||
ls.x=-(ipx-task->win_pixel_left-task->win_scroll_x-cx);
|
||||
ls.y=-(ipy-task->win_pixel_top-task->win_scroll_y-cy);
|
||||
ls.z=GR_WIDTH/8;
|
||||
d=1<<16/P3I32Norm(&ls);
|
||||
ls.x*=d;
|
||||
ls.y*=d;
|
||||
ls.z*=d;
|
||||
|
||||
|
||||
dc->x=cx;
|
||||
dc->y=cy;
|
||||
dc->z=MaxI64(cx,cy);
|
||||
radius =MinI64(cx,cy)/2;
|
||||
|
||||
|
||||
for (i=0;i<RINGS;i++) {
|
||||
è = i*ã/2/RINGS;
|
||||
è2=(i+1)*ã/2/RINGS+SLOP;
|
||||
for (j=0;j<FACES;j++) {
|
||||
é = j*2*ã/FACES;
|
||||
é2=(j+1)*2*ã/FACES+SLOP;
|
||||
|
||||
//Upper half
|
||||
poly[0].x=radius*Cos(è)*Cos(é);
|
||||
poly[0].y=radius*Cos(è)*Sin(é);
|
||||
poly[0].z=radius*Sin(è);
|
||||
poly[1].x=radius*Cos(è)*Cos(é2);
|
||||
poly[1].y=radius*Cos(è)*Sin(é2);
|
||||
poly[1].z=radius*Sin(è);
|
||||
poly[2].x=radius*Cos(è2)*Cos(é+2*ã/FACES/2);
|
||||
poly[2].y=radius*Cos(è2)*Sin(é+2*ã/FACES/2);
|
||||
poly[2].z=radius*Sin(è2);
|
||||
Lighting(dc,&ls,poly,BLUE);
|
||||
GrFillPoly3(dc,3,poly);
|
||||
|
||||
poly[2].x=radius*Cos(è2)*Cos(é +2*ã/FACES/2);
|
||||
poly[2].y=radius*Cos(è2)*Sin(é +2*ã/FACES/2);
|
||||
poly[2].z=radius*Sin(è2);
|
||||
poly[1].x=radius*Cos(è2)*Cos(é2+2*ã/FACES/2);
|
||||
poly[1].y=radius*Cos(è2)*Sin(é2+2*ã/FACES/2);
|
||||
poly[1].z=radius*Sin(è2);
|
||||
poly[0].x=radius*Cos(è)*Cos(é2);
|
||||
poly[0].y=radius*Cos(è)*Sin(é2);
|
||||
poly[0].z=radius*Sin(è);
|
||||
Lighting(dc,&ls,poly,BLUE);
|
||||
GrFillPoly3(dc,3,poly);
|
||||
|
||||
//Lower half
|
||||
poly[2].x=radius*Cos(è)*Cos(é);
|
||||
poly[2].y=radius*Cos(è)*Sin(é);
|
||||
poly[2].z=-radius*Sin(è);
|
||||
poly[1].x=radius*Cos(è)*Cos(é2);
|
||||
poly[1].y=radius*Cos(è)*Sin(é2);
|
||||
poly[1].z=-radius*Sin(è);
|
||||
poly[0].x=radius*Cos(è2)*Cos(é+2*ã/FACES/2);
|
||||
poly[0].y=radius*Cos(è2)*Sin(é+2*ã/FACES/2);
|
||||
poly[0].z=-radius*Sin(è2);
|
||||
Lighting(dc,&ls,poly,RED);
|
||||
GrFillPoly3(dc,3,poly);
|
||||
|
||||
poly[0].x=radius*Cos(è2)*Cos(é +2*ã/FACES/2);
|
||||
poly[0].y=radius*Cos(è2)*Sin(é +2*ã/FACES/2);
|
||||
poly[0].z=-radius*Sin(è2);
|
||||
poly[1].x=radius*Cos(è2)*Cos(é2+2*ã/FACES/2);
|
||||
poly[1].y=radius*Cos(è2)*Sin(é2+2*ã/FACES/2);
|
||||
poly[1].z=-radius*Sin(è2);
|
||||
poly[2].x=radius*Cos(è)*Cos(é2);
|
||||
poly[2].y=radius*Cos(è)*Sin(é2);
|
||||
poly[2].z=-radius*Sin(è);
|
||||
Lighting(dc,&ls,poly,RED);
|
||||
GrFillPoly3(dc,3,poly);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//See $LK,"::/SparrowOS/Demo/Graphics/SpritePlot3D.CPP.Z","FI:::/SparrowOS/Demo/Graphics/SpritePlot3D.CPP.Z"$.
|
||||
//for a CSprite example.
|
||||
|
||||
//See $LK,"CSpriteMesh","MN:CSpriteMesh"$() for a fancy example.
|
||||
|
||||
U0 Main()
|
||||
{
|
||||
CCtrl *c=ViewAnglesNew;
|
||||
CViewAngles *s=c->state;
|
||||
s->sx=2*VIEWANGLES_SNAP;
|
||||
s->sy=7*VIEWANGLES_SNAP;
|
||||
s->sz=6*VIEWANGLES_SNAP;
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
DocClear;
|
||||
WinMax;
|
||||
WinBorder;
|
||||
WordStat;
|
||||
Fs->draw_it=&DrawIt;
|
||||
try {
|
||||
"\n\nMove mouse to change light source.\n\n";
|
||||
PressAKey;
|
||||
} catch
|
||||
CatchAll;
|
||||
SettingsPop;
|
||||
DocClear;
|
||||
ViewAnglesDel;
|
||||
}
|
||||
|
||||
Main;
|
||||
Binary file not shown.
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
This was done with <CTRL-SHIFT-L> managed code.
|
||||
It's conceptually easy to do a ctrl,
|
||||
but tedious. You have complete freedom.
|
||||
|
||||
See $LK,"CCtrl","MN:CCtrl"$.
|
||||
*/
|
||||
|
||||
// Start of autocreated Code
|
||||
#define SLIDER_RANGE 30
|
||||
#define SLIDER_SPACING 20
|
||||
#define SLIDER_BORDER 2
|
||||
|
||||
class CSliderState
|
||||
{
|
||||
I64 left_pos;
|
||||
I64 right_pos;
|
||||
} sld;
|
||||
|
||||
U0 DrawSliderCtrl(CDC *dc,CCtrl *c)
|
||||
{
|
||||
CSliderState *s=c->state;
|
||||
|
||||
dc->color=LTRED;
|
||||
GrRect(dc, c->left,c->top,SLIDER_SPACING*3+2,SLIDER_SPACING*2+SLIDER_RANGE);
|
||||
dc->color=BLUE;
|
||||
GrRect(dc, c->left+SLIDER_BORDER,c->top+SLIDER_BORDER,
|
||||
SLIDER_SPACING*3+2-2*SLIDER_BORDER,SLIDER_SPACING*2+SLIDER_RANGE-2*SLIDER_BORDER);
|
||||
dc->color=BLACK;
|
||||
GrLine(dc,c->left+1*SLIDER_SPACING+0,c->top+SLIDER_SPACING,
|
||||
c->left+1*SLIDER_SPACING+0,c->top+SLIDER_SPACING+SLIDER_RANGE-1);
|
||||
GrLine(dc,c->left+2*SLIDER_SPACING+1,c->top+SLIDER_SPACING,
|
||||
c->left+2*SLIDER_SPACING+1,c->top+SLIDER_SPACING+SLIDER_RANGE-1);
|
||||
dc->color=LTRED;
|
||||
GrPrintF(dc,c->left+1*SLIDER_SPACING+0-FONT_WIDTH/2,
|
||||
c->top+SLIDER_SPACING+SLIDER_RANGE+3,
|
||||
"%d",s->left_pos*10/SLIDER_RANGE);
|
||||
GrPrintF(dc,c->left+2*SLIDER_SPACING+1-FONT_WIDTH/2,
|
||||
c->top+SLIDER_SPACING+SLIDER_RANGE+3,
|
||||
"%d",s->right_pos*10/SLIDER_RANGE);
|
||||
GrRect(dc,c->left+1*SLIDER_SPACING+0-3,c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->left_pos-2,7,5);
|
||||
GrRect(dc,c->left+2*SLIDER_SPACING+1-3,c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->right_pos-2,7,5);
|
||||
dc->color=YELLOW;
|
||||
GrRect(dc,c->left+1*SLIDER_SPACING+0-2,c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->left_pos-1,5,3);
|
||||
GrRect(dc,c->left+2*SLIDER_SPACING+1-2,c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->right_pos-1,5,3);
|
||||
}
|
||||
|
||||
U0 UpdateDerivedSliderCtrl(CCtrl *c)
|
||||
{
|
||||
CSliderState *s=c->state;
|
||||
c->left=c->win_task->win_pixel_width/2-(SLIDER_SPACING*3+2)/2;
|
||||
c->right=c->left+3*SLIDER_SPACING+2;
|
||||
c->top=c->win_task->win_pixel_height/2-(SLIDER_SPACING*2+SLIDER_RANGE)/2;
|
||||
c->bottom=c->top+SLIDER_SPACING*2+SLIDER_RANGE;
|
||||
s->left_pos=LimitI64(s->left_pos,0,SLIDER_RANGE-1);
|
||||
s->right_pos=LimitI64(s->right_pos,0,SLIDER_RANGE-1);
|
||||
}
|
||||
|
||||
U0 LeftClickSlider(CCtrl *c,I64 x,I64 y,Bool)
|
||||
{
|
||||
CSliderState *s=c->state;
|
||||
if (x<c->left+1*SLIDER_SPACING+0+SLIDER_SPACING/2)
|
||||
s->left_pos=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));
|
||||
else
|
||||
s->right_pos=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));
|
||||
if (c->update_derived_vals)
|
||||
(*c->update_derived_vals)(c);
|
||||
}
|
||||
|
||||
CCtrl *SliderNew()
|
||||
{
|
||||
Bool old_preempt;
|
||||
CCtrl *c=CAlloc(sizeof(CCtrl));
|
||||
c->win_task=Fs;
|
||||
c->flags=CTRLF_SHOW|CTRLF_CAPTURE_LEFT_IP;
|
||||
c->type=CTRLT_GENERIC;
|
||||
c->state=&sld;
|
||||
MemSet(&sld,0,sizeof(CSliderState));
|
||||
c->draw_it=&DrawSliderCtrl;
|
||||
c->left_click=&LeftClickSlider;
|
||||
c->update_derived_vals=&UpdateDerivedSliderCtrl;
|
||||
old_preempt=Preempt(OFF);
|
||||
QueIns(c,Fs->last_ctrl);
|
||||
TaskDerivedValsUpdate;
|
||||
Preempt(old_preempt);
|
||||
return c;
|
||||
}
|
||||
|
||||
U0 SliderDel(CCtrl *c)
|
||||
{
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
QueRem(c);
|
||||
Preempt(old_preempt);
|
||||
Free(c);
|
||||
}
|
||||
|
||||
// End of autocreated Code
|
||||
|
||||
U0 Main()
|
||||
{
|
||||
"This is to demo ctrls.\n";
|
||||
CCtrl *c=SliderNew;
|
||||
PressAKey;
|
||||
"Left: %d Right: %d\n",
|
||||
sld.left_pos*10/SLIDER_RANGE,
|
||||
sld.right_pos*10/SLIDER_RANGE;
|
||||
SliderDel(c);
|
||||
DocBottom;
|
||||
}
|
||||
|
||||
Main;
|
||||
@@ -0,0 +1,49 @@
|
||||
//This is a drawing program
|
||||
|
||||
public U0 SpeedLineDemo()
|
||||
{
|
||||
I64 msg_code,cnt,x1,y1,x2,y2,p1,p2,color=BLACK;
|
||||
CDC *dc=DCAlias;
|
||||
dc->color=ROP_EQU+color;
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
Fs->win_inhibit=WIF_ALL-WIF_BORDER;
|
||||
|
||||
WinMax;
|
||||
WordStat;
|
||||
DCFill;
|
||||
"$$CL$$";
|
||||
do {
|
||||
msg_code=GetMsg(&p1,&p2,
|
||||
1<<MSG_KEY_DOWN+1<<MSG_IP_L_DOWN+
|
||||
1<<MSG_IP_R_UP);
|
||||
switch (msg_code) {
|
||||
case MSG_IP_R_UP:
|
||||
color=PopUpColor;
|
||||
if (color>=0)
|
||||
dc->color=ROP_EQU+color;
|
||||
break;
|
||||
case MSG_IP_L_DOWN:
|
||||
x1=p1; y1=p2;
|
||||
x2=p1; y2=p2;
|
||||
cnt=0;
|
||||
while (msg_code!=MSG_IP_L_UP) {
|
||||
dc->pen_width=0.04*ip_speed;
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
msg_code=GetMsg(&p1,&p2,
|
||||
1<<MSG_IP_L_UP+1<<MSG_IP_MOVE);
|
||||
x1=x2; y1=y2;
|
||||
x2=p1; y2=p2;
|
||||
}
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
break;
|
||||
case MSG_KEY_DOWN:
|
||||
break;
|
||||
}
|
||||
} while (msg_code!=MSG_KEY_DOWN || !p1);
|
||||
DCFill;
|
||||
DCDel(dc);
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
SpeedLineDemo; //Execute when #included
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
If you press <CTRL-T> you will see this:
|
||||
|
||||
$$IB+BP,"<1>",1,"::/SparrowOS/Demo/Graphics/SpritePut.CPP.Z,2"$$
|
||||
|
||||
That imports an external sprite. It's
|
||||
called a $LK,"DOCEF2_BIN_PTR_LINK","MN:DOCEF2_BIN_PTR_LINK"$.
|
||||
|
||||
Press <CTRL-R> and "pointer to sprite".
|
||||
Then, enter a file and the number of
|
||||
the sprite in the file. Note: the
|
||||
number can get messed-up if you change
|
||||
the order of sprites in the source file.
|
||||
You can enter a tag instead of a num.
|
||||
|
||||
*/
|
||||
|
||||
U0 SpritePutExt()
|
||||
{
|
||||
I64 i;
|
||||
for (i=0;i<3;i++) {
|
||||
"US Map:";
|
||||
PutSprite($IB+BP,"<1>",1,"::/SparrowOS/Demo/Graphics/SpritePut.CPP.Z,2"$);
|
||||
NewLine(12);
|
||||
}
|
||||
}
|
||||
|
||||
SpritePutExt;
|
||||
Binary file not shown.
@@ -0,0 +1,61 @@
|
||||
//This is demonstrates symmetry.
|
||||
//Right-click and draw line of symmetry.
|
||||
//If the line of symmetry is a point, symmetry is turned-off.
|
||||
|
||||
U0 SymmetryDemo()
|
||||
{
|
||||
I64 msg_code,x1,y1,x2,y2,p1,p2;
|
||||
CDC *dc=DCAlias;
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
Fs->win_inhibit=WIF_ALL-WIF_BORDER;
|
||||
|
||||
WinMax;
|
||||
DCFill;
|
||||
"$$CL$$";
|
||||
dc->flags|=DCF_SYMMETRY;
|
||||
GrSetSymmetry(dc,Fs->win_pixel_width/2,0,Fs->win_pixel_width/2,1);
|
||||
do {
|
||||
msg_code=GetMsg(&p1,&p2,
|
||||
1<<MSG_KEY_DOWN+1<<MSG_IP_L_DOWN+
|
||||
1<<MSG_IP_R_DOWN);
|
||||
switch (msg_code) {
|
||||
case MSG_IP_R_DOWN:
|
||||
dc->flags&=~DCF_SYMMETRY;
|
||||
dc->color=ROP_XOR+RED^COLOR_TRANSPARENT;
|
||||
x1=p1; y1=p2;
|
||||
x2=p1; y2=p2;
|
||||
while (msg_code!=MSG_IP_R_UP) {
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
msg_code=GetMsg(&p1,&p2,
|
||||
1<<MSG_IP_R_UP+1<<MSG_IP_MOVE);
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
x2=p1; y2=p2;
|
||||
}
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
if (GrSetSymmetry3(dc,x1,y1,0,x2,y2,0,x2,y2,1))
|
||||
dc->flags|=DCF_SYMMETRY;
|
||||
break;
|
||||
case MSG_IP_L_DOWN:
|
||||
dc->color=ROP_XOR+BLACK^COLOR_TRANSPARENT;
|
||||
x1=p1; y1=p2;
|
||||
x2=p1; y2=p2;
|
||||
while (msg_code!=MSG_IP_L_UP) {
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
msg_code=GetMsg(&p1,&p2,
|
||||
1<<MSG_IP_L_UP+1<<MSG_IP_MOVE);
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
x2=p1; y2=p2;
|
||||
}
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
break;
|
||||
case MSG_KEY_DOWN:
|
||||
break;
|
||||
}
|
||||
} while (msg_code!=MSG_KEY_DOWN || !p1);
|
||||
DCFill;
|
||||
DCDel(dc);
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
SymmetryDemo; //Execute when #included
|
||||
Binary file not shown.
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
This was done with <CTRL-SHIFT-L> managed code
|
||||
that was modified.
|
||||
|
||||
This is an advanced demo that shows
|
||||
that you can place ctrls on the
|
||||
wall paper.
|
||||
|
||||
See $LK,"::/SparrowOS/Demo/Graphics/SliderCtrl.CPP.Z","FI:::/SparrowOS/Demo/Graphics/SliderCtrl.CPP.Z"$
|
||||
and $LK,"::/SparrowOS/Demo/Graphics/MyWallPaper.CPP.Z","FI:::/SparrowOS/Demo/Graphics/MyWallPaper.CPP.Z"$
|
||||
before messing with this program.
|
||||
|
||||
It must be "Adam Included".
|
||||
*/
|
||||
|
||||
#define SLIDER_RANGE 30
|
||||
#define SLIDER_SPACING 20
|
||||
#define SLIDER_BORDER 2
|
||||
|
||||
class CSliderState
|
||||
{
|
||||
I64 left_pos;
|
||||
I64 right_pos;
|
||||
};
|
||||
|
||||
U0 DrawSliderCtrl(CDC *dc,CCtrl *c)
|
||||
{
|
||||
CSliderState *s=c->state;
|
||||
|
||||
dc->color=LTRED;
|
||||
GrRect(dc, c->left,c->top,SLIDER_SPACING*3+2,SLIDER_SPACING*2+SLIDER_RANGE);
|
||||
dc->color=BLUE;
|
||||
GrRect(dc, c->left+SLIDER_BORDER,c->top+SLIDER_BORDER,
|
||||
SLIDER_SPACING*3+2-2*SLIDER_BORDER,SLIDER_SPACING*2+SLIDER_RANGE-2*SLIDER_BORDER);
|
||||
dc->color=BLACK;
|
||||
GrLine(dc,c->left+1*SLIDER_SPACING+0,c->top+SLIDER_SPACING,
|
||||
c->left+1*SLIDER_SPACING+0,c->top+SLIDER_SPACING+SLIDER_RANGE-1);
|
||||
GrLine(dc,c->left+2*SLIDER_SPACING+1,c->top+SLIDER_SPACING,
|
||||
c->left+2*SLIDER_SPACING+1,c->top+SLIDER_SPACING+SLIDER_RANGE-1);
|
||||
dc->color=LTRED;
|
||||
GrPrintF(dc,c->left+1*SLIDER_SPACING+0-FONT_WIDTH/2,
|
||||
c->top+SLIDER_SPACING+SLIDER_RANGE+3,
|
||||
"%d",s->left_pos*10/SLIDER_RANGE);
|
||||
GrPrintF(dc,c->left+2*SLIDER_SPACING+1-FONT_WIDTH/2,
|
||||
c->top+SLIDER_SPACING+SLIDER_RANGE+3,
|
||||
"%d",s->right_pos*10/SLIDER_RANGE);
|
||||
GrRect(dc,c->left+1*SLIDER_SPACING+0-3,c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->left_pos-2,7,5);
|
||||
GrRect(dc,c->left+2*SLIDER_SPACING+1-3,c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->right_pos-2,7,5);
|
||||
dc->color=YELLOW;
|
||||
GrRect(dc,c->left+1*SLIDER_SPACING+0-2,c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->left_pos-1,5,3);
|
||||
GrRect(dc,c->left+2*SLIDER_SPACING+1-2,c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->right_pos-1,5,3);
|
||||
}
|
||||
|
||||
U0 UpdateDerivedSliderCtrl(CCtrl *c)
|
||||
{
|
||||
CSliderState *s=c->state;
|
||||
c->left=c->win_task->win_pixel_width/2-(SLIDER_SPACING*3+2)/2;
|
||||
c->right=c->left+3*SLIDER_SPACING+2;
|
||||
c->top=c->win_task->win_pixel_height/2-(SLIDER_SPACING*2+SLIDER_RANGE)/2;
|
||||
c->bottom=c->top+SLIDER_SPACING*2+SLIDER_RANGE;
|
||||
s->left_pos=LimitI64(s->left_pos,0,SLIDER_RANGE-1);
|
||||
s->right_pos=LimitI64(s->right_pos,0,SLIDER_RANGE-1);
|
||||
}
|
||||
|
||||
U0 LeftClickSlider(CCtrl *c,I64 x,I64 y,Bool)
|
||||
{
|
||||
CSliderState *s=c->state;
|
||||
if (x<c->left+1*SLIDER_SPACING+0+SLIDER_SPACING/2)
|
||||
s->left_pos=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));
|
||||
else
|
||||
s->right_pos=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));
|
||||
if (c->update_derived_vals)
|
||||
(*c->update_derived_vals)(c);
|
||||
}
|
||||
|
||||
CCtrl *SliderNew()
|
||||
{
|
||||
Bool old_preempt;
|
||||
CCtrl *c=ACAlloc(sizeof(CCtrl));
|
||||
c->win_task=sys_winmgr_task;
|
||||
c->flags=CTRLF_SHOW|CTRLF_CAPTURE_LEFT_IP;
|
||||
c->type=CTRLT_GENERIC;
|
||||
c->state=ACAlloc(sizeof(CSliderState));
|
||||
c->draw_it=&DrawSliderCtrl;
|
||||
c->left_click=&LeftClickSlider;
|
||||
c->update_derived_vals=&UpdateDerivedSliderCtrl;
|
||||
old_preempt=Preempt(OFF);
|
||||
QueIns(c,sys_winmgr_task->last_ctrl);
|
||||
TaskDerivedValsUpdate;
|
||||
Preempt(old_preempt);
|
||||
return c;
|
||||
}
|
||||
|
||||
U0 SliderDel(CCtrl *c)
|
||||
{
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
QueRem(c);
|
||||
Preempt(old_preempt);
|
||||
Free(c->state);
|
||||
Free(c);
|
||||
}
|
||||
|
||||
SliderNew;
|
||||
@@ -0,0 +1,22 @@
|
||||
U0 DrawIt(CTask *,CDC *dc)
|
||||
{
|
||||
I64 i,j;
|
||||
U16 *ptr=gr_win_z_buf;
|
||||
dc->color=BLACK;
|
||||
GrPutS(dc,0,0,"Move the windows around and watch.");
|
||||
for (i=0;i<TEXT_ROWS;i++)
|
||||
for (j=0;j<TEXT_COLS;j++) {
|
||||
dc->color=*ptr++&15;
|
||||
GrPlot(dc,j,i+FONT_HEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
U0 ScrollBars()
|
||||
{
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
Fs->draw_it=&DrawIt;
|
||||
GetChar(NULL,FALSE);
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
ScrollBars;
|
||||
Reference in new issue
Block a user