Initial (manual) import
This commit is contained in:
1 parent
f39611c506
commit
895fe109de
661 files changed
+245862
No files matched your search
@@ -0,0 +1,117 @@
|
||||
U0 Main()
|
||||
{
|
||||
F64 é=0,č=0,ę=0;
|
||||
CD3I32 poly[4];
|
||||
CDC *dc=DCAlias;
|
||||
DCDepthBufAlloc(dc);
|
||||
dc->flags|=DCF_TRANSFORMATION|DCF_SYMMETRY;
|
||||
try {
|
||||
while (!ScanChar) {
|
||||
DCDepthBufRst(dc);
|
||||
DCSymmetrySet(dc,Fs->pix_width/2,Fs->pix_height/2,
|
||||
ms.pos.x-Fs->pix_left-Fs->scroll_x,
|
||||
ms.pos.y-Fs->pix_top-Fs->scroll_y);
|
||||
dc->color=LTBLUE;
|
||||
GrLine(dc,Fs->pix_width/2,Fs->pix_height/2,
|
||||
ms.pos.x-Fs->pix_left-Fs->scroll_x,
|
||||
ms.pos.y-Fs->pix_top-Fs->scroll_y);
|
||||
|
||||
Mat4x4IdentEqu(dc->r);
|
||||
Mat4x4RotX(dc->r,ę);
|
||||
Mat4x4RotY(dc->r,č);
|
||||
Mat4x4RotZ(dc->r,é);
|
||||
DCMat4x4Set(dc,dc->r);
|
||||
|
||||
dc->x=Fs->pix_width/2;
|
||||
dc->y=Fs->pix_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);
|
||||
|
||||
Refresh;
|
||||
DCFill;
|
||||
é+=2.1*ă/180.0;
|
||||
č+=1.1*ă/180.0;
|
||||
ę+=0.5*ă/180.0;
|
||||
}
|
||||
} catch
|
||||
PutExcept;
|
||||
|
||||
DCFill;
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
Main;
|
||||
@@ -0,0 +1,35 @@
|
||||
#define PTS_NUM 16
|
||||
|
||||
U0 BSplineDemo()
|
||||
{
|
||||
CDC *dc=DCAlias;
|
||||
I64 arg1,arg2,i=0,msg_code;
|
||||
CD3I32 c[PTS_NUM];
|
||||
|
||||
SettingsPush;
|
||||
Fs->win_inhibit=WIG_TASK_DFT-WIF_SELF_FOCUS-WIF_SELF_BORDER;
|
||||
|
||||
DocClear;
|
||||
"Sel ctrl points with left mouse. Right when finished.\n";
|
||||
DCFill;
|
||||
do {
|
||||
msg_code=GetMsg(&arg1,&arg2,1<<MSG_MS_L_UP+1<<MSG_MS_R_UP);
|
||||
if (msg_code==MSG_MS_L_UP) {
|
||||
c[i].x=arg1; c[i].y=arg2; c[i].z=0;
|
||||
dc->color=GREEN;
|
||||
GrCircle(dc,arg1,arg2,10);
|
||||
i++;
|
||||
}
|
||||
} while (i<PTS_NUM && msg_code!=MSG_MS_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,38 @@
|
||||
// Classic Commodore 64 Sprite
|
||||
|
||||
U8 a[60]={0,127,0,1,255,192,3,255,224,3,231,224,
|
||||
7,217,240,7,223,240,7,217,240,3,231,224,
|
||||
3,255,224,3,255,224,2,255,160,1,127,64,
|
||||
1,62,64,0,156,128,0,156,128,0,73,0,0,73,0,
|
||||
0,62,0,0,62,0,0,28,0};
|
||||
|
||||
U0 Balloon()
|
||||
{
|
||||
I64 i,j,k;
|
||||
|
||||
CLI
|
||||
|
||||
OutU8(VGAP_IDX,VGAR_MAP_MASK);
|
||||
OutU8(VGAP_DATA,0xF);
|
||||
MemSetI64(text.vga_alias,0,640*480/64);
|
||||
|
||||
OutU8(VGAP_IDX,VGAR_MAP_MASK);
|
||||
OutU8(VGAP_DATA,RED+GREEN+8);
|
||||
for (k=100;k<150;k++) {
|
||||
|
||||
for (i=0;i<20;i++)
|
||||
for (j=0;j<3;j++)
|
||||
*(text.vga_alias(I64)+0x1000+(i+k)*640/8+j)(U8 *)=a[i*3+j];
|
||||
|
||||
Busy(40000);
|
||||
|
||||
for (i=0;i<20;i++)
|
||||
for (j=0;j<3;j++)
|
||||
*(text.vga_alias(I64)+0x1000+(i+k)*640/8+j)(U8 *)=0;
|
||||
}
|
||||
|
||||
STI
|
||||
VGAFlush;
|
||||
}
|
||||
|
||||
Balloon;
|
||||
@@ -0,0 +1,41 @@
|
||||
CDC *dc=DCAlias;
|
||||
CDC *img1=DCNew(64,64);
|
||||
CDC *img2=DCNew(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=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) {
|
||||
Refresh;
|
||||
DCFill;
|
||||
GrBlot(dc,i-256,i-256,img2);
|
||||
Sleep(10);
|
||||
}
|
||||
U8 *tmpg=DC2Sprite(img1);
|
||||
Sprite(tmpg);
|
||||
Free(tmpg);
|
||||
"%h9c",'\n';
|
||||
|
||||
DCDel(img1);
|
||||
DCDel(img2);
|
||||
DCDel(dc);
|
||||
|
||||
PressAKey;
|
||||
DCFill;
|
||||
@@ -0,0 +1,47 @@
|
||||
//Uses $LK,"fixed-point-arithmetic",A="FI:::/Demo/Lectures/FixedPoint.HC"$.
|
||||
|
||||
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]=I32_MAX*Cos(é);
|
||||
dy[i]=I32_MAX*Sin(é);
|
||||
}
|
||||
}
|
||||
|
||||
U0 Bounce()
|
||||
{
|
||||
CDC *dc=DCAlias;
|
||||
I64 i,ch;
|
||||
Init;
|
||||
try {//Catch <CTRL-ALT-c>
|
||||
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->pix_width<<32)) {
|
||||
x[i]-=dx[i];
|
||||
dx[i]=-dx[i];
|
||||
}
|
||||
if (!(0<=y[i]<Fs->pix_height<<32)) {
|
||||
y[i]-=dy[i];
|
||||
dy[i]=-dy[i];
|
||||
}
|
||||
}
|
||||
Yield;
|
||||
} while (!(ch=ScanChar) || (ch!=CH_SHIFT_ESC && ch!=CH_ESC));
|
||||
} catch
|
||||
PutExcept;
|
||||
DCFill(dc);
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
Bounce;
|
||||
@@ -0,0 +1,50 @@
|
||||
I64 glbl_r[4][4];
|
||||
|
||||
U0 DrawIt(CTask *,CDC *dc)
|
||||
{
|
||||
I64 *old_r=dc->r;
|
||||
dc->pen_width=2;
|
||||
dc->color=RED;
|
||||
dc->x=200;
|
||||
dc->y=200;
|
||||
dc->flags|=DCF_TRANSFORMATION;
|
||||
DCMat4x4Set(dc,glbl_r); //This assigns to dc->r and sets r_norm.
|
||||
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);
|
||||
dc->r=old_r;
|
||||
}
|
||||
|
||||
U0 Box()
|
||||
{
|
||||
F64 é=0,è=0,ê=0,s=1,s1=1.05;
|
||||
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
|
||||
DocClear;
|
||||
Fs->draw_it=&DrawIt;
|
||||
while (!ScanChar) {
|
||||
Mat4x4IdentEqu(glbl_r);
|
||||
Mat4x4RotZ(glbl_r,é);
|
||||
Mat4x4RotX(glbl_r,è);
|
||||
Mat4x4RotZ(glbl_r,ê);
|
||||
Mat4x4Scale(glbl_r,s);
|
||||
|
||||
Sleep(20);
|
||||
é+=2*ã/70;
|
||||
è+=2*ã/90;
|
||||
ê+=2*ã/110;
|
||||
s*=s1;
|
||||
if ( !(0.2<s<1.4) ) s1=1/s1;
|
||||
}
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
Box;
|
||||
@@ -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=GetStr) {
|
||||
if (*st) {
|
||||
h=Fs->pix_width/2;
|
||||
v=Fs->pix_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=-ExePrint("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;
|
||||
|
||||
//For better performance, compile the expression entered by the
|
||||
//user one time with $LK,"LexExpression2Bin",A="MN:LexExpression2Bin"$() and use $LK,"Call",A="MN:Call"$().
|
||||
//See $LK,"::/Demo/CompileDemo.HC"$.
|
||||
@@ -0,0 +1,30 @@
|
||||
U8 *old_font=text.font;
|
||||
|
||||
// See $LK,"::/Kernel/FontStd.HC"$, $LK,"::/Demo/ScrnCodes.HC"$,
|
||||
//$LK,"::/Demo/ExtChars.HC"$, and $LK,"::/Demo/Graphics/FontEd.HC"$.
|
||||
|
||||
U64 waves[4]={
|
||||
0x0011AA440011AA44,0x0022558800225588,
|
||||
0x0044AA110044AA11,0x0088552200885522};
|
||||
|
||||
U0 AnimateEndCB()
|
||||
{
|
||||
text.font=old_font;
|
||||
Exit;
|
||||
}
|
||||
|
||||
U0 AnimateTask(I64)
|
||||
{
|
||||
I64 i;
|
||||
U64 *font=MAlloc(256*8);
|
||||
Fs->task_end_cb=&AnimateEndCB;
|
||||
MemCpy(font,text.font,256*8);
|
||||
text.font=font;
|
||||
while (TRUE) {
|
||||
font[CH_SPACE]=waves[i++&0x3];
|
||||
Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
Spawn(&AnimateTask,NULL,"Animate",,Fs);
|
||||
TaskRep;
|
||||
Binary file not shown.
@@ -0,0 +1,120 @@
|
||||
#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 *tmpn,I64 *_node_x,I64 *_tree_x,I64 y)
|
||||
{
|
||||
I64 node_x;
|
||||
if (tmpn) {
|
||||
if (tmpn->left) {
|
||||
ShowTree(dc,tmpn->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 (tmpn->n==n1 || tmpn->n==n2) {
|
||||
if (tmpn->n==common_ancestor)
|
||||
dc->color=YELLOW;
|
||||
else
|
||||
dc->color=RED;
|
||||
} else if (tmpn->n==common_ancestor)
|
||||
dc->color=GREEN;
|
||||
else
|
||||
dc->color=BLUE;
|
||||
|
||||
*_node_x=*_tree_x;
|
||||
GrPrint(dc,*_node_x,y,"%d",tmpn->n);
|
||||
*_tree_x+=X_SPACING;
|
||||
|
||||
if (tmpn->right) {
|
||||
ShowTree(dc,tmpn->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 *tmpn)
|
||||
{
|
||||
Node *root=*_root;
|
||||
if (!root)
|
||||
*_root=tmpn;
|
||||
else if (tmpn->n==root->n)
|
||||
Free(tmpn);
|
||||
else if (tmpn->n<root->n)
|
||||
TreeAdd(&root->left,tmpn);
|
||||
else
|
||||
TreeAdd(&root->right,tmpn);
|
||||
}
|
||||
|
||||
U0 TreeNew()
|
||||
{
|
||||
I64 i;
|
||||
Node *tmpn;
|
||||
for (i=0;i<N;i++) {
|
||||
tmpn=CAlloc(sizeof(Node));
|
||||
tmpn->n=RandU16%N;
|
||||
|
||||
if (i==N-1)
|
||||
n1=tmpn->n;
|
||||
else if (i==N-2)
|
||||
n2=tmpn->n;
|
||||
|
||||
TreeAdd(&root,tmpn);
|
||||
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",A="MN:SettingsPush"$
|
||||
Fs->draw_it=&DrawIt;
|
||||
DocClear;
|
||||
"Scroll with {CTRL-Left Grab}.\n";
|
||||
try {
|
||||
TreeNew;
|
||||
TreeCommonAncestorFind(root);
|
||||
PressAKey;
|
||||
} catch
|
||||
PutExcept;
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
TreeCommonAncestor;
|
||||
/*Be careful with recursive routines in TempleOS
|
||||
because the stack does not grow and will overflow.
|
||||
|
||||
See $LK,"::/Demo/StkGrow.HC"$.
|
||||
*/
|
||||
@@ -0,0 +1,48 @@
|
||||
//This is a drawing program
|
||||
|
||||
U0 Doodle()
|
||||
{
|
||||
I64 msg_code,i,x1,y1,x2,y2,arg1,arg2,color=BLACK;
|
||||
CDC *dc=DCAlias;
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
|
||||
Fs->win_inhibit=WIG_TASK_DFT-WIF_SELF_FOCUS-WIF_SELF_BORDER;
|
||||
|
||||
AutoComplete;
|
||||
WinBorder;
|
||||
WinMax;
|
||||
DocClear;
|
||||
DCFill;
|
||||
do {
|
||||
msg_code=GetMsg(&arg1,&arg2,
|
||||
1<<MSG_KEY_DOWN+1<<MSG_MS_L_DOWN+1<<MSG_MS_R_UP);
|
||||
switch (msg_code) {
|
||||
case MSG_MS_R_UP:
|
||||
i=PopUpColor;
|
||||
if (i>=0) color=i;
|
||||
break;
|
||||
case MSG_MS_L_DOWN:
|
||||
x1=arg1; y1=arg2;
|
||||
x2=arg1; y2=arg2;
|
||||
dc->color=ROP_XOR+color^TRANSPARENT;
|
||||
dc->pen_width=7;
|
||||
while (msg_code!=MSG_MS_L_UP) {
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
msg_code=GetMsg(&arg1,&arg2,
|
||||
1<<MSG_MS_L_UP+1<<MSG_MS_MOVE);
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
x2=arg1; y2=arg2;
|
||||
}
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
break;
|
||||
case MSG_KEY_DOWN:
|
||||
break;
|
||||
}
|
||||
} while (msg_code!=MSG_KEY_DOWN || !arg1);
|
||||
GetMsg(,,1<<MSG_KEY_UP);
|
||||
DCFill;
|
||||
DCDel(dc);
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
Doodle; //Execute when #included
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,152 @@
|
||||
/*After making a font...
|
||||
|
||||
You can save it as a binary file with:
|
||||
FileWrite("filename.BIN.Z",text.font,256*FONT_HEIGHT);
|
||||
|
||||
You can load it with:
|
||||
U64 *my_font=FileRead("filename.BIN.Z");
|
||||
text.aux_font=my_font;
|
||||
|
||||
<CTRL-ALT-f> will toggle main font and aux_font.
|
||||
|
||||
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,"::/Kernel/FontStd.HC"$.
|
||||
You will need to recompile Kernel by calling $LK,"BootHDIns",A="MN:BootHDIns"$().
|
||||
|
||||
See $LK,"::/Demo/ExtChars.HC"$, $LK,"::/Demo/Games/CharDemo.HC"$,
|
||||
$LK,"::/Demo/Graphics/CharAnimation.HC"$ and $LK,"::/Demo/ScrnCodes.HC"$.
|
||||
*/
|
||||
|
||||
#define BLOW_UP_CHAR_X (18*FONT_WIDTH)
|
||||
#define BLOW_UP_CHAR_Y (4*FONT_HEIGHT)
|
||||
|
||||
U8 cur_ch;
|
||||
|
||||
U0 DrawIt(CTask *task,CDC *dc)
|
||||
{
|
||||
I64 i,j,k,c;
|
||||
TextPrint(task,0,0,BLUE<<4+YELLOW,"Press <CTRL-ALT-f> to Toggle Aux Font.");
|
||||
k=0;
|
||||
for (i=0;i<16;i++)
|
||||
for (j=0;j<16;j++) {
|
||||
if (k==cur_ch) {
|
||||
if (Blink)
|
||||
c=(BLUE<<4+YELLOW)<<8 + k++;
|
||||
else
|
||||
c=(YELLOW<<4+BLUE)<<8 + k++;
|
||||
} else
|
||||
c=(BLUE<<4+WHITE)<<8 + k++;
|
||||
TextChar(task,,j,i+2,c);
|
||||
}
|
||||
|
||||
k=0;
|
||||
for (i=0;i<FONT_HEIGHT;i++)
|
||||
for (j=0;j<FONT_WIDTH;j++) {
|
||||
if (Bt(&text.font[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;
|
||||
for (i=0;i<256;i++) {
|
||||
DocPrint(doc,"0x%016X,",text.font[i]);
|
||||
if (Bt(char_bmp_safe_dollar,i))
|
||||
DocPrint(doc,"//%c",i);
|
||||
else if (i=='$$')
|
||||
DocPrint(doc,"//$$$$",i);
|
||||
DocPrint(doc,"\n");
|
||||
}
|
||||
Fs->draw_it=NULL;
|
||||
DocWrite(doc,pmt);
|
||||
Fs->draw_it=old_draw_it;
|
||||
DocDel(doc);
|
||||
}
|
||||
|
||||
U0 FontEd()
|
||||
{
|
||||
I64 msg_code,arg1,arg2,k;
|
||||
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
|
||||
MenuPush(
|
||||
"File {"
|
||||
" SaveAs(,CH_CTRLA);"
|
||||
" Abort(,CH_SHIFT_ESC);"
|
||||
" Exit(,CH_ESC);"
|
||||
"}");
|
||||
AutoComplete;
|
||||
DocCursor;
|
||||
DocClear;
|
||||
Fs->win_inhibit|=WIG_DBL_CLICK;
|
||||
cur_ch=0;
|
||||
try {
|
||||
Fs->draw_it=&DrawIt;
|
||||
while (TRUE) {
|
||||
switch (msg_code=GetMsg(&arg1,&arg2,
|
||||
1<<MSG_KEY_DOWN|1<<MSG_MS_L_DOWN|1<<MSG_MS_R_DOWN|1<<MSG_MS_MOVE)) {
|
||||
case MSG_KEY_DOWN:
|
||||
switch (arg1) {
|
||||
case 0:
|
||||
switch (arg2.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=arg1;
|
||||
}
|
||||
break;
|
||||
case MSG_MS_L_DOWN:
|
||||
case MSG_MS_R_DOWN:
|
||||
if (0<=arg1<FONT_WIDTH*16 && FONT_HEIGHT*2<=arg2<FONT_HEIGHT*16) {
|
||||
cur_ch=(arg2/FONT_HEIGHT-2)*16+arg1/FONT_WIDTH;
|
||||
break;
|
||||
} //fall through
|
||||
case MSG_MS_MOVE:
|
||||
k=((arg2-BLOW_UP_CHAR_Y)/FONT_HEIGHT)*FONT_WIDTH+
|
||||
(arg1-BLOW_UP_CHAR_X)/FONT_WIDTH;
|
||||
if (0<=k<FONT_WIDTH*FONT_HEIGHT) {
|
||||
if (ms.lb||msg_code==MSG_MS_L_DOWN)
|
||||
Bts(&text.font[cur_ch],k);
|
||||
if (ms.rb||msg_code==MSG_MS_R_DOWN)
|
||||
Btr(&text.font[cur_ch],k);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
fe_done:
|
||||
GetMsg(,,1<<MSG_KEY_UP);
|
||||
} catch
|
||||
PutExcept;
|
||||
MenuPop;
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
FontEd;
|
||||
@@ -0,0 +1,30 @@
|
||||
#define GRID 5
|
||||
|
||||
U0 DrawMyMs(CDC *dc,I64 x,I64 y)
|
||||
{
|
||||
dc->pen_width=1;
|
||||
dc->flags&=~(DCF_TRANSFORMATION|DCF_SYMMETRY);
|
||||
GrRect(dc,x,y,GRID,GRID);
|
||||
}
|
||||
|
||||
U0 GridDemo()
|
||||
{
|
||||
CGridGlbls old_grid;
|
||||
U0 (*old_draw_ms)(CDC *dc,I64 x,I64 y); //Can't init this type of var.
|
||||
MemCpy(&old_grid,&ms_grid,sizeof(CGridGlbls));
|
||||
GridInit;
|
||||
ms_grid.snap=TRUE; //You can set other $LK,"stuff",A="MN:CGridGlbls"$.
|
||||
ms_grid.x=GRID;
|
||||
ms_grid.y=GRID;
|
||||
old_draw_ms=gr.fp_draw_ms;
|
||||
gr.fp_draw_ms=&DrawMyMs;
|
||||
while (!ms.lb) {//Left bttn to exit.
|
||||
GrPlot(,ms.pos.x,ms.pos.y);
|
||||
Yield;
|
||||
}
|
||||
DCFill;
|
||||
gr.fp_draw_ms=old_draw_ms;
|
||||
MemCpy(&ms_grid,&old_grid,sizeof(CGridGlbls));
|
||||
}
|
||||
|
||||
GridDemo;
|
||||
@@ -0,0 +1,154 @@
|
||||
#define DISKS_NUM 6
|
||||
#define PEDESTAL_HEIGHT 20
|
||||
#define DISK_HEIGHT 7
|
||||
#define DISK_UNIT_WIDTH 5
|
||||
|
||||
I64 poles_x[3];
|
||||
I64 disks_x[DISKS_NUM],disks_y[DISKS_NUM],disks_pole[DISKS_NUM];
|
||||
|
||||
I64 OtherPole(I64 pole1,I64 pole2)
|
||||
{
|
||||
return 3-pole1-pole2;
|
||||
}
|
||||
|
||||
I64 TopDisk(I64 pole)
|
||||
{
|
||||
I64 i;
|
||||
for (i=0;i<DISKS_NUM;i++)
|
||||
if (disks_pole[i]==pole)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
I64 PosInStk(I64 pole,I64 disk)
|
||||
{
|
||||
I64 res=0,i;
|
||||
for (i=DISKS_NUM-1;i>disk;i--)
|
||||
if (disks_pole[i]==pole)
|
||||
res++;
|
||||
return res;
|
||||
}
|
||||
|
||||
U0 SetDisksRestXY()
|
||||
{
|
||||
I64 i;
|
||||
for (i=0;i<DISKS_NUM;i++) {
|
||||
disks_x[i]=poles_x[disks_pole[i]];
|
||||
disks_y[i]=Fs->pix_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->pix_width/4;
|
||||
|
||||
dc->color=BLACK;
|
||||
GrRect(dc,poles_x[0]-50,task->pix_height-PEDESTAL_HEIGHT,
|
||||
poles_x[2]-poles_x[0]+100,PEDESTAL_HEIGHT-FONT_HEIGHT);
|
||||
dc->color=DKGRAY;
|
||||
GrRect(dc,poles_x[0]-49,task->pix_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->pix_height-PEDESTAL_HEIGHT-(DISKS_NUM+1)*(DISK_HEIGHT+1),
|
||||
7,(DISKS_NUM+1)*(DISK_HEIGHT+1));
|
||||
dc->color=YELLOW;
|
||||
GrRect(dc,poles_x[i]-2,
|
||||
task->pix_height-PEDESTAL_HEIGHT+1-(DISKS_NUM+1)*(DISK_HEIGHT+1),
|
||||
5,(DISKS_NUM+1)*(DISK_HEIGHT+1)-1);
|
||||
}
|
||||
|
||||
for (i=0;i<DISKS_NUM;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)
|
||||
throw;
|
||||
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->pix_height-PEDESTAL_HEIGHT-(DISK_HEIGHT+1)/2
|
||||
-(DISK_HEIGHT+1)*(DISKS_NUM+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->pix_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->pix_width/4;
|
||||
|
||||
for (i=0;i<DISKS_NUM;i++)
|
||||
disks_pole[i]=0;
|
||||
|
||||
SetDisksRestXY;
|
||||
}
|
||||
|
||||
U0 Hanoi()
|
||||
{
|
||||
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
|
||||
Init;
|
||||
DocClear;
|
||||
Fs->draw_it=&DrawIt;
|
||||
|
||||
Sleep(1000);
|
||||
try {
|
||||
MoveDisks(0,2,DISKS_NUM);
|
||||
Beep; Beep;
|
||||
DocClear;
|
||||
DocBottom;
|
||||
PressAKey;
|
||||
} catch
|
||||
PutExcept;
|
||||
DocClear;
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
Hanoi;
|
||||
@@ -0,0 +1,266 @@
|
||||
#define TURTLE_SIZE 4
|
||||
#define TURTLE_SPEED_STEP 2
|
||||
|
||||
#define ANGLES 35
|
||||
F64 angles[ANGLES]={
|
||||
-2*ã/1,-2*ã/2,-2*ã/3,-2*ã/4,-2*ã/5,
|
||||
-2*ã/6,-2*ã/8,-2*ã/9,-2*ã/10,
|
||||
-2*ã/12,-2*ã/15,-2*ã/18,-2*ã/20,
|
||||
-2*ã/24,-2*ã/30,-2*ã/36,-2*ã/40,
|
||||
0,
|
||||
2*ã/40,2*ã/36,2*ã/30,2*ã/24,
|
||||
2*ã/20,2*ã/18,2*ã/15,2*ã/12,
|
||||
2*ã/10,2*ã/9,2*ã/8,2*ã/6,
|
||||
2*ã/5,2*ã/4,2*ã/3,2*ã/2,2*ã/1
|
||||
};
|
||||
|
||||
class Turtle
|
||||
{
|
||||
F64 x,y,z,speed,é,w;
|
||||
I64 dé_idx;
|
||||
CColorROPU16 edge,middle;
|
||||
Bool ends,first;
|
||||
} tt;
|
||||
|
||||
U0 TurtlePlot(CDC *dc,Turtle *t,CColorROPU16 edge,CColorROPU16 middle)
|
||||
{
|
||||
F64 w=t->w/2.0-1;
|
||||
if (w<0) w=0;
|
||||
dc->color=middle;
|
||||
GrLine3(dc,t->x+w*Cos(t->é+ã/2),t->y+w*Sin(t->é+ã/2),t->z,
|
||||
t->x+w*Cos(t->é-ã/2),t->y+w*Sin(t->é-ã/2),t->z);
|
||||
w=t->w/2.0;
|
||||
dc->color=edge;
|
||||
GrPlot3(dc,t->x+w*Cos(t->é+ã/2),t->y+w*Sin(t->é+ã/2),t->z);
|
||||
GrPlot3(dc,t->x+w*Cos(t->é-ã/2),t->y+w*Sin(t->é-ã/2),t->z);
|
||||
}
|
||||
|
||||
U0 TurtleMicroMove(Turtle *t,F64 dt)
|
||||
{
|
||||
t->x+=dt*t->speed*Cos(t->é);
|
||||
t->y+=dt*t->speed*Sin(t->é);
|
||||
t->é=Wrap(t->é+dt*angles[t->dé_idx]);
|
||||
}
|
||||
|
||||
U0 TurtleEnd(CDC *dc,Turtle *t,CColorROPU16 edge,CColorROPU16 middle,F64 é)
|
||||
{
|
||||
F64 r,x,y2;
|
||||
Turtle t2;
|
||||
if (r=t->w) {
|
||||
MemCpy(&t2,t,sizeof(Turtle)); //Save
|
||||
x=0;
|
||||
while (TRUE) {
|
||||
t->x+=1/r*Cos(é);
|
||||
t->y+=1/r*Sin(é);
|
||||
x+=1/r;
|
||||
y2=r*r-4*x*x;
|
||||
if (y2>=0) {
|
||||
t->w=Sqrt(y2);
|
||||
TurtlePlot(dc,t,edge,middle);
|
||||
} else
|
||||
break;
|
||||
}
|
||||
MemCpy(t,&t2,sizeof(Turtle));
|
||||
}
|
||||
}
|
||||
|
||||
U0 TurtleMove(CDC *dc,Turtle *t,CColorROPU16 edge,CColorROPU16 middle)
|
||||
{
|
||||
I64 i,l=16*AbsI64(t->w+1)*AbsI64(t->speed+1);
|
||||
|
||||
if (t->ends && t->first)
|
||||
TurtleEnd(dc,t,edge,middle,t->é+ã);
|
||||
t->first=FALSE;
|
||||
|
||||
for (i=0;i<l;i++) {
|
||||
TurtleMicroMove(t,1.0/l);
|
||||
TurtlePlot(dc,t,edge,middle);
|
||||
}
|
||||
if (t->ends)
|
||||
TurtleEnd(dc,t,edge,middle,t->é);
|
||||
}
|
||||
|
||||
U0 TurtleInit(Turtle *t)
|
||||
{
|
||||
MemSet(t,0,sizeof(Turtle));
|
||||
t->x=Fs->pix_width>>1;
|
||||
t->y=Fs->pix_height>>1;
|
||||
t->z=5;
|
||||
t->edge=BLACK;
|
||||
t->middle=YELLOW;
|
||||
t->dé_idx=ANGLES/2;
|
||||
t->first=TRUE;
|
||||
t->ends=TRUE;
|
||||
}
|
||||
|
||||
U0 DrawIt(CTask *,CDC *dc)
|
||||
{
|
||||
Turtle t2;
|
||||
MemCpy(&t2,&tt,sizeof(Turtle));
|
||||
GrPrint(dc,0,0,"Layer:%f Speed:%f é:%5.1f dé:%5.1f Width:%f",
|
||||
tt.z,tt.speed,tt.é*180/ã,angles[tt.dé_idx]*180/ã,tt.w);
|
||||
|
||||
TurtleMove(dc,&t2,RED,LTRED);
|
||||
dc->color=LTRED;
|
||||
GrLine(dc,t2.x+TURTLE_SIZE*Cos(t2.é+ã/2),t2.y+TURTLE_SIZE*Sin(t2.é+ã/2),
|
||||
t2.x+TURTLE_SIZE*Cos(t2.é-ã/2),t2.y+TURTLE_SIZE*Sin(t2.é-ã/2));
|
||||
GrLine(dc,t2.x+TURTLE_SIZE*Cos(t2.é+ã/2),t2.y+TURTLE_SIZE*Sin(t2.é+ã/2),
|
||||
t2.x+TURTLE_SIZE*Cos(t2.é), t2.y+TURTLE_SIZE*Sin(t2.é));
|
||||
GrLine(dc,t2.x+TURTLE_SIZE*Cos(t2.é-ã/2),t2.y+TURTLE_SIZE*Sin(t2.é-ã/2),
|
||||
t2.x+TURTLE_SIZE*Cos(t2.é), t2.y+TURTLE_SIZE*Sin(t2.é));
|
||||
}
|
||||
|
||||
U0 SetMenu()
|
||||
{
|
||||
I64 i;
|
||||
U8 buf[STR_LEN];
|
||||
CMenuEntry *tmpse;
|
||||
for (i=0;i<=9;i++) {
|
||||
StrPrint(buf,"Settings/Layer%d",i);
|
||||
if (tmpse=MenuEntryFind(Fs->cur_menu,buf)) {
|
||||
if (i==tt.z)
|
||||
tmpse->checked=TRUE;
|
||||
else
|
||||
tmpse->checked=FALSE;
|
||||
}
|
||||
}
|
||||
if (tmpse=MenuEntryFind(Fs->cur_menu,"Settings/Ends")) {
|
||||
if (tt.ends)
|
||||
tmpse->checked=TRUE;
|
||||
else
|
||||
tmpse->checked=FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
U0 Lattice()
|
||||
{
|
||||
Bool aim=FALSE;
|
||||
I64 arg1,arg2;
|
||||
CDC *dc=DCAlias;
|
||||
DCDepthBufAlloc(dc);
|
||||
MenuPush(
|
||||
"File {"
|
||||
" Abort(,CH_SHIFT_ESC);"
|
||||
" Exit(,CH_ESC);"
|
||||
"}"
|
||||
"Play {"
|
||||
" Restart(,'\n');"
|
||||
" Step(,CH_SPACE);"
|
||||
" Accelerator(,,SC_CURSOR_UP);"
|
||||
" Break(,,SC_CURSOR_DOWN);"
|
||||
" Left(,,SC_CURSOR_LEFT);"
|
||||
" Right(,,SC_CURSOR_RIGHT);"
|
||||
"}"
|
||||
"Settings {"
|
||||
" Color(,'c');"
|
||||
" Wider(,'+');"
|
||||
" Narrower(,'-');"
|
||||
" Ends(,'e');"
|
||||
" Layer0(,'0');"
|
||||
" Layer1(,'1');"
|
||||
" Layer2(,'2');"
|
||||
" Layer3(,'3');"
|
||||
" Layer4(,'4');"
|
||||
" Layer5(,'5');"
|
||||
" Layer6(,'6');"
|
||||
" Layer7(,'7');"
|
||||
" Layer8(,'8');"
|
||||
" Layer9(,'9');"
|
||||
"}"
|
||||
);
|
||||
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
|
||||
AutoComplete;
|
||||
WinBorder;
|
||||
WinMax;
|
||||
DocCursor;
|
||||
DocClear;
|
||||
TurtleInit(&tt);
|
||||
SetMenu;
|
||||
Fs->win_inhibit=WIG_TASK_DFT-WIF_FOCUS_TASK_MENU
|
||||
-WIF_SELF_FOCUS-WIF_SELF_GRAB_SCROLL;
|
||||
Fs->draw_it=&DrawIt;
|
||||
try {
|
||||
while (TRUE) {
|
||||
switch (GetMsg(&arg1,&arg2,1<<MSG_KEY_DOWN|1<<MSG_MS_L_DOWN|
|
||||
1<<MSG_MS_R_DOWN|1<<MSG_MS_R_UP|1<<MSG_MS_MOVE)) {
|
||||
case MSG_MS_L_DOWN:
|
||||
tt.first=TRUE;
|
||||
tt.x=arg1;
|
||||
tt.y=arg2;
|
||||
break;
|
||||
case MSG_MS_R_DOWN:
|
||||
aim=TRUE;
|
||||
tt.é=Arg(arg1-tt.x,arg2-tt.y);
|
||||
break;
|
||||
case MSG_MS_MOVE:
|
||||
if (aim)
|
||||
tt.é=Arg(arg1-tt.x,arg2-tt.y);
|
||||
break;
|
||||
case MSG_MS_R_UP:
|
||||
tt.é=Arg(arg1-tt.x,arg2-tt.y);
|
||||
aim=FALSE;
|
||||
break;
|
||||
case MSG_KEY_DOWN:
|
||||
switch (arg1) {
|
||||
case 0:
|
||||
switch (arg2.u8[0]) {
|
||||
case SC_CURSOR_LEFT:
|
||||
if (tt.dé_idx)
|
||||
tt.dé_idx--;
|
||||
break;
|
||||
case SC_CURSOR_RIGHT:
|
||||
if (tt.dé_idx<ANGLES-1)
|
||||
tt.dé_idx++;
|
||||
break;
|
||||
case SC_CURSOR_UP:
|
||||
tt.speed+=TURTLE_SPEED_STEP;
|
||||
break;
|
||||
case SC_CURSOR_DOWN:
|
||||
if (tt.speed>=TURTLE_SPEED_STEP)
|
||||
tt.speed-=TURTLE_SPEED_STEP;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '0'...'9':
|
||||
tt.z=arg1-'0';
|
||||
SetMenu;
|
||||
break;
|
||||
case 'c':
|
||||
tt.middle=PopUpColor("Mid Color\n\n");
|
||||
tt.edge =PopUpColor("Edge Color\n\n");
|
||||
break;
|
||||
case 'e':
|
||||
tt.ends=!tt.ends;
|
||||
break;
|
||||
case '+':
|
||||
tt.w++;
|
||||
break;
|
||||
case '-':
|
||||
if (tt.w)
|
||||
tt.w--;
|
||||
break;
|
||||
case '\n':
|
||||
DCFill(dc);
|
||||
TurtleInit(&tt);
|
||||
SetMenu;
|
||||
break;
|
||||
case CH_ESC:
|
||||
case CH_SHIFT_ESC:
|
||||
goto lt_done;
|
||||
case CH_SPACE:
|
||||
TurtleMove(dc,&tt,tt.edge,tt.middle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
lt_done:
|
||||
GetMsg(,,1<<MSG_KEY_UP);
|
||||
} catch
|
||||
PutExcept;
|
||||
SettingsPop;
|
||||
DCFill(dc);
|
||||
DCDel(dc);
|
||||
MenuPop;
|
||||
}
|
||||
|
||||
Lattice;
|
||||
@@ -0,0 +1,98 @@
|
||||
//Conway's Game of Life
|
||||
|
||||
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->pix_height-1;y++) {
|
||||
for (x=1;x<Fs->parent_task->pix_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,arg1,arg2;
|
||||
|
||||
dc[0]=DCNew(GR_WIDTH,GR_HEIGHT);
|
||||
dc[1]=DCNew(GR_WIDTH,GR_HEIGHT);
|
||||
cur_dc=0;
|
||||
restart=FALSE;
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
|
||||
AutoComplete;
|
||||
WinBorder;
|
||||
WinMax;
|
||||
DocClear;
|
||||
DCFill;
|
||||
|
||||
Fs->animate_task=Spawn(&AnimateTask,NULL,"Animate",,Fs);
|
||||
Fs->draw_it=&DrawIt;
|
||||
Fs->win_inhibit=WIG_TASK_DFT-WIF_SELF_FOCUS-WIF_SELF_BORDER;
|
||||
do {
|
||||
msg_code=GetMsg(&arg1,&arg2,1<<MSG_KEY_DOWN+1<<MSG_MS_L_DOWN);
|
||||
switch (msg_code) {
|
||||
case MSG_MS_L_DOWN:
|
||||
x1=arg1; y1=arg2;
|
||||
x2=arg1; y2=arg2;
|
||||
cnt=0;
|
||||
while (msg_code!=MSG_MS_L_UP) {
|
||||
restart=TRUE;
|
||||
dc[cur_dc]->color=GREEN;
|
||||
dc[cur_dc]->pen_width=0.04*ms.speed;
|
||||
GrLine3(dc[cur_dc],x1,y1,0,x2,y2,0);
|
||||
restart=TRUE;
|
||||
msg_code=GetMsg(&arg1,&arg2,1<<MSG_MS_L_UP+1<<MSG_MS_MOVE);
|
||||
x1=x2; y1=y2;
|
||||
x2=arg1; y2=arg2;
|
||||
}
|
||||
GrLine3(dc[cur_dc],x1,y1,0,x2,y2,0);
|
||||
break;
|
||||
case MSG_KEY_DOWN:
|
||||
break;
|
||||
}
|
||||
} while (msg_code!=MSG_KEY_DOWN || !arg1);
|
||||
GetMsg(,,1<<MSG_KEY_UP);
|
||||
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=ClampI64(vx1+SignI64(RandI16),-5,5);
|
||||
vy1=ClampI64(vy1+SignI64(RandI16),-5,5);
|
||||
vx2=ClampI64(vx2+SignI64(RandI16),-5,5);
|
||||
vy2=ClampI64(vy2+SignI64(RandI16),-5,5);
|
||||
x1=ClampI64(x1+vx1,0,Fs->pix_width-1);
|
||||
y1=ClampI64(y1+vy1,0,Fs->pix_height-1);
|
||||
x2=ClampI64(x2+vx2,0,Fs->pix_width-1);
|
||||
y2=ClampI64(y2+vy2,0,Fs->pix_height-1);
|
||||
Sleep(1); //Replace this with Yield() ort Sleep(0) and see what happens!
|
||||
}
|
||||
DCFill(dc);
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
Main;
|
||||
@@ -0,0 +1,83 @@
|
||||
#define STEP_SIZE 400
|
||||
|
||||
U0 LowPassFilterDemo()
|
||||
{
|
||||
F64 y,y1,t,dt;
|
||||
CDC *dc=DCAlias;
|
||||
|
||||
WinBorder;
|
||||
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,106 @@
|
||||
F64 MySin(F64 d)
|
||||
{ //Sin() does not have an address.
|
||||
return Sin(d);
|
||||
}
|
||||
|
||||
F64 MyCos(F64 d)
|
||||
{ //Cos() does not have an address.
|
||||
return Cos(d);
|
||||
}
|
||||
|
||||
U0 FunDraw1(CDC *dc,F64 (*f)(F64 t))
|
||||
{
|
||||
I64 i,w=Fs->pix_width,h=Fs->pix_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->pix_width,h=Fs->pix_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->pix_width,h=Fs->pix_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;
|
||||
GrPrint(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;
|
||||
GrPrint(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);
|
||||
"$$RED$$Sin$$FG$$\n";
|
||||
PressAKey;
|
||||
dc->color=BLUE;
|
||||
FunDraw2(dc,&Saw,1.0);
|
||||
"$$BLUE$$Saw$$FG$$\n";
|
||||
PressAKey;
|
||||
dc->color=GREEN;
|
||||
FunDraw2(dc,&FullSaw,1.0);
|
||||
"$$GREEN$$FullSaw$$FG$$\n";
|
||||
PressAKey;
|
||||
|
||||
Init(dc);
|
||||
dc->color=RED;
|
||||
FunDraw1(dc,&MyCos);
|
||||
"$$RED$$Cos$$FG$$\n";
|
||||
PressAKey;
|
||||
dc->color=BLUE;
|
||||
FunDraw2(dc,&Caw,1.0);
|
||||
"$$BLUE$$Caw$$FG$$\n";
|
||||
PressAKey;
|
||||
dc->color=GREEN;
|
||||
FunDraw2(dc,&FullCaw,1.0);
|
||||
"$$GREEN$$FullCaw$$FG$$\n";
|
||||
PressAKey;
|
||||
|
||||
Init(dc);
|
||||
dc->color=RED;
|
||||
FunDraw1(dc,&MySin);
|
||||
"$$RED$$Sin$$FG$$\n";
|
||||
PressAKey;
|
||||
dc->color=BLUE;
|
||||
FunDraw2(dc,&Tri,1.0);
|
||||
"$$BLUE$$Tri$$FG$$\n";
|
||||
PressAKey;
|
||||
dc->color=GREEN;
|
||||
FunDraw2(dc,&FullTri,1.0);
|
||||
"$$GREEN$$FullTri$$FG$$\n";
|
||||
PressAKey;
|
||||
|
||||
DCFill(dc);
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
SndMathDemo;
|
||||
@@ -0,0 +1,11 @@
|
||||
U0 Mouse()
|
||||
{
|
||||
"Press left mouse bttn to exit.\n";
|
||||
while (!ms.lb) { //Left bttn to exit.
|
||||
GrPlot(,ms.pos.x,ms.pos.y);
|
||||
Refresh;
|
||||
}
|
||||
DCFill;
|
||||
}
|
||||
|
||||
Mouse;
|
||||
@@ -0,0 +1,16 @@
|
||||
//Press <F5> to compile and run.
|
||||
|
||||
U0 NetOfDots()
|
||||
{
|
||||
I64 i;
|
||||
CDC *dc=DCAlias;
|
||||
DocClear;
|
||||
dc->color=RED;
|
||||
for (i=0;i<480;i+=20)
|
||||
GrLine(dc,i,0,0,480-i,3);
|
||||
DCDel(dc);
|
||||
PressAKey;
|
||||
DCFill;
|
||||
}
|
||||
|
||||
NetOfDots; //Run when #included
|
||||
@@ -0,0 +1,27 @@
|
||||
U0 PaletteDemo()
|
||||
{
|
||||
I64 i,j;
|
||||
CBGR48 bgr;
|
||||
for (i=0;i<COLORS_NUM;i++)
|
||||
"$$BLACK$$$$BG,%d$$__%-8Z__$$FG$$$$BG$$\n",i,i,"ST_COLORS";
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
|
||||
//Alternatively, use $LK,"GrPaletteSet",A="MN:GrPaletteSet"$(gr_palette_gray);
|
||||
for (i=0;i<COLORS_NUM;i++) {
|
||||
j=0xFFFF*i/(COLORS_NUM-1);
|
||||
bgr.b=j;
|
||||
bgr.g=j;
|
||||
bgr.r=j;
|
||||
GrPaletteColorSet(i,bgr);
|
||||
}
|
||||
PressAKey;
|
||||
|
||||
//You can do it this way, too.
|
||||
GrPaletteColorSet(WHITE,0xFFFFFFFF0000);
|
||||
PressAKey;
|
||||
|
||||
//$LK,"SettingsPop",A="MN:SettingsPop"$() restores original palette
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
PaletteDemo;
|
||||
@@ -0,0 +1,35 @@
|
||||
U0 PanText()
|
||||
{
|
||||
I64 i;
|
||||
for (i=0;i<=7;i++) {
|
||||
gr.pan_text_x=i;
|
||||
Sleep(30);
|
||||
}
|
||||
i--;
|
||||
for (;i>=-7;i--) {
|
||||
gr.pan_text_x=i;
|
||||
Sleep(30);
|
||||
}
|
||||
i++;
|
||||
for (;i<=0;i++) {
|
||||
gr.pan_text_x=i;
|
||||
Sleep(30);
|
||||
}
|
||||
|
||||
for (i=0;i<=7;i++) {
|
||||
gr.pan_text_y=i;
|
||||
Sleep(30);
|
||||
}
|
||||
i--;
|
||||
for (;i>=-7;i--) {
|
||||
gr.pan_text_y=i;
|
||||
Sleep(30);
|
||||
}
|
||||
i++;
|
||||
for (;i<=0;i++) {
|
||||
gr.pan_text_y=i;
|
||||
Sleep(30);
|
||||
}
|
||||
}
|
||||
|
||||
PanText;
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,174 @@
|
||||
#define ZEROS_NUM 2
|
||||
Complex zeros[ZEROS_NUM]={{10.0,0},{-30,0}};
|
||||
#define POLES_NUM 2
|
||||
Complex poles[POLES_NUM]={{-20.0,-15.0},{-20.0,15.0}};
|
||||
|
||||
F64 scale;
|
||||
|
||||
Complex *PoleZeroFind(I64 x,I64 y)
|
||||
{
|
||||
I64 i;
|
||||
F64 dd,best_dd=F64_MAX;
|
||||
Complex *res=NULL;
|
||||
for (i=0;i<POLES_NUM;i++) {
|
||||
dd=Sqr(poles[i].x-x)+Sqr(poles[i].y-y);
|
||||
if (dd<best_dd) {
|
||||
best_dd=dd;
|
||||
res=&poles[i];
|
||||
}
|
||||
}
|
||||
for (i=0;i<ZEROS_NUM;i++) {
|
||||
dd=Sqr(zeros[i].x-x)+Sqr(zeros[i].y-y);
|
||||
if (dd<best_dd) {
|
||||
best_dd=dd;
|
||||
res=&zeros[i];
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
F64 F(Complex *x)
|
||||
{
|
||||
F64 m,a;
|
||||
Complex num,denom,n1;
|
||||
|
||||
CPoly(&num, ZEROS_NUM,zeros,x);
|
||||
CPoly(&denom,POLES_NUM,poles,x);
|
||||
CDiv(&n1,&num,&denom);
|
||||
|
||||
R2P(&m,&a,n1.x,n1.y);
|
||||
if (ms.rb)
|
||||
return ã+a;
|
||||
else
|
||||
return m;
|
||||
}
|
||||
|
||||
F64 MPDraw(CTask *task)
|
||||
{
|
||||
Complex xx;
|
||||
I64 x,y,w=task->pix_width,h=task->pix_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(,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=Clamp(yy,0,14);
|
||||
y_total+=Clamp(yy,-14,14);
|
||||
GrPlot(dc,x,y);
|
||||
}
|
||||
}
|
||||
DCDel(dc);
|
||||
return y_total;
|
||||
}
|
||||
|
||||
U0 Draw()
|
||||
{
|
||||
CJob *tmpm[MP_PROCESSORS_NUM];
|
||||
F64 y_total,old_y_total=F64_MAX;
|
||||
I64 i,w=Fs->pix_width,h=Fs->pix_height,cx=w/2,cy=h/2;
|
||||
CDC *dc=DCAlias;
|
||||
while (TRUE) {
|
||||
for (i=0;i<mp_cnt;i++)
|
||||
tmpm[i]=JobQue(&MPDraw,Fs,i,0);
|
||||
y_total=0;
|
||||
for (i=0;i<mp_cnt;i++)
|
||||
y_total+=JobResGet(tmpm[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<ZEROS_NUM;i++)
|
||||
GrPrint(dc,cx+zeros[i].x-FONT_WIDTH/2,cy-zeros[i].y-FONT_HEIGHT/2,"o");
|
||||
for (i=0;i<POLES_NUM;i++)
|
||||
GrPrint(dc,cx+poles[i].x-FONT_WIDTH/2,cy-poles[i].y-FONT_HEIGHT/2,"x");
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
U0 PoleZeros()
|
||||
{
|
||||
I64 msg_code,arg1,arg2,p11,p22,cx,cy;
|
||||
Complex *tmpc=NULL;
|
||||
|
||||
PopUpOk(
|
||||
"Drag the poles and zeros with left mouse.\n"
|
||||
"Hold right mouse for phase plot.\n"
|
||||
);
|
||||
Refresh;
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
|
||||
Fs->win_inhibit=WIG_TASK_DFT-WIF_SELF_FOCUS-WIF_SELF_BORDER;
|
||||
GrPaletteSet(gr_palette_gray);
|
||||
GrPaletteColorSet(15,0xFFFF00000000); //White is red
|
||||
|
||||
AutoComplete;
|
||||
WinBorder;
|
||||
WinMax;
|
||||
DocClear;
|
||||
DCFill;
|
||||
scale=1.0;
|
||||
|
||||
try {
|
||||
Draw;
|
||||
while (TRUE) {
|
||||
msg_code=GetMsg(&arg1,&arg2,1<<MSG_KEY_DOWN+1<<MSG_MS_L_DOWN+
|
||||
1<<MSG_MS_L_UP+1<<MSG_MS_R_DOWN+1<<MSG_MS_R_UP+1<<MSG_MS_MOVE);
|
||||
pz_msg:
|
||||
cx=Fs->pix_width/2;
|
||||
cy=Fs->pix_height/2;
|
||||
switch (msg_code) {
|
||||
case MSG_MS_L_DOWN:
|
||||
tmpc=PoleZeroFind(arg1-cx,cy-arg2);
|
||||
break;
|
||||
case MSG_MS_MOVE:
|
||||
if (tmpc) {
|
||||
p11=arg1;p22=arg2;
|
||||
//get to last mouse move
|
||||
while (msg_code=ScanMsg(&arg1,&arg2,
|
||||
1<<MSG_KEY_DOWN+1<<MSG_MS_L_DOWN+
|
||||
1<<MSG_MS_L_UP+1<<MSG_MS_R_DOWN+
|
||||
1<<MSG_MS_R_UP+1<<MSG_MS_MOVE))
|
||||
if (msg_code==MSG_MS_MOVE) {
|
||||
p11=arg1;p22=arg2;
|
||||
} else
|
||||
goto pz_msg;
|
||||
|
||||
tmpc->x=p11-cx;
|
||||
tmpc->y=cy-p22;
|
||||
Draw;
|
||||
}
|
||||
break;
|
||||
case MSG_MS_L_UP:
|
||||
if (tmpc) {
|
||||
tmpc->x=arg1-cx;
|
||||
tmpc->y=cy-arg2;
|
||||
tmpc=NULL;
|
||||
Draw;
|
||||
}
|
||||
break;
|
||||
case MSG_MS_R_DOWN:
|
||||
case MSG_MS_R_UP:
|
||||
Draw;
|
||||
break;
|
||||
case MSG_KEY_DOWN:
|
||||
if (arg1==CH_SHIFT_ESC||arg1==CH_ESC)
|
||||
goto pz_done;
|
||||
}
|
||||
Refresh;
|
||||
}
|
||||
pz_done:
|
||||
GetMsg(,,1<<MSG_KEY_UP);
|
||||
} catch
|
||||
PutExcept;
|
||||
SettingsPop;
|
||||
DCFill;
|
||||
}
|
||||
|
||||
PoleZeros;
|
||||
@@ -0,0 +1,81 @@
|
||||
//Classic 2nd order nonlinear ordinary differential equation
|
||||
|
||||
I64 mp_not_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(,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);
|
||||
LBtr(&mp_not_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",A="MN:SettingsPush"$
|
||||
try {
|
||||
AutoComplete;
|
||||
WinBorder;
|
||||
WinMax;
|
||||
DocClear;
|
||||
Refresh;
|
||||
|
||||
dc->color=BLACK;
|
||||
GrLine(dc,OX,0,OX,GR_HEIGHT-FONT_HEIGHT-1);
|
||||
GrLine(dc,0,OY,GR_WIDTH-1,OY);
|
||||
while (!ScanChar) {
|
||||
mp_not_done_flags=1<<mp_cnt-1;
|
||||
for (i=0;i<mp_cnt;i++)
|
||||
JobQue(&PlotTrajectory,Fs,i);
|
||||
do Yield;
|
||||
while (mp_not_done_flags);
|
||||
}
|
||||
} catch
|
||||
PutExcept;
|
||||
SettingsPop;
|
||||
DCFill(dc);
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
PredatorPrey;
|
||||
Binary file not shown.
@@ -0,0 +1,15 @@
|
||||
//See $LK,"::/Demo/Games/Stadium/StadiumGen.HC"$.
|
||||
|
||||
U0 Main()
|
||||
{
|
||||
"Capture scrn...\n";
|
||||
PressAKey;
|
||||
GRScrnCaptureWrite("~/DemoScrnShot");
|
||||
"View captured scrn...\n";
|
||||
PressAKey;
|
||||
GRScrnCaptureRead("~/DemoScrnShot");
|
||||
PressAKey;
|
||||
DCFill;
|
||||
}
|
||||
|
||||
Main;
|
||||
Binary file not shown.
@@ -0,0 +1,177 @@
|
||||
//"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.
|
||||
Mat4x4MulXYZ(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.
|
||||
|
||||
//TempleOS will generate a random U16
|
||||
//and compare to dither_probability_u16 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_u16=-i;
|
||||
} else {
|
||||
dc->color=ROPF_PROBABILITY_DITHER+(color^8)<<16+color;
|
||||
dc->dither_probability_u16=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*(tS%10.0)/10.0)+2.0),
|
||||
é,é2,è,è2,radius,d;
|
||||
I64 i,j,cx=task->pix_width/2,cy=task->pix_height/2;
|
||||
CD3I32 poly[3],ls;
|
||||
|
||||
dc->flags|=DCF_TRANSFORMATION;
|
||||
DCDepthBufAlloc(dc);
|
||||
|
||||
Mat4x4IdentEqu(dc->r);
|
||||
Mat4x4RotZ(dc->r,s->az);
|
||||
Mat4x4RotY(dc->r,s->ay);
|
||||
Mat4x4RotX(dc->r,s->ax+ã);
|
||||
Mat4x4Scale(dc->r,tt);
|
||||
DCMat4x4Set(dc,dc->r);
|
||||
|
||||
ls.x=-(ms.pos.x-task->pix_left-task->scroll_x-cx);
|
||||
ls.y=-(ms.pos.y-task->pix_top-task->scroll_y-cy);
|
||||
ls.z=GR_WIDTH/8;
|
||||
d=1<<16/D3I32Norm(&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,"::/Demo/Graphics/SpritePlot3D.HC"$.
|
||||
//for a CSprite example.
|
||||
|
||||
//See $LK,"SpriteMeshEd",A="MN:SpriteMeshEd"$() 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",A="MN:SettingsPush"$
|
||||
AutoComplete;
|
||||
WinBorder;
|
||||
WinMax;
|
||||
DocClear;
|
||||
Fs->draw_it=&DrawIt;
|
||||
try {
|
||||
"\n\nMove mouse to change light source.\n\n";
|
||||
PressAKey;
|
||||
} catch
|
||||
PutExcept;
|
||||
DocClear;
|
||||
SettingsPop;
|
||||
ViewAnglesDel;
|
||||
}
|
||||
|
||||
Main;
|
||||
Binary file not shown.
@@ -0,0 +1,110 @@
|
||||
/*This was done with <CTRL-SHIFT-L> template code.
|
||||
It's conceptually easy to do a ctrl,
|
||||
but tedious. You have complete freedom.
|
||||
|
||||
See $LK,"CCtrl",A="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 DrawCtrlSlider(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;
|
||||
GrPrint(dc,c->left+1*SLIDER_SPACING+0-FONT_WIDTH/2,
|
||||
c->top+SLIDER_SPACING+SLIDER_RANGE+3,
|
||||
"%d",s->left_pos*10/SLIDER_RANGE);
|
||||
GrPrint(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 UpdateDerivedCtrlSlider(CCtrl *c)
|
||||
{
|
||||
CSliderState *s=c->state;
|
||||
c->left=c->win_task->pix_width/2-(SLIDER_SPACING*3+2)/2;
|
||||
c->right=c->left+3*SLIDER_SPACING+2;
|
||||
c->top=c->win_task->pix_height/2-(SLIDER_SPACING*2+SLIDER_RANGE)/2;
|
||||
c->bottom=c->top+SLIDER_SPACING*2+SLIDER_RANGE;
|
||||
s->left_pos=ClampI64(s->left_pos,0,SLIDER_RANGE-1);
|
||||
s->right_pos=ClampI64(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()
|
||||
{
|
||||
CCtrl *c=CAlloc(sizeof(CCtrl));
|
||||
c->win_task=Fs;
|
||||
c->flags=CTRLF_SHOW|CTRLF_CAPTURE_LEFT_MS;
|
||||
c->type=CTRLT_GENERIC;
|
||||
c->state=&sld;
|
||||
MemSet(&sld,0,sizeof(CSliderState));
|
||||
c->draw_it=&DrawCtrlSlider;
|
||||
c->left_click=&LeftClickSlider;
|
||||
c->update_derived_vals=&UpdateDerivedCtrlSlider;
|
||||
QueIns(c,Fs->last_ctrl);
|
||||
TaskDerivedValsUpdate;
|
||||
return c;
|
||||
}
|
||||
|
||||
U0 SliderDel(CCtrl *c)
|
||||
{
|
||||
QueRem(c);
|
||||
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,50 @@
|
||||
//This is a drawing program
|
||||
|
||||
public U0 SpeedLineDemo()
|
||||
{
|
||||
I64 msg_code,cnt,x1,y1,x2,y2,arg1,arg2,color=BLACK;
|
||||
CDC *dc=DCAlias;
|
||||
dc->color=color;
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
|
||||
Fs->win_inhibit=WIG_TASK_DFT-WIF_SELF_FOCUS-WIF_SELF_BORDER;
|
||||
|
||||
AutoComplete;
|
||||
WinBorder;
|
||||
WinMax;
|
||||
DocClear;
|
||||
DCFill;
|
||||
do {
|
||||
msg_code=GetMsg(&arg1,&arg2,
|
||||
1<<MSG_KEY_DOWN+1<<MSG_MS_L_DOWN+1<<MSG_MS_R_UP);
|
||||
switch (msg_code) {
|
||||
case MSG_MS_R_UP:
|
||||
color=PopUpColor;
|
||||
if (color>=0)
|
||||
dc->color=color;
|
||||
break;
|
||||
case MSG_MS_L_DOWN:
|
||||
x1=arg1; y1=arg2;
|
||||
x2=arg1; y2=arg2;
|
||||
cnt=0;
|
||||
while (msg_code!=MSG_MS_L_UP) {
|
||||
dc->pen_width=0.04*ms.speed;
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
msg_code=GetMsg(&arg1,&arg2,
|
||||
1<<MSG_MS_L_UP+1<<MSG_MS_MOVE);
|
||||
x1=x2; y1=y2;
|
||||
x2=arg1; y2=arg2;
|
||||
}
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
break;
|
||||
case MSG_KEY_DOWN:
|
||||
break;
|
||||
}
|
||||
} while (msg_code!=MSG_KEY_DOWN || !arg1);
|
||||
GetMsg(,,1<<MSG_KEY_UP);
|
||||
DCFill;
|
||||
DCDel(dc);
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
SpeedLineDemo; //Execute when #included
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,26 @@
|
||||
/*If you press <CTRL-t> you will see this:
|
||||
|
||||
$$IB,"<1>",BI=1,BP="::/Demo/Graphics/SpritePut.HC,2"$$
|
||||
|
||||
That imports an external sprite. It's
|
||||
called a $LK,"DOCEF_BIN_PTR_LINK",A="MN:DOCEF_BIN_PTR_LINK"$. See $LK,"BP=\"\"",A="FF:::/Doc/DolDocOverview.DD,BP=\"\""$.
|
||||
|
||||
Press <CTRL-r> and "Ptr 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 link to a tag string instead of a num.
|
||||
*/
|
||||
|
||||
U0 SpritePutExt()
|
||||
{
|
||||
I64 i;
|
||||
for (i=0;i<3;i++) {
|
||||
"US Map:";
|
||||
Sprite($IB,"<1>",BI=1,BP="::/Demo/Graphics/SpritePut.HC,2"$);
|
||||
"%h12c",'\n'; //"h" is a secondary arg. $LK,"Print",A="FI:::/Doc/Print.DD"$ 12 newline chars.
|
||||
}
|
||||
}
|
||||
|
||||
SpritePutExt;
|
||||
@@ -0,0 +1,38 @@
|
||||
//Normally, you make sprites with <CTRL-r>.
|
||||
//This shows how to build a sprite by hand.
|
||||
//See $MA-X+PU,"::/Apps/GrModels",LM="Cd(\"::/Apps/GrModels\");Dir;View;\n"$.
|
||||
|
||||
class MySprite
|
||||
{ // See $LK,"Sprite Elem Types",A="MN:SPT_LINE"$
|
||||
CSpriteColor color;
|
||||
CSpritePtPt line1;
|
||||
CSpritePtPt line2;
|
||||
CSpritePtPt line3;
|
||||
CSpritePt fill;
|
||||
CSpriteBase end;
|
||||
};
|
||||
|
||||
|
||||
U0 SpriteRawDemo()
|
||||
{
|
||||
MySprite s;
|
||||
|
||||
MemSet(&s,0,sizeof(s));
|
||||
s.color.type=SPT_COLOR;
|
||||
s.color.color=GREEN;
|
||||
s.line1.type=SPT_LINE;
|
||||
s.line1.x2=100; s.line1.y2=50;
|
||||
s.line2.type=SPT_LINE;
|
||||
s.line2.x2=50; s.line2.y2=100;
|
||||
s.line3.type=SPT_LINE;
|
||||
s.line3.x1=100; s.line3.y1=50;
|
||||
s.line3.x2=50; s.line3.y2=100;
|
||||
s.fill.type=SPT_FLOOD_FILL;
|
||||
s.fill.x1=20; s.fill.y1=20;
|
||||
s.end.type=SPT_END;
|
||||
|
||||
Sprite(&s);
|
||||
"%h13c",'\n';
|
||||
}
|
||||
|
||||
SpriteRawDemo;
|
||||
Binary file not shown.
@@ -0,0 +1,43 @@
|
||||
/*$LK,"gr.dc",A="MN:CGrGlbls"$ is the persistent layer. You can access
|
||||
it directly but two tasks accessing it simultaneously
|
||||
with no $LK,"DCAlias",A="MN:DCAlias"$() will screw-up color and stuff.
|
||||
*/
|
||||
|
||||
U0 SunMoon()
|
||||
{
|
||||
I64 i,x,y,radius;
|
||||
|
||||
AutoComplete; //AutoComplete Off
|
||||
WinBorder; //No Border
|
||||
WinMax; //Maximize window
|
||||
DocClear; //Clear command-line text
|
||||
Fs->text_attr=BLACK<<4+WHITE; //Current $LK,"CTask",A="MN:CTask"$ is Fs segment register.
|
||||
|
||||
for (i=0;i<0x8000;i+=0x200) {
|
||||
//Sun
|
||||
x=0.2*GR_WIDTH; y=0.5*GR_HEIGHT; radius=120;
|
||||
gr.dc->color=DKGRAY;
|
||||
GrCircle(gr.dc,x,y,radius);
|
||||
gr.dc->color=ROPF_DITHER+RED<<16+YELLOW;
|
||||
GrFloodFill(gr.dc,x,y);
|
||||
|
||||
//Moon
|
||||
x=0.8*GR_WIDTH-i/0x200; y=0.5*GR_HEIGHT; radius=75;
|
||||
gr.dc->color=DKGRAY;
|
||||
GrCircle(gr.dc,x,y,radius);
|
||||
//<CTRL-ALT-a> for the "ã" character.
|
||||
GrCircle(gr.dc,x+0.5*radius,y,1.2*radius,,ã-.31*ã,0.62*ã);
|
||||
gr.dc->color=ROPF_PROBABILITY_DITHER+LTGRAY<<16+BLACK;
|
||||
gr.dc->dither_probability_u16=i; //U16 can be [0,65535]
|
||||
GrFloodFill(gr.dc,x+0.5*radius,y);
|
||||
gr.dc->dither_probability_u16=2*i; //U16 can be [0,65535]
|
||||
GrFloodFill(gr.dc,x-0.75*radius,y);
|
||||
|
||||
Refresh; //Typically 30 fps
|
||||
DCFill;
|
||||
}
|
||||
|
||||
Fs->text_attr=WHITE<<4+BLUE;
|
||||
}
|
||||
|
||||
SunMoon;
|
||||
@@ -0,0 +1,62 @@
|
||||
/*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,arg1,arg2;
|
||||
CDC *dc=DCAlias;
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
|
||||
Fs->win_inhibit=WIG_TASK_DFT-WIF_SELF_FOCUS-WIF_SELF_BORDER;
|
||||
|
||||
WinBorder;
|
||||
WinMax;
|
||||
DocClear;
|
||||
DCFill;
|
||||
dc->flags|=DCF_SYMMETRY;
|
||||
DCSymmetrySet(dc,Fs->pix_width/2,0,Fs->pix_width/2,1);
|
||||
do {
|
||||
msg_code=GetMsg(&arg1,&arg2,
|
||||
1<<MSG_KEY_DOWN+1<<MSG_MS_L_DOWN+
|
||||
1<<MSG_MS_R_DOWN);
|
||||
switch (msg_code) {
|
||||
case MSG_MS_R_DOWN:
|
||||
dc->flags&=~DCF_SYMMETRY;
|
||||
dc->color=ROP_XOR+RED^TRANSPARENT;
|
||||
x1=arg1; y1=arg2;
|
||||
x2=arg1; y2=arg2;
|
||||
while (msg_code!=MSG_MS_R_UP) {
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
msg_code=GetMsg(&arg1,&arg2,
|
||||
1<<MSG_MS_R_UP+1<<MSG_MS_MOVE);
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
x2=arg1; y2=arg2;
|
||||
}
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
if (DCSymmetry3Set(dc,x1,y1,0,x2,y2,0,x2,y2,1))
|
||||
dc->flags|=DCF_SYMMETRY;
|
||||
break;
|
||||
case MSG_MS_L_DOWN:
|
||||
dc->color=ROP_XOR+BLACK^TRANSPARENT;
|
||||
x1=arg1; y1=arg2;
|
||||
x2=arg1; y2=arg2;
|
||||
while (msg_code!=MSG_MS_L_UP) {
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
msg_code=GetMsg(&arg1,&arg2,
|
||||
1<<MSG_MS_L_UP+1<<MSG_MS_MOVE);
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
x2=arg1; y2=arg2;
|
||||
}
|
||||
GrLine3(dc,x1,y1,0,x2,y2,0);
|
||||
break;
|
||||
}
|
||||
} while (msg_code!=MSG_KEY_DOWN || (arg1!=CH_ESC && arg1!=CH_SHIFT_ESC));
|
||||
GetMsg(,,1<<MSG_KEY_UP);
|
||||
DCFill;
|
||||
DCDel(dc);
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
SymmetryDemo; //Execute when #included
|
||||
Binary file not shown.
@@ -0,0 +1,108 @@
|
||||
/*Done with <CTRL-SHIFT-L> template code
|
||||
that was modified.
|
||||
|
||||
This is an advanced demo that shows
|
||||
that you can place ctrls on the
|
||||
wall paper.
|
||||
|
||||
See $LK,"::/Demo/Graphics/Slider.HC"$
|
||||
and $LK,"::/Demo/Graphics/WallPaperFish.HC"$
|
||||
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 DrawCtrlSlider(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;
|
||||
GrPrint(dc,c->left+1*SLIDER_SPACING+0-FONT_WIDTH/2,
|
||||
c->top+SLIDER_SPACING+SLIDER_RANGE+3,
|
||||
"%d",s->left_pos*10/SLIDER_RANGE);
|
||||
GrPrint(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 UpdateDerivedCtrlSlider(CCtrl *c)
|
||||
{
|
||||
CSliderState *s=c->state;
|
||||
c->left=c->win_task->pix_width/2-(SLIDER_SPACING*3+2)/2;
|
||||
c->right=c->left+3*SLIDER_SPACING+2;
|
||||
c->top=c->win_task->pix_height/2-(SLIDER_SPACING*2+SLIDER_RANGE)/2;
|
||||
c->bottom=c->top+SLIDER_SPACING*2+SLIDER_RANGE;
|
||||
s->left_pos=ClampI64(s->left_pos,0,SLIDER_RANGE-1);
|
||||
s->right_pos=ClampI64(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()
|
||||
{
|
||||
CCtrl *c;
|
||||
if (Fs!=adam_task) {
|
||||
"Must be Adam Included with SHIFT-F5.\n"
|
||||
"(Would crash when code mem was freed.)\n";
|
||||
return NULL;
|
||||
}
|
||||
c=ACAlloc(sizeof(CCtrl));
|
||||
c->win_task=sys_winmgr_task;
|
||||
c->flags=CTRLF_SHOW|CTRLF_CAPTURE_LEFT_MS;
|
||||
c->type=CTRLT_GENERIC;
|
||||
c->state=ACAlloc(sizeof(CSliderState));
|
||||
c->draw_it=&DrawCtrlSlider;
|
||||
c->left_click=&LeftClickSlider;
|
||||
c->update_derived_vals=&UpdateDerivedCtrlSlider;
|
||||
QueIns(c,sys_winmgr_task->last_ctrl);
|
||||
TaskDerivedValsUpdate;
|
||||
return c;
|
||||
}
|
||||
|
||||
U0 SliderDel(CCtrl *c)
|
||||
{
|
||||
QueRem(c);
|
||||
Free(c->state);
|
||||
Free(c);
|
||||
}
|
||||
|
||||
SliderNew;
|
||||
Binary file not shown.
@@ -0,0 +1,23 @@
|
||||
U0 DrawIt(CTask *,CDC *dc)
|
||||
{
|
||||
I64 i,j;
|
||||
U16 *ptr=gr.win_z_buf;
|
||||
dc->color=BLACK;
|
||||
GrPrint(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",A="MN:SettingsPush"$
|
||||
DocClear;
|
||||
Fs->draw_it=&DrawIt;
|
||||
GetChar(,FALSE);
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
ScrollBars;
|
||||
Reference in new issue
Block a user