doc_content
stringlengths
1
386k
doc_id
stringlengths
5
188
pygame.gfxdraw.pixel() draw a pixel pixel(surface, x, y, color) -> None Draws a single pixel, at position (x ,y), on the given surface. Parameters: surface (Surface) -- surface to draw on x (int) -- x coordinate of the pixel y (int) -- y coordinate of the pixel color (Color or tuple(int, int, int, [int]))...
pygame.ref.gfxdraw#pygame.gfxdraw.pixel
pygame.gfxdraw.polygon() draw a polygon polygon(surface, points, color) -> None Draws an unfilled polygon on the given surface. For a filled polygon use filled_polygon(). The adjacent coordinates in the points argument, as well as the first and last points, will be connected by line segments. e.g. For the points [(x...
pygame.ref.gfxdraw#pygame.gfxdraw.polygon
pygame.gfxdraw.rectangle() draw a rectangle rectangle(surface, rect, color) -> None Draws an unfilled rectangle on the given surface. For a filled rectangle use box(). Parameters: surface (Surface) -- surface to draw on rect (Rect) -- rectangle to draw, position and dimensions color (Color or tuple(int, in...
pygame.ref.gfxdraw#pygame.gfxdraw.rectangle
pygame.gfxdraw.textured_polygon() draw a textured polygon textured_polygon(surface, points, texture, tx, ty) -> None Draws a textured polygon on the given surface. For better performance, the surface and the texture should have the same format. A per-pixel alpha texture blit to a per-pixel alpha surface will differ ...
pygame.ref.gfxdraw#pygame.gfxdraw.textured_polygon
pygame.gfxdraw.trigon() draw a trigon/triangle trigon(surface, x1, y1, x2, y2, x3, y3, color) -> None Draws an unfilled trigon (triangle) on the given surface. For a filled trigon use filled_trigon(). A trigon can also be drawn using polygon() e.g. polygon(surface, ((x1, y1), (x2, y2), (x3, y3)), color) Paramet...
pygame.ref.gfxdraw#pygame.gfxdraw.trigon
pygame.gfxdraw.vline() draw a vertical line vline(surface, x, y1, y2, color) -> None Draws a straight vertical line ((x, y1) to (x, y2)) on the given surface. There are no endcaps. Parameters: surface (Surface) -- surface to draw on x (int) -- x coordinate of the line y1 (int) -- y coordinate of one end of...
pygame.ref.gfxdraw#pygame.gfxdraw.vline
pygame.image pygame module for image transfer The image module contains functions for loading and saving pictures, as well as transferring Surfaces to formats usable by other packages. Note that there is no Image class; an image is loaded as a Surface object. The Surface class allows manipulation (drawing lines, s...
pygame.ref.image
pygame.image.frombuffer() create a new Surface that shares data inside a bytes buffer frombuffer(bytes, size, format) -> Surface Create a new Surface that shares pixel data directly from a bytes buffer. This method takes similar arguments to pygame.image.fromstring(), but is unable to vertically flip the source data...
pygame.ref.image#pygame.image.frombuffer
pygame.image.fromstring() create new Surface from a string buffer fromstring(string, size, format, flipped=False) -> Surface This function takes arguments similar to pygame.image.tostring(). The size argument is a pair of numbers representing the width and height. Once the new Surface is created you can destroy the ...
pygame.ref.image#pygame.image.fromstring
pygame.image.get_extended() test if extended image formats can be loaded get_extended() -> bool If pygame is built with extended image formats this function will return True. It is still not possible to determine which formats will be available, but generally you will be able to load them all.
pygame.ref.image#pygame.image.get_extended
pygame.image.get_sdl_image_version() get version number of the SDL_Image library being used get_sdl_image_version() -> None get_sdl_image_version() -> (major, minor, patch) If pygame is built with extended image formats, then this function will return the SDL_Image library's version number as a tuple of 3 integers (...
pygame.ref.image#pygame.image.get_sdl_image_version
pygame.image.load() load new image from a file (or file-like object) load(filename) -> Surface load(fileobj, namehint="") -> Surface Load an image from a file source. You can pass either a filename or a Python file-like object. Pygame will automatically determine the image type (e.g., GIF or bitmap) and create a new...
pygame.ref.image#pygame.image.load
pygame.image.load_basic() load new BMP image from a file (or file-like object) load_basic(file) -> Surface Load an image from a file source. You can pass either a filename or a Python file-like object. This function only supports loading "basic" image format, ie BMP format. This function is always available, no matt...
pygame.ref.image#pygame.image.load_basic
pygame.image.load_extended() load an image from a file (or file-like object) load_extended(filename) -> Surface load_extended(fileobj, namehint="") -> Surface This function is similar to pygame.image.load(), except that this function can only be used if pygame was built with extended image format support. From versi...
pygame.ref.image#pygame.image.load_extended
pygame.image.save() save an image to file (or file-like object) save(Surface, filename) -> None save(Surface, fileobj, namehint="") -> None This will save your Surface as either a BMP, TGA, PNG, or JPEG image. If the filename extension is unrecognized it will default to TGA. Both TGA, and BMP file formats create unc...
pygame.ref.image#pygame.image.save
pygame.image.save_extended() save a png/jpg image to file (or file-like object) save_extended(Surface, filename) -> None save_extended(Surface, fileobj, namehint="") -> None This will save your Surface as either a PNG or JPEG image. Incase the image is being saved to a file-like object, this function uses the namehi...
pygame.ref.image#pygame.image.save_extended
pygame.image.tostring() transfer image to string buffer tostring(Surface, format, flipped=False) -> string Creates a string that can be transferred with the 'fromstring' method in other Python imaging packages. Some Python image packages prefer their images in bottom-to-top format (PyOpenGL for example). If you pass...
pygame.ref.image#pygame.image.tostring
pygame.init() initialize all imported pygame modules init() -> (numpass, numfail) Initialize all imported pygame modules. No exceptions will be raised if a module fails, but the total number if successful and failed inits will be returned as a tuple. You can always initialize individual modules manually, but pygame....
pygame.ref.pygame#pygame.init
pygame.joystick Pygame module for interacting with joysticks, gamepads, and trackballs. The joystick module manages the joystick devices on a computer. Joystick devices include trackballs and video-game-style gamepads, and the module allows the use of multiple buttons and "hats". Computers may manage multiple joys...
pygame.ref.joystick
pygame.joystick.get_count() Returns the number of joysticks. get_count() -> count Return the number of joystick devices on the system. The count will be 0 if there are no joysticks on the system. When you create Joystick objects using Joystick(id), you pass an integer that must be lower than this count.
pygame.ref.joystick#pygame.joystick.get_count
pygame.joystick.get_init() Returns True if the joystick module is initialized. get_init() -> bool Test if the pygame.joystick.init() function has been called.
pygame.ref.joystick#pygame.joystick.get_init
pygame.joystick.init() Initialize the joystick module. init() -> None This function is called automatically by pygame.init(). It initializes the joystick module. The module must be initialized before any other functions will work. It is safe to call this function more than once.
pygame.ref.joystick#pygame.joystick.init
pygame.joystick.Joystick Create a new Joystick object. Joystick(id) -> Joystick Create a new joystick to access a physical device. The id argument must be a value from 0 to pygame.joystick.get_count() - 1. Joysticks are initialised on creation and are shut down when deallocated. Once the device is initialized the py...
pygame.ref.joystick#pygame.joystick.Joystick
get_axis() get the current position of an axis get_axis(axis_number) -> float Returns the current position of a joystick axis. The value will range from -1 to 1 with a value of 0 being centered. You may want to take into account some tolerance to handle jitter, and joystick drift may keep the joystick from centering...
pygame.ref.joystick#pygame.joystick.Joystick.get_axis
get_ball() get the relative position of a trackball get_ball(ball_number) -> x, y Returns the relative movement of a joystick button. The value is a x, y pair holding the relative movement since the last call to get_ball. The ball number must be an integer from 0 to get_numballs() - 1.
pygame.ref.joystick#pygame.joystick.Joystick.get_ball
get_button() get the current button state get_button(button) -> bool Returns the current state of a joystick button.
pygame.ref.joystick#pygame.joystick.Joystick.get_button
get_guid() → str get the joystick GUID get_guid() -> str Get the GUID string. This identifies the exact hardware of the joystick device. New in pygame 2.0.0dev11.
pygame.ref.joystick#pygame.joystick.Joystick.get_guid
get_hat() get the position of a joystick hat get_hat(hat_number) -> x, y Returns the current position of a position hat. The position is given as two values representing the x and y position for the hat. (0, 0) means centered. A value of -1 means left/down and a value of 1 means right/up: so (-1, 0) means left; (1, ...
pygame.ref.joystick#pygame.joystick.Joystick.get_hat
get_id() get the device index (deprecated) get_id() -> int Returns the original device index for this device. This is the same value that was passed to the Joystick() constructor. This method can safely be called while the Joystick is not initialized. Deprecated since pygame 2.0.0: The original device index is not ...
pygame.ref.joystick#pygame.joystick.Joystick.get_id
get_init() check if the Joystick is initialized get_init() -> bool Return True if the Joystick object is currently initialised.
pygame.ref.joystick#pygame.joystick.Joystick.get_init
get_instance_id() → int get the joystick instance id get_instance_id() -> int Get the joystick instance ID. This matches the instance_id field that is given in joystick events. New in pygame 2.0.0dev11.
pygame.ref.joystick#pygame.joystick.Joystick.get_instance_id
get_name() get the Joystick system name get_name() -> string Returns the system name for this joystick device. It is unknown what name the system will give to the Joystick, but it should be a unique name that identifies the device. This method can safely be called while the Joystick is not initialized.
pygame.ref.joystick#pygame.joystick.Joystick.get_name
get_numaxes() get the number of axes on a Joystick get_numaxes() -> int Returns the number of input axes are on a Joystick. There will usually be two for the position. Controls like rudders and throttles are treated as additional axes. The pygame.JOYAXISMOTION events will be in the range from -1.0 to 1.0. A value of...
pygame.ref.joystick#pygame.joystick.Joystick.get_numaxes
get_numballs() get the number of trackballs on a Joystick get_numballs() -> int Returns the number of trackball devices on a Joystick. These devices work similar to a mouse but they have no absolute position; they only have relative amounts of movement. The pygame.JOYBALLMOTION event will be sent when the trackball ...
pygame.ref.joystick#pygame.joystick.Joystick.get_numballs
get_numbuttons() get the number of buttons on a Joystick get_numbuttons() -> int Returns the number of pushable buttons on the joystick. These buttons have a boolean (on or off) state. Buttons generate a pygame.JOYBUTTONDOWN and pygame.JOYBUTTONUP event when they are pressed and released.
pygame.ref.joystick#pygame.joystick.Joystick.get_numbuttons
get_numhats() get the number of hat controls on a Joystick get_numhats() -> int Returns the number of joystick hats on a Joystick. Hat devices are like miniature digital joysticks on a joystick. Each hat has two axes of input. The pygame.JOYHATMOTION event is generated when the hat changes position. The position att...
pygame.ref.joystick#pygame.joystick.Joystick.get_numhats
get_power_level() → str get the approximate power status of the device get_power_level() -> str Get a string giving the power status of the device. One of: empty, low, medium, full, wired, max, or unknown. New in pygame 2.0.0dev11.
pygame.ref.joystick#pygame.joystick.Joystick.get_power_level
init() initialize the Joystick init() -> None Initialize the joystick, if it has been closed. It is safe to call this even if the joystick is already initialized. Deprecated since pygame 2.0.0: In future it will not be possible to reinitialise a closed Joystick object. Will be removed in Pygame 2.1.
pygame.ref.joystick#pygame.joystick.Joystick.init
quit() uninitialize the Joystick quit() -> None Close a Joystick object. After this the pygame event queue will no longer receive events from the device. It is safe to call this more than once.
pygame.ref.joystick#pygame.joystick.Joystick.quit
pygame.joystick.quit() Uninitialize the joystick module. quit() -> None Uninitialize the joystick module. After you call this any existing joystick objects will no longer work. It is safe to call this function more than once.
pygame.ref.joystick#pygame.joystick.quit
pygame.key pygame module to work with the keyboard This module contains functions for dealing with the keyboard. The pygame.event queue gets pygame.KEYDOWN and pygame.KEYUP events when the keyboard buttons are pressed and released. Both events have key and mod attributes. key: an integer ID representing every ...
pygame.ref.key
pygame.key.get_focused() true if the display is receiving keyboard input from the system get_focused() -> bool Returns True when the display window has keyboard focus from the system. If the display needs to ensure it does not lose keyboard focus, it can use pygame.event.set_grab() to grab all input.
pygame.ref.key#pygame.key.get_focused
pygame.key.get_mods() determine which modifier keys are being held get_mods() -> int Returns a single integer representing a bitmask of all the modifier keys being held. Using bitwise operators you can test if specific modifier keys are pressed.
pygame.ref.key#pygame.key.get_mods
pygame.key.get_pressed() get the state of all keyboard buttons get_pressed() -> bools Returns a sequence of boolean values representing the state of every key on the keyboard. Use the key constant values to index the array. A True value means the that button is pressed. Note Getting the list of pushed buttons with ...
pygame.ref.key#pygame.key.get_pressed
pygame.key.get_repeat() see how held keys are repeated get_repeat() -> (delay, interval) Get the delay and interval keyboard repeat values. Refer to pygame.key.set_repeat() for a description of these values. New in pygame 1.8.
pygame.ref.key#pygame.key.get_repeat
pygame.key.key_code() get the key identifier from a key name key_code(name=string) -> int Get the key identifier code from the descriptive name of the key. This returns an integer matching one of the K_* keycodes. For example: >>> pygame.key.key_code("return") == pygame.K_RETURN True >>> pygame.key.key_code("0") == ...
pygame.ref.key#pygame.key.key_code
pygame.key.name() get the name of a key identifier name(key) -> string Get the descriptive name of the button from a keyboard button id constant.
pygame.ref.key#pygame.key.name
pygame.key.set_mods() temporarily set which modifier keys are pressed set_mods(int) -> None Create a bitmask of the modifier key constants you want to impose on your program.
pygame.ref.key#pygame.key.set_mods
pygame.key.set_repeat() control how held keys are repeated set_repeat() -> None set_repeat(delay) -> None set_repeat(delay, interval) -> None When the keyboard repeat is enabled, keys that are held down will generate multiple pygame.KEYDOWN events. The delay parameter is the number of milliseconds before the first r...
pygame.ref.key#pygame.key.set_repeat
pygame.key.set_text_input_rect() controls the position of the candidate list set_text_input_rect(Rect) -> None This sets the rectangle used for typing with an IME. It controls where the candidate list will open, if supported. New in pygame 2.0.0.
pygame.ref.key#pygame.key.set_text_input_rect
pygame.key.start_text_input() start handling Unicode text input events start_text_input() -> None Start receiving pygame.TEXTEDITING and pygame.TEXTINPUT events. A pygame.TEXTEDITING event is received when an IME composition is started or changed. It contains the composition text, length, and editing start position ...
pygame.ref.key#pygame.key.start_text_input
pygame.key.stop_text_input() stop handling Unicode text input events stop_text_input() -> None Stop receiving pygame.TEXTEDITING and pygame.TEXTINPUT events. Text input events handling is on by default New in pygame 2.0.0.
pygame.ref.key#pygame.key.stop_text_input
pygame.locals pygame constants This module contains various constants used by pygame. Its contents are automatically placed in the pygame module namespace. However, an application can use pygame.locals to include only the pygame constants with a from pygame.locals import *. Detailed descriptions of the various con...
pygame.ref.locals
pygame.mask pygame module for image masks. Useful for fast pixel perfect collision detection. A mask uses 1 bit per-pixel to store which parts collide. New in pygame 1.8. pygame.mask.from_surface() Creates a Mask from the given surface from_surface(Surface) -> Mask from_surface(Surface, threshold=127) -> Mas...
pygame.ref.mask
pygame.mask.from_surface() Creates a Mask from the given surface from_surface(Surface) -> Mask from_surface(Surface, threshold=127) -> Mask Creates a Mask object from the given surface by setting all the opaque pixels and not setting the transparent pixels. If the surface uses a color-key, then it is used to decide ...
pygame.ref.mask#pygame.mask.from_surface
pygame.mask.from_threshold() Creates a mask by thresholding Surfaces from_threshold(Surface, color) -> Mask from_threshold(Surface, color, threshold=(0, 0, 0, 255), othersurface=None, palette_colors=1) -> Mask This is a more featureful method of getting a Mask from a surface. If the optional othersurface is not used...
pygame.ref.mask#pygame.mask.from_threshold
pygame.mask.Mask pygame object for representing 2D bitmasks Mask(size=(width, height)) -> Mask Mask(size=(width, height), fill=False) -> Mask A Mask object is used to represent a 2D bitmask. Each bit in the mask represents a pixel. 1 is used to indicate a set bit and 0 is used to indicate an unset bit. Set bits in a...
pygame.ref.mask#pygame.mask.Mask
angle() Returns the orientation of the set bits angle() -> theta Finds the approximate orientation (from -90 to 90 degrees) of the set bits in the mask. This works best if performed on a mask with only one connected component. Returns: the orientation of the set bits in the mask, it will return 0.0 if the mask ...
pygame.ref.mask#pygame.mask.Mask.angle
centroid() Returns the centroid of the set bits centroid() -> (x, y) Finds the centroid (the center mass of the set bits) for this mask. Returns: a coordinate tuple indicating the centroid of the mask, it will return (0, 0) if the mask has no bits set Return type: tuple(int, int)
pygame.ref.mask#pygame.mask.Mask.centroid
clear() Sets all bits to 0 clear() -> None Sets all bits in the mask to 0. Returns: None Return type: NoneType
pygame.ref.mask#pygame.mask.Mask.clear
connected_component() Returns a mask containing a connected component connected_component() -> Mask connected_component((x, y)) -> Mask A connected component is a group (1 or more) of connected set bits (orthogonally and diagonally). The SAUF algorithm, which checks 8 point connectivity, is used to find a connected ...
pygame.ref.mask#pygame.mask.Mask.connected_component
connected_components() Returns a list of masks of connected components connected_components() -> [Mask, ...] connected_components(min=0) -> [Mask, ...] Provides a list containing a Mask object for each connected component. Parameters: min (int) -- (optional) indicates the minimum number of bits (to filter out ...
pygame.ref.mask#pygame.mask.Mask.connected_components
convolve() Returns the convolution of this mask with another mask convolve(othermask) -> Mask convolve(othermask, outputmask=None, offset=(0, 0)) -> Mask Convolve this mask with the given othermask. Parameters: othermask (Mask) -- mask to convolve this mask with outputmask (Mask or NoneType) -- (optional) m...
pygame.ref.mask#pygame.mask.Mask.convolve
copy() Returns a new copy of the mask copy() -> Mask Returns: a new copy of this mask, the new mask will have the same width, height, and set/unset bits as the original Return type: Mask Note If a mask subclass needs to copy any instance specific attributes then it should override the __copy__() method. T...
pygame.ref.mask#pygame.mask.Mask.copy
count() Returns the number of set bits count() -> bits Returns: the number of set bits in the mask Return type: int
pygame.ref.mask#pygame.mask.Mask.count
draw() Draws a mask onto another draw(othermask, offset) -> None Performs a bitwise OR, drawing othermask onto this mask. Parameters: othermask (Mask) -- the mask to draw onto this mask offset (tuple(int, int) or list[int, int]) -- the offset of othermask from this mask, for more details refer to the Mask o...
pygame.ref.mask#pygame.mask.Mask.draw
erase() Erases a mask from another erase(othermask, offset) -> None Erases (clears) all bits set in othermask from this mask. Parameters: othermask (Mask) -- the mask to erase from this mask offset (tuple(int, int) or list[int, int]) -- the offset of othermask from this mask, for more details refer to the M...
pygame.ref.mask#pygame.mask.Mask.erase
fill() Sets all bits to 1 fill() -> None Sets all bits in the mask to 1. Returns: None Return type: NoneType
pygame.ref.mask#pygame.mask.Mask.fill
get_at() Gets the bit at the given position get_at((x, y)) -> int Parameters: pos (tuple(int, int) or list[int, int]) -- the position of the bit to get Returns: 1 if the bit is set, 0 if the bit is not set Return type: int Raises: IndexError -- if the position is outside of the mask's bounds
pygame.ref.mask#pygame.mask.Mask.get_at
get_bounding_rects() Returns a list of bounding rects of connected components get_bounding_rects() -> [Rect, ...] Provides a list containing a bounding rect for each connected component. Returns: a list containing a bounding rect for each connected component, an empty list is returned if the mask has no bits se...
pygame.ref.mask#pygame.mask.Mask.get_bounding_rects
get_rect() Returns a Rect based on the size of the mask get_rect(**kwargs) -> Rect Returns a new pygame.Rect() object based on the size of this mask. The rect's default position will be (0, 0) and its default width and height will be the same as this mask's. The rect's attributes can be altered via pygame.Rect() att...
pygame.ref.mask#pygame.mask.Mask.get_rect
get_size() Returns the size of the mask get_size() -> (width, height) Returns: the size of the mask, (width, height) Return type: tuple(int, int)
pygame.ref.mask#pygame.mask.Mask.get_size
invert() Flips all the bits invert() -> None Flips all of the bits in the mask. All the set bits are cleared to 0 and all the unset bits are set to 1. Returns: None Return type: NoneType
pygame.ref.mask#pygame.mask.Mask.invert
outline() Returns a list of points outlining an object outline() -> [(x, y), ...] outline(every=1) -> [(x, y), ...] Returns a list of points of the outline of the first connected component encountered in the mask. To find a connected component, the mask is searched per row (left to right) starting in the top left co...
pygame.ref.mask#pygame.mask.Mask.outline
overlap() Returns the point of intersection overlap(othermask, offset) -> (x, y) overlap(othermask, offset) -> None Returns the first point of intersection encountered between this mask and othermask. A point of intersection is 2 overlapping set bits. The current algorithm searches the overlapping area in sizeof(uns...
pygame.ref.mask#pygame.mask.Mask.overlap
overlap_area() Returns the number of overlapping set bits overlap_area(othermask, offset) -> numbits Returns the number of overlapping set bits between between this mask and othermask. This can be useful for collision detection. An approximate collision normal can be found by calculating the gradient of the overlapp...
pygame.ref.mask#pygame.mask.Mask.overlap_area
overlap_mask() Returns a mask of the overlapping set bits overlap_mask(othermask, offset) -> Mask Returns a Mask, the same size as this mask, containing the overlapping set bits between this mask and othermask. Parameters: othermask (Mask) -- the other mask to overlap with this mask offset (tuple(int, int) ...
pygame.ref.mask#pygame.mask.Mask.overlap_mask
scale() Resizes a mask scale((width, height)) -> Mask Creates a new Mask of the requested size with its bits scaled from this mask. Parameters: size (tuple(int, int) or list[int, int]) -- the width and height (size) of the mask to create Returns: a new Mask object with its bits scaled from this mask Return...
pygame.ref.mask#pygame.mask.Mask.scale
set_at() Sets the bit at the given position set_at((x, y)) -> None set_at((x, y), value=1) -> None Parameters: pos (tuple(int, int) or list[int, int]) -- the position of the bit to set value (int) -- any nonzero int will set the bit to 1, 0 will set the bit to 0 (default is 1) Returns: None Return t...
pygame.ref.mask#pygame.mask.Mask.set_at
to_surface() Returns a surface with the mask drawn on it to_surface() -> Surface to_surface(surface=None, setsurface=None, unsetsurface=None, setcolor=(255, 255, 255, 255), unsetcolor=(0, 0, 0, 255), dest=(0, 0)) -> Surface Draws this mask on the given surface. Set bits (bits set to 1) and unset bits (bits set to 0)...
pygame.ref.mask#pygame.mask.Mask.to_surface
pygame.math pygame module for vector classes The pygame math module currently provides Vector classes in two and three dimensions, Vector2 and Vector3 respectively. They support the following numerical operations: vec+vec, vec-vec, vec*number, number*vec, vec/number, vec//number, vec+=vec, vec-=vec, vec*=number, v...
pygame.ref.math
pygame.math.disable_swizzling() globally disables swizzling for vectors. disable_swizzling() -> None DEPRECATED: Not needed anymore. Will be removed in a later version. Disables swizzling for all vectors until enable_swizzling() is called. By default swizzling is disabled.
pygame.ref.math#pygame.math.disable_swizzling
pygame.math.enable_swizzling() globally enables swizzling for vectors. enable_swizzling() -> None DEPRECATED: Not needed anymore. Will be removed in a later version. Enables swizzling for all vectors until disable_swizzling() is called. By default swizzling is disabled. Lets you get or set multiple coordinates as on...
pygame.ref.math#pygame.math.enable_swizzling
pygame.math.Vector2 a 2-Dimensional Vector Vector2() -> Vector2 Vector2(int) -> Vector2 Vector2(float) -> Vector2 Vector2(Vector2) -> Vector2 Vector2(x, y) -> Vector2 Vector2((x, y)) -> Vector2 Some general information about the Vector2 class. dot() calculates the dot- or scalar-product with the other vector dot...
pygame.ref.math#pygame.math.Vector2
angle_to() calculates the angle to a given vector in degrees. angle_to(Vector2) -> float Returns the angle between self and the given vector.
pygame.ref.math#pygame.math.Vector2.angle_to
as_polar() returns a tuple with radial distance and azimuthal angle. as_polar() -> (r, phi) Returns a tuple (r, phi) where r is the radial distance, and phi is the azimuthal angle.
pygame.ref.math#pygame.math.Vector2.as_polar
cross() calculates the cross- or vector-product cross(Vector2) -> Vector2 calculates the third component of the cross-product.
pygame.ref.math#pygame.math.Vector2.cross
distance_squared_to() calculates the squared Euclidean distance to a given vector. distance_squared_to(Vector2) -> float
pygame.ref.math#pygame.math.Vector2.distance_squared_to
distance_to() calculates the Euclidean distance to a given vector. distance_to(Vector2) -> float
pygame.ref.math#pygame.math.Vector2.distance_to
dot() calculates the dot- or scalar-product with the other vector dot(Vector2) -> float
pygame.ref.math#pygame.math.Vector2.dot
elementwise() The next operation will be performed elementwise. elementwise() -> VectorElementwiseProxy Applies the following operation to each element of the vector.
pygame.ref.math#pygame.math.Vector2.elementwise
from_polar() Sets x and y from a polar coordinates tuple. from_polar((r, phi)) -> None Sets x and y from a tuple (r, phi) where r is the radial distance, and phi is the azimuthal angle.
pygame.ref.math#pygame.math.Vector2.from_polar
is_normalized() tests if the vector is normalized i.e. has length == 1. is_normalized() -> Bool Returns True if the vector has length equal to 1. Otherwise it returns False.
pygame.ref.math#pygame.math.Vector2.is_normalized
length() returns the Euclidean length of the vector. length() -> float calculates the Euclidean length of the vector which follows from the Pythagorean theorem: vec.length() == math.sqrt(vec.x**2 + vec.y**2)
pygame.ref.math#pygame.math.Vector2.length
length_squared() returns the squared Euclidean length of the vector. length_squared() -> float calculates the Euclidean length of the vector which follows from the Pythagorean theorem: vec.length_squared() == vec.x**2 + vec.y**2. This is faster than vec.length() because it avoids the square root.
pygame.ref.math#pygame.math.Vector2.length_squared
lerp() returns a linear interpolation to the given vector. lerp(Vector2, float) -> Vector2 Returns a Vector which is a linear interpolation between self and the given Vector. The second parameter determines how far between self and other the result is going to be. It must be a value between 0 and 1 where 0 means sel...
pygame.ref.math#pygame.math.Vector2.lerp
magnitude() returns the Euclidean magnitude of the vector. magnitude() -> float calculates the magnitude of the vector which follows from the theorem: vec.magnitude() == math.sqrt(vec.x**2 + vec.y**2)
pygame.ref.math#pygame.math.Vector2.magnitude
magnitude_squared() returns the squared magnitude of the vector. magnitude_squared() -> float calculates the magnitude of the vector which follows from the theorem: vec.magnitude_squared() == vec.x**2 + vec.y**2. This is faster than vec.magnitude() because it avoids the square root.
pygame.ref.math#pygame.math.Vector2.magnitude_squared
normalize() returns a vector with the same direction but length 1. normalize() -> Vector2 Returns a new vector that has length equal to 1 and the same direction as self.
pygame.ref.math#pygame.math.Vector2.normalize
normalize_ip() normalizes the vector in place so that its length is 1. normalize_ip() -> None Normalizes the vector so that it has length equal to 1. The direction of the vector is not changed.
pygame.ref.math#pygame.math.Vector2.normalize_ip