April 8, 2011

Graphics Codes in C ~ part 2


Visit the previous post Graphics Codes in C
Here are some more Graphics Codes in C.. presented by My C Files

Code 1


Code1

/*WWW.mycfiles.com*/
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <graphics.h>
#include<stdlib.h>
void main()
{
int dr,md,midx,i, midy,dx,dy,mx, my,k,x,y,ax[100], ay[100];
int nx[100], ny[100];
double pi,tpi,a,t;
dr = DETECT;

initgraph(&dr, &md, "c:\\tc\\bgi");
midx = getmaxx()/2; midy = getmaxy()/2;
pi = 3.14159;
tpi = pi * 2.0;
k=0;
for (a = 0.0; a<=tpi; a=a+pi/2)
{
x = 550 + 70 * cos(a);
y = 200 + 70 * sin(a);

setcolor(random(getmaxcolor()));
putpixel(x,y,random(getmaxcolor()));
ax[k] = x;
ay[k] = y;
k++;
}



for (a=0.0; a<=tpi; a=a+pi/50)
{
for (i=0; i<k; i++)
{
nx[i]=((ax[i]-midx)*cos(a)) - ((ay[i]-midy)*sin(a)) + midx ;
ny[i]=((ax[i]-midx)*sin(a)) + ((ay[i]-midy)*cos(a)) + midy;
if (i==0)
{
dx = nx[i]; dy = ny[i];
}
else
{
line (nx[i],ny[i], dx,dy);
dx=nx[i]; dy = ny[i];
}
}
getch();

}


getch();
}




Code 2

Code 2
/*www.mycfiles.com*/
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <graphics.h>
#include<stdlib.h>
void main()
{
int dr,md,midx, midy, mx, my,i,j,k,x,y,x1,y1;
double pi,tpi,a,t;
dr = DETECT;


initgraph(&dr, &md, "c:\\tc\\bgi");
midx = getmaxx()/2; midy = getmaxy()/2;
pi = 3.14159;
tpi = pi * 2.0;
t=100;

for (t = 0; t < 40 * 5; t += .1)
{
  x = midx+ (t+t * cos(t));
  y = midy+ (t * sin(t));
  x1 = midx+ (t * cos(t));
  y1 = midy+ (t+t * sin(t));
  putpixel(x,y,random(getmaxcolor()));
  putpixel(x1,y1,random(getmaxcolor()));

  setcolor(random(getmaxcolor()));
  if (t==0.0)
  circle(x,y,50);

  if (kbhit()) break;
}


getch();

}



Code 3

Code 3
/*www.mycfiles.com*/
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <graphics.h>
#include<stdlib.h>
void main()
{
int dr,md,midx,i, midy,dx,dy,mx, my,k,x,y,ax[100], ay[100];
int nx[100], ny[100];
double pi,tpi,a,t;
dr = DETECT;

initgraph(&dr, &md, "c:\\tc\\bgi");
midx = getmaxx()/2; midy = getmaxy()/2;
pi = 3.14159;
tpi = pi * 2.0;
k=0;
for (a = 0.0; a<=tpi; a=a+pi/3)
{
x = midx + 100 * cos(a);
y = midy + 100 * sin(a);
putpixel(x,y,WHITE);
ax[k] = x;
ay[k] = y;
k++;
}

for (a=0.0; a<=tpi; a=a+pi/12)
{
for (i=0; i<k; i++)
{
nx[i]=( (ax[i]-midx)*cos(a)) - ((ay[i]-midy)*sin(a)  ) + midx;
ny[i]=( (ax[i]-midx)*sin(a)) + ((ay[i]-midy)*cos(a) ) + midy;
if (i==0)
{
dx = nx[i]; dy = ny[i];
}
else
{
line (nx[i],ny[i], dx,dy);
dx=nx[i]; dy = ny[i];
}
}
getch();

}

getch();
}



Code 4

Code 4
/*www.mycfiles.com*/
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <graphics.h>
#include<stdlib.h>
#include<dos.h>
void main()
{
int dr,md,midx,i, midy,mx, my,x,y,r,k,kk;
double pi,tpi,a,t;
dr = DETECT;

initgraph(&dr, &md, "c:\\tc\\bgi");
midx = getmaxx()/2; midy = getmaxy()/2;
pi = 3.14159;
tpi = pi * 2.0;
r=50;
for (midy = 100; midy<=400; midy+=100)
{

for (x = 1; x<=600; x++)
{
y = midy + r * sin(x*pi/10);
putpixel(x,y,GREEN);
putpixel(600-x,y,YELLOW);
     // getch();
sleep(0.0001);
}
getch();
}
}


Hope you like the Post, Post your comment and queries below... :)

Related Posts :



Categories:

5 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Related Posts with Thumbnails