Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q 2 : Simple Drawing Widget In this program, you have a gray background and a toolbox on the left side of the canvas. The

Q2: Simple Drawing Widget
In this program, you have a gray background and a toolbox
on the left side of the canvas. The toolbox area is separated
from the drawing area by a vertical line. You have three
different shapes in the toolbox: a circle, a square and a
triangle (Figure 1). If the mouse is inside any of the shapes
in the toolbox, only that shapes color should change from
white to some different color (pick a different color for each
of the three shapes as shown in Figure 2-4). If the mouse is
clicked on one of the three shapes, then that shape should
become the chosen shape. When the mouse is clicked in the
drawing area, draw the chosen shape, centered on the
mouse position. But if any part of the shape would be drawn
in the toolbox area, then the shape should not be drawn. Its
OK to draw the shape partially off the canvas at the top,
right, or bottom, but not in the toolbox area.
Use the default canvas size of (500,500)
The diameter of the circle is 1/6 of the canvas size.
The height and width of the square is 1/6 of the canvas size.
The distance from the top of the triangle to the base of the triangle is also 1/6 of the canvas
size.
The toolbox area is of the canvas width.
The centre of all of the shapes are located at the centre of the toolbox.
There is a vertical gap before and after of each shape in the toolbox. This gap is 1/6 of the
canvas size.
Figure 1: mouse is not inside any of the
shapes in the toolbox
Figure 2: mouse is inside the circle
area in the toolbox
Figure 3: mouse is inside the square
area in the toolbox
Figure 4: mouse is inside the triangle
area in the toolbox
ASSIGNMENT 2
COURSE NUMBER: COMP 1010
4
Set the thickness of the stroke to 4.
Make sure all of the components in the canvas scales up or down according to the canvas
size. For example, canvas size of 200 X 200 should produce the same results but in a
smaller scale.
Figure 5 shows a sample drawing of the
shapes.
There should be only one method call in the
draw() function which is drawToolBox().
Create a void function drawToolBox() that
is responsible for drawing and handling the
color change of the whole toolbox (you are
allowed to create more functions to make the
task simpler).
Use variables and constants of primitive data
types (int, float, boolean)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What steps should be taken to address any undesirable phenomena?

Answered: 1 week ago