Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

proto-Pong, the bouncing/color-changing square ball code

def pong():
  x = 0 # x position of ball
  y = 0 # y position of ball
  w = 10 # width of ball
  h = 10 # height of ball
  lr = 1 # left-right direction of movement. (+1 = l-to-right, -1 = r-to-left)
  color = red # Color of ball

  for frameNum in range(1, 100):
    picture = makeEmptyPicture(640, 480)
    addRectFilled(picture, x, y, w, h, color)

    # If we get to the RHS, going left-to-right, change direction and change color
    if x >= getWidth(picture) and lr == 1:
      lr = -1
      color = blue

    x = x + (10*lr) # Increments or decrements x depending on lr direction
    y = y + 2 # Keep going down by incrementing y whether l-to-r or r-to-l
    writePictureTo(picture, filename(frameNum))

def filename(n):
  if n < 10:
    stem = "pong0"
  else:
    stem = "pong"
  return getMediaPath(stem + str(n) + ".jpg")


Link to this Page