def makeCollage(pics = []): # Get 8 images total if there aren't at least 8 provided picCount = len(pics) if picCount < 8: for i in range (picCount, 8): pics.append(makePicture(pickAFile())) # Shuffle the images shuffle(pics) # Create blank 8.5"x11" canvas collage = makeEmptyPicture(816,1056) show(collage) # Determine how many rows and columns to use columns = floor(sqrt(picCount)) rows = int(ceil(picCount / columns)) remainder = picCount - (rows * columns) # Determine width of columns and height of rows columnWidth = ceil(getWidth(collage) / columns) rowHeight = ceil(getHeight(collage) / rows) # Create list of transformation functions from previous labs collageFunctions = [lessRed,moreRed,roseColoredGlasses,lightenUp,makeNegative,betterBnW,halfBetter, \ mirrorVertical,mirrorTop,mirrorBottom,mirrorQuadruple,sepia,artify,noBlue] # Resize each image, apply a random transformation, add to the collage for i in range (0, picCount): # Determine collage row number currentRow = int(i / columns) # For the last row, recalculate the number of required columns for remaining images if currentRow == rows - 1 and i % columns == 0: columnWidth = ceil(getWidth(collage) / (columns + remainder)) # Get starting coordinates for image currentY = int(currentRow * rowHeight) currentX = int((i % columns) * columnWidth) # Copy and resize image pic = resize(pics[i],columnWidth,rowHeight) # Get transformation function index index = i % len(collageFunctions) # Shuffle transformation functions each time through list if index == 0: shuffle(collageFunctions) # Apply transformation collageFunctions[index](pic) # Add image to collage pyCopy(pic,collage,currentX,currentY) # Update when each pic is added to make it seem faster repaint(collage) return collage
def thanksgivingCard(): # Create blank card, get dimensions card = makeEmptyPicture(96*5,96*7) # 96 ppi cardWidth = getWidth(card) cardHeight = getHeight(card) # Add background image to card # Make sure LAB_DIR is set to the correct directory background = makePicture(LAB_DIR + "\\Card\\background.jpg") background = resize(background,cardWidth,cardHeight) pyCopy(background,card,0,0) # Get green-screened wishbone picture # Make sure LAB_DIR is set to the correct directory wishbone = makePicture(LAB_DIR + "\\Card\\wishboneGreen.jpg") wishbone = resize(wishbone,cardWidth,cardHeight/3) # Replace wishbone background with dinner picture # Make sure LAB_DIR is set to the correct directory dinner = makePicture(LAB_DIR + "\\Card\\dinner.jpg") wishbone = chromakey(wishbone,dinner) # Add wishbone/dinner image to card wishboneY = cardHeight/5 pyCopy(wishbone,card,0,wishboneY) # Add text to card fontSize = int(cardHeight * 0.1) fontStyle = makeStyle(serif,italic+bold,fontSize) text = ["Wishing you a","very happy","Thanksgiving!"] for t in range(0,len(text)): addTextWithStyle(card,int((cardWidth-(len(text[t])*fontSize*.5))/2), \ int((wishboneY + getHeight(wishbone) + fontSize) + t * fontSize * 1.25), \ text[t], fontStyle,orange) return card