Picture Class

The various functions of the picture class


Picture(w,h): Opens an empty drawing canvas whose width is w and whose height is h

Picture(imageFileName): Maks a new canvas initialized to the picture in the image file, which should be of type ".bmp".

Drawing Shapes

drawOval(x,y,hrad,vrad), drawOvalFill(x,y,hrad,vrad): Draws an empty or filled oval centered at x,y with a horizontal radius of hrad and a vertical radius of vrad.

drawCircle(x,y,r), drawCircleFill(x,y,r): Draws a circle centered at x,y, with radius r.

drawRect(x,y,w,h), drawRectFill(x,y,w,h): Draws a rectangle with its upper lefthand corner at x,y, with width w and height h.

drawSquare(x,y,side), drawSquareFill(x,y,side): Draws a square with its upper lefthand corner at x,y, with side length side.

drawPolygon(vertices), drawPolygonFill(vertices): Vertices is a list of x,y coordinates, so using this method will look something like pic.drawPolygon([(1,20),(20,20),(1,30),(20,30)]). This will draw a shape that connects all of the vertices in order, connecting the last vertex to the first vertex.

drawLine(x1,y1,x2,y2): Draws a line from point (x1,y1) to point (x2, y2).

drawText(x, y, TEXT): Writes string TEXT starting at point x,y. The font is very small.

drawPixel(x,y,color): Sets the pixel at position x,y to color color. color is a r,g,b value, so setting the pixel at (5,5) to red would look like pic.drawPixel(5,5, (255,0,0)).

Using the Pen

setPosition(x,y), getPostion(), setPenX(x), setPenY(y): Move the pen to x,y. getPosition will return the current pen position.

rotate(theta), setDirection(theta), getDirection(): Changes the direction the pen will move. rotate adds theta degrees to the angle of the pen, setDirection sets the angle to theta degrees, and getDirection() returns the current angle.

drawForward(distance): Draws a line of length distance from the current pen position, at the current pen angle.

setPenWidth(width), getPenWidth(): Sets the width of the line drawn by the pen. getPenWidth returns the current width.

Reading and Writing Individual Pixels

getPixelRed(x,y), getPixelGreen(x,y), getPixelBlue(x,y): These return the red, green, and blue color values for pixel (x,y).

setPixelRed(x,y,r), setPixelGreen(x,y,g), setPixelBlue(x,y,b): These chanage the red, green, or blue color values for pixel (x,y) to r, g, or b.

Settings and Utility Functions

setFillColor(r,g,b), setOutlineColor(r,g,b), setPenColor(r,g,b): Sets the appropriate color to the r,g,b value

getWidth(), getHeight(): These return the dimensions of the picture.

setTitle(s): This writes string s in the menu bar at the topo of the picture.

display(): This will update the canvas with whatever you have drawn.

writeFile(fileName): This writes the currrent image to a flile with the given name. The name should end in ".bmp".

delay(millisecond): This will wait millisecond milliseconds before it does anything. This may be useful for animations.

C. Taylor, R. Geitz