Graphics programming using c
Home
Question Paperz
Java Projectz
ASP Projectz
8086
Data structures
c++
8085
Monday, October 4, 2010
Animation of some real world objects(Wind Mill)
#include<stdio.h> #include<graphics.h> #include<math.h> #define ROUND(a)((int)(a+0.5)) void paraCircle(int,int,int,int,int); void plotellipse(int,int,int,int); void paraCircle(int xc,int yc,int r,int t,int c) { int i,x,y; for(i=0;i<10;i++) { x=xc+ROUND(r*cos(3.1412*(i+t)/180)); y=yc+ROUND(r*sin(3.1412*(i+t)/180)); line(xc,yc,x,y); putpixel(x,y,c); } line(xc,yc,x,y); for(i=120;i<130;i++) { x=xc+ROUND(r*cos(3.1412*(i+t)/180)); y=yc+ROUND(r*sin(3.1412*(i+t)/180)); line(xc,yc,x,y); putpixel(x,y,c); } line(xc,yc,x,y); for(i=240;i<250;i++) { x=xc+ROUND(r*cos(3.1412*(i+t)/180)); y=yc+ROUND(r*sin(3.1412*(i+t)/180)); line(xc,yc,x,y); putpixel(x,y,c); } line(xc,yc,x,y); } void midpointellipse(int xc,int yc,int rx,int ry) { int rx2=rx*rx; int ry2=ry*ry; int tworx2=2*rx2; int twory2=2*ry2; int p,x=0,y=ry,px=0,py=tworx2*y; plotellipse(xc,yc,x,y); p=ROUND(ry2-(rx2*ry)+(0.25*rx2)); while(px<py) { x++; px+=twory2; if(p<0) p+=ry2+px; else { y--; py-=tworx2; p+=ry2+px-py; } plotellipse(xc,yc,x,y); } p=ROUND(ry2*(x+.5)*(x+.5)+rx2*(y-1)*(y-1)-rx2*ry2); while(y>0) { y--; py-=tworx2; if(p>0) p+=rx2-py; else { x++; px+=twory2; p+=rx2-py+px; } plotellipse(xc,yc,x,y); } } void plotellipse(int xc,int yc,int x,int y) { putpixel(xc+x,yc+y,7); putpixel(xc-x,yc+y,7); putpixel(xc+x,yc-y,7); putpixel(xc-x,yc-y,7); } int main() { int theta=0,speed=500; int gd=DETECT,gm=VGAMAX; initgraph(&gd,&gm,"NULL"); midpointellipse(300,350,30,5); line(290,350,300,200); line(310,350,300,200); paraCircle(300,200,50,theta,7); outtextxy(200,30,"Press any key to continue"); getch(); cleardevice(); midpointellipse(300,350,30,5); while(!kbhit()){ setcolor(7); line(290,350,300,200); line(310,350,300,200); paraCircle(300,200,50,theta,7); delay(speed); setcolor(0); paraCircle(300,200,50,theta,0); theta=theta+10; if(speed>=100) speed-=30; } closegraph(); return 0; }
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment