How to Think Like a Computer Scientist: Learning with Python 2nd Edition/GASP
Graphics API for Students of Python: GASPEdit
Describe gasp here...
(0, 0) is at the bottom left of the window. The window is 640 pixels by 480, by default. (You can make it a different size if you want to.) Coordinates are given in units of one pixel.
All functions that take coordinates take them as a tuple (x, y).
To access the color module GASP has to offer. Call color.* where * is the color you wish to call. For example: ` color.BLACK ` This is the color black. Check out the gasp color refrence chart to see all of the available color options.
These are the essentials. ` from gasp import * ` imports the gasp module, begin_graphics() starts the graphics window, and end_graphics() quits the graphics window and ends the program. It's dead simple, but also dead necessary.
This creates a graphics window with the dimensions 800x600, a title of My Game , and a background color of yellow. With no arguments you get a white 640x480 graphics window titled Gasp .
- The width of the window in pixels.
- The windows height in pixels.
- A string that will be the title of the window.
- It is the background of the graphics window. It can either be a color or an image
Ends a graphics window.
Clears everything off of the graphics window. It looks like a new graphcs window as if you just called begin_graphics().
removes those objects from the screen
- A screen object of a list of screen_objects you would like to remove from the screen
The objects that you will be displayed in your graphics window. You can manipulate these objects using the screen object methods
It puts a dot on the screen.
- The coordinate on the screen that you wish to plot.
- The color you wish the dot to be.
- An integer that determines the size the of the dot
Creates a line on the screen.
- The starting coordinate of the line.
- The coordinate at which the line will end.
- The color of the line
This creates a Box on the screen
- A coordinate where the center of your box will be.
- The width in pixels of the box.
- The height of the box in pixels.
- A boolean value that determines if your box will be filled
- The color of your box.
- The thickness in pixels of your box's lines.
Creates a polygon on the screen
- A list of coordinates that is each point on the polygon. The must be more than two items in the list
- A boolean value. If it is False the polygon will not be filled. Else, the polygon will not be filled
- The color of the polygon's lines
- An integer that determines the thickness of the lines.
Draws a circle, its center is a set of coordinates, and the radius is in pixels. It defaults to not being filled and the color black.
- The circle's center coordinate.
- An integer that is the radius of the circle
- A boolean value that determines if your circle will be filled
- The color of your circle.
- The thickness in pixels of the circles lines.
Creates an arc on the screen.
- A coordinate that is the center of the arc.
- An integer that is the distance between the center and the outer edge of the arc.
- The start angle in degrees of the arc
- The end angle in degrees of your arc
- A boolean value that if True it fills the arc
- The color the arc
- The thickness in pixels of the arc
Puts an oval on the screen wherever you want.
- The center coordinate of the Oval
- The width in pixels of the oval
- The height of the oval in pixels
- A boolean value determining if the oval will be filles or not.
- The oval's color
- The thickness of the ovals lines
Loads an image onto the screen. If you only pass a width and not a height it automatically scales the height to fit the width you passed it. It behaves likewise when you pass just a height.
- The path to the image
- The center coordinates of the image
- The width of the image in pixels. If width equals None then it defaults to the image file's width
- The height of the image in pixels. If no height is passed it defaults to the image file's height
Screen Object MethodsEdit
The methods that manipulates screen objects
Move a screen object to a pos
- A screen object you wish to move.
- The coordinate on the screen that the object will move to
Move a screen object relative to it's position
- The screen object you wish to move
- How much the object will move in the 'x' direction. Positive or negative.
- How much the object will move in the 'y' direction. A pixel value.
Rotate an object to an angle
- The screen object that will be rotated
- The angle in degrees that the object will be rotated to
Rotate an object a certain degree.
- The screen object you wish to rotate
- The degree that the object will be rotate. Can be positive or negative.
Puts text on the screen
- A string of the text that will be displayed
- The center coordinate of the text
- The color of the text
- The font size
Returns the current mouse coordinate
returns a dictionary of the buttons state. There is a 'left', 'middle', and 'right' key.
returns a list of all of the keys pressed at that moment.
Saves a screenshot of the current graphics screen to a png file.
- The file path relative to the current directory that the image will be written to.