Write a function doGraphics that will take a list as input. The function doGraphics will start by creating a canvas from the 640x480.jpg file in the mediasources folder. You will draw on the canvas according to the commands in the input list. Each element of the list will be a string. There will be two kinds of strings in the list:
• “b 200 120” means to draw a black dot at x position 200 and y position 120–(200,120).
The numbers, of course, will change, but the command will always be a “b.” You can assume that the input numbers will always have three digits.
• “l 000 010 100 200” means to draw a line from position (0,10) to position (100,200).
So an input list might look like: ["b 100 200","b 101 200","b 102 200","l 102 200 102 300"] (but have any number of elements).
Note: The important thing here is to iterate through the list’s items and handle each case with the “split” method.
```
def doGraphics (list):
canvas = makePicture("640x480.jpg")
for item in list:
if item[0]=="b":
parts = item.split(" ")
px = getPixel(canvas, int(parts[1]), int(parts[2]))
setColor(px, makeColor(0,0,0))
elif item[0]=="l":
parts = item.split(" ")
x1 = int(parts[1])
y1 = int(parts[2])
x2 = int(parts[3])
y2 = int(parts[4])
addLine(canvas, x1, y1, x2, y2)
return canvas
```
You might also like to view...
Which of the following do NOT make VBA code easy to read?
A) Paragraphs B) Comments C) Line breaks D) Indentations
Explain how to use the Formula Builder in the Toolbox to find the average of the values in a range of cells.
What will be an ideal response?