Midterm Exam 2 Review Spring 2004: Graphics from a List
Comments, answers, and questions go here:
(Link back to Sp2004 Midterm 2 Review)
In the example given it says that "1 000 010 100 200" draws a line from (0,10) to (100,200). In the next paragraph "1 102 200 102 300" is given. Why does 000 change to 102? Why are there 6 numbers given and only 4 numbers needed in the coordinates? What coordinates would the second input draw a line between?
def doGraphics(list):
canvas=makePicture(getMediaPath("640x480.jpg")
for i in list:
if list[0]=="b":
addRectFilled(canvas, int(list[1,3]), int(list[4,6]),black)
if list[0]=="l":
addLine(canvas, int(list[1,3]), int(list[4,6]), int(list[7,9]), int(list[10,12]))
return canvas
asides from the indentation...
Can someone give a hint of where to start...please :-(
<pre>
I think I am pretty close, but this code still doesn't work when I run it through JES. Any hints?
list=["b 100 200","b 101 200","b 102 200","l 102 200 102 300"]
def doGraphics(list):
canvas=makePicture(getMediaPath("7x95in.jpg"))
i=0
for eachString in list:
Ax= int(eachString[2]+eachString[3]+eachString[4])
Ay=int(eachString[6]+eachString[7]+eachString[8])
if len(eachString) < 10:
addLine(canvas,Ax,Ay,Ax,Ay)
if len(eachString) > 9:
Bx=int(eachString[10]+eachString[11]+eachString[12])
By=int(eachString[14]+eachString[15]+eachString[16])
addLine(canvas,Ax,Ay,Bx,By)
return canvas
show (canvas)
Shelley Moister
In the example given it says that "1 000 010 100 200" draws a line from (0,10) to (100,200). In the next paragraph "1 102 200 102 300" is given. Why does 000 change to 102? Why are there 6 numbers given and only 4 numbers needed in the coordinates? What coordinates would the second input draw a line between?
Think of it as :a line from (102,200) to (102,300). but the first number is always 1. That designates it as a line.
Section 11.2 deals with the last homework, where we make the website.
I am trying to figure out how to get the actual coordinates from the list into where we want it to be. I looked in the book and above but still dont understand it.
Thomas Sobeck
| Section 11.1.2, p. 284, has the solution to this problem. Thomas, try printing out the values you're getting. It can be hard to get the indexes just right. Mark Guzdial |
Link to this Page