بسم الله الرحمن الرحيم
السلام عليكم ورحمة الله وبركاته
هذا برنامج عمل دائره متحركه
عرض الكل
السلام عليكم ورحمة الله وبركاته
هذا برنامج عمل دائره متحركه
كود المصدر
- #include<stdio.h>
- #include<conio.h>
- #include<dos.h>
- #include<graphics.h>
- #define left 0
- #define top 0
- #define right 319
- #define bottom 199
- #define radius 8
- void main()
- {
- int driver,mode;
- int x,y,dx,dy,oldx,oldy;
- void *ballbuff;
- unsigned size;
- driver=DETECT;
- initgraph(&driver,&mode,"");
- rectangle(left,top,right,bottom);
- x=y=radius + 10;
- setcolor(WHITE);
- setfillstyle(1,WHITE);
- circle(x,y,GREEN);
- floodfill(x,y,GREEN);
- size=imagesize(x-radius,y-radius,x+radius,y+radius);
- ballbuff=(void *)malloc(size);
- getimage(x-radius,y-radius,x+radius,y+radius,ballbuff);
- dx=2;
- dy=1;
- while(!kbhit())
- {
- putimage(x-radius,y-radius,ballbuff,COPY_PUT);
- oldx=x;
- oldy=y;
- x+=dx;
- y+=dy;
- sound(10 *x);
- delay(10);
- if(x<=left+radius+2 || x>=right-radius-2)
- dx=dx;
- if(y<=top+radius+1 || y>=bottom-radius-1)
- dy=dy;
- putimage(oldx-radius,oldy-radius,ballbuff,XOP_PUT);
- }
- nosound();
- closegraph();
- }