کد:
#include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <dos.h> int gdriver = DETECT, gmode, errorcode; int x1,x11,y1,y11; int x2,y2; int x3,y3; int x4,y4; int i,j; int x=0,l=0; char ch; void paint(void); void calc(void); int main() { initgraph(&gdriver, &gmode, ""); //initializ for grapic errorcode = graphresult(); if (errorcode != grOk) { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); } delay(500); calc(); paint(); up: ch=getch(); switch(ch){ case 'r': //goto rigth x+=20; paint(); break; case 'l': //goto left x-=20; paint(); break; case 'u': //litgh on l=14; paint(); break; case 'v': //litgh off l=0; paint(); break; case 'b': // beep delay(20); sound(900); delay(120); nosound(); break; case 0x1b: //Esc for Exit closegraph(); return 0; } goto up; } //////////////////////////////////// void calc(){ x1=getmaxx()/3; y1=getmaxy()/4; x11=(getmaxx()/3)*2; y11=(getmaxy()/2); x2=(getmaxx()/3)+30; y2=(getmaxy()/2)+20; x3=((getmaxx()/3)*2)-30; y3=(getmaxy()/2)+20; x4=(getmaxx()/3); y4=(getmaxy()/2)-30; } /////////////////////////////////// void paint() { delay(30); cleardevice(); setbkcolor(7); if (x>200) x=200; if (x<-180) x=-180; setfillstyle(9,9); // badaneh asli bar(x1+x,y1,x11+x,y11); setcolor(1); setlinestyle(0,0,3); rectangle(x1+x,y1,x11+x,y11); setcolor(8); setfillstyle(9,8); // charkh ha fillellipse(x2+x,y2,20,20); //lastic ha fillellipse(x3+x,y3,20,20); setcolor(6); // cherag jelo setfillstyle(1,l); pieslice(x4+x,y4,90,270,20); }
کد:
#include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <dos.h> int gdriver = DETECT, gmode, errorcode; int x1,x11,y1,y11; int x2,y2; int x3,y3; int x4,y4; int i,j; int x=0,l=0; char ch; void paint(void); void calc(void); int main() { //**************************************** initgraph(&gdriver, &gmode, ""); //initializ for grapic errorcode = graphresult(); if (errorcode != grOk) { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); } //**************************************** delay(500); calc(); paint(); up: ch=getch(); switch(ch){ case 'r': //goto rigth x+=20; paint(); break; case 'l': //goto left x-=20; paint(); break; case 'u': //litgh on l=14; paint(); break; case 'v': //litgh off l=0; paint(); break; case 'b': // beep delay(20); sound(900); delay(80); sound(1700); delay(80); sound(700); delay(80); sound(900); delay(80); nosound(); break; case 0x1b: //Esc for Exit closegraph(); return 0; default: for(j=0;j<2;j++) { for (i=10;i<15;i+=2) { setcolor(i); settextjustify(0,1); outtextxy((getmaxx()/2)-100,((getmaxy()/6)*5-20),"Press (L) to Move to Left"); outtextxy((getmaxx()/2)-100,(((getmaxy()/6)*5)-5),"Press (R) to Move to Right"); outtextxy((getmaxx()/2)-100,(((getmaxy()/6)*5)+10),"Press (B) to Beep"); outtextxy((getmaxx()/2)-100,(((getmaxy()/6)*5)+25),"Press (U) to Turn On Litgh"); outtextxy((getmaxx()/2)-100,(((getmaxy()/6)*5)+40),"Press (L) to Turn Off Litgh"); delay(50); } } paint(); } goto up; closegraph(); return 0; } //////////////////////////////////// void calc(){ x1=getmaxx()/3; y1=getmaxy()/4; x11=(getmaxx()/3)*2; y11=(getmaxy()/2); x2=(getmaxx()/3)+30; y2=(getmaxy()/2)+20; x3=((getmaxx()/3)*2)-30; y3=(getmaxy()/2)+20; x4=(getmaxx()/3); y4=(getmaxy()/2)-30; } //++++++++++++++++++++++++++++++++ void paint(){ //++++++++++ delay(30); //clrscr(); cleardevice(); setbkcolor(7); setfillstyle(1,1); // hashieh ha bar(0,0,getmaxx(),getmaxy()); setfillstyle(1,7); bar(7,7,getmaxx()-7,getmaxy()-7); setcolor(7); setlinestyle(0,0,1); rectangle(3,3,getmaxx()-3,getmaxy()-3); setfillstyle(8,8); // khiaban bar(7,((getmaxy()/2)+43),getmaxx()-7,((getmaxy()/2)+80)); setcolor(8); setlinestyle(0,0,3); rectangle(7,((getmaxy()/2)+43),getmaxx()-7,((getmaxy()/2)+80)); setfillstyle(1,15); bar(40,((getmaxy()/2)+55),120,((getmaxy()/2)+65)); bar(160,((getmaxy()/2)+55),240,((getmaxy()/2)+65)); bar(280,((getmaxy()/2)+55),360,((getmaxy()/2)+65)); bar(400,((getmaxy()/2)+55),480,((getmaxy()/2)+65)); bar(520,((getmaxy()/2)+55),600,((getmaxy()/2)+65)); setcolor(4); settextjustify(0,1); outtextxy((getmaxx()/2)-100,((getmaxy()/6)*5-20),"Press (L) to Move to Left"); outtextxy((getmaxx()/2)-100,(((getmaxy()/6)*5)-5),"Press (R) to Move to Right"); outtextxy((getmaxx()/2)-100,(((getmaxy()/6)*5)+10),"Press (B) to Beep"); outtextxy((getmaxx()/2)-100,(((getmaxy()/6)*5)+25),"Press (U) to Turn On Litgh"); outtextxy((getmaxx()/2)-100,(((getmaxy()/6)*5)+40),"Press (L) to Turn Off Litgh"); setcolor(1); if (x>190) { x=190; settextjustify(1,1); outtextxy((getmaxx()/2),((getmaxy()/4)*3-10),"End of move to Left"); } if (x<-180) { x=-180; settextjustify(1,1); outtextxy((getmaxx()/2),((getmaxy()/4)*3-10),"End of move to Right"); } setfillstyle(9,9); // badaneh asli bar(x1+x,y1,x11+x,y11); setcolor(1); setlinestyle(0,0,3); rectangle(x1+x,y1,x11+x,y11); setfillstyle(1,11); bar(x1+x+5,y1+5,x1+x+65,y1+60); // panjareh ha rectangle(x1+x+5,y1+5,x1+x+65,y1+60); setfillstyle(1,11); bar(x1+x+70,y1+5,x1+x+135,y1+60); rectangle(x1+x+70,y1+5,x1+x+135,y1+60); setfillstyle(1,11); bar(x1+x+140,y1+5,x1+x+208,y1+60); rectangle(x1+x+140,y1+5,x1+x+208,y1+60); line(x1+x+35,y1+5,x1+x+35,y1+60); line(x1+x+102,y1+5,x1+x+102,y1+60); line(x1+x+173,y1+5,x1+x+173,y1+60); setcolor(8); setfillstyle(9,8); // charkh ha fillellipse(x2+x,y2,20,20); //lastic ha fillellipse(x3+x,y3,20,20); setfillstyle(8,8); // ring ha fillellipse(x2+x,y2,10,10); fillellipse(x3+x,y3,10,10); setcolor(6); // cherag jelo setfillstyle(1,l); pieslice(x4+x,y4,90,270,20); setfillstyle(1,12); // cherag agab bar(x11+x,y11-30,x11+10+x,y11-10); setcolor(4); rectangle(x11+x,y11-30,x11+10+x,y11-10); //++++++++++ }
موفق باشین [img]images/smilies/Smileys/8.gif[/img]