from Myro import * init() pic = takePicture() show(pic) picWidth = getWidth(pic) picHeight = getHeight(pic) print ("Image WxH is", picWidth, "x", picHeight, "pixels.") savePicture(pic, "OfficeScene.jpg") savePicture(pic, "OfficeScene.gif") mySavedPicture = makePicture("OfficeScene.jpg") show(mySavedPicture) mySavedPicture = makePicture(pickAFile()) show(mySavedPicture) grayPic = takePicture("gray") show(grayPic) joystick() for i in range(25): pic = takePicture("gray") show(pic) pic1 = takePicture() turnLeft(0.5,0.25) pic2 = takePicture() turnLeft(0.5,0.25) pic3 = takePicture() turnLeft(0.5,0.25) pic4 = takePicture() listOfPictures = [pic1, pic2, pic3, pic4] savePicture(listOfPictures, "turningMovie.gif") pictureList = [] #Start with an empty list. for i in range(15): pic = takePicture() pictureList = pictureList + [pic] #Append the new picture turnLeft(0.5,0.1) savePicture(pictureList,"rotatingMovie.gif") W = H = 100 newPic = makePicture(W, H, makeColor("black")) show(newPic) for x in range(W): for y in range(H): pixel = getPixel(newPic, x, y) setColor(pixel, makeColor("white")) myRed = makeColor(255, 0, 0) myColor = pickAColor() setRGB(pixel, (255, 0, 0)) r, g, b = getRGB(pixel) for pixel in getPixels(newPic): setColor(pixel, makeColor("gray")) def gray(v): # returns an rgb gray color for v return makeColor(v, v, v) def main(): MAX = 255 W = 100 H = 100 # Create the blank image myPic = makePicture(W, H) show(myPic, "Shades of Gray") # Fill in each pixel with x+y shade of gray for x in range(W): for y in range(H): setPixel(myPic, x, y, gray((x+y)%(MAX+1))) main() MAX = 50 def gray(v): # returns an rgb gray color for v brightness = v*255/MAX return makeColor(brightness, brightness, brightness) def main(): # read an image and display it oldPic = makePicture(pickAFile()) show(oldPic, "Before") X = getWidth(oldPic) Y = getHeight(oldPic) # Input the shrink factor and computer size of new image F = int(ask("Enter the shrink factor.")) newx = X/F newy = Y/F # create the new image newPic = makePicture(newx, newy) for x in range(newx): for y in range(newy): setPixel(newPic, x, y, getPixel(oldPic, x*F, y*F)) show(newPic, "After") for x in range(X): for y in range(Y): pixel = getPixel(oldPic, x, y) v = MAX - getRed(pixel) setPixel(newPic, x, y, gray(v)) p = takePicture() show(p) for pixel in getPixels(p): r, g, b = getRGB(pixel) if r > 200 and g < 100: setRGB(pixel, (255, 255, 255)) else: setRGB(pixel, (0, 0, 0)) def locateBall(picture): tot_x = 0 count = 0 for pixel in getPixels(p): r, g, b = getRGB(pixel) if r > 200 and g < 100: tot_x = tot_x + getX(pixel) count = count + 1 return tot_x/count def main(): for t in timer(T): # take picture and locate the ball pic = takePicture() ballLocation = locateBall(pic) if ballLocation <= 85: turnLeft(cruiseSpeed) elif ballLocation <= 170: forward(cruiseSpeed) else: turnRight(cruiseSpeed) pic = takePicture("blob") onPixels, avgX, avgY = getBlob() def exercise1(): for x in range (1, W): for y in range(1, H): r, theta = polar(x, y) setPixel(myPic, x, y, gray((((r+theta)%16)-8)*MAX/16+MAX/2))