Sahilcg
Sahilcg
Objective:
Implement the Flood Fill algorithm to fill a bounded area in a raster graphics image.
Theory:
In computer graphics, the Flood Fill algorithm is used to fill a connected area of pixels with a selected
color. It's a versatile tool for tasks such as coloring regions or creating fill patterns in 2D images.
Advantages:
• The Flood Fill algorithm is efficient for filling large connected regions with a selected color.
• It is widely used in various image editing and graphics applications.
• It's a simple and intuitive algorithm to implement.
Disadvantages:
• In some cases, the Flood Fill algorithm may not perform well with complex shapes or areas with
intricate boundaries.
• The algorithm can be sensitive to the choice of connectivity (4-connected or 8-connected), which
affects its behavior.
• It might not be suitable for filling areas with patterns or textures that have varying colors.
Code:
Output:
Experiment 8: Boundary Fill Algorithm
Objective:
Implement the Boundary Fill algorithm to fill a closed area in a raster graphics image.
Theory:
In computer graphics, the Boundary Fill algorithm is used to fill a closed area with a selected color. It
starts from a seed point and recursively fills adjacent pixels until it reaches the boundary.
Advantages:
• The Boundary Fill algorithm is straightforward and easy to implement.
• It works well for filling complex shapes with many interior boundaries.
Disadvantages:
• It may be slow for large regions or regions with intricate boundaries.
• The recursive nature of the algorithm can lead to stack overflow errors for very large regions.
Code:
Output:
Experiment 11: Thick Line Algorithm
Objective:
Implement a program and graphical representation of thick line algorithm.
Theory:
A thick line, in computer graphics and image processing, represents a broader and more visually
prominent version of a standard thin line. Unlike a thin line, which is typically just one pixel wide, a
thick line has a variable and often greater width.
Advantages:
• Thick lines are more visible and easier to perceive compared to thin lines, especially when dealing
with complex or crowded visualizations.
• They can enhance the visual appeal of a drawing or visualization.
• They can enhance the visual appeal of a drawing or visualization, providing a more substantial and
bold appearance.
Disadvantages:
• Drawing thick lines requires more processing power and memory compared to thin lines, especially
when dealing with large number of lines.
Codes:
Output:
Experiment 12: Translating Transformation
Objective:
Implement a program to repeatedly translate two geometric objects (a rectangle and a circle) and
visualize the effect of multiple translations.
Theory:
Translation in computer graphics involves moving objects from one position to another. This
experiment will demonstrate the effect of repeated translations on geometric objects.
Advantages:
• Demonstrates the cumulative effect of repeated translations on geometric objects.
• Provides hands-on experience with visualizing multiple translations in computer graphic
Disadvantages:
• The experiment focuses on translation, which is a fundamental concept in computer graphics.
• The objects being translated are simple, and the principles can be applied to more complex shapes.
Code:
Output:
Experiment 13: Rotation Transformation
Objective:
Write a program to implement Rotation of an object
Theory:
It is a method of altering the object's angle. Rotation may be done either clockwise or
counterclockwise. In order to rotate, we must give the rotation point and angle. A pivot point is another
name for a rotation point.
Rotation Algorithm:
1. Initialize a graphical canvas or window for visualization.
2. Define the properties of the geometric objects, such as coordinates, width, height (for the
rectangle), and radius (for the circle).
3. Set a list of rotation amounts for each object. Each rotation is a pair of (x, y) values that
determines how far the objects will be moved.
4. Calculate new coordinates for each object after each translation by adding the translation values
to their original coordinates
5. Draw both the original and translated objects on the canvas using Matplotlib after each
translation.
6. Display the canvas with both the original and translated objects for visualization.
Advantages:
• Demonstrates the cumulative effect of repeated translations on geometric objects.
• Provides hands-on experience with visualizing multiple translations in computer graphic
Disadvantages:
• The experiment focuses on rotation, which is a fundamental concept in computer graphics.
• The objects being rotated are simple, and the principles can be applied to more complex shapes.
Code:
Output:
Experiment 14: Scaling Transformation
Objective:
Write a program to implement Scaling of an object.
Theory:
A scaling transformation modifies an object's size. It either reduce or increase the object's dimension
throughout the scaling procedure. The polygon's vertex coordinates (x, y) can be scaled by multiplying
each by the scaling factors Sx and Sy to create the converted coordinates (x', y').
Consequently,
x' = x * Sx
y' = y * Sy.
The object is scaled in the X and Y directions, respectively, by the scaling factors Sx and Sy
Advantages:
• Scaling enables the adjustment of object sizes to fit within a specific region or to achieve the
desired visual effect.
Disadvantages:
• Scaling alone cannot change the shape or orientation of an object. It can only move it within the
coordinate system.
Code:
Output:
Experiment 16: Reflection Transformation
Objective:
Write a program to implement Reflection of an object
Theory:
Three kinds of Reflections are possible in 3D space:
• Reflection along the X-Y plane.
• Reflection along Y-Z plane.
• Reflection along X-Z plane.
The reflection transformation matrix for x - y axes is as follows:
Consider, a point P[x, y, z] which is in 3D space is made to reflect along X-Y direction
after reflection P[x, y, z] becomes P'[x’ ,y’ ,z’].
Advantages:
• Easy to implement and straightforward.
• Easy to implement.
Disadvantages:
• The experiment focuses on translation, which is a fundamental concept in computer graphics.
• The objects being translated are simple, and the principles can be applied to more complex shapes.
• Can be computationally expensive for very complex scenes.
Code:
Output:
Experiment 16: Shearing Transformation
Objective:
Write a program to implement Shearing of an object.
Theory:
Shearing deals with changing the shape and size of the 2D object along x-axis and y-axis. It is
similar to sliding the layers in one direction to change the shape of the 2D object.It is an ideal
technique to change the shape of an existing object in a two dimensional plane. In a two
dimensional plane, the object size can be changed along X direction as well as Y direction.
x-Shear :
In x shear, the y co-ordinates remain the same but the x co-ordinates changes. If P(x, y) is the
point then the new points will be P’(x’, y’) given as –
Matrix Form:
y-Shear :
In y shear, the x co-ordinates remain the same but the y co-ordinates changes. If P(x, y) is the
point then the new points will be P’(x’, y’) given as –
Matrix Form:
x-y Shear :
In x-y shear, both the x and y co-ordinates changes. If P(x, y) is the point then the new points
will be P’(x’, y’) given as –
Matrix Form:
Advantages:
• Easy to implement and straightforward.
• Easy to implement.
Disadvantages:
• The experiment focuses on translation, which is a fundamental concept in computer graphics.
• The objects being translated are simple, and the principles can be applied to more complex shapes.
• Can be computationally expensive for very complex scenes.
Code:
Output:
Experiment 17: Polygon Drawing Algorithm
Objective:
Write a program to implement Polygon Drawing Algorithm.
Theory:
polygon is a flat two-dimensional shape with straight sides that are fully closed. The sides must be
straight, not curved. However, polygons can have any number of sides.
Advantages:
• Easy to implement and straightforward.
• Easy to implement.
Disadvantages:
• The experiment focuses on translation, which is a fundamental concept in computer graphics.
• The objects being translated are simple, and the principles can be applied to more complex shapes.
• Can be computationally expensive for very complex scenes.
Code:
Output: