CPSC120
Fundamentals of Computer Science

Activity 28

Objects

Sprites

Complete the following Python program to use the sprite module to draw a sprite that follows the user’s mouse. The program should also draw a second sprite that doesn’t move. The program should prevent the two sprites from overlapping by uncolliding the moving sprite if the two sprites collide.

import graphics
import sprite
import mouse
import keyboard

# Declare sprite objects here
# Initialize sprite objects here
graphics.double_buffer()
while not keyboard.down("Escape"):
    graphics.clear()
    # Update sprite position using mouse location here
    # Test for collision here
        # Uncollide here
    # Draw sprites here
    graphics.update()
    graphics.wait()

Example


Constraint

Create a Python program that uses the physics module to drop a compound object. The program should create two Boxes and use a LockConstraint to join them together and then drop them from some height above the ground.

Example


Plots

Create a Python program that uses the plot module to display two random scatter plots. The program should create two Plots, add random points to both plots, and draw them side-by-side.

Example

Plots