computer graphics Archives - Ebhor.com Read The Latest Post Java, Css, Html, Php learning articles Sat, 28 Jan 2023 07:11:23 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.2 https://www.ebhor.com/wp-content/uploads/2021/05/ebhor_logo_100x.jpg computer graphics Archives - Ebhor.com 32 32 Implementation of Cohen Sutherland line clipping algorithm https://www.ebhor.com/implementation-of-cohen-sutherland-line-clipping-algorithm/ https://www.ebhor.com/implementation-of-cohen-sutherland-line-clipping-algorithm/#respond Fri, 27 Jan 2023 06:48:26 +0000 http://ebhor.com/?p=83 [crayon-663d159cb8393207667859/]

The post Implementation of Cohen Sutherland line clipping algorithm appeared first on Ebhor.com.

]]>

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.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 &gt; ymax)
    oc |= TOP;
    else if (y &lt; ymin)
    oc |= BOTTOM;
    if (x &gt; xmax)
    oc |= RIGHT;
    else if (x &lt; 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 &amp;&amp; outcode2 == 0)
        {
            accept = TRUE;
            done = TRUE;
        }
        else if (outcode1 &amp; outcode2)
        {
            done = TRUE;
        }
        else
        {
            double x, y;
            int outcode_ex = outcode1 ? outcode1 : outcode2;
            if (outcode_ex &amp; TOP)
            {
                x = x1 + (x2 - x1) * (ymax - y1) / (y2 - y1);
                y = ymax;
            }
            else if (outcode_ex &amp; BOTTOM)
            {
                x = x1 + (x2 - x1) * (ymin - y1) / (y2 - y1);
                y = ymin;
            }
            else if (outcode_ex &amp; 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", &amp;n);
    printf ("Enter the x- and y-coordinates of the line-endpoints:\n");
    for (i=0; i&lt;n; i++)
    for (j=0; j&lt;4; j++)
    scanf ("%d", &amp;ln[i][j]);
    clip[0]=100;
    clip[1]=100;
    clip[2]=300;
    clip[3]=300;
    initgraph (&amp;gd, &amp;gm, "..//bgi");
    rectangle (clip[0], clip[1], clip[2], clip[3]);
    for (i=0; i&lt;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&lt;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();
}

The post Implementation of Cohen Sutherland line clipping algorithm appeared first on Ebhor.com.

]]>
https://www.ebhor.com/implementation-of-cohen-sutherland-line-clipping-algorithm/feed/ 0
Breshanham line drawing program https://www.ebhor.com/brashanham-line-drawing-program/ https://www.ebhor.com/brashanham-line-drawing-program/#respond Fri, 27 Jan 2023 06:46:58 +0000 http://ebhor.com/?p=81 [crayon-663d159cb88a1979852748/]

The post Breshanham line drawing program appeared first on Ebhor.com.

]]>

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>


void main()
{
int Xs,Ys,Xe,Ye,dx,dy;
float X,Y,p;
int gd=DETECT,gm ;
initgraph(&amp;gd,&amp;gm,"C:\\tc\\bgi");
printf ("Enter the value of (Xs , Xs ) &amp; (Xe , Ye)\n");
scanf ("%d%d%d%d", &amp;Xs ,&amp;Ys , &amp;Xe , &amp;Ye);
dy=Ye-Ys;
dx=Xe-Xs;
p=(2*dy)-dx;
X=Xs;
Y=Ys;
cleardevice( );
putpixel(X,Y,YELLOW);
while(X!=Xe &amp;&amp; Y!=Ye)
{
if(p&lt;1)
{
X=X+1;
p=p+(2*dy);
putpixel (X,Y,RED);
}
else
{
X=X+1;
Y=Y+1;
p=p+(2*dy)-(2*dx);
putpixel(X,Y,GREEN);
}
}
getch ( );
closegraph ( );
}

The post Breshanham line drawing program appeared first on Ebhor.com.

]]>
https://www.ebhor.com/brashanham-line-drawing-program/feed/ 0
Implementation of Brashanham circle drawing algorithm https://www.ebhor.com/brashanham-circle-drawing-program/ https://www.ebhor.com/brashanham-circle-drawing-program/#respond Fri, 27 Jan 2023 06:45:59 +0000 http://ebhor.com/?p=79 [crayon-663d159cb8a6a930325629/]

The post Implementation of Brashanham circle drawing algorithm appeared first on Ebhor.com.

]]>

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int r,x,y,p,xc=320,yc=240;
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TC\\BGI");
cleardevice();
printf("Enter the radius ");
scanf("%d",&r);
putpixel(xc,yc,YELLOW);
x=0;
y=r;
putpixel(xc+x,yc-y,1);
p=3-(2*r);
for(x=0;x<=y;x++)
{
if (p>0)
{
y=y;
p=(p+(4*x)+6);
}
else
{
y=y-1;
p=p+((4*(x-y)+10));
}
putpixel(xc+x,yc-y,1);
putpixel(xc-x,yc-y,2);
putpixel(xc+x,yc+y,3);
putpixel(xc-x,yc+y,4);
putpixel(xc+y,yc-x,5);
putpixel(xc-y,yc-x,6);
putpixel(xc+y,yc+x,7);
putpixel(xc-y,yc+x,8);
}
getch();
closegraph();
}

The post Implementation of Brashanham circle drawing algorithm appeared first on Ebhor.com.

]]>
https://www.ebhor.com/brashanham-circle-drawing-program/feed/ 0
Bresenhams line drawing algorithm https://www.ebhor.com/bresenhams-line-drawing-algorithm/ https://www.ebhor.com/bresenhams-line-drawing-algorithm/#respond Fri, 27 Jan 2023 06:28:34 +0000 http://ebhor.com/?p=73 #include #include #include #include void main() { int Xs,Ys,Xe,Ye,dx,dy; float X,Y,p; int gd=DETECT,gm ; initgraph(&gd,&gm,”C:\\tc\\bgi”); printf (“Enter the value of (Xs , Xs ) & (Xe , Ye)\n”); scanf (“%d%d%d%d”, &Xs ,&Ys , &Xe , &Ye); dy=Ye-Ys; dx=Xe-Xs; p=(2*dy)-dx; X=Xs; Y=Ys; cleardevice( ); putpixel(X,Y,YELLOW); while(X!=Xe && Y!=Ye) { if(p<1) { X=X+1; p=p+(2*dy); putpixel (X,Y,RED); } ... Read more

The post Bresenhams line drawing algorithm appeared first on Ebhor.com.

]]>
#include
#include
#include
#include

void main()
{
int Xs,Ys,Xe,Ye,dx,dy;
float X,Y,p;
int gd=DETECT,gm ;
initgraph(&gd,&gm,”C:\\tc\\bgi”);
printf (“Enter the value of (Xs , Xs ) & (Xe , Ye)\n”);
scanf (“%d%d%d%d”, &Xs ,&Ys , &Xe , &Ye);
dy=Ye-Ys;
dx=Xe-Xs;
p=(2*dy)-dx;
X=Xs;
Y=Ys;
cleardevice( );
putpixel(X,Y,YELLOW);
while(X!=Xe && Y!=Ye)
{
if(p<1)
{
X=X+1;
p=p+(2*dy);
putpixel (X,Y,RED);
}
else
{
X=X+1;
Y=Y+1;
p=p+(2*dy)-(2*dx);
putpixel(X,Y,GREEN);
}
}
getch ( );
closegraph ( );
}

The post Bresenhams line drawing algorithm appeared first on Ebhor.com.

]]>
https://www.ebhor.com/bresenhams-line-drawing-algorithm/feed/ 0
Implementation of Bresenhams circle drawing algorithm https://www.ebhor.com/brac/ https://www.ebhor.com/brac/#respond Fri, 27 Jan 2023 06:27:15 +0000 http://ebhor.com/?p=71 #include #include #include #include void main() { int r,x,y,p,xc=320,yc=240; int gd=DETECT,gm; initgraph(&gd,&gm,”C:\\TC\\BGI”); cleardevice(); printf(“Enter the radius “); scanf(“%d”,&r); putpixel(xc,yc,YELLOW); x=0; y=r; putpixel(xc+x,yc-y,1); p=3-(2*r); for(x=0;x<=y;x++) { if (p<0) { y=y; p=(p+(4*x)+6); } else { y=y-1; p=p+((4*(x-y)+10)); } putpixel(xc+x,yc-y,1); putpixel(xc-x,yc-y,2); putpixel(xc+x,yc+y,3); putpixel(xc-x,yc+y,4); putpixel(xc+y,yc-x,5); putpixel(xc-y,yc-x,6); putpixel(xc+y,yc+x,7); putpixel(xc-y,yc+x,8); } getch(); closegraph(); }

The post Implementation of Bresenhams circle drawing algorithm appeared first on Ebhor.com.

]]>
#include
#include
#include
#include
void main()
{
int r,x,y,p,xc=320,yc=240;
int gd=DETECT,gm;
initgraph(&gd,&gm,”C:\\TC\\BGI”);
cleardevice();
printf(“Enter the radius “);
scanf(“%d”,&r);
putpixel(xc,yc,YELLOW);
x=0;
y=r;
putpixel(xc+x,yc-y,1);
p=3-(2*r);
for(x=0;x<=y;x++)
{
if (p<0)
{
y=y;
p=(p+(4*x)+6);
}
else
{
y=y-1;
p=p+((4*(x-y)+10));
}
putpixel(xc+x,yc-y,1);
putpixel(xc-x,yc-y,2);
putpixel(xc+x,yc+y,3);
putpixel(xc-x,yc+y,4);
putpixel(xc+y,yc-x,5);
putpixel(xc-y,yc-x,6);
putpixel(xc+y,yc+x,7);
putpixel(xc-y,yc+x,8);
}
getch();
closegraph();
}

The post Implementation of Bresenhams circle drawing algorithm appeared first on Ebhor.com.

]]>
https://www.ebhor.com/brac/feed/ 0
Implementation of Bezier curve plotting https://www.ebhor.com/bezier-curv-plotting/ https://www.ebhor.com/bezier-curv-plotting/#respond Fri, 27 Jan 2023 06:24:11 +0000 http://ebhor.com/?p=68 #include #include #include #include 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 ... Read more

The post Implementation of Bezier curve plotting appeared first on Ebhor.com.

]]>
#include
#include
#include
#include
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”, &x[i], &y[i]);
bezier (x, y);
}

The post Implementation of Bezier curve plotting appeared first on Ebhor.com.

]]>
https://www.ebhor.com/bezier-curv-plotting/feed/ 0