Tags » Computer Graphics

Dinophor

My Friends,

We lived as kings
none as fierce
We unleashed massive power
taking what we needed
Impenetrable as we were
we did not understand… 35 more words

My Art & Writing

Reading #3 for Computer Graphics

1) A skill that a graphic designer needs is to be observant. Noticing the little things in one’s surroundings is super important not only for inspiration, but for working. 163 more words

Computer Graphics

Ellipse trignometric program

#include<iostream.h>
#include<graphic.h>
#include<conio.h>
#include<dos.h>
#include<math.h>
void main()
{
	int gd=DETECT,gm;
	float a,b,x1=0,y,xend,h,k,beg,xend,x;
	initgraph(&gd,&gm," ");
	cout<<"Enter the value of center and axis:"; 	cin>>h>>k>>a>>b;
	xend=90;
	for(x1=0;x1<xend;)
	{
		x=a*cos(x1);
		y=b*sin(x1);
		putpixel(x+h,y+k,10);
		putpixel(-x+h,y+k,10);
		putpixel(-x+h,-y+k,10);
		putpixel(x+h,-y+k,10);
		x1=x1+0.1;
	}
	getch();
}

Computer Graphics

Ellipse polynomial program

#include<iostream.h>
#include<graphic.h>
#include<conio.h>
#include<dos.h>
#include<math.h>
void main()
{
	int gd=DETECT,gm;
	float a,b,x=0,y,xend,h,k,i=0.1;
	initgraph(&gd,&gm," ");
	cout<<"Enter the value of center and axis:"; 	cin>>h>>k>>a>>b;
	xend=a;
	for(x=0;x<=xend;)
	{
		y=b*sqrt(1-(x*x)/(a*a));
		putpixel(x+h,y+k,10);
		putpixel(-x+h,y+k,10);
		putpixel(-x+h,-y+k,10);
		putpixel(x+h,-y+k,10);
	}
	getch();
}

Computer Graphics

DDA line drawing program

#include<iostream.h>
#include<graphic.h>
#include<conio.h>
#include<dos.h>
void main()
{
	int gd=DETECT,gm,i,k=0;
	initgraph(&gd,&gm," ");
 	float xa,xb,ya,yb,x,y,dx,dy,steps,k,xincr,yinncr;
	cout<<"Enter the starting co-ordinates:"; 	cin>>xa>>ya;
	cout<<endl<<"Enter the ending co-ordinates:"; 	cin>>xb>>yb;
	dx=abs(xb-xa);
	dy=abs(yb-ya);
	if(dx>=dy)
	{
		steps=dx;
	}
	else
	{
		steps=dy;
	}
	xincr=dx/steps;
	yincr=dy/steps;
	x=xa;
	y=ya;
	putpixel(x,y,RED);
	for(k=1;k<steps;k++)
	{
		x=xincr+x;
		y=yincr+y;
		putpixel(x,y,k);
		delay(1);
	}
	getch();
}


Computer Graphics

Circle program

#include<iostream.h>
#include<graphic.h>
#include<conio.h>
#include<dos.h>
void main()
{
	int gd=DETECT,gm;
	initgraph(&gd,&gm," ");
	for(int i=0;i<255;i++)
	{
		setcolor(i);
		setlinestyle(0,i,2);
		circle(200,200,i+10);
		outtextxy(140,150,"Circle");
		sleep(1);
	}
	getch();
}
Computer Graphics

Bresenhem line algorithm program

#include<iostream.h>
#include<graphic.h>
#include<conio.h>
#include<dos.h>
void main()
{
	int gd=DETECT,gm,x,y,xa,ya,xb,yb,xend,yend,p,dx,dy;
	initgraph(&gd,&gm," ");
	cout<<"Enter the starting co-ordinates:"; 	cin>>xa>>ya;
	cout<<endl<<"Enter the ending co-ordinates:"; 	cin>>xb>>yb;
	dx=abs(xb-xa);
	dy=abs(yb-ya);
	p=2*dy-dx;
	if(xa>xb)
	{
		x=xb;
		y=yb;
		xend=xa;
		yend=ya;
	}
	else
	{
		x=xa;
		y=ya;
		xend=xb;
		yend=yb;
	}
	putpixel(x,y,WHITE);
	while(x<xend)
	{
		x=x+1;
		if(p<0) 		{ 			p=p+2*dy; 		} 		else 		{ 			y=y+1; 			p=p+2*(dy-dx); 		} 		putpixel(x,y,WHITE); 		delay(1); 	} 	if(xa==xb) 	{ 		if(ya>yb)
		{
			ya=yb;
			yend=ya;
		}
		else
		{
			y=ya;
			yend=yb;
		}
		while(y<yend)
		{
			putpixel(x,y,WHITE);
			y=y+1;
		}
	}
	getch();
}


Computer Graphics