Drawing a Rainbow Using
Computer Graphics
Programming
A Mini Project on Computer Graphics
Name: Khushi Kumari
Roll No: SU23BCA114
Semester: BCA 5th Sem
Under the Guidance of Faculty
PROJECT OVERVIEW
Drawing a Rainbow Using Computer Graphics
This project demonstrates the fundamental principles of computer graphics by
creating a visually appealing rainbow using programming techniques. A rainbow, with
its seven distinct colours arranged in concentric arcs, serves as an excellent example
to understand coordinate systems, colour manipulation, and geometric rendering in
graphics programming.
The project utilises graphics libraries to draw multiple semi-circular arcs in the
sequence of VIBGYOR (Violet, Indigo, Blue, Green, Yellow, Orange, Red), showcasing
how mathematical functions and graphical primitives combine to create beautiful
visual representations.
GRATITUDE
Acknowledgement
I would like to express my sincere gratitude to my faculty guide for their invaluable support and guidance throughout this computer graphics
project. Their expertise in graphics programming and patient mentorship helped me understand the intricate concepts of graphical rendering and
coordinate systems.
I am also thankful to my institution for providing the necessary computational resources and development environment that enabled me to
implement and test this rainbow drawing programme effectively. The laboratory facilities and software tools were instrumental in bringing this
project to completion.
Special thanks to my peers and classmates who provided constructive feedback during the development phase, helping me refine the visual output
and optimise the code structure. Their suggestions significantly improved the final presentation of the rainbow graphics.
BACKGROUND
Introduction to Rainbow Graphics
What is a Rainbow? Computer Graphics Graphics Programming
A natural optical phenomenon displaying The field of creating, manipulating, and Writing code to generate visual elements
a spectrum of seven colours in an arc rendering visual content using by controlling pixels, coordinates, colours,
formation, created by light refraction and computational algorithms and and geometric shapes through
reflection in water droplets. programming techniques. programming languages and graphics
libraries.
Computer graphics enables us to recreate natural phenomena like rainbows digitally. By understanding coordinate geometry, colour theory, and arc
drawing functions, we can programmatically generate a rainbow that mirrors nature's beauty. This project bridges theoretical knowledge of
graphics with practical implementation, demonstrating how mathematical concepts translate into visual output on a computer screen.
Theoretical Foundations
Graphics Fundamentals Colour Theory in Graphics
Computer graphics relies on a coordinate system where the screen is VIBGYOR Spectrum: The rainbow displays seven colours in order:
treated as a Cartesian plane. The origin point (0,0) typically represents Violet, Indigo, Blue, Green, Yellow, Orange, and Red. Each colour is
the top-left corner, with x-coordinates increasing rightward and y- represented using RGB (Red, Green, Blue) values ranging from 0-255.
coordinates increasing downward.
Graphics libraries provide functions like setcolor() and arc() to set
Arc Drawing Mathematics: A rainbow consists of concentric semi- drawing colours and create curved shapes. By systematically drawing
circular arcs. Each arc is defined by its centre point, radius, and arcs with decreasing radii and changing colours, we recreate the
angular range. The mathematical formula for a circle is (x-h)² + (y-k)² = rainbow's layered appearance.
r², where (h,k) is the centre and r is the radius.
The theoretical foundation combines geometry, trigonometry, and colour science to transform mathematical concepts into visual reality through
programmatic control.
GOALS
Project Objectives
Understand Graphics Primitives
Learn and implement fundamental graphics functions including initialisation, coordinate systems, and arc drawing methods to
create geometric shapes.
Master Colour Manipulation
Demonstrate proficiency in using RGB colour models and graphics colour functions to accurately represent the seven colours of the
rainbow spectrum.
Implement Mathematical Concepts
Apply coordinate geometry and trigonometric principles to position and size rainbow arcs correctly, creating a visually balanced and
proportionate output.
Create Reusable Graphics Code
Develop clean, well-structured programme code that can be adapted for other graphics projects, demonstrating good programming
practices and documentation.
IMPLEMENTATION
Programme Code Structure
Key Components of the Rainbow Programme
01 02
Graphics Initialisation Define Centre and Radius
Initialise graphics mode using initgraph() function, detecting graphics Set the centre point coordinates for the rainbow and define the initial
driver and setting up the graphics environment. radius for the outermost arc (Red colour).
03 04
Loop Through Colours Draw Concentric Arcs
Create a loop to iterate through each of the seven colours, setting Use arc() function to draw semi-circular arcs with parameters: centre_x,
appropriate colour codes using setcolor() for VIBGYOR sequence. centre_y, start_angle (0°), end_angle (180°), and current radius.
05 06
Decrement Radius Close Graphics
Reduce the radius value for each subsequent arc to create the layered Use getch() to pause the output for viewing, then closegraph() to
rainbow effect with proper spacing between colour bands. properly terminate the graphics mode and free resources.
Note: The actual implementation uses graphics libraries such as graphics.h in C/C++ or equivalent libraries in other programming
languages. The code demonstrates nested loops, function calls, and systematic colour management.
Conclusion and Key Learnings
This computer graphics project successfully demonstrated the creation of a
rainbow using programming techniques, combining theoretical knowledge
with practical implementation. Through this exercise, I gained hands-on
experience with graphics libraries, coordinate systems, and colour
manipulation functions.
Key Achievements:
Successfully implemented arc drawing functions to create concentric
semi-circles
Accurately represented the VIBGYOR colour spectrum using appropriate
RGB values
Applied mathematical concepts to position and scale graphical elements
precisely
Developed clean, efficient code following programming best practices
Technical Skills Enhanced Future Applications Academic Growth
Proficiency in graphics programming, The concepts learnt can be extended to This project reinforced the connection
understanding of coordinate geometry, create more complex graphics projects between mathematical theory and
and mastery of colour theory application including animations, interactive practical programming, essential for
in digital environments. visualisations, and advanced geometric computer science education and
patterns. development.