<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Graphics | Student Projects</title>
	<atom:link href="https://studentprojects.in/category/software-development/c-tutorials/c/graphics/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Wed, 10 Mar 2010 14:52:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>C graphics program for analog clock</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-graphics-program-for-analog-clock/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-graphics-program-for-analog-clock/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Fri, 02 Oct 2009 12:51:49 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Source Codes]]></category>
		<category><![CDATA[c graphics]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[analog clock]]></category>
		<category><![CDATA[clock in c]]></category>
		<category><![CDATA[digital clock]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=843</guid>

					<description><![CDATA[<p>Time_Dig[0]=hour/10+48;<br />
      Time_Dig[1]=hour%10+48;<br />
      Time_Dig[2]=':';<br />
      Time_Dig[3]=min/10+48;<br />
      Time_Dig[4]=min%10+48;<br />
      Time_Dig[5]=':';<br />
      Time_Dig[6]=sec/10+48;</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-graphics-program-for-analog-clock/">C graphics program for analog clock</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="c">
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>

#define arg_sec M_PI/30
#define arg_hour M_PI/6
#define arg_min M_PI/360
void main()
{
  int gd=DETECT,gm,sec=0,hour,min,x1=0,y1=0,x2=0,y2=0,x3=0,y3=0;
  char *k[12]={"1","2","3","4","5","6","7","8","9","10","11","12"};
  struct time t;
  initgraph(&gd,&gm,"");
  setcolor(YELLOW);
  circle(300,200,200);
  circle(300,200,180);
  setfillstyle(1,RED);
  floodfill(300,390,YELLOW);
  settextstyle(DEFAULT_FONT,0,2);
//----------------------Constants----------------------//

  int a,b;
  for(int i=1;i<13;i++)
    {
	a=160*cos(arg_hour*i-M_PI_2);
	b=160*sin(arg_hour*i-M_PI_2);
	outtextxy(a+300,b+200,k[i-1]);
    }

//----------------------Constants----------------------//
/*****************************************************
		 1-Good
		 2-Small
		 3-Watse
		 4-caligraphy
		 5-cursive
		 6-good
		 7-excellent
		 8-Good
		 9-Big
		 10-Double
 ****************************************************/
 int dig_sec;
 char Time_Dig[14];
  while(!kbhit())
   {
       settextstyle(7,0,4);
      outtextxy(264,100,"Satya");
      settextstyle(7,0,1);
      outtextxy(278,280,"Quartz");
      setcolor(BLACK);
      line(300,200,x1+300,y1+200);
      line(300,200,x2+300,y2+200);
      line(300,200,x3+300,y3+200);
      gettime(&#038;t);
      if(sec!=t.ti_sec)
	{
	   sound(5000);
	   delay(1);
	   nosound();
	}
      hour=t.ti_hour;
      sec=t.ti_sec;
      min=t.ti_min;
      Time_Dig[0]=hour/10+48;
      Time_Dig[1]=hour%10+48;
      Time_Dig[2]=':';
      Time_Dig[3]=min/10+48;
      Time_Dig[4]=min%10+48;
      Time_Dig[5]=':';
      Time_Dig[6]=sec/10+48;
      Time_Dig[7]=sec%10+48;
      Time_Dig[8]='\0';
      outtextxy(270,250,"ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ");
      x1=150*cos(arg_sec*sec-M_PI_2)*0.98;
      y1=150*sin(arg_sec*sec-M_PI_2)*0.98;
      x2=150*cos(arg_sec*min-M_PI_2)*0.9;
      y2=150*sin(arg_sec*min-M_PI_2)*0.9;
      if(hour>12) hour-=12;
      x3=150*cos(arg_hour*hour-M_PI_2+arg_min*min)*0.6;
      y3=150*sin(arg_hour*hour-M_PI_2+arg_min*min)*0.6;
      setcolor(YELLOW);
      line(300,200,x1+300,y1+200);
      setcolor(CYAN);
      line(300,200,x2+300,y2+200);
      setcolor(WHITE);
      line(300,200,x3+300,y3+200);
      setcolor(YELLOW);
      outtextxy(270,250,Time_Dig);
      delay(50);

   }

  getch();
  closegraph();
  restorecrtmode();
}
</pre>
<p><a href="https://studentprojects.in/wp-content/uploads/2009/10/Clock.zip"><br />
Click here</a> to download the source code.</p><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-graphics-program-for-analog-clock/">C graphics program for analog clock</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-graphics-program-for-analog-clock/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>C Program to fill any given polygon using scan-line area filling algorithm</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-fill-any-given-polygon-using-scan-line-area-filling-algorithm/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-fill-any-given-polygon-using-scan-line-area-filling-algorithm/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Fri, 02 Oct 2009 10:34:38 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[c graphics]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[dos]]></category>
		<category><![CDATA[Data structure]]></category>
		<category><![CDATA[polygon]]></category>
		<category><![CDATA[filling algorithm]]></category>
		<category><![CDATA[filcolor]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=841</guid>

					<description><![CDATA[<p>setcolor (WHITE);<br />
    line (pt[0][0], pt[0][1], pt[1][0], pt[1][1]);<br />
    line (pt[1][0], pt[1][1], pt[2][0], pt[2][1]);<br />
    line (pt[2][0], pt[2][1], pt[0][0], pt[0][1]);<br />
    getch();</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-fill-any-given-polygon-using-scan-line-area-filling-algorithm/">C Program to fill any given polygon using scan-line area filling algorithm</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="c" escaped="true" line="1">
#include <graphics.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

struct Node
{
    int x;
    int y;
    struct Node* next;
};

void fill (int pt[][2], int clr);
void floodfill4 (int x, int y, int oldclr, int newclr);
void insert (int x, int y, struct Node** last);

void main()
{
    int i, j;
    int pt[3][2];
    int clr;

    printf ("This program demonstrates filling a polygon.\n");
    printf ("Enter the x- and y-coordinates for three points:\n");
    for (i=0; i<3; i++)
	for (j=0; j<2; j++)
	    scanf ("%d", &#038;pt[i][j]);

    printf ("Enter the fill-colour: (Any number from 1 to 14) ");
    scanf ("%d", &#038;clr);
    fill (pt, clr);
}

void fill (int pt[][2], int clr)
{
    int gd = DETECT, gm;
    int seedx, seedy;

    initgraph (&#038;gd, &#038;gm, "..\\bgi");

    setcolor (WHITE);
    line (pt[0][0], pt[0][1], pt[1][0], pt[1][1]);
    line (pt[1][0], pt[1][1], pt[2][0], pt[2][1]);
    line (pt[2][0], pt[2][1], pt[0][0], pt[0][1]);
    getch();

    seedx = (pt[0][0] + pt[1][0] + pt[2][0]) / 3;
    seedy = (pt[0][1] + pt[1][1] + pt[2][1]) / 3;

    floodfill4 (seedx, seedy, BLACK, clr);
    getch();

    closegraph();
    return;
}

void floodfill4 (int x, int y, int oldclr, int newclr)
{
    struct Node* first, *last, *tmp;

    first = (struct Node*) malloc (sizeof (struct Node));
    if (first == NULL)
    {
	closegraph();
	fprintf (stderr, "floodfill4: Out of memory.\n");
	exit (2);
    }
    if (oldclr == newclr)
    {
	free (first);
	return;
    }
   
    first->x = x;
    first->y = y;
    first->next = NULL;
    last = first;

    while (first != NULL)
    {
	putpixel (x, y, newclr);
	
	if (getpixel (x, y-1) == oldclr)
	{
	    putpixel (x, y-1, newclr);
	    insert (x, y-1, &last);
	}
	

	if (getpixel (x, y+1) == oldclr)
	{
	    putpixel (x, y+1, newclr);
	    insert (x, y+1, &last);
	}
	
	if (getpixel (x-1, y) == oldclr)
	{
	    putpixel (x-1, y, newclr);
	    insert (x-1, y, &last);
	}
	
	if (getpixel (x+1, y) == oldclr)
	{
	    putpixel (x+1, y, newclr);
	    insert (x+1, y, &last);
	}
	
	tmp = first;
	first = first->next;
	x = first->x;
	y = first->y;
	free (tmp);
    }
}

void insert (int x, int y, struct Node** last)
{
    struct Node* p;
    p = (struct Node*) malloc (sizeof (struct Node));
    if (p == NULL)
    {
	closegraph();
	fprintf (stderr, "\n insert: Out of memory.\n");
	exit (2);
    }
    
    p->x = x;
    p->y = y;
    p->next = NULL;
    (*last)->next = p;
    *last = (*last)->next;
}
</pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-fill-any-given-polygon-using-scan-line-area-filling-algorithm/">C Program to fill any given polygon using scan-line area filling algorithm</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-fill-any-given-polygon-using-scan-line-area-filling-algorithm/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>C Program to implement 3-D rotation with respect to x-axis, y-axis and z-axis</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-3-d-rotation-with-respect-to-x-axis-y-axis-and-z-axis/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-3-d-rotation-with-respect-to-x-axis-y-axis-and-z-axis/#respond</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Fri, 02 Oct 2009 10:32:20 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[c graphics]]></category>
		<category><![CDATA[3-d rotation in c]]></category>
		<category><![CDATA[3d rotaion graphics]]></category>
		<category><![CDATA[model of a cube]]></category>
		<category><![CDATA[codes]]></category>
		<category><![CDATA[free]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=839</guid>

					<description><![CDATA[<p>C Program to implement 3-D rotation with respect to x-axis, y-axis and z-axis (wire frame model of a cube). Use appropriate data structures to manipulate the wire frame model.</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-3-d-rotation-with-respect-to-x-axis-y-axis-and-z-axis/">C Program to implement 3-D rotation with respect to x-axis, y-axis and z-axis</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>C Program to implement 3-D rotation with respect to x-axis, y-axis and z-axis (wire frame model of a cube). Use appropriate data structures to manipulate the wire frame model.</p>
<pre lang="c" escaped="true" line="1">
#include <stdio.h>
#include <graphics.h>
#include <math.h>
#include <stdlib.h>
#include <dos.h>
#include <conio.h>

#define ORG -50

double face1[5][2] = {
			    { 250, 125 },
			    { 350, 125 },
			    { 350, 225 },
			    { 250, 225 },
			    { 250, 125 }
		           };

double face2[5][2] = {
			    { 250+ORG, 125-ORG },
			    { 350+ORG, 125-ORG },
			    { 350+ORG, 225-ORG },
			    { 250+ORG, 225-ORG },
			    { 250+ORG, 125-ORG }
		           };

double angle = 5.0 * M_PI / 180;
double midx1, midy1, midx2, midy2;

void rotate (void)
{
    int i;
    for (i=0; i<5; i++)
    {
	double xnew, ynew;

	xnew = midx1 + (face1[i][0] - midx1) * cos (angle) -
	       (face1[i][1] - midy1) * sin (angle);
	ynew = midy1 + (face1[i][0] - midx1) * sin (angle) +
		(face1[i][1] - midy1) * cos (angle);

	face1[i][0] = xnew;
	face1[i][1] = ynew;

	xnew = midx2 + (face2[i][0] - midx2) * cos (angle) -
		(face2[i][1] - midy2) * sin (angle);
	ynew = midy2 + (face2[i][0] - midx2) * sin (angle) +
		(face2[i][1] - midy2) * cos (angle);

	face2[i][0] = xnew;
	face2[i][1] = ynew;
    }

    cleardevice();

    for (i=0; i<4; i++)
    {
	setcolor(7);
	line (face1[i][0], face1[i][1], face1[i+1][0], face1[i+1][1]);
	setcolor(8);
	line (face2[i][0], face2[i][1], face2[i+1][0], face2[i+1][1]);
	setcolor(9);
	line (face1[i][0], face1[i][1], face2[i][0], face2[i][1]);
    }

    delay (125);
}

void main()
{
    int gd = DETECT, gm;

    midx1 = (face1[0][0] + face1[1][0]) / 2.0;
    midy1 = (face1[1][1] + face1[2][1]) / 2.0;
    midx2 = (face2[0][0] + face2[1][0]) / 2.0;
    midy2 = (face2[1][1] + face2[2][1]) / 2.0;

    initgraph (&#038;gd, &#038;gm, "..\\bgi");

    while (!kbhit())
	rotate();

    closegraph();
}
</pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-3-d-rotation-with-respect-to-x-axis-y-axis-and-z-axis/">C Program to implement 3-D rotation with respect to x-axis, y-axis and z-axis</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-3-d-rotation-with-respect-to-x-axis-y-axis-and-z-axis/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>C Program to implement Bezier curves for a given set of control points.</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-bezier-curves-for-a-given-set-of-control-points/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-bezier-curves-for-a-given-set-of-control-points/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Fri, 02 Oct 2009 10:26:58 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[bgi]]></category>
		<category><![CDATA[Bezier curves]]></category>
		<category><![CDATA[control points]]></category>
		<category><![CDATA[dos]]></category>
		<category><![CDATA[c graphics]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=835</guid>

					<description><![CDATA[<p>double xt = pow (1-t, 3) * x[0] + 3 * t * pow (1-t, 2) * x[1] +<br />
    3 * pow (t, 2) * (1-t) * x[2] + pow (t, 3) * x[3];</p>
<p>double yt = pow (1-t, 3) * y[0] + 3 * t * pow (1-t, 2) * y[1] +<br />
    3 * pow (t, 2) * (1-t) * y[2] + pow (t, 3) * y[3];</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-bezier-curves-for-a-given-set-of-control-points/">C Program to implement Bezier curves for a given set of control points.</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="c" escaped="true" line="1">
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <math.h>

void bezier (int x[4], int y[4])
{
    int gd = DETECT, gm;
    int i;
    double t;

    initgraph (&gd, &gm, "..\\bgi");

    for (t = 0.0; t < 1.0; t += 0.0005)
    {
	double xt = pow (1-t, 3) * x[0] + 3 * t * pow (1-t, 2) * x[1] +
		    3 * pow (t, 2) * (1-t) * x[2] + pow (t, 3) * x[3];

	double yt = pow (1-t, 3) * y[0] + 3 * t * pow (1-t, 2) * y[1] +
		    3 * pow (t, 2) * (1-t) * y[2] + pow (t, 3) * y[3];

	putpixel (xt, yt, WHITE);
    }

    for (i=0; i<4; i++)
	putpixel (x[i], y[i], YELLOW);

    getch();
    closegraph();
    return;
}

void main()
{
    int x[4], y[4];
    int i;

    printf ("Enter the x- and y-coordinates of the four control points.\n");
    for (i=0; i<4; i++)
	scanf ("%d%d", &#038;x[i], &#038;y[i]);

    bezier (x, y);
}
</pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-bezier-curves-for-a-given-set-of-control-points/">C Program to implement Bezier curves for a given set of control points.</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-bezier-curves-for-a-given-set-of-control-points/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>C Program to implement Hermite curves for a given set of control points.</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-hermite-curves-for-a-given-set-of-control-points/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-hermite-curves-for-a-given-set-of-control-points/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Fri, 02 Oct 2009 10:26:54 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[c program]]></category>
		<category><![CDATA[Hermite curves]]></category>
		<category><![CDATA[Hermite curves in c]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=836</guid>

					<description><![CDATA[<p>point p1,p2;<br />
	printf("Enter 2 hermite points:\n");<br />
	scanf("%d%d%d%d",&#038;p1.x,&#038;p1.y,&#038;p2.x,&#038;p2.y);<br />
	printf("Enter the tangents at p1,p4");<br />
	scanf("%d%d",&#038;r1,&#038;r4);<br />
	cleardevice();</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-hermite-curves-for-a-given-set-of-control-points/">C Program to implement Hermite curves for a given set of control points.</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="c" escaped="true" line="1">
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<stdio.h>

struct point
{
int x,y;
};

void hermite(point p1,point p4,double r1,double r4)
{
	float x,y,t;
	for(t=0.0;t<=1.0;t+=.001)
	{
		x=(2*t*t*t-3*t*t+1)*p1.x+(-2*t*t*t+3*t*t)*p4.x+(t*t*t-2*t*t+t)*r1+(t*t*t-t*t)*r4;
		y=(2*t*t*t-3*t*t+1)*p1.y+(-2*t*t*t+3*t*t)*p4.y+(t*t*t-2*t*t+1)*r1+(t*t*t-t*t)*r4;
		putpixel(x,y,YELLOW);
	 }
}

int main()
{
	int gd=DETECT,gm;
	double r1,r4;
	initgraph(&#038;gd,&#038;gm,"..//BGI");
	point p1,p2;
	printf("Enter 2 hermite points:\n");
	scanf("%d%d%d%d",&#038;p1.x,&#038;p1.y,&#038;p2.x,&#038;p2.y);
	printf("Enter the tangents at p1,p4");
	scanf("%d%d",&#038;r1,&#038;r4);
	cleardevice();
	hermite(p1,p2,r1,r4);
	putpixel(x1,y1,WHITE);
	putpixel(x2,y2,WHITE);
	getch();
	closegraph();
	return 0;
}
</pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-hermite-curves-for-a-given-set-of-control-points/">C Program to implement Hermite curves for a given set of control points.</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-hermite-curves-for-a-given-set-of-control-points/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>C Program to implement the Cohen-Sutherland line-clipping algorithm.</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-the-cohen-sutherland-line-clipping-algorithm/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-the-cohen-sutherland-line-clipping-algorithm/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Fri, 02 Oct 2009 10:19:36 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[line clipping]]></category>
		<category><![CDATA[clipping]]></category>
		<category><![CDATA[c graphics]]></category>
		<category><![CDATA[line functions]]></category>
		<category><![CDATA[rectangle functions]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=832</guid>

					<description><![CDATA[<p>C Program to implement the Cohen-Sutherland line-clipping algorithm. Make provision to specify the input line, window for clipping and view port for displaying the clipped image.  (Use built-in line and rectangle functions).</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-the-cohen-sutherland-line-clipping-algorithm/">C Program to implement the Cohen-Sutherland line-clipping algorithm.</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>C Program to implement the Cohen-Sutherland line-clipping algorithm. Make provision to specify the input line, window for clipping and view port for displaying the clipped image.  (Use built-in line and rectangle functions).</p>
<pre lang="c" escaped="true" line="1">
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#define MAX 20

enum { TOP = 0x1, BOTTOM = 0x2, RIGHT = 0x4, LEFT = 0x8 };

enum { FALSE, TRUE };
typedef unsigned int outcode;

outcode compute_outcode(int x, int y,
		int xmin, int ymin, int xmax, int ymax)
{
    outcode oc = 0;

    if (y > ymax)
	oc |= TOP;
    else if (y < ymin)
	oc |= BOTTOM;


    if (x > xmax)
	oc |= RIGHT;
    else if (x < xmin)
	oc |= LEFT;

    return oc;
}

void cohen_sutherland (double x1, double y1, double x2, double y2,
		double xmin, double ymin, double xmax, double ymax)
{
    int accept;
    int done;
    outcode outcode1, outcode2;

    accept = FALSE;
    done = FALSE;

    outcode1 = compute_outcode (x1, y1, xmin, ymin, xmax, ymax);
    outcode2 = compute_outcode (x2, y2, xmin, ymin, xmax, ymax);
    do
    {
	if (outcode1 == 0 &#038;&#038; outcode2 == 0)
	{
	    accept = TRUE;
	    done = TRUE;
	}
	else if (outcode1 &#038; outcode2)
	{
	    done = TRUE;
	}
	else
	{
	    double x, y;
	    int outcode_ex = outcode1 ? outcode1 : outcode2;
	    if (outcode_ex &#038; TOP)
	    {
		x = x1 + (x2 - x1) * (ymax - y1) / (y2 - y1);
		y = ymax;
	    }

	    else if (outcode_ex &#038; BOTTOM)
	    {
		x = x1 + (x2 - x1) * (ymin - y1) / (y2 - y1);
		y = ymin;
	    }
	    else if (outcode_ex &#038; RIGHT)
	    {
		y = y1 + (y2 - y1) * (xmax - x1) / (x2 - x1);
		x = xmax;
	    }
	    else
	    {
		y = y1 + (y2 - y1) * (xmin - x1) / (x2 - x1);
		x = xmin;
	    }
	    if (outcode_ex == outcode1)
	    {
		x1 = x;
		y1 = y;
		outcode1 = compute_outcode (x1, y1, xmin, ymin, xmax, ymax);
	    }
	    else
	    {
		x2 = x;
		y2 = y;
		outcode2 = compute_outcode (x2, y2, xmin, ymin, xmax, ymax);
	    }
	}
    } while (done == FALSE);

    if (accept == TRUE)
	line (x1, y1, x2, y2);
}



void main()
{
    int n;
    int i, j;
    int ln[MAX][4];
    int clip[4];
    int gd = DETECT, gm;

    printf ("Enter the number of lines to be clipped");
    scanf ("%d", &#038;n);

    printf ("Enter the x- and y-coordinates of the line-endpoints:\n");
    for (i=0; i<n; i++)
	for (j=0; j<4; j++)
	    scanf ("%d", &#038;ln[i][j]);

    printf ("Enter the x- and y-coordinates of the left-top and right-");
    printf ("bottom corners\nof the clip window:\n");
    for (i=0; i<4; i++)
	scanf ("%d", &#038;clip[i]);

    initgraph (&#038;gd, &#038;gm, "..//bgi");

    rectangle (clip[0], clip[1], clip[2], clip[3]);
    for (i=0; i<n; i++)
	line (ln[i][0], ln[i][1], ln[i][2], ln[i][3]);
    getch();
    cleardevice();
    rectangle (clip[0], clip[1], clip[2], clip[3]);
    for (i=0; i<n; i++)
    {
	cohen_sutherland (ln[i][0], ln[i][1], ln[i][2], ln[i][3],
	    clip[0], clip[1], clip[2], clip[3]);
	getch();
    }
    closegraph();
}
</pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-the-cohen-sutherland-line-clipping-algorithm/">C Program to implement the Cohen-Sutherland line-clipping algorithm.</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-the-cohen-sutherland-line-clipping-algorithm/feed/</wfw:commentRss>
			<slash:comments>18</slash:comments>
		
		
			</item>
		<item>
		<title>C Program to create a house and perform the operations.</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-create-a-house-and-perform-the-operations/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-create-a-house-and-perform-the-operations/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Fri, 02 Oct 2009 10:14:18 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[create a house]]></category>
		<category><![CDATA[scaling]]></category>
		<category><![CDATA[reflect]]></category>
		<category><![CDATA[y = mx+c]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=830</guid>

					<description><![CDATA[<p>C Program to create a house like figure and perform the following operations.<br />
	a. Scaling about the origin followed by translation.<br />
        b. Scaling with reference to an arbitrary point.<br />
        c. Reflect about the line y = mx + c.</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-create-a-house-and-perform-the-operations/">C Program to create a house and perform the operations.</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>C Program to create a house like figure and perform the following operations.<br />
	a. Scaling about the origin followed by translation.<br />
        b. Scaling with reference to an arbitrary point.<br />
        c. Reflect about the line y = mx + c.</p>
<pre lang="c" escaped="true" line="1">
#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>

void reset (int h[][2])
{
    int val[9][2] = {
			{ 50, 50 },{ 75, 50 },{ 75, 75 },{ 100, 75 },
			{ 100, 50 },{ 125, 50 },{ 125, 100 },{ 87, 125 },{ 50, 100 }
		    };
    int i;
    for (i=0; i<9; i++)
    {
	h[i][0] = val[i][0]-50;
	h[i][1] = val[i][1]-50;
    }
}
void draw (int h[][2])
{
    int i;
    setlinestyle (DOTTED_LINE, 0, 1);
    line (320, 0, 320, 480);
    line (0, 240, 640, 240);
    setlinestyle (SOLID_LINE, 0, 1);
    for (i=0; i<8; i++)
	line (320+h[i][0], 240-h[i][1], 320+h[i+1][0], 240-h[i+1][1]);
    line (320+h[0][0], 240-h[0][1], 320+h[8][0], 240-h[8][1]);
}
void rotate (int h[][2], float angle)
{
    int i;
    for (i=0; i<9; i++)
    {
	int xnew, ynew;
	xnew = h[i][0] * cos (angle) - h[i][1] * sin (angle);
	ynew = h[i][0] * sin (angle) + h[i][1] * cos (angle);
	h[i][0] = xnew; h[i][1] = ynew;
    }
}
void scale (int h[][2], int sx, int sy)
{
    int i;
    for (i=0; i<9; i++)
    {
	h[i][0] *= sx;
	h[i][1] *= sy;
    }
}
void translate (int h[][2], int dx, int dy)
{
    int i;
    for (i=0; i<9; i++)
    {
	h[i][0] += dx;
	h[i][1] += dy;
    }
}
void reflect (int h[][2], int m, int c)
{
	int i;
	float angle;
	for (i=0; i<9; i++)
		h[i][1] -= c;
	angle = M_PI/2 - atan (m);
	rotate (h, angle);
	for (i=0; i<9; i++)
		h[i][0] = -h[i][0];
	angle = -angle;
	rotate (h, angle);
	for (i=0; i<9; i++)
		h[i][1] += c;
}

void ini()
{
	int gd=DETECT,gm;
	initgraph(&#038;gd,&#038;gm,"..\\bgi");
}
void dini()
{
	getch();
	closegraph();
}
void main()
{

	int h[9][2],sx,sy,x,y,m,c,choice;
	do
	{
		clrscr();
		printf("1. Scaling about the origin.\n");
		printf("2. Scaling about an arbitrary point.\n");
		printf("3. Reflection about the line y = mx + c.\n");
		printf("4. Exit\n");
		printf("Enter the choice: ");
		scanf("%d",&#038;choice);
		switch(choice)
		{
			case 1: printf ("Enter the x- and y-scaling factors: ");
				scanf ("%d%d", &#038;sx, &#038;sy);
				ini();
				reset (h);
				draw (h);getch();
				scale (h, sx, sy);
				cleardevice();
				draw (h);
				dini();
				break;

			case 2: printf ("Enter the x- and y-scaling factors: ");
				scanf ("%d%d", &#038;sx, &#038;sy);
				printf ("Enter the x- and y-coordinates of the point: ");
				scanf ("%d%d", &#038;x, &#038;y);
				ini();
				reset (h);
				translate (h, x, y);// Go to arbitrary point
				draw(h); getch();//Show its arbitrary position
				cleardevice();
				translate(h,-x,-y);//Take it back to origin
				draw(h);
				getch();
				cleardevice();
				scale (h, sx, sy);//Now Scale it
				draw(h);
				getch();
				translate (h, x, y);//Back to Arbitrary point
				cleardevice();
				draw (h);
				putpixel (320+x, 240-y, WHITE);
				dini();
				break;

			case 3: printf ("Enter the values of m and c: ");
				scanf ("%d%d", &#038;m, &#038;c);
				ini();
				reset (h);
				draw (h); getch();
				reflect (h, m, c);
				cleardevice();
				draw (h);
				dini();
				break;
			
			case 4: exit(0);
		}
	}while(choice!=4);
}
</pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-create-a-house-and-perform-the-operations/">C Program to create a house and perform the operations.</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-create-a-house-and-perform-the-operations/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>C Program to draw a rectangle and perform the operations.</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-draw-a-rectangle-and-perform-the-operations/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-draw-a-rectangle-and-perform-the-operations/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Fri, 02 Oct 2009 10:11:58 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[c graphics]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[draw rectangle]]></category>
		<category><![CDATA[Rotation of rectangle]]></category>
		<category><![CDATA[shear]]></category>
		<category><![CDATA[arbitory point]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=828</guid>

					<description><![CDATA[<p>C Program to draw a rectangle and perform the following operations.<br />
	a. Rotation about the origin followed by translation.<br />
	b. Rotation about an arbitrary point.<br />
	c. Apply X shear and Y shear on the rectangle.</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-draw-a-rectangle-and-perform-the-operations/">C Program to draw a rectangle and perform the operations.</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>C Program to draw a rectangle and perform the following operations.<br />
	a. Rotation about the origin followed by translation.<br />
	b. Rotation about an arbitrary point.<br />
	c. Apply X shear and Y shear on the rectangle.</p>
<pre lang="c" escaped="true" line="1">
#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <math.h>

void draw (int r[][2])
{
    int i;
    setlinestyle (DOTTED_LINE, 0, 1);
    line (320, 0, 320, 480);
    line (0, 240, 640, 240);

    setlinestyle (SOLID_LINE, 0, 1);
    line (320+r[0][0], 240-r[0][1], 320+r[1][0], 240-r[1][1]);
    line (320+r[0][0], 240-r[0][1], 320+r[3][0], 240-r[3][1]);
    line (320+r[1][0], 240-r[1][1], 320+r[2][0], 240-r[2][1]);
    line (320+r[2][0], 240-r[2][1], 320+r[3][0], 240-r[3][1]);
}

void reset (int r[][2])
{
    int i;
    int val[4][2] = {
			{ 0, 0 },{ 100, 0 },{ 100, 50 },{ 0, 50 }
		    };
	for (i=0; i<4; i++)
    {
	r[i][0] = val[i][0];
	r[i][1] = val[i][1];
    }
}

void rotate (int r[][2], int angle)
{
    int i;
    double ang_rad = (angle * M_PI) / 180;
    for (i=0; i<4; i++)
    {
	double xnew, ynew;
	xnew = r[i][0] * cos (ang_rad) - r[i][1] * sin (ang_rad);
	ynew = r[i][0] * sin (ang_rad) + r[i][1] * cos (ang_rad);
	r[i][0] = xnew;
	r[i][1] = ynew;
    }
}

void shear (int r[][2], int sx, int sy)
{
    int i;
    for (i=0; i<4; i++)
    {
	int xnew, ynew;
	xnew = r[i][0] + r[i][1] * sx;
	ynew = r[i][1] + r[i][0] * sy;
	r[i][0] = xnew;
	r[i][1] = ynew;
    }
}

void translate (int r[][2], int dx, int dy)
{
    int i;
    for (i=0; i<4; i++)
    {
	r[i][0] += dx;
	r[i][1] += dy;
    }
}

void ini()
{
	int gd=DETECT,gm;
	initgraph(&#038;gd,&#038;gm,"..//bgi");
}
void main()
{

	int r[4][2],angle,dx,dy,x, y,choice;

	do
	{
		clrscr();
		printf("1.Rotation about the origin followed by translation\n");
		printf("2.Rotation about an arbitrary point\n");
		printf("3.Shear about the origin\n");
		printf("4.Exit\n\n");
		printf("Enter your choice: ");
		scanf("%d",&#038;choice);
		switch(choice)
		{
			case 1: printf("Enter the rotation angle: ");
				scanf("%d", &#038;angle);
				printf("Enter the x- and y-coordinates for translation: ");
				scanf("%d%d",&#038;dx,&#038;dy);
				ini();
				cleardevice();
				reset(r);
				draw(r);getch();
				rotate(r, angle);
				cleardevice();
				draw(r);getch();
				translate(r,dx,dy);
				cleardevice();
				draw(r);getch();
				closegraph();
				break;
			case 2: printf("Enter the rotation angle: ");
				scanf("%d",&#038;angle);
				printf("Enter the x- and y-coordinates of the point: ");
				scanf("%d%d",&#038;x,&#038;y);
				ini();
				cleardevice();
				reset(r);
				translate(r,x,y);
				draw(r);
				putpixel(320+x,240-y,WHITE);
				getch();
				translate(r,-x,-y);
				draw(r);getch();
				rotate(r,angle);
				draw(r);getch();
				translate(r,x,y);
				cleardevice();
				draw(r);
				putpixel(320+x,240-y,WHITE);
				getch();
				closegraph();
				break;
			case 3: printf("Enter the x- and y-shears: ");
				scanf("%d%d",&#038;x,&#038;y);
				ini();
				reset(r);
				draw(r);getch();
				shear(r, x, y);
				cleardevice();
				draw (r);getch();
				closegraph();
				break;
			case 4: closegraph();
		}
	}while(choice!=4);
}
</pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-draw-a-rectangle-and-perform-the-operations/">C Program to draw a rectangle and perform the operations.</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-draw-a-rectangle-and-perform-the-operations/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>C Program to implement the midpoint circle drawing algorithm</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-the-midpoint-circle-drawing-algorithm/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-the-midpoint-circle-drawing-algorithm/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Fri, 02 Oct 2009 10:09:47 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[c program]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[midpoint circle]]></category>
		<category><![CDATA[circle drawing]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=825</guid>

					<description><![CDATA[<p>C Program to implement the midpoint circle drawing algorithm to draw a circle. Modify the algorithm toimplement specified arc or sector.</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-the-midpoint-circle-drawing-algorithm/">C Program to implement the midpoint circle drawing algorithm</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>C Program to implement the midpoint circle drawing algorithm to draw a circle. Modify the algorithm toimplement specified arc or sector.</p>
<pre lang="c" escaped="true" line="1">
#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <stdio.h>

#define PI 3.14

float startangle,endangle;
int x,y;

int Can_draw( float theta )
{
	if( theta >= startangle && theta<= endangle )
		return 1;
	return 0;
}

void Circlepoints(int x,int y,int xc,int yc)
{
	float theta;
	theta = atan( (float)y/x );
	theta = theta * (180/M_PI);
	
if( Can_draw(theta))
		putpixel(xc+x,yc-y,WHITE);
	if( Can_draw(360-theta))
		putpixel(xc+x,yc+y,WHITE);
	
if( Can_draw(90-theta))
		putpixel(xc+y,yc-x,WHITE);
	if( Can_draw(270+theta))
		putpixel(xc+y,yc+x,WHITE);
	
if( Can_draw(180-theta))
		putpixel(xc-x,yc-y,WHITE);
	if( Can_draw(180+theta))
		putpixel(xc-x,yc+y,WHITE);
	
if( Can_draw(90+theta))
		putpixel(xc-y,yc-x,WHITE);
	if( Can_draw(270-theta))
		putpixel(xc-y,yc+x,WHITE);
}

void MidPointcircle(int xc,int yc,int rad)
{
	float d = (5/4.0) - rad;
	x=0,y=rad;

	while(y>x)
	{
		if(d<0) 
 			d += 2*x+3;
		else 	
			d+=(2*x)-(2*y)+5,y--;
		x++;
		Circlepoints(x,y,xc,yc);
		delay(90);
	}
}
void main()
{
	int gd=DETECT,gm;
	int radius,xc,yc,choice,temp;
	float xstart,ystart,xend,yend;
	initgraph(&#038;gd,&#038;gm,"..\\bgi");
	do
	{
		clrscr();
		cleardevice();
		printf("\n Enter your choice\n");
		printf("\n 1.Draw a Circle\n 2.Draw a Sector\n 3.Draw an Arc\n 4.Exit\n");
		scanf("%d",&#038;choice);
		switch(choice)
		{
			case 1: printf("\n Enter the center:");
				scanf("%d %d",&#038;xc,&#038;yc);
				printf("\n Enter the radius:");
				scanf("%d",&#038;radius);
				cleardevice();
				startangle=0,endangle=360;
				MidPointcircle(xc,yc,radius);
				getch();
				break;

			case 2: printf("\n Enter the center:");
				scanf("%d %d",&#038;xc,&#038;yc);
				printf("\n Enter the radius:");
				scanf("%d",&#038;radius);
				printf("\n Enter the startangle:");
				scanf("%f",&#038;startangle);
				printf("\n Enter the endangle:");
				scanf("%f",&#038;endangle);
				cleardevice();
				if(startangle>endangle)
				{
					temp=startangle;
					startangle=endangle;
					endangle=temp;
				}
				MidPointcircle(xc,yc,radius);
				xstart=xc+radius*cos(PI/180*startangle);
				ystart=yc-radius*sin(PI/180*startangle);
				xend=xc+radius*cos(PI/180*endangle);
				yend=yc-radius*sin(PI/180*endangle);
				line(xc,yc,xstart,ystart);
				line(xc,yc,xend,yend);
				getch();
				break;

			case 3: printf("\n Enter the center:");
				scanf("%d %d",&xc,&yc);
				printf("\n Enter the radius:");
				scanf("%d",&radius);
				printf("\n Enter the startangle:");
				scanf("%f",&startangle);
				printf("\n Enter the endangle:");
				scanf("%f",&endangle);
				cleardevice();
				if(startangle>endangle)
				{
					temp=startangle;
					startangle=endangle;
					endangle=temp;
				}
				MidPointcircle(xc,yc,radius);
				getch();
				break;

		       case 4:  closegraph();
		}
	}while(choice!=4);
}
</pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-the-midpoint-circle-drawing-algorithm/">C Program to implement the midpoint circle drawing algorithm</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-implement-the-midpoint-circle-drawing-algorithm/feed/</wfw:commentRss>
			<slash:comments>12</slash:comments>
		
		
			</item>
		<item>
		<title>C Program to display a line graph using midpoint line algorithm.</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-display-a-line-graph-using-midpoint-line-algorithm/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-display-a-line-graph-using-midpoint-line-algorithm/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Fri, 02 Oct 2009 10:07:21 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[c graphics]]></category>
		<category><![CDATA[Software Programs]]></category>
		<category><![CDATA[line graph]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=823</guid>

					<description><![CDATA[<p>Program to display a line graph using midpoint line algorithm. The input to the program is a set of data corresponding to the X and Y-axes. Data parts are to be displayed as asterisk (*) according to the input specification.</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-display-a-line-graph-using-midpoint-line-algorithm/">C Program to display a line graph using midpoint line algorithm.</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Program to display a line graph using midpoint line algorithm. The input to the program is a set of data corresponding to the X and Y-axes. Data parts are to be displayed as asterisk (*) according to the input specification.</p>
<pre lang="c" escaped="true" line="1">
#include<stdio.h>
#include<graphics.h>
#include<stdlib.h>
#include<conio.h>

#define MAX 20

void swap(int* a,int* b)
{
	int t=*a;
	*a=*b;
	*b=t;
}

void midpointline(int x1,int y1,int x2,int y2)
{
	int dx,dy,d,incry,incre,incrne,slopegt1=0;
	dx=abs(x1-x2);dy=abs(y1-y2);
	if(dy>dx)
	{
		swap(&x1,&y1);
		swap(&x2,&y2);
		swap(&dx,&dy);
		slopegt1=1;
	}
	if(x1>x2)
	{
		swap(&x1,&x2);
		swap(&y1,&y2);
	}
	if(y1>y2)
		incry=-1;
	else
		incry=1;
	d=2*dy-dx;
	incre=2*dy;
	incrne=2*(dy-dx);
	while(x1<x2)
	{
		if(d<=0)
			d+=incre;
		else
		{
			d+=incrne;
			y1+=incry;
		}
		x1++;
		if(slopegt1)
			putpixel(y1,x1,WHITE);
		else
			putpixel(x1,y1,WHITE);
	}
}

void main()
{
	int n,i;
	int pt[MAX][2];
	int gd=DETECT,gm;

	printf("Enter the number of points:");
	scanf("%d",&#038;n);

	printf("Enter the x and y coordinates:");
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&#038;pt[i][0],&#038;pt[i][1]);
		pt[i][1]=480 - pt[i][1];
	}

	initgraph(&#038;gd,&#038;gm,"..\\bgi");

	line(1,0,1,480);		// X - Axis
	line(0,479,639,479);		// Y - Axis

	outtextxy(pt[0][0]-2,pt[0][1]-3,"*");

	for(i=0;i<n-1;i++)
	{
		midpointline(pt[i][0],pt[i][1],pt[i+1][0],pt[i+1][1]);
		outtextxy(pt[i+1][0]-2,pt[i+1][1]-3,"*");
	}
	getch();
	closegraph();
}
</pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-display-a-line-graph-using-midpoint-line-algorithm/">C Program to display a line graph using midpoint line algorithm.</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-display-a-line-graph-using-midpoint-line-algorithm/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
