Drawing
For this problem, you will draw a single line in the function draw(). The parameters are:
canvas- the canvas to draw onwidth, height- the width and height of the canvasmargin_top, margin_bot- height of blank vertical areas at the top and bottom of the canvas. Do not draw in these areas. The rectangle of canvas not including the margins is the drawable area.x_pct- an int in the range 0..100 inclusive. Compute the line endpoint x from this, with x_pct=0 placing the endpoint x at the leftmost column of the drawable area, and x_pct=100 the rightmosty_pct- an int in the range 0..100 inclusive. Compute the line endpoint y from this, with y_pct=0 placing the endpoint y at the topmost row of the drawable area, and y_pct=100 the bottommost
Write code to draw 1 line, with one endpoint at the lower-right corner of the drawable area, and the other endpoint given proportionately by x_pct, y_pct. Reminder: Use canvas.draw_line(x1, y1, x2, y2) to draw the line.
def draw(canvas, width, height, margin_top, margin_bot,
x_pct, y_pct):
View solution
def draw(canvas, width, height, margin_top, margin_bot,
x_pct, y_pct):
canvas.draw_line(
width - 1,
height - margin_bot - 1,
(x_pct / 100) * (width - 1),
(y_pct / 100) * (height - margin_top - margin_bot - 1) + margin_top
)