Defines how the width and height of an element are calculated: The pixel format is surface specific.
Lock the pixel data of a Surface for access. On accelerated Surfaces, the pixel data may be stored in volatile video memory or nonlinear compressed forms. When a Surface is locked the pixel memory becomes available to access by regular software. Code that reads or writes pixel values will need the Surface to be locked. Surfaces should not remain locked for more than necessary. A locked Surface can often not be displayed or managed by pygame.
Not all Surfaces require locking. There is no performance penalty for locking and unlocking a Surface that does not need it. All pygame functions will automatically lock and unlock the Surface data as needed. If a section of code is going to make calls that will repeatedly lock and unlock the Surface many times, it can be helpful to wrap the block inside a lock and unlock pair.
It is safe to nest locking and unlocking calls. The surface will only be unlocked after the final lock is released. Unlock the Surface pixel data after it has been locked. The unlocked Surface can once again be drawn and managed by pygame. Returns True if the Surface is required to be locked to access pixel data. Usually pure software Surfaces do not require locking. This method is rarely needed, since it is safe and quickest to just lock all Surfaces as needed. If the Surface has no per pixel alpha, then the alpha value will always be opaque.
If the pixel position is outside the area of the Surface an IndexError exception will be raised. Getting and setting pixels one at a time is generally too slow to be used in a game or realtime situation.
Returning a Color instead of tuple, New in pygame 1. This should only matter if you want to use the color as a key in a dict. Set the RGBA or mapped integer color value for a single pixel.
If the Surface does not have per pixel alphas, the alpha value is ignored. Setting pixels outside the Surface area or outside the Surface clipping will have no effect. Return the integer value of the given pixel. Return a list of up to color elements that represent the indexed colors used in an 8-bit Surface.
The returned list is a copy of the palette, and changes will have no effect on the Surface. Returning a list of Color with length 3 instances instead of tuples, New in pygame 1.
Returns the red, green, and blue color values for a single index in a Surface palette. The index should be a value from 0 to Returning Color with length 3 instance instead of a tuple, New in pygame 1. Set the full palette for an 8-bit Surface. This will replace the colors in the existing palette. A partial palette can be passed and only the first colors in the original palette will be changed. Set the palette value for a single entry in a Surface palette.
The returned integer will contain no more bits than the bit depth of the Surface. Mapped color values are not often used inside pygame, but can be passed to most functions that require a Surface and a color. Convert an mapped integer color into the RGB color components for this Surface. Each Surface has an active clipping area. This is a rectangle that represents the only pixels on the Surface that can be modified. If None is passed for the rectangle the full Surface will be available for changes.
The clipping area is always restricted to the area of the Surface itself. If the clip rectangle is too large it will be shrunk to fit inside the Surface. Return a rectangle of the current clipping area. The Surface will always return a valid rectangle that will never be outside the bounds of the image. If the Surface has had None set for the clipping area, the Surface will return a rectangle with the full area of the Surface.
Returns a new Surface that shares its pixels with its new parent. The new Surface is considered a child of the original. Modifications to either Surface pixels will effect each other. Surface information like clipping area and color keys are unique to each Surface.
It is possible to have any number of subsurfaces and subsubsurfaces on the parent. It is also possible to subsurface the display Surface if the display mode is not hardware accelerated. Returns the parent Surface of a subsurface. If this is not a subsurface then None will be returned. If this is not a subsurface then this surface will be returned.
Get the offset position of a child subsurface inside of a parent. If the Surface is not a subsurface this will return 0, 0.
Get the offset position of a child subsurface inside of its top level parent Surface. Returns a new rectangle covering the entire surface. This rectangle will always start at 0, 0 with a width. You can pass keyword argument values to this function. These named values will be applied to the attributes of the Rect before it is returned. An example would be 'mysurf.
Returns the number of bits used to represent each pixel. This value may not exactly fill the number of bytes used per pixel. For example a 15 bit Surface still requires a full 2 bytes. Returns a set of current Surface features. Each feature is a bit in the flags bitmask. Here is a more complete list of flags.
Return the number of bytes separating each row in the Surface. Surfaces in video memory are not always linearly packed. Subsurfaces will also have a larger pitch than their real width. Returns the smallest rectangular region that contains all the pixels in the surface that have an alpha value greater than or equal to the minimum alpha value.
Return an object which exports a surface's internal pixel buffer as a C level array struct, Python level array interface or a C level buffer interface. The pixel buffer is writeable.
The new buffer protocol is supported for Python 2. The old buffer protocol is also supported for Python 2. The old buffer data is in one segment for kind '0', multi-segment for other buffer view kinds. The kind argument is the length 1 string '0', '1', '2', '3', 'r', 'g', 'b', or 'a'.
The letters are case insensitive; 'A' will work as well. The argument can be either a Unicode or byte char string. The default is '2'.
No surface shape information is given. A ValueError is raised if the surface's pixels are discontinuous. A ValueError is raised if the surface pixels are discontinuous.
The pixels are surface-bytesize-d unsigned integers. The pixel format is surface specific. The 3 byte unsigned integers of 24 bit surfaces are unlikely accepted by anything other than other pygame functions. Each of the red, green, and blue components are unsigned bytes.
Only bit and bit surfaces are supported. Color components are unsigned bytes. Both bit and bit surfaces support 'r', 'g', and 'b'. The surface is locked only when an exposed interface is accessed.
For new buffer interface accesses, the surface is unlocked once the last buffer view is released. For array interface and old buffer interface accesses, the surface remains locked until the BufferProxy object is released. Return a buffer object for the pixels of the Surface. The buffer can be used for direct pixel access and manipulation. Surface pixel data is represented as an unstructured block of memory, with a start address and length in bytes.
The data need not be contiguous. Any gaps are included in the length, but otherwise ignored. This method implicitly locks the Surface. The lock will be released when the returned BufferProxy object is garbage collected. Shift the surface image in place. If the first value is greater than the second, their positions are switched.
Over a number of passes, at most equal to the number of elements in the list, all of the values drift into their correct positions large values "bubble" rapidly toward the end, pushing others down around them. Because each pass finds the maximum item and puts it at the end, the portion of the list to be sorted can be reduced at each pass.
A boolean variable is used to track whether any changes have been made in the current pass; when a pass completes without changing anything, the algorithm exits. Adapted from the above example. Note that it is not possible to return arrays from Awk functions so the array is "edited in place". The extra parameters passed in function's argument list is a well known trick to define local variables. Works with the 1k RAM model. For simplicity, and to make it easy to animate the sort as it is going on, this implementation sorts a string of eight-bit unsigned integers which can be treated as character codes; it could easily be amended to sort an array of numbers or an array of strings, but the array would need to be dimensioned at the start.
This routine uses a couple of 'tricks' to try and mitigate the inefficiency to a limited extent. Note that the array index is assumed to start at zero.
Bubble sorts a Java ArrayList in place. Uses 'doseq' iteration construct with a short-circuit when a pass didn't produce any change, and within the pass, an atomic 'changed' variable that gets reset whenever a change occurs. Here is an implementation that works efficiently for both vectors and lists. For lists it also has the nice property that the input list and the sorted list begin with the same cons cell. This solution is presented in two classes. It iterates across the set printing the elements, then it sorts the set, and reprints the elements.
Therefore, the set can be ordered and in fact is kept so under normal circumstances. It also causes, in the "Before" output, the elements to be printed in the reverse of the order in which they were added.
This would assure that the order was maintained even as elements were added. It is possible to pass your own comparison operator to sort! This is not a complete implementation of bubblesort: Sorts the 'cnt' cells stored at 'addr' using the test stored in the deferred word 'bubble-test'.
Uses forth local variables for clarity. Click this link to run this code. This version checks for changes in a separate step for simplicity, because Haskell has no variables to track them with. This version uses the polymorphic Maybe type to designate unchanged lists. It is slightly faster than the previous one.
This version is based on the above, but avoids sorting the whole list each time. To implement this without a counter and retain using pattern matching, inner sorting is reversed, and then the result is reversed back.
Sorting is based on a predicate, e. For the most part, bubble sort works against J's strengths. Print A print all items, one per column. We can read any item using StackItem , from 1 we can omit number 1 for first item, the top. Stack items can be move very fast, it is a linked list.
It will work with GNU Troff, though. The classical version of TROFF could only do recursive macro calls, which is integral to the functioning of. ASORT ; it could also only support numerical registers with name consisting of two characters maximum, so a register named A9 would be okay 2 characters , but not A 4 characters. Block comments start with. We use an array for this version so that we can update in place.
We could use a C style list as in the C example , but that seemed too easy to confuse with a Nemerle style list. This version uses the polymorphic option type to designate unchanged lists. This version exploits the "Collection Classes" and some other features of the language that are only available in Open Object Rexx. A more "traditional" implementation of version 1 using only Rexx primitive constructs.
This version has been tested with the Open Object Rexx and Regina Rexx interpreters and could equally have been exhibited as a Rexx solution. It's surprisingly easy in Prolog while coding this sort, to accidentally create a sort that is similar, but not identical to the bubble sort algorithm.
Some of these are easier and shorter to code and work as well if not better.