Jamie Starke bio photo

Jamie Starke

I develop for my career, but I also develop for fun, and whenever I think it can solve a problem I'm having. This has lead me to create side projects, such as Rental Map and BusTimes, among others.

Newsletter Email Twitter Facebook Google+ LinkedIn Github Stackoverflow More

Here is the intersection example from last Wednesay and Thursday’s tutorial.

import sys

#Set the position for the center
xCenter = 400
yCenter = 300

#How wide do we want to make our lanes on the road
lane = 50


#This section draws the sides of the roads
print "line",xCenter -lane,0,xCenter-lane, yCenter - lane
print "line",xCenter +lane,0,xCenter+lane, yCenter - lane
print "line",xCenter -lane,yCenter + lane,xCenter-lane, yCenter*2
print "line",xCenter +lane,yCenter + lane,xCenter+lane, yCenter*2
print "line",0,yCenter -lane,xCenter-lane, yCenter - lane
print "line",0,yCenter +lane,xCenter-lane, yCenter + lane
print "line",xCenter+lane,yCenter -lane,xCenter*2, yCenter - lane
print "line",xCenter+lane,yCenter +lane,xCenter*2, yCenter + lane

#Push drawing to Quickdraw
sys.stdout.flush()


# Asks the user if they want center lines
sys.stderr.write("Would you like lane markers")
user = raw_input()

# If they say yes, then draw them
if user == "yes":
    #While Loop Variables

    #Where do we want to start drawing
    start=lane
    end = xCenter

    #How far apart do we want the starts of our lines
    inc = 40

    #how long do we want the lines
    length = 20

    i=start
    while i < end:
        #For each value of i, draw a line in each direction
        print "line",xCenter+i,yCenter,xCenter+i+length,yCenter
        print "line",xCenter-i,yCenter,xCenter-(i+length),yCenter
        print "line",xCenter,yCenter-(i),xCenter,yCenter-(i+length)
        print "line",xCenter,yCenter+(i),xCenter,yCenter+(i+length)

        #Move to the start of the next line
        i = i + inc

The most important thing in this example is the following

# Where do we want it to start
start = #Fill this in#

# Where do we want it to end
end = #Fill this in#

# How much do we want our loop to increase by each time
inc = #fill this in#

i = start
while i < end:
     # The body of your loop goes here
     #Don't forget to increase your i value by whatever amount you decided above
     i = i + inc`