/*********************************************************** * 移動動作サンプルプログラムver1.1 by やすっち * allegro用C言語サンプルソース * このファイルは拡張子を c に変更してください。 * * 注意事項…DJGPP以外でのコンパイル確認はされていません * 作者の一言…移動制御、模様描画などの参考に **********************************************************/ #include #include #include #include "allegro.h" int color=1; int FlowFlg=0; double X1,X2,X3; double Y1,Y2,Y3; double i=0; BITMAP *screenbuf; void Flow00(void); void Flow01(void); void Flow02(void); void Flow03(void); void Flow04(void); int main(void) { allegro_init(); install_keyboard(); install_timer(); set_gfx_mode(GFX_AUTODETECT,400,300,0,0); screenbuf=create_bitmap(400,300); desktop_pallete[0].r=0; desktop_pallete[0].g=0; desktop_pallete[0].b=0; desktop_pallete[15].r=255; desktop_pallete[15].g=255; desktop_pallete[15].b=255; set_pallete(desktop_pallete); clear(screenbuf); while(!key[KEY_ESC]) { if(key[KEY_ENTER]) { FlowFlg++; color=1; i=401; clear(screenbuf); X1=0 ,X2=0 ,X3=0; Y1=150,Y2=150,Y3=150; } if(key[KEY_SPACE]) { color++; if(color==16)color=1; } textout(screenbuf,font,"MOVE TEST PROGRAM VER 1.1 by YASUTHI",1,1,15); if(FlowFlg>4)FlowFlg=0; while(key[KEY_ENTER] || key[KEY_SPACE]); /* 簡易フロー処理 */ if(FlowFlg==0)Flow00(); if(FlowFlg==1)Flow01(); if(FlowFlg==2)Flow02(); if(FlowFlg==3)Flow03(); if(FlowFlg==4)Flow04(); } destroy_bitmap(screenbuf); remove_timer(); remove_keyboard(); allegro_exit(); return 0; } /******************* * クレヨンペン円 ******************/ void Flow00(void) { if(i>=PI*2) { color++; if(color==16)color=1; i=0; clear(screenbuf); textout(screenbuf,font,"MOVE TEST PROGRAM VER 1.1 by YASUTHI",1,1,15); } else i+=0.005; X1=cos(i); Y1=sin(i); X2=cos(fmod(i*50,PI*2)); Y2=sin(fmod(i*50,PI*2)); textout(screenbuf,font,"x=cos(i)*100+cos(i*50)*10",1,10,color); textout(screenbuf,font,"y=sin(i)*100+sin(i*50)*10",1,19,color); textout(screenbuf,font,"CRAYON PEN CIRCLE",1,291,15); putpixel(screenbuf,X1*100+X2*10+200-5,300-(Y1*100+Y2*10+150-5),color); blit(screenbuf,screen,0,0,0,0,400,300); } /*********************** * ランダムウェーブ **********************/ void Flow01(void) { static double savex,savey; if(i>400) { color++; if(color==16)color=1; i=0; Y1=150; clear(screenbuf); textout(screenbuf,font,"MOVE TEST PROGRAM VER 1.1 by YASUTHI",1,1,15); } else i+=0.5; X2=savex; Y2=savey; X1=i; Y1+=rand()%11-5; if(Y1<150)Y1++; if(Y1>150)Y1--; savex=X1; savey=Y1; textout(screenbuf,font,"x=i y=y-5+(R%11)",1,10,color); textout(screenbuf,font,"RANDOM WAVE SCOPE",1,291,15); if(i!=0) line(screenbuf,X1,Y1,X2,Y2,color); blit(screenbuf,screen,0,0,0,0,400,300); } /********************** * マジカルライン *********************/ void Flow02(void) { static int swflg; static double savex,savey; if(i>=PI*2) { color++; if(color==16)color=1; i=0; clear(screenbuf); textout(screenbuf,font,"MOVE TEST PROGRAM VER 1.1 by YASUTHI",1,1,15); } else i+=0.05; if(swflg==0) { X2=savex; Y2=savey; X1=cos(i); Y1=sin(i); savex=X1; savey=Y1; swflg=1; } else { X1=savex; Y1=savey; X2=cos(i+PI/4); Y2=sin(i+PI/4); savex=X2; savey=Y2; swflg=0; } textout(screenbuf,font,"x1=cos(i) y1=sin(i)",1,10,color); textout(screenbuf,font,"x2=w-cos(i+PI/4) y2=h-sin(i+PI/4)",1,19,color); textout(screenbuf,font,"MAGICAL LINE",1,291,15); if(i!=0) line(screenbuf,X1*100+200,Y1*100+150,400-(X2*100+200),300-(Y2*100+150),color); blit(screenbuf,screen,0,0,0,0,400,300); } /********************* * 三角関数のグラフ ********************/ void Flow03(void) { if(i>=PI*2) { color++; if(color==16)color=1; i=0; clear(screenbuf); textout(screenbuf,font,"MOVE TEST PROGRAM VER 1.1 by YASUTHI",1,1,15); } else i+=0.01; X1=(i/(PI*2))*400; Y1=sin(i); Y2=cos(i); Y3=tan(i); textout(screenbuf,font,"x1=(i/PI)*W y1=sin(i)*100",1,10,color); textout(screenbuf,font,"x2=(i/PI)*W y2=cos(i)*100",1,19,(color)%15+1); textout(screenbuf,font,"x3=(i/PI)*W y3=tan(i)*100",1,28,(color+1)%15+1); textout(screenbuf,font,"TRIANGLE FUNCTION GRAPH",1,291,15); putpixel(screenbuf,X1,300-(Y1*100+150),color); putpixel(screenbuf,X1,300-(Y2*100+150),(color)%15+1); putpixel(screenbuf,X1,300-(Y3*100+150),(color+1)%15+1); blit(screenbuf,screen,0,0,0,0,400,300); } /************************* * 三角関数のグラフ(逆) ************************/ void Flow04(void) { if(i>=PI*2) { color++; if(color==16)color=1; i=0; clear(screenbuf); textout(screenbuf,font,"MOVE TEST PROGRAM VER 1.1 by YASUTHI",1,1,15); } else i+=0.01; X1=(i/(PI*2))*400; Y1=asin(i-PI); Y2=acos(i-PI); Y3=atan(i-PI); textout(screenbuf,font,"x1=(i/PI)*W y1=arc_sin(i)*100",1,10,color); textout(screenbuf,font,"x2=(i/PI)*W y2=arc_cos(i)*100",1,19,(color)%15+1); textout(screenbuf,font,"x3=(i/PI)*W y3=arc_tan(i)*100",1,28,(color+1)%15+1); textout(screenbuf,font,"ARC TRIANGLE FUNCTION GRAPH",1,291,15); putpixel(screenbuf,X1,300-(Y1*100+150),color); putpixel(screenbuf,X1,300-(Y2*100+150),(color)%15+1); putpixel(screenbuf,X1,300-(Y3*100+150),(color+1)%15+1); blit(screenbuf,screen,0,0,0,0,400,300); }