pygame / docs / ref / transform.html

<title>transform - Pygame Documentation</title>
<body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111>

<table cellspacing=3 width=100%><tr><td bgcolor=#00000>
<table width=100%><tr><td bgcolor=c2fc20 align=center>
    <a href=>
    <img src=../pygame_tiny.gif border=0 width=200 height=60></a><br>
</td><td bgcolor=6aee28 align=center valign=top width=100%>

	<a href=>Pygame Home</a> &nbsp;||&nbsp;
	<a href=../index.html>Help Contents</a> &nbsp;||
	<a href=index.html>Reference Index</a> &nbsp;||
<a href=cdrom.html>Cdrom</a>&nbsp;||&nbsp;
<a href=cursors.html>Cursors</a>&nbsp;||&nbsp;
<a href=display.html>Display</a>&nbsp;||&nbsp;
<a href=draw.html>Draw</a>&nbsp;||&nbsp;
<a href=event.html>Event</a>&nbsp;||&nbsp;
<a href=font.html>Font</a>&nbsp;||&nbsp;
<a href=image.html>Image</a>&nbsp;||&nbsp;
<a href=joystick.html>Joystick</a>&nbsp;||&nbsp;
<a href=key.html>Key</a>&nbsp;||&nbsp;
<a href=mixer.html>Mixer</a>&nbsp;||&nbsp;
<a href=mouse.html>Mouse</a>&nbsp;||&nbsp;
<a href=movie.html>Movie</a>&nbsp;||&nbsp;
<a href=music.html>Music</a>&nbsp;||&nbsp;
<a href=overlay.html>Overlay</a>&nbsp;||&nbsp;
<a href=pygame.html>Pygame</a>&nbsp;||&nbsp;
<a href=rect.html>Rect</a>&nbsp;||&nbsp;
<a href=sndarray.html>Sndarray</a>&nbsp;||&nbsp;
<a href=sprite.html>Sprite</a>&nbsp;||&nbsp;
<a href=surface.html>Surface</a>&nbsp;||&nbsp;
<a href=surfarray.html>Surfarray</a>&nbsp;||&nbsp;
<a href=time.html>Time</a>&nbsp;||&nbsp;
<a href=transform.html>Transform</a>


<a name="pygame.transform">
  <i>pygame module to transform surfaces</i><br>
  <tr><td><a href="transform.html#pygame.transform.flip">pygame.transform.flip</a></td><td>flip vertically and horizontally</td></tr>
  <tr><td><a href="transform.html#pygame.transform.scale">pygame.transform.scale</a></td><td>resize to new resolution</td></tr>
  <tr><td><a href="transform.html#pygame.transform.rotate">pygame.transform.rotate</a></td><td>rotate an image</td></tr>
  <tr><td><a href="transform.html#pygame.transform.rotozoom">pygame.transform.rotozoom</a></td><td>filtered scale and rotation</td></tr>
  <tr><td><a href="transform.html#pygame.transform.scale2x">pygame.transform.scale2x</a></td><td>specialized image doubler</td></tr>
  <tr><td><a href="transform.html#pygame.transform.chop">pygame.transform.chop</a></td><td>remove interior area of an image</td></tr>
<p><tt>A</tt> Surface transform is an operation that moves or resizes the pixels. All these functions take a Surface to operate on and return a new Surface with the results. </p>
<p>Some of the transforms are considered destructive. These means every time they are performed they lose pixel data. Common examples of this are resizing and rotating. For this reason, it is better to retransform the original surface than to keep transforming an image multiple times. (For example, suppose you are animating a bouncing spring which expands and contracts. If you applied the size changes incrementally to the previous images, you would lose detail. Instead, always begin with the original image and scale to the desired <tt>size.)</tt> </p>

<a name="pygame.transform.flip">
  <i>flip vertically and horizontally</i><br>
  <tt>pygame.transform.flip(Surface, xbool, ybool): return Surface</tt><br>
<p>This can flip a Surface either vertically, horizontally, or both. Flipping a Surface is nondestructive and returns a new Surface with the same dimensions. </p>

<a name="pygame.transform.scale">
  <i>resize to new resolution</i><br>
  <tt>pygame.transform.scale(Surface, (width, height)): return Surface</tt><br>
<p>Resizes the Surface to a new resolution. This is a fast scale operation that does not sample the results. </p>

<a name="pygame.transform.rotate">
  <i>rotate an image</i><br>
  <tt>pygame.transform.rotate(Surface, angle): return Surface</tt><br>
<p>Unfiltered counterclockwise rotation. The angle argument represents degrees and can be any floating point value. Negative angle amounts will rotate clockwise. </p>
<p>Unless rotating by 90 degree increments, the image will be padded larger to hold the new size. If the image has pixel alphas, the padded area will be transparent. Otherwise pygame will pick a color that matches the Surface colorkey or the topleft pixel value. </p>

<a name="pygame.transform.rotozoom">
  <i>filtered scale and rotation</i><br>
  <tt>pygame.transorm.rotozoom(Surface, angle, scale): return Surface</tt><br>
<p>This is a combined scale and rotation transform. The resulting Surface will be a filtered 32-bit Surface. The scale argument is a floating point value that will be multiplied by the current resolution. The angle argument is a floating point value that represents the counterclockwise degrees to rotate. <tt>A</tt> negative rotation angle will rotate clockwise. </p>

<a name="pygame.transform.scale2x">
  <i>specialized image doubler</i><br>
  <tt>pygame.transform.scale2x(Surface): Surface</tt><br>
<p>This will return a new image that is double the size of the original. It uses the AdvanceMAME Scale2X algorithm which does a 'jaggie-less' scale of bitmap graphics. </p>
<p>This really only has an effect on simple images with solid colors. On photographic and antialiased images it will look like a regular unfiltered scale. </p>

<a name="pygame.transform.chop">
  <i>remove interior area of an image</i><br>
  <tt>pygame.transform.chop(Surface, rect): return Surface</tt><br>
<p>Extracts a portion of an image. All vertical and horizontal pixels surrounding the given rectangle area are removed. The resulting image is shrunken by the size of pixels removed. (The original image is not altered by this <tt>operation.)</tt> </p>