U0 Main() { "Julia Set Generator\n"; SettingsPush; I64 k,j; CBGR bgr; for (k=0; k<16; k++) { j=0xFF*k/15; bgr.b=j; bgr.g=j; bgr.r=j; SetVGAPaletteColor(k, bgr); } CDC *dc=DCAlias; I64 row, col; for (row=0; row<ROWS; row++) { for (col=0; col<COLS; col++) { F64 r=LEFT+ToF64(COL_INC*col), i=BOTTOM+ToF64(ROW_INC*row); dc->color=getColor(-0.8, 0.156, r, i); I64 x=col*(640/COLS), y=row*(480/ROWS); GrRect(dc, x, y, 640/COLS, 480/ROWS); } } PressAKey; DCFill(dc); DCDel(dc); SettingsPop; }
U0 BSplineDemo() { CDC *dc=DCAlias; I64 p1,p2,i=0,msg_code; CD3I32 c[64]; SettingsPush; Fs->win_inhibit=WIF_ALL-WIF_BORDER; DocClear; "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; }
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; }
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; dc->color=GREEN; FunDraw2(dc,&FullSaw,1.0); "$$FG,GREEN$$FullSaw$$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); }
public U0 SpeedLineDemo() { I64 msg_code,cnt,x1,y1,x2,y2,p1,p2,color=BLACK; CDC *dc=DCAlias; dc->color=color; SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$ Fs->win_inhibit=WIF_ALL-WIF_BORDER; WinMax; WordStat; DCFill; DocClear; 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=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); GetMsg(,,1<<MSG_KEY_UP); DCFill; DCDel(dc); SettingsPop; }
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); }
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); }
U0 Extents() { CDC *dc=DCAlias; I64 min_x,max_x,min_y,max_y; //We want screen, not window coordinates. I64 h=Fs->win_pixel_left+Fs->win_scroll_x,v=Fs->win_pixel_top+Fs->win_scroll_y; DocClear; DCFill; //This sets a flag to record the //extents of what we draw and inits //the max's and min's.Vals are //screen coordinates. DCExtentsInit(dc); dc->pen_width=3; SpritePlot3(dc,40,GR_HEIGHT>>1,0,$IB,"<1>",1$); dc->color=LTRED; dc->pen_width=1; //This box is the extents. GrLine(dc,dc->min_x-h,dc->min_y-v,dc->max_x-h,dc->min_y-v); GrLine(dc,dc->min_x-h,dc->min_y-v,dc->min_x-h,dc->max_y-v); GrLine(dc,dc->max_x-h,dc->max_y-v,dc->max_x-h,dc->min_y-v); GrLine(dc,dc->max_x-h,dc->max_y-v,dc->min_x-h,dc->max_y-v); DCDel(dc); PressAKey; DCFill; SpriteExtents($IB,"<1>",1$,&min_x,&max_x,&min_y,&max_y); "X: %d to %d\n",min_x,max_x; "Y: %d to %d\n",min_y,max_y; }
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; }