Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <graphics.h>
- #include <stdio.h>
- #include <conio.h>
- int main() {
- int gd = DETECT, gm;
- initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
- // Drawing a House
- rectangle(100, 200, 300, 350); // Main body
- line(100, 200, 200, 100); // Left roof line
- line(200, 100, 300, 200); // Right roof line
- rectangle(170, 250, 230, 350); // Door
- rectangle(120, 230, 160, 270); // Window
- // Drawing a Bottle
- rectangle(400, 200, 450, 350); // Body
- arc(425, 200, 0, 180, 25); // Top curve
- rectangle(415, 150, 435, 200); // Neck
- // Drawing a Cup
- rectangle(500, 250, 550, 300); // Body
- arc(525, 250, 0, 180, 25); // Top curve
- line(550, 250, 570, 270); // Handle top
- line(550, 300, 570, 280); // Handle bottom
- line(570, 270, 570, 280); // Handle vertical
- // Drawing a Fan
- circle(300, 450, 30); // Center circle
- line(300, 450, 350, 400); // Blade 1
- line(300, 450, 250, 400); // Blade 2
- line(300, 450, 350, 500); // Blade 3
- line(300, 450, 250, 500); // Blade 4
- getch();
- closegraph();
- return 0;
- }
- Here are the most commonly used graphics functions:
- 1. Basic Initialization Functions:
- ```c
- initgraph(&gd, &gm, "path"); // Initialize graphics mode
- closegraph(); // Close graphics mode
- ```
- 1.2
- int points[] = {100, 100, 200, 100, 150, 50, 100, 100}; // A triangle (last point connects back to start)
- drawpoly(4, points); // 4 points including the closing point
- 2. Drawing Basic Shapes:
- ```c
- // Draw a pixel
- putpixel(int x, int y, int color);
- // Draw a line
- line(int x1, int y1, int x2, int y2);
- // Draw a rectangle
- rectangle(int left, int top, int right, int bottom);
- // Draw a circle
- circle(int x, int y, int radius);
- // Draw an ellipse
- ellipse(int x, int y, int start_angle, int end_angle, int x_radius, int y_radius);
- // Draw an arc
- arc(int x, int y, int start_angle, int end_angle, int radius);
- ```
- 3. Color and Fill Functions:
- ```c
- // Set current drawing color
- setcolor(int color);
- // Fill an enclosed area
- floodfill(int x, int y, int border_color);
- // Set fill pattern and color
- setfillstyle(int pattern, int color);
- ```
- 4. Text Functions:
- ```c
- // Output text at specified position
- outtextxy(int x, int y, "text");
- // Set text style
- settextstyle(int font, int direction, int size);
- // Set text justification
- settextjustify(int horiz, int vert);
- ```
- 5. Screen and Window Functions:
- ```c
- // Clear screen
- cleardevice();
- // Clear viewport
- clearviewport();
- // Set viewport
- setviewport(int left, int top, int right, int bottom, int clip);
- ```
- Common Color Constants:
- ```c
- BLACK // 0
- BLUE // 1
- GREEN // 2
- CYAN // 3
- RED // 4
- MAGENTA // 5
- BROWN // 6
- LIGHTGRAY // 7
- DARKGRAY // 8
- LIGHTBLUE // 9
- LIGHTGREEN // 10
- LIGHTCYAN // 11
- LIGHTRED // 12
- LIGHTMAGENTA// 13
- YELLOW // 14
- WHITE // 15
- ```
- Here's a simple example of how to use these functions together:
- ```c
- #include <graphics.h>
- int main() {
- int gd = DETECT, gm;
- initgraph(&gd, &gm, "");
- // Draw a house
- setcolor(BLUE);
- rectangle(100, 200, 300, 350); // House body
- setcolor(RED);
- line(100, 200, 200, 100); // Roof left
- line(200, 100, 300, 200); // Roof right
- setcolor(BROWN);
- rectangle(175, 250, 225, 350); // Door
- setcolor(WHITE);
- circle(190, 300, 5); // Door handle
- getch();
- closegraph();
- return 0;
- }
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement