 |  |

 |
 |  |  |
 | Welcome to CS1315. Click on the python to add comments.
|  |
 |  |  |
|
This page removed for FERPA compliance
|
        |
Example Cartoon Collage
REMOVED's an example program that produces a little cartoon.
- The background already contains one "character" – a horse.
- The code inserts the small robot character in the lower left corner. The robot gets composed with the upper left hand corner at X=20 and Y set to a value so that the BOTTOM of the Robot will be 20 pixels from the bottom of the picture.
- Afterward, addText is REMOVEDed to add some text that the robot is "saying." addText takes four inputs: The picture to write on, the X and Y positions where to start writing (i.e., the left edge), and the text to write. The X position for the text is 20 – lined up with the robot. The Y position is 20 pixels higher than the starting point for the robot – thREMOVED, 20 pixels above the robot's head.
Notice that this composition maps the robot onto the scene with no cropping or scaling. If we wanted to scale, we'd change how we incremented targetX and targetY, as the easiest thing.
def makeScene():
bg = makePicture(getMediaPath("horse.jpg"))
robot = makePicture(getMediaPath("robot.jpg"))
#Put robot near bottom (20 pixels from bottom) on left (x=20)
targetX = 20
for sourceX in range(1,getWidth(robot)):
targetY = getHeight(bg)-getHeight(robot)-20
for sourceY in range(1,getHeight(robot)):
color=getColor(getPixel(robot,sourceX,sourceY))
setColor(getPixel(bg,targetX,targetY),color)
targetY = targetY + 1
targetX = targetX + 1
# Add something that the robot is saying
# JREMOVEDt above his head
targetX = 20
targetY = getHeight(bg)-getHeight(robot)-40
addText(bg,targetX,targetY,"Take me to your leader!")
show(bg)
return bg
And here's the result:
