Functions of graphics
• First will discuss basic geometric shapes and base on that we will make a simple program where we will have a x and y axis and all the shapes in it.
1) Line Function
=> line function is used to draw a line by just giving 4 points.
syntax:
void line(int x1, int y1, int x2, int y2);
Where:
x1 : initial x-coordinate
y1 : intial y-coordinate
x2 : end x-coordinate
y2 : end y-coordinate
Example : line(100, 100, 200, 200);
Explanation: A line would be drawn from point(100, 100) to point(200,200).
2) Rectangle Function
=> Rectangle function is used to draw a rectangle.
=> Rectangle function is same as bar function already discussed in last post, only difference is in bar function we get only 3 lines in output, but in rectangle we get all the four lines.
=>Coordinates of left top and right bottom corner are required to draw the rectangle. left specifies the X-coordinate of top left corner, top specifies the Y-coordinate of top left corner, right specifies the X-coordinate of right bottom corner, bottom specifies the Y-coordinate of right bottom corner.
Syntax: void rectangle(int left, int top, int right, int bottom);
3) Circle function
Syntax: void circle(int x, int y, int radius);
=>Circle function is used to draw a circle with center (x,y) and third parameter specifies the radius of the circle.
Example: circle(100,100,10);
4) ellipse function
Syntax: void ellipse(int x, int y, int startangle, int endangle, int xradius, int yradius);
where:
(x,y): are coordinates of center of the ellipse
startangle: is the starting angle
endangle: is the ending angle
fifth and sixth parameters specifies the X and Y radius of the ellipse.
Example: ellipse(100, 100, 0, 360, 50, 25);
Explanation: ellipse will be drawn with the center of 100(x) and 100(y) and it will start from 0 angle and will end at 360 degree i.e. will make a complete ellipse, if you want half ellipse then give 180 degree as endangle.
5) getmaxx function
=> getmaxx function returns the maximum X coordinate for current graphics mode and driver.
Syntax: int getmaxx();
Example: max_x = getmaxx();
Explanation: max_x will return here maximum x coordinate.
6) getmaxy function
=> getmaxy function returns the maximum Y coordinate for current graphics mode and driver.
Syntax: int getmaxy();
Example:max_y = getmaxy();
Explanation: max_y will return here maximum y coordinate.
🎨Program Link: program to draw a axis in middle of screen
👇
https://github.com/Rinky6767/Computer-Graphics/blob/59a8d804718d23016a95bb97ec86a32dbe041565/Built%20in%20functions/getmaxx_getmaxy_line
Output:
🎨Program Link: program for all basic shapes
👇
https://github.com/Rinky6767/Computer-Graphics/blob/59a8d804718d23016a95bb97ec86a32dbe041565/Built%20in%20functions/rectange_circle_ellipse_line
Output:
Next will make a program were we will make a cave one by one with the help of delay function.
1) Arc function
Syntax: void arc(int x, int y, int startangle, int endangle, int radius);
where:
(X, y): are coordinates of center of the arc
startangle specifies starting angle, endangle specifies the end angle
last parameter specifies the radius of the arc.
=>arc function is same as ellipse function.
=>arc function can also be used to draw a circle but for that starting angle and end angle should be 0 and 360 respectively.
Example: arc(100,100,0,135,50);
Explanation: (100, 100) are coordinates of center of arc, 0 is the starting angle, 135 is the end angle and radius of the arc is 50.
2) Delay function
=>delay function is used to suspend execution of a program for a particular time.
Syntax: void delay(unsigned int);
Example: delay(1000);
Explanation: Here unsigned int is the number of milliseconds (remember 1 second = 1000 milliseconds). To use delay function in your program you should include the "dos.h" header file which is not a part of standard C library.
🎨Program Link: program for cave
👇
https://github.com/Rinky6767/Computer-Graphics/blob/59a8d804718d23016a95bb97ec86a32dbe041565/Built%20in%20functions/arc-%20Cave
Output:
🎨Program Link: program for House
Comments
Post a Comment