0% found this document useful (0 votes)
39 views4 pages

Computer Graphics Lab

This document contains the code for a computer graphics lab program that draws a natural scene. The program includes functions to draw circles, lines, and ellipses. It uses these functions to render a landscape that includes trees, a sun, and a hill in the background. The program was written by Agathiyan S for their fifth semester computer graphics course with the code CSCA 512 in session 2018-2021.

Uploaded by

Agathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views4 pages

Computer Graphics Lab

This document contains the code for a computer graphics lab program that draws a natural scene. The program includes functions to draw circles, lines, and ellipses. It uses these functions to render a landscape that includes trees, a sun, and a hill in the background. The program was written by Agathiyan S for their fifth semester computer graphics course with the code CSCA 512 in session 2018-2021.

Uploaded by

Agathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

COMPUTER GRAPHICS LAB

COURSE CODE – CSCA 512

NAME : AGATHIYAN S
REG. NO : 18352204
SEMESTER : FIFTH
SESSION : 2018-2021
NATURAL SCENE

PROGRAM CODE:
#include<stdio.h>
#include<graphics.h>

float round(float a);

void d_line(int x1, int y1, int x2, int y2)


{
int steps,k;
float xincr,yincr,x,y,dx,dy;
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>abs(dy))
steps=abs(dx);
else
steps=abs(dy);
xincr=dx/steps;
yincr=dy/steps;
x=x1;
y=y1;
for(k=1;k<=steps;k++)
{
delay(100);//for seeing the line drawing process slowly.
x+=xincr;
y+=yincr;
putpixel(round(x),round(y),WHITE);
}
}
float round(float a)
{
int b=a+0.5;
return b;
}

void drawcircle(int x0, int y0, int radius)


{
int x = radius;
int y = 0;
int err = 0;

while (x >= y)
{
putpixel(x0 + x, y0 + y, 7);
putpixel(x0 + y, y0 + x, 7);
putpixel(x0 - y, y0 + x, 7);
putpixel(x0 - x, y0 + y, 7);
putpixel(x0 - x, y0 - y, 7);
putpixel(x0 - y, y0 - x, 7);
putpixel(x0 + y, y0 - x, 7);
putpixel(x0 + x, y0 - y, 7);

if (err <= 0)
{
y += 1;
err += 2*y + 1;
}

if (err > 0)
{
x -= 1;
err -= 2*x + 1;
}
}
}

main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm, "C:\\TC\\BGI");

drawcircle(200, 200, 100);


drawcircle(235, 175, 25);
drawcircle(165, 175, 25);

d_line(250, 115, 300, 75);


d_line(300, 75, 285, 150);
d_line(100, 75, 150, 115);
d_line(100, 75, 115, 150);
d_line(200, 250, 215, 235);
d_line(185, 235, 215, 235);
d_line(185, 235, 200, 250);

d_line(40, 205, 155, 235);


d_line(50, 245, 150, 245);
d_line(40, 290, 155, 255);
d_line(245, 235, 360, 205);
d_line(250, 245, 350, 245);
d_line(245, 255, 360, 290);

arc(185, 265, 180, 360, 15);


arc(215, 265, 180, 360, 15);
arc(200, 275, 193, 347, 10);

ellipse(235, 175, 0, 360, 10, 15);


ellipse(165, 175, 0, 360, 10, 15);

ellipse(200, 450, 0, 360, 100, 150);


getch();
closegraph();
return 0;
}

You might also like