Question
PLEASE WRITE THIS PROGRAM IN C++ THANK YOU SO MUCH You shall write a C++ program that accepts 5 command-line arguments and generates an image
PLEASE WRITE THIS PROGRAM IN C++ THANK YOU SO MUCH
You shall write a C++ program that accepts 5 command-line arguments and generates an image of a Sierpinski triangle, as raw 32-bit RGBA pixels on standard output.
The command-line arguments shall consist of the following:
The width (in pixels) of the image, as a decimal integer
The height (in pixels) of the image, as a decimal integer
The background color, as a 32-bit little-endian hexadecimal integer
The foreground (drawing) color, as a 32-bit little-endian hexadecimal integer
The minimum area (in pixels) that a triangle must have in order to be drawn, as a decimal floating-point value.
The vertices for the outermost Sierpinski triangle shall be the middle of the top row, the bottom left corner, and the bottom right corner of the image.
Algorithm for Asn
Algorithm
Drawing a Sierpinski triangle is easily accomplished in a recursive manner. You will probably want to implement a recursive function that accepts arguments indicating the three x/y points of the triangle to be drawn. Consider them to be Top, Left and Right in the diagram below. The algorithm would then consist of the following steps:
If the area of the triangle represented by the three points is smaller than the predetermined minimum area, stop the process (i.e.,returnthis is a base case).
Otherwise:
Draw a triangle by drawing three lines connecting the three points. Consider how to draw a line by interpolating between the start and end pixel coordinates. Make sure to round to the nearest appropriate pixel.
(Alternately, you could draw the upside-down triangle linking each of the midpoints. This creates one or two more complications, but will end up creating a smoother image, since you don't redraw any lines.)
Perform recursive calls to this function to draw each of the three Sierpinski subtriangles (i.e., T1, T2 and T3 in the diagram below). These are recursive steps.
Pseudocode
def Sierpinski(Top, Left, Right): if this_area < minimum_area: return DrawLines((Top, Left), (Left, Right), (Right, Top)) Sierpinski(Top, Top.Midpoint(Left), Top.Midpoint(Right)) # T1 Sierpinski(Top.Midpoint(Left), Left, Left.Midpoint(Right)) # T2 Sierpinski(Top.Midpoint(Right), Left.Midpoint(Right), Right) # T3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started