Unit-I Basics of Computer Graphics
CGR-22318 www.studyroom.xyz Page 17
10.1.2. Graphics Mode functions for Shape
Computer graphics has many inbuilt commands, which can be used either to
draw a shape and /or for filling a colour in any bounded shape.
1. lineto( ): This command draws a line on screen from current cursor positions to
the(x, y) positions mentioned in command.
Syntax- lineto(x, y);
Where, (x, y) are co-ordinates of end of line.
2. line( ): This command draws a line on screen.
Syntax: line(x1, y1, x2, y2);
Where, (x1, y1) are co-ordinates of starting point of line and (x2, y2) are co-
ordinates of end point of line.
Example :- line(10, 10, 100, 100);
It will draw a line from point (10, 10) to point (100, 100).
3. circle( ): This command draws a circle on screen.
Syntax: circle(x, y, r);
Where, (x, y) are co- ordinates of centre of circle and r is radius of circle.
Example :- circle (50, 50, 10);
It draws a circle with centre 50, 50 and radius 10.
4. rectangle( ): This command draws a line on screen.
Syntax: rectangle(x1, y1, x2, y2);
Where, (x1, y1) are co-ordinates of top left corner point of rectangle and (x2, y2)
are co-ordinates of bottom right corner point of rectangle.
Example :- rectangle(10, 10, 100, 100);
It will draw a rectangle as a top left corner is(10,10) & bottom right corner
is(100,100).
5. ellipse( ): It draws an ellipse on screen.
Syntax: ellipse(x, y, start, end , xrad, yrad);
Where,
x, y are co ordinates of centre point.
start, end- starting and ending angle of ellipse.
xrad, yrad: x- axis and y-axis radius respectively.
For full ellipse, the start and end should be 0 to 360 else it will draw an arc on
screen.
Example :- ellipse(100, 100, 0, 360, 20, 10);