0% found this document useful (0 votes)
8 views8 pages

CG Practical 3

The document describes an algorithm to draw different geometric shapes like circles and lines on a graphics window. It defines classes for circle, point and line and includes methods to set properties and draw these shapes by calling functions from the graphics library. The main function takes input from the user, creates objects of these classes and calls their methods to draw the shapes on the screen.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views8 pages

CG Practical 3

The document describes an algorithm to draw different geometric shapes like circles and lines on a graphics window. It defines classes for circle, point and line and includes methods to set properties and draw these shapes by calling functions from the graphics library. The main function takes input from the user, creates objects of these classes and calls their methods to draw the shapes on the screen.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Date :

RACTCAL

AIMTo dtag the padten using oDA Jine&


Rses enhoon's ciacle deaoing alaaaithn by
appluing Cancept of encaASWoiao
encopsulatian

THEORY The gsocesg of tuning on the


pixela Fors on Jine sogmenba s called
iae qeneoion and he algczaithm for
he ne genezaisn agezilth
Algorithm
DDA ine
step li- Read the endooints (&) &Caata)
Step 22 A e = z - ; Ay= - 1
Step 3 calalate Hhe slaoe of Jine a2. m àyldoc
Step 4 :Set he initiol point af theJiae ca (
Step 5 Lak thacough X-cnozdinade af Jioe e
Calclate the coKESondiog y-Costincte
uSing the ea Ho
Shep6 Plat the pixel
step7 Repen the shep 5 6 urtil end points
is aenched

Page No. :
Date :

Baes.enham Cacle Alacithm


Stepl Rend he spett
eeapenea y &CKeYe) as Certe
Step 2 bPlat initial poirt pirel (oi)= (zoNo)
|Step 3 - Comoudte derision poometet, S= 3-23
Step u Repent step to6
S< then
else

So s=S+ 4(2-)+lo
Steps Compude emaing symme pnp
Step & plat

Page No. :
Date

To this paacica we have


leaznt abot the
) DDA ine algoaith.
5Baesenbom'sCincde algoithrm

Page No. :
Name :- Dhirajkumar Pachling
Div :-A
Roll NO. :-47

Assignment No. 3
CODE:
#include <iostream>
# include <graphics.h>
# include <stdlib.h>
using namespace std;
class dcircle

private: int x0, y0;


public:
dcircle)
{
X0-0;
y0-0;

void setoff(int xx, int yy)


x0=Xx;
y0-yy;
void drawc(int x1, int yl, int r)
float d;
int x,y;
x-0;
y=r;
d=3-2*r;
do

putpixel(xl+x0+x, y+y-y1, 15);


putpixel(x l+x0+y, yOtx-y1, 15);
putpixel(x1+x0+y,y0-x-y1,15);
putpixel(x1+x0+x,y0-y-y1,15);
putpixel(xl+x0-x,y0-y-yl,15);
putpixel(xl+x0-y, y0-x-y1,1 5);
putpixel(xltx0-y,y0+x-yl,15);
putpixel(x1+x0-x, y0ty-yl,15);
if (d<-0)
d= d+4*x+6;

else
{
d=d+4*(x-y)+10;
y-y-1;

X=x+1;

while(x<y);

}:
class pt

protected: int xco, yco,color;


public:
pt)
xco=0,yco=0,color=15;

void setco(int x, int y)


XCOFX;
yco=y;

void setcolor(int c)

colorrc;
void draw)
{
putpixel(xco,yco,color);
}
;
class dline:public pt
private: int x2, y2;
public:
dline():pt)
x2-0;
y2-0;
void setline(int x, int y, int Xx, int yy)

pt::setco(x,y);
x2-XX;
y2=yy;
void drawl( int colour)
{
float x,y,dx,dy, length;
int i;
pt:setcolor(colour);
dx= abs(x2-xco);
dy-abs(y2-yco);
if(dx>=dy)
length= dx;

else
{
length= dy;
dx-(x2-xco)/length;
dy-(y2-yco)/length;
X=XCO+0.5:
y=yco+0.5;
i=l;
while(i<=1ength)

pt::setco(x,y);
pt::draw();
X=xtdx;
y-ytdy;
iitl;

pt::setco(x,y);
pt::draw);

int main)

int gd=DETECT, gm;


initgraph(&gd, &gm, NULL);
int x,y,r, xl, x2, yl, y2, xmax, ymax, xmid, ymid, n, i;
dcircle c;
cout<<"nenter coordinates of centre of circle: ";
cout<<"n enter the value of x : ";
cin>>x;
cout<<"nenter the value ofy:";
cin>>y;
cout<<"nenter the value of radius:":
cin>>r;
xmax= getmaxx(0;
ymax=getmaxy();
xmid=xmax/2;
ymid=ymax/2;
setcolor(1);
c.setoff(xmid,ymid);
line(xmid, 0, xmid, ymax);
line(0,ymid,xmax,ymid);
setcolor(15);
c.drawc(x,y.r);
pt pl;
pl.setco(100,100);
pl.setcolor(14);
dline 1;
I.setline(x 1+xmid, ymid-yl, x2+xmid, ymid-y2);
cout<<"Enter Total Number of lines:
cin>>n;
for(i-0;i<n;it+)
cout<<"Enter co-ordinates of point xl : ";
cin>>x1;
cout<<"enter coordinates of point yl :";
cin>>yl;
cout<<"Enter co-ordinates of point x2 : ";
cin>>x2;
cout<<"enter coordinates of point y2: ";
cin>>y2;
l.setline(xl+xmid, ymid-y1, x2+xmid, ymid-y2);
1.drawl(15);
cout<<"nEnter c0ordinates of centre of circle:";
cout<<"n Enter the value ofx: ";
cin>>x;
cout<<"nEnter the value of y: ":
cin>>y;
cout<<"nEnter the value of radius : ";
cin>>r;
setcolor(5);
c.drawc(x,y.r);
getch();
delay(200);
closegraph);
return 0;

Input:
Value OfX: 100
Value OfY: 70
Value OfR:30
Assqnment AssgnentvECLRS
File Edt Search View
ProjEct Éxecute Tocts AStyle Windew
lWindows BGi Heip
-GCc 4.9.2 32-bit 2aleass
Project
CAUsers AA:signmentAsignmentÄsignment.exe
Rter the value ofy 79
enter the value of radiusi : 39
Enter Iotal Nrsber of linés:
enten togrdinates ofpoint yl 40
Enter co-6rdinates of påint x2 184
chter toord ínates of po int y2 124
Enter oordinates of po int x1 48
Rnte coordinates of point yl 40
Enter c0"0rdinates of po int x 164
enter to0Pd inates of point y2 18
ente co0rdinates of oint yl 44
Enten coordinates of point x 180
eiter cordinates of po int y2 i24
Fntr 0Pdinate of cent re f ircle
DD Com
Compilation results. . .
Abort ioripiatio
- Errors: 0
Waznang9: 0
Shorten compler paths - Output F1lername:
- Output S1ze: 1.36159801483154 M1B
- Comp1lation Tire: 2.00s
Line 200 Cot 1 Set 0 Lines 205 Length 2766 Insert Done parsing in 0.015 seconds

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy