Really stuck on this problem for a beginners course in C pro

Really stuck on this problem for a beginner\'s course in C programming. I have to write a program with descartes to draw a shaded triangle.

Let’s start by constraining the type of triangle. In this task, we’ll assume that one leg of the triangle is horizontal. More formally, the triangle consists of three points, but two of them have the same y coordinate. Your program should solicit input from the user by calling GetPoint() three times. The third point will have whatever y coordinate the user happened to pick. Copy the second point’s y coordinate and use it to overwrite the third point’s y coordinate, thereby making the final leg horizontal. Ideally, your program will have a triangle t GetTriangle(); function that solicits this input and returns a custom struct called triangle t of your own design. You can then write a void DrawTriangle(triangle t triangle); function to draw a figure like the one above. By shading, we mean drawing horizontal lines at regular intervals inside the triangle. Write another function, DrawShadedTriangle that does much the same as DrawTriangle, except it shades the triangle with a specified number of horizontal lines. As a hint, you should write a function point t PartWay(lineseg t segment, double part); which returns a point partway along a line segment. For example, if part == 0.5, then it would return the point exactly between the two ends of the line segment. Test this function first. Then intergrate it into your DrawShadedTriangle implementation. Your final program will: 1. Ask the user how many shades they want with scanf. 2. Prompt for three points in the graphics window. 3. Draw the shaded triangle with the specified number of additional horizontal lines. It is possible to solve this problem without using a struct, in which case partial marks may be awarded.

Solution

Draw the shaded triangle with the specified number of additional horizontal lines.

<!DOCTYPE html>
<html>
<head>
<title>Triangle Canvas Example</title>
</head>
<body>
<canvas id=\"myCanvas\" width=\"500\" height=\"500\"></canvas>

<script>
var canvasElement = document.querySelector(\"#myCanvas\");
var context = canvasElement.getContext(\"2d\");

// the triangle
context.beginPath();
context.moveTo(100, 100);
context.lineTo(100, 300);
context.lineTo(300, 300);
context.closePath();

// the outline
context.lineWidth = 10;
context.strokeStyle = \'#666666\';
context.stroke();

// the fill color
context.fillStyle = \"#FFCC00\";
context.fill();

</script>

</body>
</html>

Really stuck on this problem for a beginner\'s course in C programming. I have to write a program with descartes to draw a shaded triangle. Let’s start by const

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site