VOOZH about

URL: https://www.geeksforgeeks.org/c/program-to-create-a-ship-using-graphics/

⇱ Program to create a Ship using Graphics - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to create a Ship using Graphics

Last Updated : 23 Jul, 2025

In Turbo C graphics the graphics.h functions are used to draw different shapes like circle, rectangle, etc, display text(any message) in a different format (different fonts and colors). By using graphics.h we can make programs, animations and also games. These can be useful for beginners.

Function Used:

  • line(a1, b1, a2, b2): A function from graphics.h header file which draws a line from (a1, b1) point to (a2, b2) point.
  • circle( a, b, r): A function from graphics.h header file which draws a circle with (a, b) as the center and r as radius.
  • setfillstyle(pattern, color): A function from graphics.h header file by which we can give a pattern of drawing and also a specific color.
  • floodfill(a, b, c): A function from graphics.h header file by which we can color in a specific bounded area with (a, b) as the center and c is the border color.

Approach: 

  • The first step is to color the background Cyan using the setfillstyle() and floodfill() functions.
  • Then, make a straight line using the line() function which will act as the Floor of the Ship.
  • The next step is to make other lines using the line() functions to make a complete ship.
  • Total four circles are implemented using the circle() function to implement Life Jackets. Here, a total of two Life Jackets is implemented. Color it white using setfillstyle() and floodfill() functions.
  • Then, make a Railing using same the line() function and color it Black using setfillstyle() and floodfill() functions.
  • Make a Cabin using the line() function and color it Light Gray using setfillstyle() and floodfill() functions.
  • Make three windows using the circle() function and color it white using setfillstyle() and floodfill() functions.
  • Then, make two chimneys using the line() functions and color it Black using setfillstyle() and floodfill() functions.
  • Final step is to make some design using the line() function and color it Red using setfillstyle() and floodfill() functions.

Below is the C program to implement the above approach:

Output:

👁 Image

Comment