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

This page removed for FERPA compliance
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 RREMOVEDS, 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