initial
@@ -0,0 +1,363 @@
|
||||
# coding: ascii
|
||||
# pygame - Python Game Library
|
||||
# Copyright (C) 2000-2001 Pete Shinners
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the Free
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# Pete Shinners
|
||||
# pete@shinners.org
|
||||
"""Pygame is a set of Python modules designed for writing games.
|
||||
It is written on top of the excellent SDL library. This allows you
|
||||
to create fully featured games and multimedia programs in the python
|
||||
language. The package is highly portable, with games running on
|
||||
Windows, MacOS, OS X, BeOS, FreeBSD, IRIX, and Linux."""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Choose Windows display driver
|
||||
if os.name == 'nt':
|
||||
#pypy does not find the dlls, so we add package folder to PATH.
|
||||
pygame_dir = os.path.split(__file__)[0]
|
||||
os.environ['PATH'] = os.environ['PATH'] + ';' + pygame_dir
|
||||
|
||||
# when running under X11, always set the SDL window WM_CLASS to make the
|
||||
# window managers correctly match the pygame window.
|
||||
elif 'DISPLAY' in os.environ and 'SDL_VIDEO_X11_WMCLASS' not in os.environ:
|
||||
os.environ['SDL_VIDEO_X11_WMCLASS'] = os.path.basename(sys.argv[0])
|
||||
|
||||
|
||||
class MissingModule:
|
||||
_NOT_IMPLEMENTED_ = True
|
||||
|
||||
def __init__(self, name, urgent=0):
|
||||
self.name = name
|
||||
exc_type, exc_msg = sys.exc_info()[:2]
|
||||
self.info = str(exc_msg)
|
||||
self.reason = "%s: %s" % (exc_type.__name__, self.info)
|
||||
self.urgent = urgent
|
||||
if urgent:
|
||||
self.warn()
|
||||
|
||||
def __getattr__(self, var):
|
||||
if not self.urgent:
|
||||
self.warn()
|
||||
self.urgent = 1
|
||||
missing_msg = "%s module not available (%s)" % (self.name, self.reason)
|
||||
raise NotImplementedError(missing_msg)
|
||||
|
||||
def __nonzero__(self):
|
||||
return 0
|
||||
|
||||
def warn(self):
|
||||
msg_type = 'import' if self.urgent else 'use'
|
||||
message = '%s %s: %s\n(%s)' % (msg_type, self.name, self.info, self.reason)
|
||||
try:
|
||||
import warnings
|
||||
level = 4 if self.urgent else 3
|
||||
warnings.warn(message, RuntimeWarning, level)
|
||||
except ImportError:
|
||||
print (message)
|
||||
|
||||
|
||||
# we need to import like this, each at a time. the cleanest way to import
|
||||
# our modules is with the import command (not the __import__ function)
|
||||
|
||||
# first, the "required" modules
|
||||
from pygame.base import *
|
||||
from pygame.constants import *
|
||||
from pygame.version import *
|
||||
from pygame.rect import Rect
|
||||
from pygame.compat import PY_MAJOR_VERSION
|
||||
from pygame.rwobject import encode_string, encode_file_path
|
||||
import pygame.surflock
|
||||
import pygame.color
|
||||
Color = color.Color
|
||||
import pygame.bufferproxy
|
||||
BufferProxy = bufferproxy.BufferProxy
|
||||
import pygame.math
|
||||
Vector2 = pygame.math.Vector2
|
||||
Vector3 = pygame.math.Vector3
|
||||
|
||||
__version__ = ver
|
||||
|
||||
# next, the "standard" modules
|
||||
# we still allow them to be missing for stripped down pygame distributions
|
||||
if get_sdl_version() < (2, 0, 0):
|
||||
# cdrom only available for SDL 1.2.X
|
||||
try:
|
||||
import pygame.cdrom
|
||||
except (ImportError, IOError):
|
||||
cdrom = MissingModule("cdrom", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.cursors
|
||||
except (ImportError, IOError):
|
||||
cursors = MissingModule("cursors", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.display
|
||||
except (ImportError, IOError):
|
||||
display = MissingModule("display", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.draw
|
||||
except (ImportError, IOError):
|
||||
draw = MissingModule("draw", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.event
|
||||
except (ImportError, IOError):
|
||||
event = MissingModule("event", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.image
|
||||
except (ImportError, IOError):
|
||||
image = MissingModule("image", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.joystick
|
||||
except (ImportError, IOError):
|
||||
joystick = MissingModule("joystick", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.key
|
||||
except (ImportError, IOError):
|
||||
key = MissingModule("key", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.mouse
|
||||
except (ImportError, IOError):
|
||||
mouse = MissingModule("mouse", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.sprite
|
||||
except (ImportError, IOError):
|
||||
sprite = MissingModule("sprite", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.threads
|
||||
except (ImportError, IOError):
|
||||
threads = MissingModule("threads", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.pixelcopy
|
||||
except (ImportError, IOError):
|
||||
pixelcopy = MissingModule("pixelcopy", urgent=1)
|
||||
|
||||
|
||||
def warn_unwanted_files():
|
||||
"""warn about unneeded old files"""
|
||||
|
||||
# a temporary hack to warn about camera.so and camera.pyd.
|
||||
install_path = os.path.split(pygame.base.__file__)[0]
|
||||
extension_ext = os.path.splitext(pygame.base.__file__)[1]
|
||||
|
||||
# here are the .so/.pyd files we need to ask to remove.
|
||||
ext_to_remove = ["camera"]
|
||||
|
||||
# here are the .py/.pyo/.pyc files we need to ask to remove.
|
||||
py_to_remove = ["color"]
|
||||
|
||||
# Don't warn on Symbian. The color.py is used as a wrapper.
|
||||
if os.name == "e32":
|
||||
py_to_remove = []
|
||||
|
||||
# See if any of the files are there.
|
||||
extension_files = ["%s%s" % (x, extension_ext) for x in ext_to_remove]
|
||||
|
||||
py_files = ["%s%s" % (x, py_ext)
|
||||
for py_ext in [".py", ".pyc", ".pyo"]
|
||||
for x in py_to_remove]
|
||||
|
||||
files = py_files + extension_files
|
||||
|
||||
unwanted_files = []
|
||||
for f in files:
|
||||
unwanted_files.append(os.path.join(install_path, f))
|
||||
|
||||
ask_remove = []
|
||||
for f in unwanted_files:
|
||||
if os.path.exists(f):
|
||||
ask_remove.append(f)
|
||||
|
||||
if ask_remove:
|
||||
message = "Detected old file(s). Please remove the old files:\n"
|
||||
|
||||
for f in ask_remove:
|
||||
message += "%s " % f
|
||||
message += "\nLeaving them there might break pygame. Cheers!\n\n"
|
||||
|
||||
try:
|
||||
import warnings
|
||||
level = 4
|
||||
warnings.warn(message, RuntimeWarning, level)
|
||||
except ImportError:
|
||||
print (message)
|
||||
|
||||
|
||||
# disable, because we hopefully don't need it.
|
||||
# warn_unwanted_files()
|
||||
|
||||
|
||||
try:
|
||||
from pygame.surface import Surface, SurfaceType
|
||||
except (ImportError, IOError):
|
||||
Surface = lambda: Missing_Function
|
||||
|
||||
|
||||
try:
|
||||
import pygame.mask
|
||||
from pygame.mask import Mask
|
||||
except (ImportError, IOError):
|
||||
Mask = lambda: Missing_Function
|
||||
|
||||
try:
|
||||
from pygame.pixelarray import PixelArray
|
||||
except (ImportError, IOError):
|
||||
PixelArray = lambda: Missing_Function
|
||||
|
||||
try:
|
||||
from pygame.overlay import Overlay
|
||||
except (ImportError, IOError):
|
||||
Overlay = lambda: Missing_Function
|
||||
|
||||
try:
|
||||
import pygame.time
|
||||
except (ImportError, IOError):
|
||||
time = MissingModule("time", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.transform
|
||||
except (ImportError, IOError):
|
||||
transform = MissingModule("transform", urgent=1)
|
||||
|
||||
# lastly, the "optional" pygame modules
|
||||
if 'PYGAME_FREETYPE' in os.environ:
|
||||
try:
|
||||
import pygame.ftfont as font
|
||||
sys.modules['pygame.font'] = font
|
||||
except (ImportError, IOError):
|
||||
pass
|
||||
try:
|
||||
import pygame.font
|
||||
import pygame.sysfont
|
||||
pygame.font.SysFont = pygame.sysfont.SysFont
|
||||
pygame.font.get_fonts = pygame.sysfont.get_fonts
|
||||
pygame.font.match_font = pygame.sysfont.match_font
|
||||
except (ImportError, IOError):
|
||||
font = MissingModule("font", urgent=0)
|
||||
|
||||
# try and load pygame.mixer_music before mixer, for py2app...
|
||||
try:
|
||||
import pygame.mixer_music
|
||||
#del pygame.mixer_music
|
||||
#print ("NOTE2: failed importing pygame.mixer_music in lib/__init__.py")
|
||||
except (ImportError, IOError):
|
||||
pass
|
||||
|
||||
try:
|
||||
import pygame.mixer
|
||||
except (ImportError, IOError):
|
||||
mixer = MissingModule("mixer", urgent=0)
|
||||
|
||||
try:
|
||||
import pygame.movie
|
||||
except (ImportError, IOError):
|
||||
movie = MissingModule("movie", urgent=0)
|
||||
|
||||
# try:
|
||||
# import pygame.movieext
|
||||
# except (ImportError,IOError):
|
||||
# movieext=MissingModule("movieext", urgent=0)
|
||||
|
||||
try:
|
||||
import pygame.scrap
|
||||
except (ImportError, IOError):
|
||||
scrap = MissingModule("scrap", urgent=0)
|
||||
|
||||
try:
|
||||
import pygame.surfarray
|
||||
except (ImportError, IOError):
|
||||
surfarray = MissingModule("surfarray", urgent=0)
|
||||
|
||||
try:
|
||||
import pygame.sndarray
|
||||
except (ImportError, IOError):
|
||||
sndarray = MissingModule("sndarray", urgent=0)
|
||||
|
||||
try:
|
||||
import pygame.fastevent
|
||||
except (ImportError, IOError):
|
||||
fastevent = MissingModule("fastevent", urgent=0)
|
||||
|
||||
# there's also a couple "internal" modules not needed
|
||||
# by users, but putting them here helps "dependency finder"
|
||||
# programs get everything they need (like py2exe)
|
||||
try:
|
||||
import pygame.imageext
|
||||
del pygame.imageext
|
||||
except (ImportError, IOError):
|
||||
pass
|
||||
|
||||
|
||||
def packager_imports():
|
||||
"""some additional imports that py2app/py2exe will want to see"""
|
||||
import atexit
|
||||
import numpy
|
||||
import OpenGL.GL
|
||||
import pygame.macosx
|
||||
import pygame.bufferproxy
|
||||
import pygame.colordict
|
||||
import pygame._view
|
||||
|
||||
# make Rects pickleable
|
||||
if PY_MAJOR_VERSION >= 3:
|
||||
import copyreg as copy_reg
|
||||
else:
|
||||
import copy_reg
|
||||
|
||||
|
||||
def __rect_constructor(x, y, w, h):
|
||||
return Rect(x, y, w, h)
|
||||
|
||||
|
||||
def __rect_reduce(r):
|
||||
assert type(r) == Rect
|
||||
return __rect_constructor, (r.x, r.y, r.w, r.h)
|
||||
copy_reg.pickle(Rect, __rect_reduce, __rect_constructor)
|
||||
|
||||
|
||||
# make Colors pickleable
|
||||
def __color_constructor(r, g, b, a):
|
||||
return Color(r, g, b, a)
|
||||
|
||||
|
||||
def __color_reduce(c):
|
||||
assert type(c) == Color
|
||||
return __color_constructor, (c.r, c.g, c.b, c.a)
|
||||
copy_reg.pickle(Color, __color_reduce, __color_constructor)
|
||||
|
||||
|
||||
# Thanks for supporting pygame. Without support now, there won't be pygame later.
|
||||
if 'PYGAME_HIDE_SUPPORT_PROMPT' not in os.environ:
|
||||
print('pygame {} (SDL {}.{}.{}, python {}.{}.{})'.format(
|
||||
ver, *get_sdl_version() + sys.version_info[0:3]
|
||||
))
|
||||
print('Hello from the pygame community. https://www.pygame.org/contribute.html')
|
||||
|
||||
|
||||
# cleanup namespace
|
||||
del pygame, os, sys, surflock, MissingModule, copy_reg, PY_MAJOR_VERSION
|
||||
@@ -0,0 +1,72 @@
|
||||
from typing import Any, Tuple, Callable, Union, Optional, overload, Type
|
||||
|
||||
# Most useful stuff
|
||||
from pygame.constants import *
|
||||
import pygame.surface
|
||||
import pygame.rect
|
||||
import pygame.color
|
||||
import pygame.event
|
||||
import pygame.bufferproxy
|
||||
import pygame.draw
|
||||
import pygame.display
|
||||
import pygame.font
|
||||
import pygame.image
|
||||
import pygame.key
|
||||
import pygame.mixer
|
||||
import pygame.mouse
|
||||
import pygame.time
|
||||
import pygame.version
|
||||
|
||||
# Advanced stuff
|
||||
import pygame.cursors
|
||||
import pygame.joystick
|
||||
import pygame.mask
|
||||
import pygame.sprite
|
||||
import pygame.transform
|
||||
import pygame.bufferproxy
|
||||
import pygame.pixelarray
|
||||
import pygame.pixelcopy
|
||||
import pygame.sndarray
|
||||
import pygame.surfarray
|
||||
import pygame.math
|
||||
import pygame.fastevent
|
||||
|
||||
# Other
|
||||
import pygame.scrap
|
||||
|
||||
# This classes are auto imported with pygame, so I put their declaration here
|
||||
class Rect(pygame.rect.Rect): ...
|
||||
class Surface(pygame.surface.Surface): ...
|
||||
class Color(pygame.color.Color): ...
|
||||
class PixelArray(pygame.pixelarray.PixelArray): ...
|
||||
class Vector2(pygame.math.Vector2): ...
|
||||
class Vector3(pygame.math.Vector3): ...
|
||||
|
||||
|
||||
def init() -> Tuple[int, int]: ...
|
||||
def quit() -> None: ...
|
||||
def get_init() -> bool: ...
|
||||
|
||||
class error(RuntimeError):
|
||||
RuntimeError
|
||||
|
||||
def get_error() -> str: ...
|
||||
def set_error(error_msg: str) -> None: ...
|
||||
def get_sdl_version() -> Tuple[int, int, int]: ...
|
||||
def get_sdl_byteorder() -> int: ...
|
||||
def encode_string(
|
||||
obj: Union[str, bytes],
|
||||
encoding: Optional[str] = "unicode_escape",
|
||||
errors: Optional[str] = "backslashreplace",
|
||||
etype: Optional[Type[Exception]] = UnicodeEncodeError,
|
||||
) -> bytes: ...
|
||||
@overload
|
||||
def encode_file_path(
|
||||
obj: Union[str, bytes], etype: Optional[Type[Exception]] = UnicodeEncodeError
|
||||
) -> bytes: ...
|
||||
@overload
|
||||
def encode_file_path(
|
||||
obj: Any, etype: Optional[Type[Exception]] = UnicodeEncodeError
|
||||
) -> bytes: ...
|
||||
def register_quit(callable: Callable) -> None: ...
|
||||
def __getattr__(name) -> Any: ... # don't error on missing stubs
|
||||
@@ -0,0 +1,98 @@
|
||||
|
||||
import pygame
|
||||
import numpy
|
||||
|
||||
import opencv
|
||||
#this is important for capturing/displaying images
|
||||
from opencv import highgui
|
||||
|
||||
|
||||
|
||||
def list_cameras():
|
||||
"""
|
||||
"""
|
||||
# -1 for opencv means get any of them.
|
||||
return [-1]
|
||||
|
||||
def init():
|
||||
pass
|
||||
|
||||
def quit():
|
||||
pass
|
||||
|
||||
|
||||
class Camera:
|
||||
|
||||
def __init__(self, device = 0, size = (640,480), mode = "RGB"):
|
||||
"""
|
||||
"""
|
||||
self.camera = highgui.cvCreateCameraCapture(device)
|
||||
if not self.camera:
|
||||
raise ValueError ("Could not open camera. Sorry.")
|
||||
|
||||
|
||||
def set_controls(self, **kwargs):
|
||||
"""
|
||||
"""
|
||||
|
||||
|
||||
def set_resolution(self, width, height):
|
||||
"""Sets the capture resolution. (without dialog)
|
||||
"""
|
||||
# nothing to do here.
|
||||
pass
|
||||
def query_image(self):
|
||||
return True
|
||||
|
||||
def stop(self):
|
||||
pass
|
||||
|
||||
def start(self):
|
||||
# do nothing here... since the camera is already open.
|
||||
pass
|
||||
|
||||
def get_buffer(self):
|
||||
"""Returns a string containing the raw pixel data.
|
||||
"""
|
||||
return self.get_surface().get_buffer()
|
||||
|
||||
def get_image(self, dest_surf = None):
|
||||
return self.get_surface(dest_surf)
|
||||
|
||||
def get_surface(self, dest_surf = None):
|
||||
camera = self.camera
|
||||
|
||||
im = highgui.cvQueryFrame(camera)
|
||||
#convert Ipl image to PIL image
|
||||
#print type(im)
|
||||
if im:
|
||||
xx = opencv.adaptors.Ipl2NumPy(im)
|
||||
#print type(xx)
|
||||
#print xx.iscontiguous()
|
||||
#print dir(xx)
|
||||
#print xx.shape
|
||||
xxx = numpy.reshape(xx, (numpy.product(xx.shape),))
|
||||
|
||||
if xx.shape[2] != 3:
|
||||
raise ValueError("not sure what to do about this size")
|
||||
|
||||
pg_img = pygame.image.frombuffer(xxx, (xx.shape[1],xx.shape[0]), "RGB")
|
||||
|
||||
# if there is a destination surface given, we blit onto that.
|
||||
if dest_surf:
|
||||
dest_surf.blit(pg_img, (0,0))
|
||||
return dest_surf
|
||||
#return pg_img
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# try and use this camera stuff with the pygame camera example.
|
||||
import pygame.examples.camera
|
||||
|
||||
pygame.camera.Camera = Camera
|
||||
pygame.camera.list_cameras = list_cameras
|
||||
pygame.examples.camera.main()
|
||||
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
"""pygame.camera.Camera implementation using the videocapture module for windows.
|
||||
|
||||
http://videocapture.sourceforge.net/
|
||||
|
||||
Binary windows wheels:
|
||||
https://www.lfd.uci.edu/~gohlke/pythonlibs/#videocapture
|
||||
"""
|
||||
import pygame
|
||||
|
||||
def list_cameras():
|
||||
"""Always only lists one camera.
|
||||
|
||||
Functionality not supported in videocapture module.
|
||||
"""
|
||||
return [0]
|
||||
|
||||
# this just cycles through all the cameras trying to open them
|
||||
#cameras = []
|
||||
#for x in range(256):
|
||||
# try:
|
||||
# c = Camera(x)
|
||||
# except:
|
||||
# break
|
||||
# cameras.append(x)
|
||||
#return cameras
|
||||
|
||||
def init():
|
||||
global vidcap
|
||||
try:
|
||||
import vidcap as vc
|
||||
except ImportError:
|
||||
from VideoCapture import vidcap as vc
|
||||
vidcap = vc
|
||||
|
||||
def quit():
|
||||
global vidcap
|
||||
vidcap = None
|
||||
|
||||
|
||||
class Camera:
|
||||
|
||||
def __init__(self, device =0,
|
||||
size = (640,480),
|
||||
mode = "RGB",
|
||||
show_video_window=0):
|
||||
"""device: VideoCapture enumerates the available video capture devices
|
||||
on your system. If you have more than one device, specify
|
||||
the desired one here. The device number starts from 0.
|
||||
|
||||
show_video_window: 0 ... do not display a video window (the default)
|
||||
1 ... display a video window
|
||||
|
||||
Mainly used for debugging, since the video window
|
||||
can not be closed or moved around.
|
||||
"""
|
||||
self.dev = vidcap.new_Dev(device, show_video_window)
|
||||
width, height = size
|
||||
self.dev.setresolution(width, height)
|
||||
|
||||
def display_capture_filter_properties(self):
|
||||
"""Displays a dialog containing the property page of the capture filter.
|
||||
|
||||
For VfW drivers you may find the option to select the resolution most
|
||||
likely here.
|
||||
"""
|
||||
self.dev.displaycapturefilterproperties()
|
||||
|
||||
def display_capture_pin_properties(self):
|
||||
"""Displays a dialog containing the property page of the capture pin.
|
||||
|
||||
For WDM drivers you may find the option to select the resolution most
|
||||
likely here.
|
||||
"""
|
||||
self.dev.displaycapturepinproperties()
|
||||
|
||||
def set_resolution(self, width, height):
|
||||
"""Sets the capture resolution. (without dialog)
|
||||
"""
|
||||
self.dev.setresolution(width, height)
|
||||
|
||||
def get_buffer(self):
|
||||
"""Returns a string containing the raw pixel data.
|
||||
"""
|
||||
return self.dev.getbuffer()
|
||||
|
||||
def start(self):
|
||||
""" Not implemented.
|
||||
"""
|
||||
|
||||
def set_controls(self, **kwargs):
|
||||
""" Not implemented.
|
||||
"""
|
||||
|
||||
def stop(self):
|
||||
""" Not implemented.
|
||||
"""
|
||||
|
||||
def get_image(self, dest_surf = None):
|
||||
"""
|
||||
"""
|
||||
return self.get_surface(dest_surf)
|
||||
|
||||
def get_surface(self, dest_surf = None):
|
||||
"""Returns a pygame Surface.
|
||||
"""
|
||||
abuffer, width, height = self.get_buffer()
|
||||
if abuffer:
|
||||
surf = pygame.image.frombuffer(abuffer, (width, height), "RGB")
|
||||
|
||||
# swap it from a BGR surface to an RGB surface.
|
||||
r,g,b,a = surf.get_masks()
|
||||
surf.set_masks((b,g,r,a))
|
||||
|
||||
r,g,b,a = surf.get_shifts()
|
||||
surf.set_shifts((b,g,r,a))
|
||||
|
||||
surf = pygame.transform.flip(surf, 0,1)
|
||||
|
||||
# if there is a destination surface given, we blit onto that.
|
||||
if dest_surf:
|
||||
dest_surf.blit(surf, (0,0))
|
||||
else:
|
||||
dest_surf = surf
|
||||
return dest_surf
|
||||
|
||||
if __name__ == "__main__":
|
||||
import pygame.examples.camera
|
||||
|
||||
pygame.camera.Camera = Camera
|
||||
pygame.camera.list_cameras = list_cameras
|
||||
pygame.examples.camera.main()
|
||||
@@ -0,0 +1,30 @@
|
||||
"""dummy Movie class if all else fails """
|
||||
class Movie:
|
||||
def __init__(self, filename, surface=None):
|
||||
self.filename=filename
|
||||
self.surface = surface
|
||||
self.process = None
|
||||
self.loops=0
|
||||
self.playing = False
|
||||
self.paused = False
|
||||
self._backend = "DUMMY"
|
||||
self.width=0
|
||||
self.height=0
|
||||
self.finished = 1
|
||||
def play(self, loops=0):
|
||||
self.playing= not self.playing
|
||||
|
||||
def stop(self):
|
||||
self.playing=not self.playing
|
||||
self.paused =not self.paused
|
||||
|
||||
def pause(self):
|
||||
self.paused=not self.paused
|
||||
|
||||
def resize(self, w, h):
|
||||
self.width=w
|
||||
self.height=h
|
||||
|
||||
def __repr__(self):
|
||||
return "(%s 0.0s)"%self.filename
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
## pygame - Python Game Library
|
||||
## Copyright (C) 2008 Marcus von Appen
|
||||
##
|
||||
## This library is free software; you can redistribute it and/or
|
||||
## modify it under the terms of the GNU Library General Public
|
||||
## License as published by the Free Software Foundation; either
|
||||
## version 2 of the License, or (at your option) any later version.
|
||||
##
|
||||
## This library is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
## Library General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU Library General Public
|
||||
## License along with this library; if not, write to the Free
|
||||
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
##
|
||||
## Marcus von Appen
|
||||
## mva@sysfault.org
|
||||
|
||||
"""pygame module for accessing sound sample data using numpy
|
||||
|
||||
Functions to convert between numpy arrays and Sound objects. This module
|
||||
will only be available when pygame can use the external numpy package.
|
||||
|
||||
Sound data is made of thousands of samples per second, and each sample
|
||||
is the amplitude of the wave at a particular moment in time. For
|
||||
example, in 22-kHz format, element number 5 of the array is the
|
||||
amplitude of the wave after 5/22000 seconds.
|
||||
|
||||
Each sample is an 8-bit or 16-bit integer, depending on the data format.
|
||||
A stereo sound file has two values per sample, while a mono sound file
|
||||
only has one.
|
||||
"""
|
||||
|
||||
import pygame.mixer as mixer
|
||||
import numpy
|
||||
|
||||
|
||||
def array (sound):
|
||||
"""pygame._numpysndarray.array(Sound): return array
|
||||
|
||||
Copy Sound samples into an array.
|
||||
|
||||
Creates a new array for the sound data and copies the samples. The
|
||||
array will always be in the format returned from
|
||||
pygame.mixer.get_init().
|
||||
"""
|
||||
|
||||
return numpy.array (sound, copy=True)
|
||||
|
||||
def samples (sound):
|
||||
"""pygame._numpysndarray.samples(Sound): return array
|
||||
|
||||
Reference Sound samples into an array.
|
||||
|
||||
Creates a new array that directly references the samples in a Sound
|
||||
object. Modifying the array will change the Sound. The array will
|
||||
always be in the format returned from pygame.mixer.get_init().
|
||||
"""
|
||||
|
||||
return numpy.array (sound, copy=False)
|
||||
|
||||
def make_sound (array):
|
||||
"""pygame._numpysndarray.make_sound(array): return Sound
|
||||
|
||||
Convert an array into a Sound object.
|
||||
|
||||
Create a new playable Sound object from an array. The mixer module
|
||||
must be initialized and the array format must be similar to the mixer
|
||||
audio format.
|
||||
"""
|
||||
|
||||
return mixer.Sound (array=array)
|
||||
|
||||
@@ -0,0 +1,353 @@
|
||||
## pygame - Python Game Library
|
||||
## Copyright (C) 2007 Marcus von Appen
|
||||
##
|
||||
## This library is free software; you can redistribute it and/or
|
||||
## modify it under the terms of the GNU Library General Public
|
||||
## License as published by the Free Software Foundation; either
|
||||
## version 2 of the License, or (at your option) any later version.
|
||||
##
|
||||
## This library is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
## Library General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU Library General Public
|
||||
## License along with this library; if not, write to the Free
|
||||
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
##
|
||||
## Marcus von Appen
|
||||
## mva@sysfault.org
|
||||
|
||||
"""pygame module for accessing surface pixel data using numpy
|
||||
|
||||
Functions to convert pixel data between pygame Surfaces and Numpy
|
||||
arrays. This module will only be available when pygame can use the
|
||||
external Numpy package.
|
||||
|
||||
Note, that numpyarray is an optional module. It requires that Numpy is
|
||||
installed to be used. If not installed, an exception will be raised when
|
||||
it is used. eg. ImportError: no module named numpy
|
||||
|
||||
Every pixel is stored as a single integer value to represent the red,
|
||||
green, and blue colors. The 8bit images use a value that looks into a
|
||||
colormap. Pixels with higher depth use a bit packing process to place
|
||||
three or four values into a single number.
|
||||
|
||||
The Numpy arrays are indexed by the X axis first, followed by the Y
|
||||
axis. Arrays that treat the pixels as a single integer are referred to
|
||||
as 2D arrays. This module can also separate the red, green, and blue
|
||||
color values into separate indices. These types of arrays are referred
|
||||
to as 3D arrays, and the last index is 0 for red, 1 for green, and 2 for
|
||||
blue.
|
||||
|
||||
In contrast to Numeric Numpy does use unsigned 16bit integers, images
|
||||
with 16bit data will be treated as unsigned integers.
|
||||
"""
|
||||
|
||||
from pygame.pixelcopy import array_to_surface, surface_to_array, \
|
||||
map_array as pix_map_array, make_surface as pix_make_surface
|
||||
import numpy
|
||||
from numpy import array as numpy_array, empty as numpy_empty, \
|
||||
uint32 as numpy_uint32, ndarray as numpy_ndarray
|
||||
|
||||
#float96 not available on all numpy versions.
|
||||
numpy_floats = []
|
||||
for type_name in "float float32 float64 float96".split():
|
||||
if hasattr(numpy, type_name):
|
||||
numpy_floats.append(getattr(numpy, type_name))
|
||||
|
||||
# Pixel sizes corresponding to NumPy supported integer sizes, and therefore
|
||||
# permissible for 2D reference arrays.
|
||||
_pixel2d_bitdepths = set([8, 16, 32])
|
||||
|
||||
|
||||
def blit_array (surface, array):
|
||||
"""pygame.surfarray.blit_array(Surface, array): return None
|
||||
|
||||
Blit directly from a array values.
|
||||
|
||||
Directly copy values from an array into a Surface. This is faster than
|
||||
converting the array into a Surface and blitting. The array must be the
|
||||
same dimensions as the Surface and will completely replace all pixel
|
||||
values. Only integer, ascii character and record arrays are accepted.
|
||||
|
||||
This function will temporarily lock the Surface as the new values are
|
||||
copied.
|
||||
"""
|
||||
if isinstance(array, numpy_ndarray) and array.dtype in numpy_floats:
|
||||
array = array.round(0).astype(numpy_uint32)
|
||||
return array_to_surface(surface, array)
|
||||
|
||||
def make_surface(array):
|
||||
"""pygame.surfarray.make_surface (array): return Surface
|
||||
|
||||
Copy an array to a new surface.
|
||||
|
||||
Create a new Surface that best resembles the data and format on the
|
||||
array. The array can be 2D or 3D with any sized integer values.
|
||||
"""
|
||||
if isinstance(array, numpy_ndarray) and array.dtype in numpy_floats:
|
||||
array = array.round(0).astype(numpy_uint32)
|
||||
return pix_make_surface (array)
|
||||
|
||||
def array2d(surface):
|
||||
"""pygame.numpyarray.array2d(Surface): return array
|
||||
|
||||
copy pixels into a 2d array
|
||||
|
||||
Copy the pixels from a Surface into a 2D array. The bit depth of the
|
||||
surface will control the size of the integer values, and will work
|
||||
for any type of pixel format.
|
||||
|
||||
This function will temporarily lock the Surface as pixels are copied
|
||||
(see the Surface.lock - lock the Surface memory for pixel access
|
||||
method).
|
||||
"""
|
||||
bpp = surface.get_bytesize()
|
||||
try:
|
||||
dtype = (numpy.uint8, numpy.uint16, numpy.int32, numpy.int32)[bpp - 1]
|
||||
except IndexError:
|
||||
raise ValueError("unsupported bit depth %i for 2D array" % (bpp * 8,))
|
||||
size = surface.get_size()
|
||||
array = numpy.empty(size, dtype)
|
||||
surface_to_array(array, surface)
|
||||
return array
|
||||
|
||||
def pixels2d(surface):
|
||||
"""pygame.numpyarray.pixels2d(Surface): return array
|
||||
|
||||
reference pixels into a 2d array
|
||||
|
||||
Create a new 2D array that directly references the pixel values in a
|
||||
Surface. Any changes to the array will affect the pixels in the
|
||||
Surface. This is a fast operation since no data is copied.
|
||||
|
||||
Pixels from a 24-bit Surface cannot be referenced, but all other
|
||||
Surface bit depths can.
|
||||
|
||||
The Surface this references will remain locked for the lifetime of
|
||||
the array (see the Surface.lock - lock the Surface memory for pixel
|
||||
access method).
|
||||
"""
|
||||
if (surface.get_bitsize() not in _pixel2d_bitdepths):
|
||||
raise ValueError("unsupport bit depth for 2D reference array")
|
||||
try:
|
||||
return numpy_array(surface.get_view('2'), copy=False)
|
||||
except (ValueError, TypeError):
|
||||
raise ValueError("bit depth %i unsupported for 2D reference array" %
|
||||
(surface.get_bitsize(),))
|
||||
|
||||
def array3d(surface):
|
||||
"""pygame.numpyarray.array3d(Surface): return array
|
||||
|
||||
copy pixels into a 3d array
|
||||
|
||||
Copy the pixels from a Surface into a 3D array. The bit depth of the
|
||||
surface will control the size of the integer values, and will work
|
||||
for any type of pixel format.
|
||||
|
||||
This function will temporarily lock the Surface as pixels are copied
|
||||
(see the Surface.lock - lock the Surface memory for pixel access
|
||||
method).
|
||||
"""
|
||||
w, h = surface.get_size()
|
||||
array = numpy.empty((w, h, 3), numpy.uint8)
|
||||
surface_to_array(array, surface)
|
||||
return array
|
||||
|
||||
def pixels3d (surface):
|
||||
"""pygame.numpyarray.pixels3d(Surface): return array
|
||||
|
||||
reference pixels into a 3d array
|
||||
|
||||
Create a new 3D array that directly references the pixel values in a
|
||||
Surface. Any changes to the array will affect the pixels in the
|
||||
Surface. This is a fast operation since no data is copied.
|
||||
|
||||
This will only work on Surfaces that have 24-bit or 32-bit
|
||||
formats. Lower pixel formats cannot be referenced.
|
||||
|
||||
The Surface this references will remain locked for the lifetime of
|
||||
the array (see the Surface.lock - lock the Surface memory for pixel
|
||||
access method).
|
||||
"""
|
||||
return numpy_array(surface.get_view('3'), copy=False)
|
||||
|
||||
def array_alpha(surface):
|
||||
"""pygame.numpyarray.array_alpha(Surface): return array
|
||||
|
||||
copy pixel alphas into a 2d array
|
||||
|
||||
Copy the pixel alpha values (degree of transparency) from a Surface
|
||||
into a 2D array. This will work for any type of Surface
|
||||
format. Surfaces without a pixel alpha will return an array with all
|
||||
opaque values.
|
||||
|
||||
This function will temporarily lock the Surface as pixels are copied
|
||||
(see the Surface.lock - lock the Surface memory for pixel access
|
||||
method).
|
||||
"""
|
||||
size = surface.get_size()
|
||||
array = numpy.empty(size, numpy.uint8)
|
||||
surface_to_array(array, surface, 'A')
|
||||
return array
|
||||
|
||||
def pixels_alpha(surface):
|
||||
"""pygame.numpyarray.pixels_alpha(Surface): return array
|
||||
|
||||
reference pixel alphas into a 2d array
|
||||
|
||||
Create a new 2D array that directly references the alpha values
|
||||
(degree of transparency) in a Surface. Any changes to the array will
|
||||
affect the pixels in the Surface. This is a fast operation since no
|
||||
data is copied.
|
||||
|
||||
This can only work on 32-bit Surfaces with a per-pixel alpha value.
|
||||
|
||||
The Surface this array references will remain locked for the
|
||||
lifetime of the array.
|
||||
"""
|
||||
return numpy.array(surface.get_view('A'), copy=False)
|
||||
|
||||
def pixels_red(surface):
|
||||
"""pygame.surfarray.pixels_red(Surface): return array
|
||||
|
||||
Reference pixel red into a 2d array.
|
||||
|
||||
Create a new 2D array that directly references the red values
|
||||
in a Surface. Any changes to the array will affect the pixels
|
||||
in the Surface. This is a fast operation since no data is copied.
|
||||
|
||||
This can only work on 24-bit or 32-bit Surfaces.
|
||||
|
||||
The Surface this array references will remain locked for the
|
||||
lifetime of the array.
|
||||
"""
|
||||
return numpy.array(surface.get_view('R'), copy=False)
|
||||
|
||||
def array_red(surface):
|
||||
"""pygame.numpyarray.array_red(Surface): return array
|
||||
|
||||
copy pixel red into a 2d array
|
||||
|
||||
Copy the pixel red values from a Surface into a 2D array. This will work
|
||||
for any type of Surface format.
|
||||
|
||||
This function will temporarily lock the Surface as pixels are copied
|
||||
(see the Surface.lock - lock the Surface memory for pixel access
|
||||
method).
|
||||
"""
|
||||
size = surface.get_size()
|
||||
array = numpy.empty(size, numpy.uint8)
|
||||
surface_to_array(array, surface, 'R')
|
||||
return array
|
||||
|
||||
def pixels_green(surface):
|
||||
"""pygame.surfarray.pixels_green(Surface): return array
|
||||
|
||||
Reference pixel green into a 2d array.
|
||||
|
||||
Create a new 2D array that directly references the green values
|
||||
in a Surface. Any changes to the array will affect the pixels
|
||||
in the Surface. This is a fast operation since no data is copied.
|
||||
|
||||
This can only work on 24-bit or 32-bit Surfaces.
|
||||
|
||||
The Surface this array references will remain locked for the
|
||||
lifetime of the array.
|
||||
"""
|
||||
return numpy.array(surface.get_view('G'), copy=False)
|
||||
|
||||
def array_green(surface):
|
||||
"""pygame.numpyarray.array_green(Surface): return array
|
||||
|
||||
copy pixel green into a 2d array
|
||||
|
||||
Copy the pixel green values from a Surface into a 2D array. This will work
|
||||
for any type of Surface format.
|
||||
|
||||
This function will temporarily lock the Surface as pixels are copied
|
||||
(see the Surface.lock - lock the Surface memory for pixel access
|
||||
method).
|
||||
"""
|
||||
size = surface.get_size()
|
||||
array = numpy.empty(size, numpy.uint8)
|
||||
surface_to_array(array, surface, 'G')
|
||||
return array
|
||||
|
||||
def pixels_blue (surface):
|
||||
"""pygame.surfarray.pixels_blue(Surface): return array
|
||||
|
||||
Reference pixel blue into a 2d array.
|
||||
|
||||
Create a new 2D array that directly references the blue values
|
||||
in a Surface. Any changes to the array will affect the pixels
|
||||
in the Surface. This is a fast operation since no data is copied.
|
||||
|
||||
This can only work on 24-bit or 32-bit Surfaces.
|
||||
|
||||
The Surface this array references will remain locked for the
|
||||
lifetime of the array.
|
||||
"""
|
||||
return numpy.array(surface.get_view('B'), copy=False)
|
||||
|
||||
def array_blue(surface):
|
||||
"""pygame.numpyarray.array_blue(Surface): return array
|
||||
|
||||
copy pixel blue into a 2d array
|
||||
|
||||
Copy the pixel blue values from a Surface into a 2D array. This will work
|
||||
for any type of Surface format.
|
||||
|
||||
This function will temporarily lock the Surface as pixels are copied
|
||||
(see the Surface.lock - lock the Surface memory for pixel access
|
||||
method).
|
||||
"""
|
||||
size = surface.get_size()
|
||||
array = numpy.empty(size, numpy.uint8)
|
||||
surface_to_array(array, surface, 'B')
|
||||
return array
|
||||
|
||||
def array_colorkey(surface):
|
||||
"""pygame.numpyarray.array_colorkey(Surface): return array
|
||||
|
||||
copy the colorkey values into a 2d array
|
||||
|
||||
Create a new array with the colorkey transparency value from each
|
||||
pixel. If the pixel matches the colorkey it will be fully
|
||||
tranparent; otherwise it will be fully opaque.
|
||||
|
||||
This will work on any type of Surface format. If the image has no
|
||||
colorkey a solid opaque array will be returned.
|
||||
|
||||
This function will temporarily lock the Surface as pixels are
|
||||
copied.
|
||||
"""
|
||||
size = surface.get_size()
|
||||
array = numpy.empty(size, numpy.uint8)
|
||||
surface_to_array(array, surface, 'C')
|
||||
return array
|
||||
|
||||
def map_array(surface, array):
|
||||
"""pygame.numpyarray.map_array(Surface, array3d): return array2d
|
||||
|
||||
map a 3d array into a 2d array
|
||||
|
||||
Convert a 3D array into a 2D array. This will use the given Surface
|
||||
format to control the conversion.
|
||||
|
||||
Note: arrays do not need to be 3D, as long as the minor axis has
|
||||
three elements giving the component colours, any array shape can be
|
||||
used (for example, a single colour can be mapped, or an array of
|
||||
colours). The array shape is limited to eleven dimensions maximum,
|
||||
including the three element minor axis.
|
||||
"""
|
||||
if array.ndim == 0:
|
||||
raise ValueError("array must have at least 1 dimension")
|
||||
shape = array.shape
|
||||
if shape[-1] != 3:
|
||||
raise ValueError("array must be a 3d array of 3-value color data")
|
||||
target = numpy_empty(shape[:-1], numpy.int32)
|
||||
pix_map_array(target, array, surface)
|
||||
return target
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
from .sdl2 import *
|
||||
from .audio import *
|
||||
from .video import *
|
||||
@@ -0,0 +1 @@
|
||||
from .touch import *
|
||||
@@ -0,0 +1,6 @@
|
||||
from typing import Dict, Union
|
||||
|
||||
def get_num_devices() -> int: ...
|
||||
def get_device(index: int) -> int: ...
|
||||
def get_num_fingers(device_id: int) -> int: ...
|
||||
def get_finger(touchid: int, index: int) -> Dict[str, Union[int, float]]: ...
|
||||
@@ -0,0 +1,13 @@
|
||||
from typing import Any, overload, Optional, TypeVar, Text
|
||||
|
||||
AnyStr = TypeVar("AnyStr", Text, bytes)
|
||||
|
||||
class BufferProxy(object):
|
||||
parent: Any
|
||||
length: int
|
||||
raw: AnyStr
|
||||
@overload
|
||||
def __init__(self) -> None: ...
|
||||
@overload
|
||||
def __init__(self, parent: Any) -> None: ...
|
||||
def write(self, buffer: bytes, offset: Optional[int] = 0) -> None: ...
|
||||
@@ -0,0 +1,144 @@
|
||||
|
||||
_is_init = 0
|
||||
|
||||
|
||||
|
||||
def init():
|
||||
global list_cameras, Camera, colorspace, _is_init
|
||||
|
||||
|
||||
import os,sys
|
||||
|
||||
use_opencv = False
|
||||
use_vidcapture = False
|
||||
use__camera = True
|
||||
|
||||
|
||||
if sys.platform == 'win32':
|
||||
use_vidcapture = True
|
||||
use__camera = False
|
||||
|
||||
elif "linux" in sys.platform:
|
||||
use__camera = True
|
||||
elif "darwin" in sys.platform:
|
||||
use__camera = True
|
||||
else:
|
||||
use_opencv = True
|
||||
|
||||
|
||||
|
||||
# see if we have any user specified defaults in environments.
|
||||
camera_env = os.environ.get("PYGAME_CAMERA", "")
|
||||
if camera_env == "opencv":
|
||||
use_opencv = True
|
||||
if camera_env == "vidcapture":
|
||||
use_vidcapture = True
|
||||
|
||||
|
||||
|
||||
# select the camera module to import here.
|
||||
|
||||
# the _camera module has some code which can be reused by other modules.
|
||||
# it will also be the default one.
|
||||
if use__camera:
|
||||
from pygame import _camera
|
||||
colorspace = _camera.colorspace
|
||||
|
||||
list_cameras = _camera.list_cameras
|
||||
Camera = _camera.Camera
|
||||
|
||||
if use_opencv:
|
||||
try:
|
||||
from pygame import _camera_opencv_highgui
|
||||
except ImportError:
|
||||
_camera_opencv_highgui = None
|
||||
|
||||
if _camera_opencv_highgui:
|
||||
_camera_opencv_highgui.init()
|
||||
|
||||
list_cameras = _camera_opencv_highgui.list_cameras
|
||||
Camera = _camera_opencv_highgui.Camera
|
||||
|
||||
if use_vidcapture:
|
||||
try:
|
||||
from pygame import _camera_vidcapture
|
||||
except ImportError:
|
||||
_camera_vidcapture = None
|
||||
|
||||
if _camera_vidcapture:
|
||||
_camera_vidcapture.init()
|
||||
list_cameras = _camera_vidcapture.list_cameras
|
||||
Camera = _camera_vidcapture.Camera
|
||||
|
||||
|
||||
|
||||
_is_init = 1
|
||||
|
||||
|
||||
def quit():
|
||||
global _is_init
|
||||
_is_init = 0
|
||||
|
||||
|
||||
def _check_init():
|
||||
global _is_init
|
||||
if not _is_init:
|
||||
raise ValueError("Need to call camera.init() before using.")
|
||||
|
||||
def list_cameras():
|
||||
"""
|
||||
"""
|
||||
_check_init()
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class Camera:
|
||||
|
||||
def __init__(self, device =0, size = (320, 200), mode = "RGB"):
|
||||
"""
|
||||
"""
|
||||
_check_init()
|
||||
raise NotImplementedError()
|
||||
|
||||
def set_resolution(self, width, height):
|
||||
"""Sets the capture resolution. (without dialog)
|
||||
"""
|
||||
pass
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
"""
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
"""
|
||||
|
||||
def get_buffer(self):
|
||||
"""
|
||||
"""
|
||||
|
||||
def set_controls(self, **kwargs):
|
||||
"""
|
||||
"""
|
||||
|
||||
def get_image(self, dest_surf = None):
|
||||
"""
|
||||
"""
|
||||
|
||||
def get_surface(self, dest_surf = None):
|
||||
"""
|
||||
"""
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# try and use this camera stuff with the pygame camera example.
|
||||
import pygame.examples.camera
|
||||
|
||||
#pygame.camera.Camera = Camera
|
||||
#pygame.camera.list_cameras = list_cameras
|
||||
pygame.examples.camera.main()
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
from typing import List, Optional, Union, Tuple
|
||||
from pygame.surface import Surface
|
||||
|
||||
def init() -> None: ...
|
||||
def quit() -> None: ...
|
||||
def list_cameras() -> List[str]: ...
|
||||
|
||||
class Camera:
|
||||
def __init__(
|
||||
self,
|
||||
device: Optional[int] = 0,
|
||||
size: Optional[Union[Tuple[int, int], List[int]]] = (320, 200),
|
||||
format: Optional[str] = "RGB",
|
||||
): ...
|
||||
def start(self) -> None: ...
|
||||
def stop(self) -> None: ...
|
||||
def get_controls(self) -> Tuple[bool, bool, int]: ...
|
||||
def set_controls(
|
||||
self,
|
||||
hflip: Optional[bool] = ...,
|
||||
vflip: Optional[bool] = ...,
|
||||
brightness: Optional[int] = ...,
|
||||
) -> Tuple[bool, bool, int]: ...
|
||||
def get_size(self) -> Tuple[int, int]: ...
|
||||
def query_image(self) -> bool: ...
|
||||
def get_image(self, surface: Surface) -> Surface: ...
|
||||
def get_raw(self) -> str: ...
|
||||
@@ -0,0 +1,21 @@
|
||||
from typing import Text, Tuple, Union, overload
|
||||
|
||||
class Color(object):
|
||||
r: int
|
||||
g: int
|
||||
b: int
|
||||
a: int
|
||||
cmy: Tuple[float, float, float]
|
||||
hsva: Tuple[float, float, float, float]
|
||||
hsla: Tuple[float, float, float, float]
|
||||
i1i2i3: Tuple[float, float, float]
|
||||
@overload
|
||||
def __init__(self, name: Text) -> None: ...
|
||||
@overload
|
||||
def __init__(self, r: int, g: int, b: int, a: int = ...) -> None: ...
|
||||
@overload
|
||||
def __init__(self, rgbvalue: Union[Text, int]) -> None: ...
|
||||
def normalize(self) -> Tuple[float, float, float, float]: ...
|
||||
def correct_gamma(self, gamma: float) -> Color: ...
|
||||
def set_length(self, len: int) -> None: ...
|
||||
def lerp(self, color: Color, amount: float) -> Color: ...
|
||||
@@ -0,0 +1,684 @@
|
||||
## pygame - Python Game Library
|
||||
## Copyright (C) 2000-2003 Pete Shinners
|
||||
##
|
||||
## This library is free software; you can redistribute it and/or
|
||||
## modify it under the terms of the GNU Library General Public
|
||||
## License as published by the Free Software Foundation; either
|
||||
## version 2 of the License, or (at your option) any later version.
|
||||
##
|
||||
## This library is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
## Library General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU Library General Public
|
||||
## License along with this library; if not, write to the Free
|
||||
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
##
|
||||
## Pete Shinners
|
||||
## pete@shinners.org
|
||||
|
||||
from pygame.compat import unicode_
|
||||
|
||||
THECOLORS = {
|
||||
'gray17' : (43, 43, 43, 255) ,
|
||||
'gold' : (255, 215, 0, 255) ,
|
||||
'gray10' : (26, 26, 26, 255) ,
|
||||
'yellow' : (255, 255, 0, 255) ,
|
||||
'gray11' : (28, 28, 28, 255) ,
|
||||
'grey61' : (156, 156, 156, 255) ,
|
||||
'grey60' : (153, 153, 153, 255) ,
|
||||
'darkseagreen' : (143, 188, 143, 255) ,
|
||||
'grey62' : (158, 158, 158, 255) ,
|
||||
'grey65' : (166, 166, 166, 255) ,
|
||||
'gray12' : (31, 31, 31, 255) ,
|
||||
'grey67' : (171, 171, 171, 255) ,
|
||||
'grey66' : (168, 168, 168, 255) ,
|
||||
'grey69' : (176, 176, 176, 255) ,
|
||||
'gray21' : (54, 54, 54, 255) ,
|
||||
'lightsalmon4' : (139, 87, 66, 255) ,
|
||||
'lightsalmon2' : (238, 149, 114, 255) ,
|
||||
'lightsalmon3' : (205, 129, 98, 255) ,
|
||||
'lightsalmon1' : (255, 160, 122, 255) ,
|
||||
'gray32' : (82, 82, 82, 255) ,
|
||||
'green4' : (0, 139, 0, 255) ,
|
||||
'gray30' : (77, 77, 77, 255) ,
|
||||
'gray31' : (79, 79, 79, 255) ,
|
||||
'green1' : (0, 255, 0, 255) ,
|
||||
'gray37' : (94, 94, 94, 255) ,
|
||||
'green3' : (0, 205, 0, 255) ,
|
||||
'green2' : (0, 238, 0, 255) ,
|
||||
'darkslategray1' : (151, 255, 255, 255) ,
|
||||
'darkslategray2' : (141, 238, 238, 255) ,
|
||||
'darkslategray3' : (121, 205, 205, 255) ,
|
||||
'aquamarine1' : (127, 255, 212, 255) ,
|
||||
'aquamarine3' : (102, 205, 170, 255) ,
|
||||
'aquamarine2' : (118, 238, 198, 255) ,
|
||||
'papayawhip' : (255, 239, 213, 255) ,
|
||||
'black' : (0, 0, 0, 255) ,
|
||||
'darkorange3' : (205, 102, 0, 255) ,
|
||||
'oldlace' : (253, 245, 230, 255) ,
|
||||
'lightgoldenrod4' : (139, 129, 76, 255) ,
|
||||
'gray90' : (229, 229, 229, 255) ,
|
||||
'orchid1' : (255, 131, 250, 255) ,
|
||||
'orchid2' : (238, 122, 233, 255) ,
|
||||
'orchid3' : (205, 105, 201, 255) ,
|
||||
'grey68' : (173, 173, 173, 255) ,
|
||||
'brown' : (165, 42, 42, 255) ,
|
||||
'purple2' : (145, 44, 238, 255) ,
|
||||
'gray80' : (204, 204, 204, 255) ,
|
||||
'antiquewhite3' : (205, 192, 176, 255) ,
|
||||
'antiquewhite2' : (238, 223, 204, 255) ,
|
||||
'antiquewhite1' : (255, 239, 219, 255) ,
|
||||
'palevioletred3' : (205, 104, 137, 255) ,
|
||||
'hotpink' : (255, 105, 180, 255) ,
|
||||
'lightcyan' : (224, 255, 255, 255) ,
|
||||
'coral3' : (205, 91, 69, 255) ,
|
||||
'gray8' : (20, 20, 20, 255) ,
|
||||
'gray9' : (23, 23, 23, 255) ,
|
||||
'grey32' : (82, 82, 82, 255) ,
|
||||
'bisque4' : (139, 125, 107, 255) ,
|
||||
'cyan' : (0, 255, 255, 255) ,
|
||||
'gray0' : (0, 0, 0, 255) ,
|
||||
'gray1' : (3, 3, 3, 255) ,
|
||||
'gray6' : (15, 15, 15, 255) ,
|
||||
'bisque1' : (255, 228, 196, 255) ,
|
||||
'bisque2' : (238, 213, 183, 255) ,
|
||||
'bisque3' : (205, 183, 158, 255) ,
|
||||
'skyblue' : (135, 206, 235, 255) ,
|
||||
'gray' : (190, 190, 190, 255) ,
|
||||
'darkturquoise' : (0, 206, 209, 255) ,
|
||||
'rosybrown4' : (139, 105, 105, 255) ,
|
||||
'deepskyblue3' : (0, 154, 205, 255) ,
|
||||
'grey63' : (161, 161, 161, 255) ,
|
||||
'indianred1' : (255, 106, 106, 255) ,
|
||||
'grey78' : (199, 199, 199, 255) ,
|
||||
'lightpink' : (255, 182, 193, 255) ,
|
||||
'gray88' : (224, 224, 224, 255) ,
|
||||
'gray22' : (56, 56, 56, 255) ,
|
||||
'red' : (255, 0, 0, 255) ,
|
||||
'grey11' : (28, 28, 28, 255) ,
|
||||
'lemonchiffon3' : (205, 201, 165, 255) ,
|
||||
'lemonchiffon2' : (238, 233, 191, 255) ,
|
||||
'lemonchiffon1' : (255, 250, 205, 255) ,
|
||||
'indianred3' : (205, 85, 85, 255) ,
|
||||
'violetred1' : (255, 62, 150, 255) ,
|
||||
'plum2' : (238, 174, 238, 255) ,
|
||||
'plum1' : (255, 187, 255, 255) ,
|
||||
'lemonchiffon4' : (139, 137, 112, 255) ,
|
||||
'gray99' : (252, 252, 252, 255) ,
|
||||
'grey13' : (33, 33, 33, 255) ,
|
||||
'grey55' : (140, 140, 140, 255) ,
|
||||
'darkcyan' : (0, 139, 139, 255) ,
|
||||
'chocolate4' : (139, 69, 19, 255) ,
|
||||
'lightgoldenrodyellow' : (250, 250, 210, 255) ,
|
||||
'gray54' : (138, 138, 138, 255) ,
|
||||
'lavender' : (230, 230, 250, 255) ,
|
||||
'chartreuse3' : (102, 205, 0, 255) ,
|
||||
'chartreuse2' : (118, 238, 0, 255) ,
|
||||
'chartreuse1' : (127, 255, 0, 255) ,
|
||||
'grey48' : (122, 122, 122, 255) ,
|
||||
'grey16' : (41, 41, 41, 255) ,
|
||||
'thistle' : (216, 191, 216, 255) ,
|
||||
'chartreuse4' : (69, 139, 0, 255) ,
|
||||
'darkorchid4' : (104, 34, 139, 255) ,
|
||||
'grey42' : (107, 107, 107, 255) ,
|
||||
'grey41' : (105, 105, 105, 255) ,
|
||||
'grey17' : (43, 43, 43, 255) ,
|
||||
'dimgrey' : (105, 105, 105, 255) ,
|
||||
'dodgerblue4' : (16, 78, 139, 255) ,
|
||||
'darkorchid2' : (178, 58, 238, 255) ,
|
||||
'darkorchid3' : (154, 50, 205, 255) ,
|
||||
'blue' : (0, 0, 255, 255) ,
|
||||
'rosybrown2' : (238, 180, 180, 255) ,
|
||||
'honeydew' : (240, 255, 240, 255) ,
|
||||
'gray18' : (46, 46, 46, 255) ,
|
||||
'cornflowerblue' : (100, 149, 237, 255) ,
|
||||
'grey91' : (232, 232, 232, 255) ,
|
||||
'gray14' : (36, 36, 36, 255) ,
|
||||
'gray15' : (38, 38, 38, 255) ,
|
||||
'gray16' : (41, 41, 41, 255) ,
|
||||
'maroon4' : (139, 28, 98, 255) ,
|
||||
'maroon3' : (205, 41, 144, 255) ,
|
||||
'maroon2' : (238, 48, 167, 255) ,
|
||||
'maroon1' : (255, 52, 179, 255) ,
|
||||
'gray13' : (33, 33, 33, 255) ,
|
||||
'gold3' : (205, 173, 0, 255) ,
|
||||
'gold2' : (238, 201, 0, 255) ,
|
||||
'gold1' : (255, 215, 0, 255) ,
|
||||
'grey79' : (201, 201, 201, 255) ,
|
||||
'palevioletred1' : (255, 130, 171, 255) ,
|
||||
'palevioletred2' : (238, 121, 159, 255) ,
|
||||
'gold4' : (139, 117, 0, 255) ,
|
||||
'gray41' : (105, 105, 105, 255) ,
|
||||
'gray84' : (214, 214, 214, 255) ,
|
||||
'mediumpurple' : (147, 112, 219, 255) ,
|
||||
'rosybrown1' : (255, 193, 193, 255) ,
|
||||
'lightblue2' : (178, 223, 238, 255) ,
|
||||
'lightblue3' : (154, 192, 205, 255) ,
|
||||
'grey57' : (145, 145, 145, 255) ,
|
||||
'lightblue1' : (191, 239, 255, 255) ,
|
||||
'lightblue4' : (104, 131, 139, 255) ,
|
||||
'gray33' : (84, 84, 84, 255) ,
|
||||
'skyblue4' : (74, 112, 139, 255) ,
|
||||
'grey97' : (247, 247, 247, 255) ,
|
||||
'skyblue1' : (135, 206, 255, 255) ,
|
||||
'gray27' : (69, 69, 69, 255) ,
|
||||
'skyblue3' : (108, 166, 205, 255) ,
|
||||
'skyblue2' : (126, 192, 238, 255) ,
|
||||
'lavenderblush1' : (255, 240, 245, 255) ,
|
||||
'darkgrey' : (169, 169, 169, 255) ,
|
||||
'lavenderblush3' : (205, 193, 197, 255) ,
|
||||
'darkslategrey' : (47, 79, 79, 255) ,
|
||||
'lavenderblush4' : (139, 131, 134, 255) ,
|
||||
'deeppink4' : (139, 10, 80, 255) ,
|
||||
'grey99' : (252, 252, 252, 255) ,
|
||||
'gray36' : (92, 92, 92, 255) ,
|
||||
'coral4' : (139, 62, 47, 255) ,
|
||||
'magenta3' : (205, 0, 205, 255) ,
|
||||
'lightskyblue4' : (96, 123, 139, 255) ,
|
||||
'mediumturquoise' : (72, 209, 204, 255) ,
|
||||
'gray34' : (87, 87, 87, 255) ,
|
||||
'floralwhite' : (255, 250, 240, 255) ,
|
||||
'grey39' : (99, 99, 99, 255) ,
|
||||
'grey36' : (92, 92, 92, 255) ,
|
||||
'grey37' : (94, 94, 94, 255) ,
|
||||
'grey34' : (87, 87, 87, 255) ,
|
||||
'gray26' : (66, 66, 66, 255) ,
|
||||
'royalblue2' : (67, 110, 238, 255) ,
|
||||
'grey33' : (84, 84, 84, 255) ,
|
||||
'turquoise1' : (0, 245, 255, 255) ,
|
||||
'grey31' : (79, 79, 79, 255) ,
|
||||
'steelblue1' : (99, 184, 255, 255) ,
|
||||
'sienna4' : (139, 71, 38, 255) ,
|
||||
'steelblue3' : (79, 148, 205, 255) ,
|
||||
'lavenderblush2' : (238, 224, 229, 255) ,
|
||||
'sienna1' : (255, 130, 71, 255) ,
|
||||
'steelblue4' : (54, 100, 139, 255) ,
|
||||
'sienna3' : (205, 104, 57, 255) ,
|
||||
'aquamarine4' : (69, 139, 116, 255) ,
|
||||
'lightyellow1' : (255, 255, 224, 255) ,
|
||||
'lightyellow2' : (238, 238, 209, 255) ,
|
||||
'lightsteelblue' : (176, 196, 222, 255) ,
|
||||
'lightyellow4' : (139, 139, 122, 255) ,
|
||||
'magenta2' : (238, 0, 238, 255) ,
|
||||
'lightskyblue1' : (176, 226, 255, 255) ,
|
||||
'lightgoldenrod' : (238, 221, 130, 255) ,
|
||||
'magenta4' : (139, 0, 139, 255) ,
|
||||
'gray87' : (222, 222, 222, 255) ,
|
||||
'greenyellow' : (173, 255, 47, 255) ,
|
||||
'navajowhite4' : (139, 121, 94, 255) ,
|
||||
'darkslategray4' : (82, 139, 139, 255) ,
|
||||
'olivedrab' : (107, 142, 35, 255) ,
|
||||
'navajowhite1' : (255, 222, 173, 255) ,
|
||||
'navajowhite2' : (238, 207, 161, 255) ,
|
||||
'darkgoldenrod1' : (255, 185, 15, 255) ,
|
||||
'sienna' : (160, 82, 45, 255) ,
|
||||
'blue1' : (0, 0, 255, 255) ,
|
||||
'yellow1' : (255, 255, 0, 255) ,
|
||||
'gray61' : (156, 156, 156, 255) ,
|
||||
'magenta1' : (255, 0, 255, 255) ,
|
||||
'grey52' : (133, 133, 133, 255) ,
|
||||
'orangered4' : (139, 37, 0, 255) ,
|
||||
'palegreen' : (152, 251, 152, 255) ,
|
||||
'gray86' : (219, 219, 219, 255) ,
|
||||
'grey80' : (204, 204, 204, 255) ,
|
||||
'seashell' : (255, 245, 238, 255) ,
|
||||
'royalblue' : (65, 105, 225, 255) ,
|
||||
'firebrick3' : (205, 38, 38, 255) ,
|
||||
'blue4' : (0, 0, 139, 255) ,
|
||||
'peru' : (205, 133, 63, 255) ,
|
||||
'gray60' : (153, 153, 153, 255) ,
|
||||
'aquamarine' : (127, 255, 212, 255) ,
|
||||
'grey53' : (135, 135, 135, 255) ,
|
||||
'tan4' : (139, 90, 43, 255) ,
|
||||
'darkgoldenrod' : (184, 134, 11, 255) ,
|
||||
'tan2' : (238, 154, 73, 255) ,
|
||||
'tan1' : (255, 165, 79, 255) ,
|
||||
'darkslategray' : (47, 79, 79, 255) ,
|
||||
'royalblue3' : (58, 95, 205, 255) ,
|
||||
'red2' : (238, 0, 0, 255) ,
|
||||
'red1' : (255, 0, 0, 255) ,
|
||||
'dodgerblue' : (30, 144, 255, 255) ,
|
||||
'violetred4' : (139, 34, 82, 255) ,
|
||||
'lightyellow' : (255, 255, 224, 255) ,
|
||||
'paleturquoise1' : (187, 255, 255, 255) ,
|
||||
'firebrick2' : (238, 44, 44, 255) ,
|
||||
'mediumaquamarine' : (102, 205, 170, 255) ,
|
||||
'lemonchiffon' : (255, 250, 205, 255) ,
|
||||
'chocolate' : (210, 105, 30, 255) ,
|
||||
'orchid4' : (139, 71, 137, 255) ,
|
||||
'maroon' : (176, 48, 96, 255) ,
|
||||
'gray38' : (97, 97, 97, 255) ,
|
||||
'darkorange4' : (139, 69, 0, 255) ,
|
||||
'mintcream' : (245, 255, 250, 255) ,
|
||||
'darkorange1' : (255, 127, 0, 255) ,
|
||||
'antiquewhite' : (250, 235, 215, 255) ,
|
||||
'darkorange2' : (238, 118, 0, 255) ,
|
||||
'grey18' : (46, 46, 46, 255) ,
|
||||
'grey19' : (48, 48, 48, 255) ,
|
||||
'grey38' : (97, 97, 97, 255) ,
|
||||
'moccasin' : (255, 228, 181, 255) ,
|
||||
'grey10' : (26, 26, 26, 255) ,
|
||||
'chocolate1' : (255, 127, 36, 255) ,
|
||||
'chocolate2' : (238, 118, 33, 255) ,
|
||||
'chocolate3' : (205, 102, 29, 255) ,
|
||||
'saddlebrown' : (139, 69, 19, 255) ,
|
||||
'grey15' : (38, 38, 38, 255) ,
|
||||
'darkslateblue' : (72, 61, 139, 255) ,
|
||||
'lightskyblue' : (135, 206, 250, 255) ,
|
||||
'gray69' : (176, 176, 176, 255) ,
|
||||
'gray68' : (173, 173, 173, 255) ,
|
||||
'deeppink' : (255, 20, 147, 255) ,
|
||||
'gray65' : (166, 166, 166, 255) ,
|
||||
'gray64' : (163, 163, 163, 255) ,
|
||||
'gray67' : (171, 171, 171, 255) ,
|
||||
'gray66' : (168, 168, 168, 255) ,
|
||||
'gray25' : (64, 64, 64, 255) ,
|
||||
'coral' : (255, 127, 80, 255) ,
|
||||
'gray63' : (161, 161, 161, 255) ,
|
||||
'gray62' : (158, 158, 158, 255) ,
|
||||
'goldenrod4' : (139, 105, 20, 255) ,
|
||||
'grey35' : (89, 89, 89, 255) ,
|
||||
'gray89' : (227, 227, 227, 255) ,
|
||||
'goldenrod1' : (255, 193, 37, 255) ,
|
||||
'goldenrod2' : (238, 180, 34, 255) ,
|
||||
'goldenrod3' : (205, 155, 29, 255) ,
|
||||
'springgreen1' : (0, 255, 127, 255) ,
|
||||
'springgreen2' : (0, 238, 118, 255) ,
|
||||
'springgreen3' : (0, 205, 102, 255) ,
|
||||
'springgreen4' : (0, 139, 69, 255) ,
|
||||
'mistyrose1' : (255, 228, 225, 255) ,
|
||||
'sandybrown' : (244, 164, 96, 255) ,
|
||||
'grey30' : (77, 77, 77, 255) ,
|
||||
'seashell2' : (238, 229, 222, 255) ,
|
||||
'seashell3' : (205, 197, 191, 255) ,
|
||||
'tan' : (210, 180, 140, 255) ,
|
||||
'seashell1' : (255, 245, 238, 255) ,
|
||||
'mistyrose3' : (205, 183, 181, 255) ,
|
||||
'magenta' : (255, 0, 255, 255) ,
|
||||
'pink' : (255, 192, 203, 255) ,
|
||||
'ivory2' : (238, 238, 224, 255) ,
|
||||
'ivory1' : (255, 255, 240, 255) ,
|
||||
'lightcyan2' : (209, 238, 238, 255) ,
|
||||
'mediumseagreen' : (60, 179, 113, 255) ,
|
||||
'ivory4' : (139, 139, 131, 255) ,
|
||||
'darkorange' : (255, 140, 0, 255) ,
|
||||
'powderblue' : (176, 224, 230, 255) ,
|
||||
'dodgerblue1' : (30, 144, 255, 255) ,
|
||||
'gray95' : (242, 242, 242, 255) ,
|
||||
'firebrick1' : (255, 48, 48, 255) ,
|
||||
'gray7' : (18, 18, 18, 255) ,
|
||||
'mistyrose4' : (139, 125, 123, 255) ,
|
||||
'tomato' : (255, 99, 71, 255) ,
|
||||
'indianred2' : (238, 99, 99, 255) ,
|
||||
'steelblue2' : (92, 172, 238, 255) ,
|
||||
'gray100' : (255, 255, 255, 255) ,
|
||||
'seashell4' : (139, 134, 130, 255) ,
|
||||
'grey89' : (227, 227, 227, 255) ,
|
||||
'grey88' : (224, 224, 224, 255) ,
|
||||
'grey87' : (222, 222, 222, 255) ,
|
||||
'grey86' : (219, 219, 219, 255) ,
|
||||
'grey85' : (217, 217, 217, 255) ,
|
||||
'grey84' : (214, 214, 214, 255) ,
|
||||
'midnightblue' : (25, 25, 112, 255) ,
|
||||
'grey82' : (209, 209, 209, 255) ,
|
||||
'grey81' : (207, 207, 207, 255) ,
|
||||
'yellow3' : (205, 205, 0, 255) ,
|
||||
'ivory3' : (205, 205, 193, 255) ,
|
||||
'grey22' : (56, 56, 56, 255) ,
|
||||
'gray85' : (217, 217, 217, 255) ,
|
||||
'violetred3' : (205, 50, 120, 255) ,
|
||||
'dodgerblue2' : (28, 134, 238, 255) ,
|
||||
'gray42' : (107, 107, 107, 255) ,
|
||||
'sienna2' : (238, 121, 66, 255) ,
|
||||
'grey72' : (184, 184, 184, 255) ,
|
||||
'grey73' : (186, 186, 186, 255) ,
|
||||
'grey70' : (179, 179, 179, 255) ,
|
||||
'palevioletred' : (219, 112, 147, 255) ,
|
||||
'lightslategray' : (119, 136, 153, 255) ,
|
||||
'grey77' : (196, 196, 196, 255) ,
|
||||
'grey74' : (189, 189, 189, 255) ,
|
||||
'slategray1' : (198, 226, 255, 255) ,
|
||||
'pink1' : (255, 181, 197, 255) ,
|
||||
'mediumpurple1' : (171, 130, 255, 255) ,
|
||||
'pink3' : (205, 145, 158, 255) ,
|
||||
'antiquewhite4' : (139, 131, 120, 255) ,
|
||||
'lightpink1' : (255, 174, 185, 255) ,
|
||||
'honeydew2' : (224, 238, 224, 255) ,
|
||||
'khaki4' : (139, 134, 78, 255) ,
|
||||
'darkolivegreen4' : (110, 139, 61, 255) ,
|
||||
'gray45' : (115, 115, 115, 255) ,
|
||||
'slategray3' : (159, 182, 205, 255) ,
|
||||
'darkolivegreen1' : (202, 255, 112, 255) ,
|
||||
'khaki1' : (255, 246, 143, 255) ,
|
||||
'khaki2' : (238, 230, 133, 255) ,
|
||||
'khaki3' : (205, 198, 115, 255) ,
|
||||
'lavenderblush' : (255, 240, 245, 255) ,
|
||||
'honeydew4' : (131, 139, 131, 255) ,
|
||||
'salmon3' : (205, 112, 84, 255) ,
|
||||
'salmon2' : (238, 130, 98, 255) ,
|
||||
'gray92' : (235, 235, 235, 255) ,
|
||||
'salmon4' : (139, 76, 57, 255) ,
|
||||
'gray49' : (125, 125, 125, 255) ,
|
||||
'gray48' : (122, 122, 122, 255) ,
|
||||
'linen' : (250, 240, 230, 255) ,
|
||||
'burlywood1' : (255, 211, 155, 255) ,
|
||||
'green' : (0, 255, 0, 255) ,
|
||||
'gray47' : (120, 120, 120, 255) ,
|
||||
'blueviolet' : (138, 43, 226, 255) ,
|
||||
'brown2' : (238, 59, 59, 255) ,
|
||||
'brown3' : (205, 51, 51, 255) ,
|
||||
'peachpuff' : (255, 218, 185, 255) ,
|
||||
'brown4' : (139, 35, 35, 255) ,
|
||||
'firebrick4' : (139, 26, 26, 255) ,
|
||||
'azure1' : (240, 255, 255, 255) ,
|
||||
'azure3' : (193, 205, 205, 255) ,
|
||||
'azure2' : (224, 238, 238, 255) ,
|
||||
'azure4' : (131, 139, 139, 255) ,
|
||||
'tomato4' : (139, 54, 38, 255) ,
|
||||
'orange4' : (139, 90, 0, 255) ,
|
||||
'firebrick' : (178, 34, 34, 255) ,
|
||||
'indianred' : (205, 92, 92, 255) ,
|
||||
'orange1' : (255, 165, 0, 255) ,
|
||||
'orange3' : (205, 133, 0, 255) ,
|
||||
'orange2' : (238, 154, 0, 255) ,
|
||||
'darkolivegreen' : (85, 107, 47, 255) ,
|
||||
'gray2' : (5, 5, 5, 255) ,
|
||||
'slategrey' : (112, 128, 144, 255) ,
|
||||
'gray81' : (207, 207, 207, 255) ,
|
||||
'darkred' : (139, 0, 0, 255) ,
|
||||
'gray3' : (8, 8, 8, 255) ,
|
||||
'lightsteelblue1' : (202, 225, 255, 255) ,
|
||||
'lightsteelblue2' : (188, 210, 238, 255) ,
|
||||
'lightsteelblue3' : (162, 181, 205, 255) ,
|
||||
'lightsteelblue4' : (110, 123, 139, 255) ,
|
||||
'tomato3' : (205, 79, 57, 255) ,
|
||||
'gray43' : (110, 110, 110, 255) ,
|
||||
'darkgoldenrod4' : (139, 101, 8, 255) ,
|
||||
'grey50' : (127, 127, 127, 255) ,
|
||||
'yellow4' : (139, 139, 0, 255) ,
|
||||
'mediumorchid' : (186, 85, 211, 255) ,
|
||||
'yellow2' : (238, 238, 0, 255) ,
|
||||
'darkgoldenrod2' : (238, 173, 14, 255) ,
|
||||
'darkgoldenrod3' : (205, 149, 12, 255) ,
|
||||
'chartreuse' : (127, 255, 0, 255) ,
|
||||
'mediumblue' : (0, 0, 205, 255) ,
|
||||
'gray4' : (10, 10, 10, 255) ,
|
||||
'springgreen' : (0, 255, 127, 255) ,
|
||||
'orange' : (255, 165, 0, 255) ,
|
||||
'gray5' : (13, 13, 13, 255) ,
|
||||
'lightsalmon' : (255, 160, 122, 255) ,
|
||||
'gray19' : (48, 48, 48, 255) ,
|
||||
'turquoise' : (64, 224, 208, 255) ,
|
||||
'lightseagreen' : (32, 178, 170, 255) ,
|
||||
'grey8' : (20, 20, 20, 255) ,
|
||||
'grey9' : (23, 23, 23, 255) ,
|
||||
'grey6' : (15, 15, 15, 255) ,
|
||||
'grey7' : (18, 18, 18, 255) ,
|
||||
'grey4' : (10, 10, 10, 255) ,
|
||||
'grey5' : (13, 13, 13, 255) ,
|
||||
'grey2' : (5, 5, 5, 255) ,
|
||||
'grey3' : (8, 8, 8, 255) ,
|
||||
'grey0' : (0, 0, 0, 255) ,
|
||||
'grey1' : (3, 3, 3, 255) ,
|
||||
'gray50' : (127, 127, 127, 255) ,
|
||||
'goldenrod' : (218, 165, 32, 255) ,
|
||||
'grey58' : (148, 148, 148, 255) ,
|
||||
'grey59' : (150, 150, 150, 255) ,
|
||||
'gray51' : (130, 130, 130, 255) ,
|
||||
'grey54' : (138, 138, 138, 255) ,
|
||||
'mediumorchid4' : (122, 55, 139, 255) ,
|
||||
'grey56' : (143, 143, 143, 255) ,
|
||||
'navajowhite3' : (205, 179, 139, 255) ,
|
||||
'mediumorchid1' : (224, 102, 255, 255) ,
|
||||
'grey51' : (130, 130, 130, 255) ,
|
||||
'mediumorchid3' : (180, 82, 205, 255) ,
|
||||
'mediumorchid2' : (209, 95, 238, 255) ,
|
||||
'cyan2' : (0, 238, 238, 255) ,
|
||||
'cyan3' : (0, 205, 205, 255) ,
|
||||
'gray23' : (59, 59, 59, 255) ,
|
||||
'cyan1' : (0, 255, 255, 255) ,
|
||||
'darkgreen' : (0, 100, 0, 255) ,
|
||||
'gray24' : (61, 61, 61, 255) ,
|
||||
'cyan4' : (0, 139, 139, 255) ,
|
||||
'darkviolet' : (148, 0, 211, 255) ,
|
||||
'peachpuff4' : (139, 119, 101, 255) ,
|
||||
'gray28' : (71, 71, 71, 255) ,
|
||||
'slateblue4' : (71, 60, 139, 255) ,
|
||||
'slateblue3' : (105, 89, 205, 255) ,
|
||||
'peachpuff1' : (255, 218, 185, 255) ,
|
||||
'peachpuff2' : (238, 203, 173, 255) ,
|
||||
'peachpuff3' : (205, 175, 149, 255) ,
|
||||
'gray29' : (74, 74, 74, 255) ,
|
||||
'paleturquoise' : (175, 238, 238, 255) ,
|
||||
'darkgray' : (169, 169, 169, 255) ,
|
||||
'grey25' : (64, 64, 64, 255) ,
|
||||
'darkmagenta' : (139, 0, 139, 255) ,
|
||||
'palegoldenrod' : (238, 232, 170, 255) ,
|
||||
'grey64' : (163, 163, 163, 255) ,
|
||||
'grey12' : (31, 31, 31, 255) ,
|
||||
'deeppink3' : (205, 16, 118, 255) ,
|
||||
'gray79' : (201, 201, 201, 255) ,
|
||||
'gray83' : (212, 212, 212, 255) ,
|
||||
'deeppink2' : (238, 18, 137, 255) ,
|
||||
'burlywood4' : (139, 115, 85, 255) ,
|
||||
'palevioletred4' : (139, 71, 93, 255) ,
|
||||
'deeppink1' : (255, 20, 147, 255) ,
|
||||
'slateblue2' : (122, 103, 238, 255) ,
|
||||
'grey46' : (117, 117, 117, 255) ,
|
||||
'royalblue4' : (39, 64, 139, 255) ,
|
||||
'yellowgreen' : (154, 205, 50, 255) ,
|
||||
'royalblue1' : (72, 118, 255, 255) ,
|
||||
'slateblue1' : (131, 111, 255, 255) ,
|
||||
'lightgoldenrod3' : (205, 190, 112, 255) ,
|
||||
'lightgoldenrod2' : (238, 220, 130, 255) ,
|
||||
'navy' : (0, 0, 128, 255) ,
|
||||
'orchid' : (218, 112, 214, 255) ,
|
||||
'ghostwhite' : (248, 248, 255, 255) ,
|
||||
'purple' : (160, 32, 240, 255) ,
|
||||
'darkkhaki' : (189, 183, 107, 255) ,
|
||||
'grey45' : (115, 115, 115, 255) ,
|
||||
'gray94' : (240, 240, 240, 255) ,
|
||||
'wheat4' : (139, 126, 102, 255) ,
|
||||
'gray96' : (245, 245, 245, 255) ,
|
||||
'gray97' : (247, 247, 247, 255) ,
|
||||
'wheat1' : (255, 231, 186, 255) ,
|
||||
'gray91' : (232, 232, 232, 255) ,
|
||||
'wheat3' : (205, 186, 150, 255) ,
|
||||
'wheat2' : (238, 216, 174, 255) ,
|
||||
'indianred4' : (139, 58, 58, 255) ,
|
||||
'coral2' : (238, 106, 80, 255) ,
|
||||
'coral1' : (255, 114, 86, 255) ,
|
||||
'violetred' : (208, 32, 144, 255) ,
|
||||
'rosybrown3' : (205, 155, 155, 255) ,
|
||||
'deepskyblue2' : (0, 178, 238, 255) ,
|
||||
'deepskyblue1' : (0, 191, 255, 255) ,
|
||||
'bisque' : (255, 228, 196, 255) ,
|
||||
'grey49' : (125, 125, 125, 255) ,
|
||||
'khaki' : (240, 230, 140, 255) ,
|
||||
'wheat' : (245, 222, 179, 255) ,
|
||||
'lightslateblue' : (132, 112, 255, 255) ,
|
||||
'mediumpurple3' : (137, 104, 205, 255) ,
|
||||
'gray55' : (140, 140, 140, 255) ,
|
||||
'deepskyblue' : (0, 191, 255, 255) ,
|
||||
'gray98' : (250, 250, 250, 255) ,
|
||||
'steelblue' : (70, 130, 180, 255) ,
|
||||
'aliceblue' : (240, 248, 255, 255) ,
|
||||
'lightskyblue2' : (164, 211, 238, 255) ,
|
||||
'lightskyblue3' : (141, 182, 205, 255) ,
|
||||
'lightslategrey' : (119, 136, 153, 255) ,
|
||||
'blue3' : (0, 0, 205, 255) ,
|
||||
'blue2' : (0, 0, 238, 255) ,
|
||||
'gainsboro' : (220, 220, 220, 255) ,
|
||||
'grey76' : (194, 194, 194, 255) ,
|
||||
'purple3' : (125, 38, 205, 255) ,
|
||||
'plum4' : (139, 102, 139, 255) ,
|
||||
'gray56' : (143, 143, 143, 255) ,
|
||||
'plum3' : (205, 150, 205, 255) ,
|
||||
'plum' : (221, 160, 221, 255) ,
|
||||
'lightgrey' : (211, 211, 211, 255) ,
|
||||
'mediumslateblue' : (123, 104, 238, 255) ,
|
||||
'mistyrose' : (255, 228, 225, 255) ,
|
||||
'lightcyan1' : (224, 255, 255, 255) ,
|
||||
'grey71' : (181, 181, 181, 255) ,
|
||||
'darksalmon' : (233, 150, 122, 255) ,
|
||||
'beige' : (245, 245, 220, 255) ,
|
||||
'grey24' : (61, 61, 61, 255) ,
|
||||
'azure' : (240, 255, 255, 255) ,
|
||||
'honeydew1' : (240, 255, 240, 255) ,
|
||||
'slategray2' : (185, 211, 238, 255) ,
|
||||
'dodgerblue3' : (24, 116, 205, 255) ,
|
||||
'slategray4' : (108, 123, 139, 255) ,
|
||||
'grey27' : (69, 69, 69, 255) ,
|
||||
'lightcyan3' : (180, 205, 205, 255) ,
|
||||
'cornsilk' : (255, 248, 220, 255) ,
|
||||
'tomato1' : (255, 99, 71, 255) ,
|
||||
'gray57' : (145, 145, 145, 255) ,
|
||||
'mediumvioletred' : (199, 21, 133, 255) ,
|
||||
'tomato2' : (238, 92, 66, 255) ,
|
||||
'snow4' : (139, 137, 137, 255) ,
|
||||
'grey75' : (191, 191, 191, 255) ,
|
||||
'snow2' : (238, 233, 233, 255) ,
|
||||
'snow3' : (205, 201, 201, 255) ,
|
||||
'snow1' : (255, 250, 250, 255) ,
|
||||
'grey23' : (59, 59, 59, 255) ,
|
||||
'cornsilk3' : (205, 200, 177, 255) ,
|
||||
'lightcoral' : (240, 128, 128, 255) ,
|
||||
'orangered' : (255, 69, 0, 255) ,
|
||||
'navajowhite' : (255, 222, 173, 255) ,
|
||||
'mediumpurple2' : (159, 121, 238, 255) ,
|
||||
'slategray' : (112, 128, 144, 255) ,
|
||||
'pink2' : (238, 169, 184, 255) ,
|
||||
'grey29' : (74, 74, 74, 255) ,
|
||||
'grey28' : (71, 71, 71, 255) ,
|
||||
'gray82' : (209, 209, 209, 255) ,
|
||||
'burlywood' : (222, 184, 135, 255) ,
|
||||
'mediumpurple4' : (93, 71, 139, 255) ,
|
||||
'mediumspringgreen' : (0, 250, 154, 255) ,
|
||||
'grey26' : (66, 66, 66, 255) ,
|
||||
'grey21' : (54, 54, 54, 255) ,
|
||||
'grey20' : (51, 51, 51, 255) ,
|
||||
'blanchedalmond' : (255, 235, 205, 255) ,
|
||||
'pink4' : (139, 99, 108, 255) ,
|
||||
'gray78' : (199, 199, 199, 255) ,
|
||||
'tan3' : (205, 133, 63, 255) ,
|
||||
'gray76' : (194, 194, 194, 255) ,
|
||||
'gray77' : (196, 196, 196, 255) ,
|
||||
'white' : (255, 255, 255, 255) ,
|
||||
'gray75' : (191, 191, 191, 255) ,
|
||||
'gray72' : (184, 184, 184, 255) ,
|
||||
'gray73' : (186, 186, 186, 255) ,
|
||||
'gray70' : (179, 179, 179, 255) ,
|
||||
'gray71' : (181, 181, 181, 255) ,
|
||||
'lightgray' : (211, 211, 211, 255) ,
|
||||
'ivory' : (255, 255, 240, 255) ,
|
||||
'gray46' : (117, 117, 117, 255) ,
|
||||
'gray74' : (189, 189, 189, 255) ,
|
||||
'lightyellow3' : (205, 205, 180, 255) ,
|
||||
'lightpink2' : (238, 162, 173, 255) ,
|
||||
'lightpink3' : (205, 140, 149, 255) ,
|
||||
'paleturquoise4' : (102, 139, 139, 255) ,
|
||||
'lightpink4' : (139, 95, 101, 255) ,
|
||||
'paleturquoise3' : (150, 205, 205, 255) ,
|
||||
'seagreen4' : (46, 139, 87, 255) ,
|
||||
'seagreen3' : (67, 205, 128, 255) ,
|
||||
'seagreen2' : (78, 238, 148, 255) ,
|
||||
'seagreen1' : (84, 255, 159, 255) ,
|
||||
'paleturquoise2' : (174, 238, 238, 255) ,
|
||||
'gray52' : (133, 133, 133, 255) ,
|
||||
'cornsilk4' : (139, 136, 120, 255) ,
|
||||
'cornsilk2' : (238, 232, 205, 255) ,
|
||||
'darkolivegreen3' : (162, 205, 90, 255) ,
|
||||
'cornsilk1' : (255, 248, 220, 255) ,
|
||||
'limegreen' : (50, 205, 50, 255) ,
|
||||
'darkolivegreen2' : (188, 238, 104, 255) ,
|
||||
'grey' : (190, 190, 190, 255) ,
|
||||
'violetred2' : (238, 58, 140, 255) ,
|
||||
'salmon1' : (255, 140, 105, 255) ,
|
||||
'grey92' : (235, 235, 235, 255) ,
|
||||
'grey93' : (237, 237, 237, 255) ,
|
||||
'grey94' : (240, 240, 240, 255) ,
|
||||
'grey95' : (242, 242, 242, 255) ,
|
||||
'grey96' : (245, 245, 245, 255) ,
|
||||
'grey83' : (212, 212, 212, 255) ,
|
||||
'grey98' : (250, 250, 250, 255) ,
|
||||
'lightgoldenrod1' : (255, 236, 139, 255) ,
|
||||
'palegreen1' : (154, 255, 154, 255) ,
|
||||
'red3' : (205, 0, 0, 255) ,
|
||||
'palegreen3' : (124, 205, 124, 255) ,
|
||||
'palegreen2' : (144, 238, 144, 255) ,
|
||||
'palegreen4' : (84, 139, 84, 255) ,
|
||||
'cadetblue' : (95, 158, 160, 255) ,
|
||||
'violet' : (238, 130, 238, 255) ,
|
||||
'mistyrose2' : (238, 213, 210, 255) ,
|
||||
'slateblue' : (106, 90, 205, 255) ,
|
||||
'grey43' : (110, 110, 110, 255) ,
|
||||
'grey90' : (229, 229, 229, 255) ,
|
||||
'gray35' : (89, 89, 89, 255) ,
|
||||
'turquoise3' : (0, 197, 205, 255) ,
|
||||
'turquoise2' : (0, 229, 238, 255) ,
|
||||
'burlywood3' : (205, 170, 125, 255) ,
|
||||
'burlywood2' : (238, 197, 145, 255) ,
|
||||
'lightcyan4' : (122, 139, 139, 255) ,
|
||||
'rosybrown' : (188, 143, 143, 255) ,
|
||||
'turquoise4' : (0, 134, 139, 255) ,
|
||||
'whitesmoke' : (245, 245, 245, 255) ,
|
||||
'lightblue' : (173, 216, 230, 255) ,
|
||||
'grey40' : (102, 102, 102, 255) ,
|
||||
'gray40' : (102, 102, 102, 255) ,
|
||||
'honeydew3' : (193, 205, 193, 255) ,
|
||||
'dimgray' : (105, 105, 105, 255) ,
|
||||
'grey47' : (120, 120, 120, 255) ,
|
||||
'seagreen' : (46, 139, 87, 255) ,
|
||||
'red4' : (139, 0, 0, 255) ,
|
||||
'grey14' : (36, 36, 36, 255) ,
|
||||
'snow' : (255, 250, 250, 255) ,
|
||||
'darkorchid1' : (191, 62, 255, 255) ,
|
||||
'gray58' : (148, 148, 148, 255) ,
|
||||
'gray59' : (150, 150, 150, 255) ,
|
||||
'cadetblue4' : (83, 134, 139, 255) ,
|
||||
'cadetblue3' : (122, 197, 205, 255) ,
|
||||
'cadetblue2' : (142, 229, 238, 255) ,
|
||||
'cadetblue1' : (152, 245, 255, 255) ,
|
||||
'olivedrab4' : (105, 139, 34, 255) ,
|
||||
'purple4' : (85, 26, 139, 255) ,
|
||||
'gray20' : (51, 51, 51, 255) ,
|
||||
'grey44' : (112, 112, 112, 255) ,
|
||||
'purple1' : (155, 48, 255, 255) ,
|
||||
'olivedrab1' : (192, 255, 62, 255) ,
|
||||
'olivedrab2' : (179, 238, 58, 255) ,
|
||||
'olivedrab3' : (154, 205, 50, 255) ,
|
||||
'orangered3' : (205, 55, 0, 255) ,
|
||||
'orangered2' : (238, 64, 0, 255) ,
|
||||
'orangered1' : (255, 69, 0, 255) ,
|
||||
'darkorchid' : (153, 50, 204, 255) ,
|
||||
'thistle3' : (205, 181, 205, 255) ,
|
||||
'thistle2' : (238, 210, 238, 255) ,
|
||||
'thistle1' : (255, 225, 255, 255) ,
|
||||
'salmon' : (250, 128, 114, 255) ,
|
||||
'gray93' : (237, 237, 237, 255) ,
|
||||
'thistle4' : (139, 123, 139, 255) ,
|
||||
'gray39' : (99, 99, 99, 255) ,
|
||||
'lawngreen' : (124, 252, 0, 255) ,
|
||||
'hotpink3' : (205, 96, 144, 255) ,
|
||||
'hotpink2' : (238, 106, 167, 255) ,
|
||||
'hotpink1' : (255, 110, 180, 255) ,
|
||||
'lightgreen' : (144, 238, 144, 255) ,
|
||||
'hotpink4' : (139, 58, 98, 255) ,
|
||||
'darkseagreen4' : (105, 139, 105, 255) ,
|
||||
'darkseagreen3' : (155, 205, 155, 255) ,
|
||||
'darkseagreen2' : (180, 238, 180, 255) ,
|
||||
'darkseagreen1' : (193, 255, 193, 255) ,
|
||||
'deepskyblue4' : (0, 104, 139, 255) ,
|
||||
'gray44' : (112, 112, 112, 255) ,
|
||||
'navyblue' : (0, 0, 128, 255) ,
|
||||
'darkblue' : (0, 0, 139, 255) ,
|
||||
'forestgreen' : (34, 139, 34, 255) ,
|
||||
'gray53' : (135, 135, 135, 255) ,
|
||||
'grey100' : (255, 255, 255, 255) ,
|
||||
'brown1' : (255, 64, 64, 255) ,
|
||||
}
|
||||
|
||||
for k,v in THECOLORS.items():
|
||||
THECOLORS[unicode_(k)] = v
|
||||
@@ -0,0 +1,103 @@
|
||||
# coding: ascii
|
||||
"""Python 2.x/3.x compatibility tools"""
|
||||
|
||||
import sys
|
||||
|
||||
__all__ = ['geterror', 'long_', 'xrange_', 'ord_', 'unichr_',
|
||||
'unicode_', 'raw_input_', 'as_bytes', 'as_unicode',
|
||||
'bytes_', 'imap_', 'PY_MAJOR_VERSION']
|
||||
|
||||
PY_MAJOR_VERSION = sys.version_info[0]
|
||||
|
||||
|
||||
def geterror():
|
||||
return sys.exc_info()[1]
|
||||
|
||||
# Python 3
|
||||
if PY_MAJOR_VERSION >= 3:
|
||||
long_ = int
|
||||
xrange_ = range
|
||||
from io import StringIO
|
||||
from io import BytesIO
|
||||
unichr_ = chr
|
||||
unicode_ = str
|
||||
bytes_ = bytes
|
||||
raw_input_ = input
|
||||
imap_ = map
|
||||
|
||||
# Represent escaped bytes and strings in a portable way.
|
||||
#
|
||||
# as_bytes: Allow a Python 3.x string to represent a bytes object.
|
||||
# e.g.: as_bytes("a\x01\b") == b"a\x01b" # Python 3.x
|
||||
# as_bytes("a\x01\b") == "a\x01b" # Python 2.x
|
||||
# as_unicode: Allow a Python "r" string to represent a unicode string.
|
||||
# e.g.: as_unicode(r"Bo\u00F6tes") == u"Bo\u00F6tes" # Python 2.x
|
||||
# as_unicode(r"Bo\u00F6tes") == "Bo\u00F6tes" # Python 3.x
|
||||
def as_bytes(string):
|
||||
""" '<binary literal>' => b'<binary literal>' """
|
||||
return string.encode('latin-1', 'strict')
|
||||
|
||||
def as_unicode(rstring):
|
||||
""" r'<Unicode literal>' => '<Unicode literal>' """
|
||||
return rstring.encode('ascii', 'strict').decode('unicode_escape',
|
||||
'strict')
|
||||
|
||||
# Python 2
|
||||
else:
|
||||
long_ = long
|
||||
xrange_ = xrange
|
||||
from cStringIO import StringIO
|
||||
BytesIO = StringIO
|
||||
unichr_ = unichr
|
||||
unicode_ = unicode
|
||||
bytes_ = str
|
||||
raw_input_ = raw_input
|
||||
from itertools import imap as imap_
|
||||
|
||||
# Represent escaped bytes and strings in a portable way.
|
||||
#
|
||||
# as_bytes: Allow a Python 3.x string to represent a bytes object.
|
||||
# e.g.: as_bytes("a\x01\b") == b"a\x01b" # Python 3.x
|
||||
# as_bytes("a\x01\b") == "a\x01b" # Python 2.x
|
||||
# as_unicode: Allow a Python "r" string to represent a unicode string.
|
||||
# e.g.: as_unicode(r"Bo\u00F6tes") == u"Bo\u00F6tes" # Python 2.x
|
||||
# as_unicode(r"Bo\u00F6tes") == "Bo\u00F6tes" # Python 3.x
|
||||
def as_bytes(string):
|
||||
""" '<binary literal>' => '<binary literal>' """
|
||||
return string
|
||||
|
||||
def as_unicode(rstring):
|
||||
""" r'<Unicode literal>' => u'<Unicode literal>' """
|
||||
return rstring.decode('unicode_escape', 'strict')
|
||||
|
||||
|
||||
def get_BytesIO():
|
||||
return BytesIO
|
||||
|
||||
|
||||
def get_StringIO():
|
||||
return StringIO
|
||||
|
||||
|
||||
def ord_(o):
|
||||
try:
|
||||
return ord(o)
|
||||
except TypeError:
|
||||
return o
|
||||
|
||||
if sys.platform == 'win32':
|
||||
filesystem_errors = "replace"
|
||||
elif PY_MAJOR_VERSION >= 3:
|
||||
filesystem_errors = "surrogateescape"
|
||||
else:
|
||||
filesystem_errors = "strict"
|
||||
|
||||
|
||||
def filesystem_encode(u):
|
||||
fsencoding = sys.getfilesystemencoding()
|
||||
if fsencoding.lower() in ['ascii', 'ansi_x3.4-1968'] and sys.platform.startswith('linux'):
|
||||
# Don't believe Linux systems claiming ASCII-only filesystems. In
|
||||
# practice, arbitrary bytes are allowed, and most things expect UTF-8.
|
||||
fsencoding = 'utf-8'
|
||||
return u.encode(fsencoding, filesystem_errors)
|
||||
|
||||
@@ -0,0 +1,521 @@
|
||||
"""
|
||||
Script used to generate this file (if we change something in the constants in the future):
|
||||
import pygame.constants
|
||||
const = []
|
||||
for element in dir(pygame.constants):
|
||||
constant_type = getattr(pygame.constants, element)
|
||||
if not element.startswith("_"):
|
||||
const.append("{}: {}\n".format(element, constant_type.__class__.__name__))
|
||||
with open("constants.pyi", "w") as f:
|
||||
for line in const:
|
||||
f.write(str(line))
|
||||
"""
|
||||
|
||||
ACTIVEEVENT: int
|
||||
ANYFORMAT: int
|
||||
APPACTIVE: int
|
||||
APPFOCUSMOUSE: int
|
||||
APPINPUTFOCUS: int
|
||||
ASYNCBLIT: int
|
||||
AUDIODEVICEADDED: int
|
||||
AUDIODEVICEREMOVED: int
|
||||
AUDIO_ALLOW_ANY_CHANGE: int
|
||||
AUDIO_ALLOW_CHANNELS_CHANGE: int
|
||||
AUDIO_ALLOW_FORMAT_CHANGE: int
|
||||
AUDIO_ALLOW_FREQUENCY_CHANGE: int
|
||||
AUDIO_S16: int
|
||||
AUDIO_S16LSB: int
|
||||
AUDIO_S16MSB: int
|
||||
AUDIO_S16SYS: int
|
||||
AUDIO_S8: int
|
||||
AUDIO_U16: int
|
||||
AUDIO_U16LSB: int
|
||||
AUDIO_U16MSB: int
|
||||
AUDIO_U16SYS: int
|
||||
AUDIO_U8: int
|
||||
BIG_ENDIAN: int
|
||||
BLENDMODE_ADD: int
|
||||
BLENDMODE_BLEND: int
|
||||
BLENDMODE_MOD: int
|
||||
BLENDMODE_NONE: int
|
||||
BLEND_ADD: int
|
||||
BLEND_MAX: int
|
||||
BLEND_MIN: int
|
||||
BLEND_MULT: int
|
||||
BLEND_PREMULTIPLIED: int
|
||||
BLEND_RGBA_ADD: int
|
||||
BLEND_RGBA_MAX: int
|
||||
BLEND_RGBA_MIN: int
|
||||
BLEND_RGBA_MULT: int
|
||||
BLEND_RGBA_SUB: int
|
||||
BLEND_RGB_ADD: int
|
||||
BLEND_RGB_MAX: int
|
||||
BLEND_RGB_MIN: int
|
||||
BLEND_RGB_MULT: int
|
||||
BLEND_RGB_SUB: int
|
||||
BLEND_SUB: int
|
||||
BUTTON_LEFT: int
|
||||
BUTTON_MIDDLE: int
|
||||
BUTTON_RIGHT: int
|
||||
BUTTON_WHEELDOWN: int
|
||||
BUTTON_WHEELUP: int
|
||||
BUTTON_X1: int
|
||||
BUTTON_X2: int
|
||||
CONTROLLERAXISMOTION: int
|
||||
CONTROLLERBUTTONDOWN: int
|
||||
CONTROLLERBUTTONUP: int
|
||||
CONTROLLERDEVICEADDED: int
|
||||
CONTROLLERDEVICEREMAPPED: int
|
||||
CONTROLLERDEVICEREMOVED: int
|
||||
CONTROLLER_AXIS_INVALID: int
|
||||
CONTROLLER_AXIS_LEFTX: int
|
||||
CONTROLLER_AXIS_LEFTY: int
|
||||
CONTROLLER_AXIS_MAX: int
|
||||
CONTROLLER_AXIS_RIGHTX: int
|
||||
CONTROLLER_AXIS_RIGHTY: int
|
||||
CONTROLLER_AXIS_TRIGGERLEFT: int
|
||||
CONTROLLER_AXIS_TRIGGERRIGHT: int
|
||||
CONTROLLER_BUTTON_A: int
|
||||
CONTROLLER_BUTTON_B: int
|
||||
CONTROLLER_BUTTON_BACK: int
|
||||
CONTROLLER_BUTTON_DPAD_DOWN: int
|
||||
CONTROLLER_BUTTON_DPAD_LEFT: int
|
||||
CONTROLLER_BUTTON_DPAD_RIGHT: int
|
||||
CONTROLLER_BUTTON_DPAD_UP: int
|
||||
CONTROLLER_BUTTON_GUIDE: int
|
||||
CONTROLLER_BUTTON_INVALID: int
|
||||
CONTROLLER_BUTTON_LEFTSHOULDER: int
|
||||
CONTROLLER_BUTTON_LEFTSTICK: int
|
||||
CONTROLLER_BUTTON_MAX: int
|
||||
CONTROLLER_BUTTON_RIGHTSHOULDER: int
|
||||
CONTROLLER_BUTTON_RIGHTSTICK: int
|
||||
CONTROLLER_BUTTON_START: int
|
||||
CONTROLLER_BUTTON_X: int
|
||||
CONTROLLER_BUTTON_Y: int
|
||||
DOUBLEBUF: int
|
||||
DROPBEGIN: int
|
||||
DROPCOMPLETE: int
|
||||
DROPFILE: int
|
||||
DROPTEXT: int
|
||||
FINGERDOWN: int
|
||||
FINGERMOTION: int
|
||||
FINGERUP: int
|
||||
FULLSCREEN: int
|
||||
GL_ACCELERATED_VISUAL: int
|
||||
GL_ACCUM_ALPHA_SIZE: int
|
||||
GL_ACCUM_BLUE_SIZE: int
|
||||
GL_ACCUM_GREEN_SIZE: int
|
||||
GL_ACCUM_RED_SIZE: int
|
||||
GL_ALPHA_SIZE: int
|
||||
GL_BLUE_SIZE: int
|
||||
GL_BUFFER_SIZE: int
|
||||
GL_CONTEXT_DEBUG_FLAG: int
|
||||
GL_CONTEXT_FLAGS: int
|
||||
GL_CONTEXT_FORWARD_COMPATIBLE_FLAG: int
|
||||
GL_CONTEXT_MAJOR_VERSION: int
|
||||
GL_CONTEXT_MINOR_VERSION: int
|
||||
GL_CONTEXT_PROFILE_COMPATIBILITY: int
|
||||
GL_CONTEXT_PROFILE_CORE: int
|
||||
GL_CONTEXT_PROFILE_ES: int
|
||||
GL_CONTEXT_PROFILE_MASK: int
|
||||
GL_CONTEXT_RELEASE_BEHAVIOR: int
|
||||
GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH: int
|
||||
GL_CONTEXT_RELEASE_BEHAVIOR_NONE: int
|
||||
GL_CONTEXT_RESET_ISOLATION_FLAG: int
|
||||
GL_CONTEXT_ROBUST_ACCESS_FLAG: int
|
||||
GL_DEPTH_SIZE: int
|
||||
GL_DOUBLEBUFFER: int
|
||||
GL_FRAMEBUFFER_SRGB_CAPABLE: int
|
||||
GL_GREEN_SIZE: int
|
||||
GL_MULTISAMPLEBUFFERS: int
|
||||
GL_MULTISAMPLESAMPLES: int
|
||||
GL_RED_SIZE: int
|
||||
GL_SHARE_WITH_CURRENT_CONTEXT: int
|
||||
GL_STENCIL_SIZE: int
|
||||
GL_STEREO: int
|
||||
GL_SWAP_CONTROL: int
|
||||
HAT_CENTERED: int
|
||||
HAT_DOWN: int
|
||||
HAT_LEFT: int
|
||||
HAT_LEFTDOWN: int
|
||||
HAT_LEFTUP: int
|
||||
HAT_RIGHT: int
|
||||
HAT_RIGHTDOWN: int
|
||||
HAT_RIGHTUP: int
|
||||
HAT_UP: int
|
||||
HIDDEN: int
|
||||
HWACCEL: int
|
||||
HWPALETTE: int
|
||||
HWSURFACE: int
|
||||
JOYAXISMOTION: int
|
||||
JOYBALLMOTION: int
|
||||
JOYBUTTONDOWN: int
|
||||
JOYBUTTONUP: int
|
||||
JOYHATMOTION: int
|
||||
KEYDOWN: int
|
||||
KEYUP: int
|
||||
KMOD_ALT: int
|
||||
KMOD_CAPS: int
|
||||
KMOD_CTRL: int
|
||||
KMOD_GUI: int
|
||||
KMOD_LALT: int
|
||||
KMOD_LCTRL: int
|
||||
KMOD_LGUI: int
|
||||
KMOD_LMETA: int
|
||||
KMOD_LSHIFT: int
|
||||
KMOD_META: int
|
||||
KMOD_MODE: int
|
||||
KMOD_NONE: int
|
||||
KMOD_NUM: int
|
||||
KMOD_RALT: int
|
||||
KMOD_RCTRL: int
|
||||
KMOD_RGUI: int
|
||||
KMOD_RMETA: int
|
||||
KMOD_RSHIFT: int
|
||||
KMOD_SHIFT: int
|
||||
KSCAN_0: int
|
||||
KSCAN_1: int
|
||||
KSCAN_2: int
|
||||
KSCAN_3: int
|
||||
KSCAN_4: int
|
||||
KSCAN_5: int
|
||||
KSCAN_6: int
|
||||
KSCAN_7: int
|
||||
KSCAN_8: int
|
||||
KSCAN_9: int
|
||||
KSCAN_A: int
|
||||
KSCAN_APOSTROPHE: int
|
||||
KSCAN_B: int
|
||||
KSCAN_BACKSLASH: int
|
||||
KSCAN_BACKSPACE: int
|
||||
KSCAN_BREAK: int
|
||||
KSCAN_C: int
|
||||
KSCAN_CAPSLOCK: int
|
||||
KSCAN_CLEAR: int
|
||||
KSCAN_COMMA: int
|
||||
KSCAN_CURRENCYSUBUNIT: int
|
||||
KSCAN_CURRENCYUNIT: int
|
||||
KSCAN_D: int
|
||||
KSCAN_DELETE: int
|
||||
KSCAN_DOWN: int
|
||||
KSCAN_E: int
|
||||
KSCAN_END: int
|
||||
KSCAN_EQUALS: int
|
||||
KSCAN_ESCAPE: int
|
||||
KSCAN_EURO: int
|
||||
KSCAN_F: int
|
||||
KSCAN_F1: int
|
||||
KSCAN_F10: int
|
||||
KSCAN_F11: int
|
||||
KSCAN_F12: int
|
||||
KSCAN_F13: int
|
||||
KSCAN_F14: int
|
||||
KSCAN_F15: int
|
||||
KSCAN_F2: int
|
||||
KSCAN_F3: int
|
||||
KSCAN_F4: int
|
||||
KSCAN_F5: int
|
||||
KSCAN_F6: int
|
||||
KSCAN_F7: int
|
||||
KSCAN_F8: int
|
||||
KSCAN_F9: int
|
||||
KSCAN_G: int
|
||||
KSCAN_GRAVE: int
|
||||
KSCAN_H: int
|
||||
KSCAN_HELP: int
|
||||
KSCAN_HOME: int
|
||||
KSCAN_I: int
|
||||
KSCAN_INSERT: int
|
||||
KSCAN_INTERNATIONAL1: int
|
||||
KSCAN_INTERNATIONAL2: int
|
||||
KSCAN_INTERNATIONAL3: int
|
||||
KSCAN_INTERNATIONAL4: int
|
||||
KSCAN_INTERNATIONAL5: int
|
||||
KSCAN_INTERNATIONAL6: int
|
||||
KSCAN_INTERNATIONAL7: int
|
||||
KSCAN_INTERNATIONAL8: int
|
||||
KSCAN_INTERNATIONAL9: int
|
||||
KSCAN_J: int
|
||||
KSCAN_K: int
|
||||
KSCAN_KP0: int
|
||||
KSCAN_KP1: int
|
||||
KSCAN_KP2: int
|
||||
KSCAN_KP3: int
|
||||
KSCAN_KP4: int
|
||||
KSCAN_KP5: int
|
||||
KSCAN_KP6: int
|
||||
KSCAN_KP7: int
|
||||
KSCAN_KP8: int
|
||||
KSCAN_KP9: int
|
||||
KSCAN_KP_0: int
|
||||
KSCAN_KP_1: int
|
||||
KSCAN_KP_2: int
|
||||
KSCAN_KP_3: int
|
||||
KSCAN_KP_4: int
|
||||
KSCAN_KP_5: int
|
||||
KSCAN_KP_6: int
|
||||
KSCAN_KP_7: int
|
||||
KSCAN_KP_8: int
|
||||
KSCAN_KP_9: int
|
||||
KSCAN_KP_DIVIDE: int
|
||||
KSCAN_KP_ENTER: int
|
||||
KSCAN_KP_EQUALS: int
|
||||
KSCAN_KP_MINUS: int
|
||||
KSCAN_KP_MULTIPLY: int
|
||||
KSCAN_KP_PERIOD: int
|
||||
KSCAN_KP_PLUS: int
|
||||
KSCAN_L: int
|
||||
KSCAN_LALT: int
|
||||
KSCAN_LANG1: int
|
||||
KSCAN_LANG2: int
|
||||
KSCAN_LANG3: int
|
||||
KSCAN_LANG4: int
|
||||
KSCAN_LANG5: int
|
||||
KSCAN_LANG6: int
|
||||
KSCAN_LANG7: int
|
||||
KSCAN_LANG8: int
|
||||
KSCAN_LANG9: int
|
||||
KSCAN_LCTRL: int
|
||||
KSCAN_LEFT: int
|
||||
KSCAN_LEFTBRACKET: int
|
||||
KSCAN_LGUI: int
|
||||
KSCAN_LMETA: int
|
||||
KSCAN_LSHIFT: int
|
||||
KSCAN_LSUPER: int
|
||||
KSCAN_M: int
|
||||
KSCAN_MENU: int
|
||||
KSCAN_MINUS: int
|
||||
KSCAN_MODE: int
|
||||
KSCAN_N: int
|
||||
KSCAN_NONUSBACKSLASH: int
|
||||
KSCAN_NONUSHASH: int
|
||||
KSCAN_NUMLOCK: int
|
||||
KSCAN_NUMLOCKCLEAR: int
|
||||
KSCAN_O: int
|
||||
KSCAN_P: int
|
||||
KSCAN_PAGEDOWN: int
|
||||
KSCAN_PAGEUP: int
|
||||
KSCAN_PAUSE: int
|
||||
KSCAN_PERIOD: int
|
||||
KSCAN_POWER: int
|
||||
KSCAN_PRINT: int
|
||||
KSCAN_PRINTSCREEN: int
|
||||
KSCAN_Q: int
|
||||
KSCAN_R: int
|
||||
KSCAN_RALT: int
|
||||
KSCAN_RCTRL: int
|
||||
KSCAN_RETURN: int
|
||||
KSCAN_RGUI: int
|
||||
KSCAN_RIGHT: int
|
||||
KSCAN_RIGHTBRACKET: int
|
||||
KSCAN_RMETA: int
|
||||
KSCAN_RSHIFT: int
|
||||
KSCAN_RSUPER: int
|
||||
KSCAN_S: int
|
||||
KSCAN_SCROLLLOCK: int
|
||||
KSCAN_SCROLLOCK: int
|
||||
KSCAN_SEMICOLON: int
|
||||
KSCAN_SLASH: int
|
||||
KSCAN_SPACE: int
|
||||
KSCAN_SYSREQ: int
|
||||
KSCAN_T: int
|
||||
KSCAN_TAB: int
|
||||
KSCAN_U: int
|
||||
KSCAN_UNKNOWN: int
|
||||
KSCAN_UP: int
|
||||
KSCAN_V: int
|
||||
KSCAN_W: int
|
||||
KSCAN_X: int
|
||||
KSCAN_Y: int
|
||||
KSCAN_Z: int
|
||||
K_0: int
|
||||
K_1: int
|
||||
K_2: int
|
||||
K_3: int
|
||||
K_4: int
|
||||
K_5: int
|
||||
K_6: int
|
||||
K_7: int
|
||||
K_8: int
|
||||
K_9: int
|
||||
K_AMPERSAND: int
|
||||
K_ASTERISK: int
|
||||
K_AT: int
|
||||
K_BACKQUOTE: int
|
||||
K_BACKSLASH: int
|
||||
K_BACKSPACE: int
|
||||
K_BREAK: int
|
||||
K_CAPSLOCK: int
|
||||
K_CARET: int
|
||||
K_CLEAR: int
|
||||
K_COLON: int
|
||||
K_COMMA: int
|
||||
K_CURRENCYSUBUNIT: int
|
||||
K_CURRENCYUNIT: int
|
||||
K_DELETE: int
|
||||
K_DOLLAR: int
|
||||
K_DOWN: int
|
||||
K_END: int
|
||||
K_EQUALS: int
|
||||
K_ESCAPE: int
|
||||
K_EURO: int
|
||||
K_EXCLAIM: int
|
||||
K_F1: int
|
||||
K_F10: int
|
||||
K_F11: int
|
||||
K_F12: int
|
||||
K_F13: int
|
||||
K_F14: int
|
||||
K_F15: int
|
||||
K_F2: int
|
||||
K_F3: int
|
||||
K_F4: int
|
||||
K_F5: int
|
||||
K_F6: int
|
||||
K_F7: int
|
||||
K_F8: int
|
||||
K_F9: int
|
||||
K_GREATER: int
|
||||
K_HASH: int
|
||||
K_HELP: int
|
||||
K_HOME: int
|
||||
K_INSERT: int
|
||||
K_KP0: int
|
||||
K_KP1: int
|
||||
K_KP2: int
|
||||
K_KP3: int
|
||||
K_KP4: int
|
||||
K_KP5: int
|
||||
K_KP6: int
|
||||
K_KP7: int
|
||||
K_KP8: int
|
||||
K_KP9: int
|
||||
K_KP_0: int
|
||||
K_KP_1: int
|
||||
K_KP_2: int
|
||||
K_KP_3: int
|
||||
K_KP_4: int
|
||||
K_KP_5: int
|
||||
K_KP_6: int
|
||||
K_KP_7: int
|
||||
K_KP_8: int
|
||||
K_KP_9: int
|
||||
K_KP_DIVIDE: int
|
||||
K_KP_ENTER: int
|
||||
K_KP_EQUALS: int
|
||||
K_KP_MINUS: int
|
||||
K_KP_MULTIPLY: int
|
||||
K_KP_PERIOD: int
|
||||
K_KP_PLUS: int
|
||||
K_LALT: int
|
||||
K_LCTRL: int
|
||||
K_LEFT: int
|
||||
K_LEFTBRACKET: int
|
||||
K_LEFTPAREN: int
|
||||
K_LESS: int
|
||||
K_LGUI: int
|
||||
K_LMETA: int
|
||||
K_LSHIFT: int
|
||||
K_LSUPER: int
|
||||
K_MENU: int
|
||||
K_MINUS: int
|
||||
K_MODE: int
|
||||
K_NUMLOCK: int
|
||||
K_NUMLOCKCLEAR: int
|
||||
K_PAGEDOWN: int
|
||||
K_PAGEUP: int
|
||||
K_PAUSE: int
|
||||
K_PERCENT: int
|
||||
K_PERIOD: int
|
||||
K_PLUS: int
|
||||
K_POWER: int
|
||||
K_PRINT: int
|
||||
K_PRINTSCREEN: int
|
||||
K_QUESTION: int
|
||||
K_QUOTE: int
|
||||
K_QUOTEDBL: int
|
||||
K_RALT: int
|
||||
K_RCTRL: int
|
||||
K_RETURN: int
|
||||
K_RGUI: int
|
||||
K_RIGHT: int
|
||||
K_RIGHTBRACKET: int
|
||||
K_RIGHTPAREN: int
|
||||
K_RMETA: int
|
||||
K_RSHIFT: int
|
||||
K_RSUPER: int
|
||||
K_SCROLLLOCK: int
|
||||
K_SCROLLOCK: int
|
||||
K_SEMICOLON: int
|
||||
K_SLASH: int
|
||||
K_SPACE: int
|
||||
K_SYSREQ: int
|
||||
K_TAB: int
|
||||
K_UNDERSCORE: int
|
||||
K_UNKNOWN: int
|
||||
K_UP: int
|
||||
K_a: int
|
||||
K_b: int
|
||||
K_c: int
|
||||
K_d: int
|
||||
K_e: int
|
||||
K_f: int
|
||||
K_g: int
|
||||
K_h: int
|
||||
K_i: int
|
||||
K_j: int
|
||||
K_k: int
|
||||
K_l: int
|
||||
K_m: int
|
||||
K_n: int
|
||||
K_o: int
|
||||
K_p: int
|
||||
K_q: int
|
||||
K_r: int
|
||||
K_s: int
|
||||
K_t: int
|
||||
K_u: int
|
||||
K_v: int
|
||||
K_w: int
|
||||
K_x: int
|
||||
K_y: int
|
||||
K_z: int
|
||||
LIL_ENDIAN: int
|
||||
MIDIIN: int
|
||||
MIDIOUT: int
|
||||
MOUSEBUTTONDOWN: int
|
||||
MOUSEBUTTONUP: int
|
||||
MOUSEMOTION: int
|
||||
MOUSEWHEEL: int
|
||||
MULTIGESTURE: int
|
||||
NOEVENT: int
|
||||
NOFRAME: int
|
||||
NUMEVENTS: int
|
||||
OPENGL: int
|
||||
OPENGLBLIT: int
|
||||
PREALLOC: int
|
||||
QUIT: int
|
||||
RESIZABLE: int
|
||||
RLEACCEL: int
|
||||
RLEACCELOK: int
|
||||
SCALED: int
|
||||
SCRAP_BMP: str
|
||||
SCRAP_CLIPBOARD: int
|
||||
SCRAP_PBM: str
|
||||
SCRAP_PPM: str
|
||||
SCRAP_SELECTION: int
|
||||
SCRAP_TEXT: str
|
||||
SHOWN: int
|
||||
SRCALPHA: int
|
||||
SRCCOLORKEY: int
|
||||
SWSURFACE: int
|
||||
SYSWMEVENT: int
|
||||
TEXTEDITING: int
|
||||
TEXTINPUT: int
|
||||
TIMER_RESOLUTION: int
|
||||
USEREVENT: int
|
||||
USEREVENT_DROPFILE: int
|
||||
VIDEOEXPOSE: int
|
||||
VIDEORESIZE: int
|
||||
WINDOWEVENT: int
|
||||
WINDOWEVENT_CLOSE: int
|
||||
@@ -0,0 +1,310 @@
|
||||
## pygame - Python Game Library
|
||||
## Copyright (C) 2000-2003 Pete Shinners
|
||||
##
|
||||
## This library is free software; you can redistribute it and/or
|
||||
## modify it under the terms of the GNU Library General Public
|
||||
## License as published by the Free Software Foundation; either
|
||||
## version 2 of the License, or (at your option) any later version.
|
||||
##
|
||||
## This library is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
## Library General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU Library General Public
|
||||
## License along with this library; if not, write to the Free
|
||||
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
##
|
||||
## Pete Shinners
|
||||
## pete@shinners.org
|
||||
|
||||
"""Set of cursor resources available for use. These cursors come
|
||||
in a sequence of values that are needed as the arguments for
|
||||
pygame.mouse.set_cursor(). to dereference the sequence in place
|
||||
and create the cursor in one step, call like this;
|
||||
pygame.mouse.set_cursor(*pygame.cursors.arrow).
|
||||
|
||||
Here is a list of available cursors; arrow, diamond, ball,
|
||||
broken_x, tri_left, tri_right
|
||||
|
||||
There is also a sample string cursor named 'thickarrow_strings'.
|
||||
The compile() function can convert these string cursors into cursor byte data.
|
||||
"""
|
||||
|
||||
#default pygame black arrow
|
||||
arrow = ((16, 16), (0, 0),
|
||||
(0x00,0x00,0x40,0x00,0x60,0x00,0x70,0x00,0x78,0x00,0x7C,0x00,0x7E,0x00,0x7F,0x00,
|
||||
0x7F,0x80,0x7C,0x00,0x6C,0x00,0x46,0x00,0x06,0x00,0x03,0x00,0x03,0x00,0x00,0x00),
|
||||
(0x40,0x00,0xE0,0x00,0xF0,0x00,0xF8,0x00,0xFC,0x00,0xFE,0x00,0xFF,0x00,0xFF,0x80,
|
||||
0xFF,0xC0,0xFF,0x80,0xFE,0x00,0xEF,0x00,0x4F,0x00,0x07,0x80,0x07,0x80,0x03,0x00))
|
||||
|
||||
diamond = ((16, 16), (7, 7),
|
||||
(0, 0, 1, 0, 3, 128, 7, 192, 14, 224, 28, 112, 56, 56, 112, 28, 56,
|
||||
56, 28, 112, 14, 224, 7, 192, 3, 128, 1, 0, 0, 0, 0, 0),
|
||||
(1, 0, 3, 128, 7, 192, 15, 224, 31, 240, 62, 248, 124, 124, 248, 62,
|
||||
124, 124, 62, 248, 31, 240, 15, 224, 7, 192, 3, 128, 1, 0, 0, 0))
|
||||
|
||||
ball = ((16, 16), (7, 7),
|
||||
(0, 0, 3, 192, 15, 240, 24, 248, 51, 252, 55, 252, 127, 254, 127, 254,
|
||||
127, 254, 127, 254, 63, 252, 63, 252, 31, 248, 15, 240, 3, 192, 0, 0),
|
||||
(3, 192, 15, 240, 31, 248, 63, 252, 127, 254, 127, 254, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 127, 254, 127, 254, 63, 252, 31, 248, 15, 240,
|
||||
3, 192))
|
||||
|
||||
broken_x = ((16, 16), (7, 7),
|
||||
(0, 0, 96, 6, 112, 14, 56, 28, 28, 56, 12, 48, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
12, 48, 28, 56, 56, 28, 112, 14, 96, 6, 0, 0),
|
||||
(224, 7, 240, 15, 248, 31, 124, 62, 62, 124, 30, 120, 14, 112, 0, 0, 0,
|
||||
0, 14, 112, 30, 120, 62, 124, 124, 62, 248, 31, 240, 15, 224, 7))
|
||||
|
||||
|
||||
tri_left = ((16, 16), (1, 1),
|
||||
(0, 0, 96, 0, 120, 0, 62, 0, 63, 128, 31, 224, 31, 248, 15, 254, 15, 254,
|
||||
7, 128, 7, 128, 3, 128, 3, 128, 1, 128, 1, 128, 0, 0),
|
||||
(224, 0, 248, 0, 254, 0, 127, 128, 127, 224, 63, 248, 63, 254, 31, 255,
|
||||
31, 255, 15, 254, 15, 192, 7, 192, 7, 192, 3, 192, 3, 192, 1, 128))
|
||||
|
||||
tri_right = ((16, 16), (14, 1),
|
||||
(0, 0, 0, 6, 0, 30, 0, 124, 1, 252, 7, 248, 31, 248, 127, 240, 127, 240,
|
||||
1, 224, 1, 224, 1, 192, 1, 192, 1, 128, 1, 128, 0, 0),
|
||||
(0, 7, 0, 31, 0, 127, 1, 254, 7, 254, 31, 252, 127, 252, 255, 248, 255,
|
||||
248, 127, 240, 3, 240, 3, 224, 3, 224, 3, 192, 3, 192, 1, 128))
|
||||
|
||||
|
||||
|
||||
#here is an example string resource cursor. to use this;
|
||||
# curs, mask = pygame.cursors.compile_cursor(pygame.cursors.thickarrow_strings, 'X', '.')
|
||||
# pygame.mouse.set_cursor((24, 24), (0, 0), curs, mask)
|
||||
|
||||
thickarrow_strings = ( #sized 24x24
|
||||
"XX ",
|
||||
"XXX ",
|
||||
"XXXX ",
|
||||
"XX.XX ",
|
||||
"XX..XX ",
|
||||
"XX...XX ",
|
||||
"XX....XX ",
|
||||
"XX.....XX ",
|
||||
"XX......XX ",
|
||||
"XX.......XX ",
|
||||
"XX........XX ",
|
||||
"XX........XXX ",
|
||||
"XX......XXXXX ",
|
||||
"XX.XXX..XX ",
|
||||
"XXXX XX..XX ",
|
||||
"XX XX..XX ",
|
||||
" XX..XX ",
|
||||
" XX..XX ",
|
||||
" XX..XX ",
|
||||
" XXXX ",
|
||||
" XX ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
)
|
||||
|
||||
sizer_x_strings = ( #sized 24x16
|
||||
" X X ",
|
||||
" XX XX ",
|
||||
" X.X X.X ",
|
||||
" X..X X..X ",
|
||||
" X...XXXXXXXX...X ",
|
||||
"X................X ",
|
||||
" X...XXXXXXXX...X ",
|
||||
" X..X X..X ",
|
||||
" X.X X.X ",
|
||||
" XX XX ",
|
||||
" X X ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
)
|
||||
sizer_y_strings = ( #sized 16x24
|
||||
" X ",
|
||||
" X.X ",
|
||||
" X...X ",
|
||||
" X.....X ",
|
||||
" X.......X ",
|
||||
"XXXXX.XXXXX ",
|
||||
" X.X ",
|
||||
" X.X ",
|
||||
" X.X ",
|
||||
" X.X ",
|
||||
" X.X ",
|
||||
" X.X ",
|
||||
" X.X ",
|
||||
"XXXXX.XXXXX ",
|
||||
" X.......X ",
|
||||
" X.....X ",
|
||||
" X...X ",
|
||||
" X.X ",
|
||||
" X ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
)
|
||||
sizer_xy_strings = ( #sized 24x16
|
||||
"XXXXXXXX ",
|
||||
"X.....X ",
|
||||
"X....X ",
|
||||
"X...X ",
|
||||
"X..X.X ",
|
||||
"X.X X.X ",
|
||||
"XX X.X X ",
|
||||
"X X.X XX ",
|
||||
" X.XX.X ",
|
||||
" X...X ",
|
||||
" X...X ",
|
||||
" X....X ",
|
||||
" X.....X ",
|
||||
" XXXXXXXX ",
|
||||
" ",
|
||||
" ",
|
||||
)
|
||||
textmarker_strings = ( #sized 8x16
|
||||
"ooo ooo ",
|
||||
" o ",
|
||||
" o ",
|
||||
" o ",
|
||||
" o ",
|
||||
" o ",
|
||||
" o ",
|
||||
" o ",
|
||||
" o ",
|
||||
" o ",
|
||||
" o ",
|
||||
"ooo ooo ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
)
|
||||
|
||||
|
||||
|
||||
def compile(strings, black='X', white='.',xor='o'):
|
||||
"""pygame.cursors.compile(strings, black, white,xor) -> data, mask
|
||||
compile cursor strings into cursor data
|
||||
|
||||
This takes a set of strings with equal length and computes
|
||||
the binary data for that cursor. The string widths must be
|
||||
divisible by 8.
|
||||
|
||||
The black and white arguments are single letter strings that
|
||||
tells which characters will represent black pixels, and which
|
||||
characters represent white pixels. All other characters are
|
||||
considered clear.
|
||||
|
||||
This returns a tuple containing the cursor data and cursor mask
|
||||
data. Both these arguments are used when setting a cursor with
|
||||
pygame.mouse.set_cursor().
|
||||
"""
|
||||
|
||||
#first check for consistent lengths
|
||||
size = len(strings[0]), len(strings)
|
||||
if size[0] % 8 or size[1] % 8:
|
||||
raise ValueError("cursor string sizes must be divisible by 8 %s" %
|
||||
(size,))
|
||||
|
||||
for s in strings[1:]:
|
||||
if len(s) != size[0]:
|
||||
raise ValueError("Cursor strings are inconsistent lengths")
|
||||
|
||||
#create the data arrays.
|
||||
#this could stand a little optimizing
|
||||
maskdata = []
|
||||
filldata = []
|
||||
maskitem = fillitem = 0
|
||||
step = 8
|
||||
for s in strings:
|
||||
for c in s:
|
||||
maskitem = maskitem << 1
|
||||
fillitem = fillitem << 1
|
||||
step = step - 1
|
||||
if c == black:
|
||||
maskitem = maskitem | 1
|
||||
fillitem = fillitem | 1
|
||||
elif c == white:
|
||||
maskitem = maskitem | 1
|
||||
elif c == xor:
|
||||
fillitem = fillitem | 1
|
||||
if not step:
|
||||
maskdata.append(maskitem)
|
||||
filldata.append(fillitem)
|
||||
maskitem = fillitem = 0
|
||||
step = 8
|
||||
return tuple(filldata), tuple(maskdata)
|
||||
|
||||
|
||||
|
||||
|
||||
def load_xbm(curs, mask):
|
||||
"""pygame.cursors.load_xbm(cursorfile, maskfile) -> cursor_args
|
||||
reads a pair of XBM files into set_cursor arguments
|
||||
|
||||
Arguments can either be filenames or filelike objects
|
||||
with the readlines method. Not largely tested, but
|
||||
should work with typical XBM files.
|
||||
"""
|
||||
def bitswap(num):
|
||||
val = 0
|
||||
for x in range(8):
|
||||
b = num&(1<<x) != 0
|
||||
val = val<<1 | b
|
||||
return val
|
||||
|
||||
if type(curs) is type(''):
|
||||
with open(curs) as cursor_f:
|
||||
curs = cursor_f.readlines()
|
||||
else:
|
||||
curs = curs.readlines()
|
||||
|
||||
if type(mask) is type(''):
|
||||
with open(mask) as mask_f:
|
||||
mask = mask_f.readlines()
|
||||
else:
|
||||
mask = mask.readlines()
|
||||
|
||||
#avoid comments
|
||||
for line in range(len(curs)):
|
||||
if curs[line].startswith("#define"):
|
||||
curs = curs[line:]
|
||||
break
|
||||
for line in range(len(mask)):
|
||||
if mask[line].startswith("#define"):
|
||||
mask = mask[line:]
|
||||
break
|
||||
#load width,height
|
||||
width = int(curs[0].split()[-1])
|
||||
height = int(curs[1].split()[-1])
|
||||
#load hotspot position
|
||||
if curs[2].startswith('#define'):
|
||||
hotx = int(curs[2].split()[-1])
|
||||
hoty = int(curs[3].split()[-1])
|
||||
else:
|
||||
hotx = hoty = 0
|
||||
|
||||
info = width, height, hotx, hoty
|
||||
|
||||
for line in range(len(curs)):
|
||||
if curs[line].startswith('static char') or curs[line].startswith('static unsigned char'):
|
||||
break
|
||||
data = ' '.join(curs[line+1:]).replace('};', '').replace(',', ' ')
|
||||
cursdata = []
|
||||
for x in data.split():
|
||||
cursdata.append(bitswap(int(x, 16)))
|
||||
cursdata = tuple(cursdata)
|
||||
|
||||
for line in range(len(mask)):
|
||||
if mask[line].startswith('static char') or mask[line].startswith('static unsigned char'):
|
||||
break
|
||||
data = ' '.join(mask[line+1:]).replace('};', '').replace(',', ' ')
|
||||
maskdata = []
|
||||
for x in data.split():
|
||||
maskdata.append(bitswap(int(x, 16)))
|
||||
maskdata = tuple(maskdata)
|
||||
return info[:2], info[2:], cursdata, maskdata
|
||||
@@ -0,0 +1,121 @@
|
||||
from typing import Tuple, Sequence, Optional
|
||||
|
||||
_Bitmap = Tuple[
|
||||
Tuple[int, int],
|
||||
Tuple[int, int],
|
||||
Tuple[
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
],
|
||||
Tuple[
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
],
|
||||
]
|
||||
_Small_string = Tuple[
|
||||
str, str, str, str, str, str, str, str, str, str, str, str, str, str, str, str
|
||||
]
|
||||
_Big_string = Tuple[
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
]
|
||||
|
||||
arrow: _Bitmap
|
||||
diamond: _Bitmap
|
||||
broken_x: _Bitmap
|
||||
tri_left: _Bitmap
|
||||
tri_right: _Bitmap
|
||||
thickarrow_strings: _Big_string
|
||||
sizer_x_strings: _Small_string
|
||||
sizer_y_strings: _Big_string
|
||||
sizer_xy_strings: _Small_string
|
||||
|
||||
def compile(
|
||||
strings: Sequence[str],
|
||||
black: Optional[str] = "X",
|
||||
white: Optional[str] = ".",
|
||||
xor="o",
|
||||
) -> Tuple[Sequence[int], Sequence[int]]: ...
|
||||
def load_xbm(cursorfile: str, maskfile: str): ...
|
||||
@@ -0,0 +1,79 @@
|
||||
from typing import Union, Tuple, List, Optional, Dict, Sequence
|
||||
|
||||
from pygame.color import Color
|
||||
from pygame.surface import Surface
|
||||
from pygame.rect import Rect
|
||||
from pygame.math import Vector2
|
||||
from pygame.constants import FULLSCREEN
|
||||
|
||||
_Coordinate = Union[Tuple[float, float], List[float], Vector2]
|
||||
_RectValue = Union[
|
||||
Rect,
|
||||
Union[Tuple[int, int, int, int], List[int]],
|
||||
Union[Tuple[_Coordinate, _Coordinate], List[_Coordinate]],
|
||||
]
|
||||
_ColorValue = Union[
|
||||
Color, int, Tuple[int, int, int], Tuple[int, int, int, int], List[int]
|
||||
]
|
||||
|
||||
class _VidInfo:
|
||||
hw: int
|
||||
wm: int
|
||||
video_mem: int
|
||||
bitsize: int
|
||||
bytesize: int
|
||||
masks: Tuple[int, int, int, int]
|
||||
shifts: Tuple[int, int, int, int]
|
||||
losses: Tuple[int, int, int, int]
|
||||
blit_hw: int
|
||||
blit_hw_CC: int
|
||||
blit_hw_A: int
|
||||
blit_sw: int
|
||||
blit_sw_CC: int
|
||||
blit_sw_A: int
|
||||
current_h: int
|
||||
current_w: int
|
||||
|
||||
def init() -> None: ...
|
||||
def quit() -> None: ...
|
||||
def get_init() -> bool: ...
|
||||
def set_mode(
|
||||
size: Optional[Union[Tuple[int, int], Sequence[int]]],
|
||||
flags: Optional[int] = 0,
|
||||
depth: Optional[int] = 0,
|
||||
display: Optional[int] = 0,
|
||||
) -> Surface: ...
|
||||
def get_surface() -> Surface: ...
|
||||
def flip() -> None: ...
|
||||
def update(rectangle: Optional[Union[_RectValue, List[_RectValue]]] = None) -> None: ...
|
||||
def get_driver() -> str: ...
|
||||
def Info() -> _VidInfo: ...
|
||||
def get_wm_info() -> Dict[str, int]: ...
|
||||
def list_modes(
|
||||
depth: Optional[int] = 0,
|
||||
flags: Optional[int] = FULLSCREEN,
|
||||
display: Optional[int] = 0,
|
||||
) -> List[Tuple[int, int]]: ...
|
||||
def mode_ok(
|
||||
size: Union[Sequence[int], Tuple[int, int]],
|
||||
flags: Optional[int] = 0,
|
||||
depth: Optional[int] = 0,
|
||||
display: Optional[int] = 0,
|
||||
) -> int: ...
|
||||
def gl_get_attribute(flag: int) -> int: ...
|
||||
def gl_set_attribute(flag: int, value: int) -> None: ...
|
||||
def get_active() -> int: ...
|
||||
def iconify() -> int: ...
|
||||
def toggle_fullscreen() -> int: ...
|
||||
def set_gamma(
|
||||
red: float, green: Optional[float] = None, blue: Optional[float] = None
|
||||
) -> int: ...
|
||||
def set_gamma_ramp(
|
||||
red: Sequence[int], green: Sequence[int], blue: Sequence[int]
|
||||
) -> int: ...
|
||||
def set_icon(surface: Surface) -> None: ...
|
||||
def set_caption(title: str, icontitle: Optional[str] = None) -> None: ...
|
||||
def get_caption() -> Tuple[str, str]: ...
|
||||
def set_palette(palette: Sequence[_ColorValue]) -> None: ...
|
||||
def get_num_displays() -> int: ...
|
||||
def get_window_size() -> Tuple[int, int]: ...
|
||||
@@ -0,0 +1,12 @@
|
||||
# Make docs a package that brings up the main page in a web brower when
|
||||
# executed.
|
||||
#
|
||||
# python -m pygame.docs
|
||||
|
||||
if __name__ == '__main__':
|
||||
import os
|
||||
pkg_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
main = os.path.join(pkg_dir, '__main__.py')
|
||||
exec(open(main).read())
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
# python -m pygame.docs
|
||||
|
||||
import os
|
||||
import webbrowser
|
||||
try:
|
||||
from urllib.parse import urlunparse, quote
|
||||
except ImportError:
|
||||
from urlparse import urlunparse
|
||||
from urllib import quote
|
||||
|
||||
def iterpath(path):
|
||||
path, last = os.path.split(path)
|
||||
if last:
|
||||
for p in iterpath(path):
|
||||
yield p
|
||||
yield last
|
||||
|
||||
pkg_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
main_page = os.path.join(pkg_dir, 'index.html')
|
||||
if os.path.exists(main_page):
|
||||
url_path = quote('/'.join(iterpath(main_page)))
|
||||
drive, rest = os.path.splitdrive(__file__)
|
||||
if drive:
|
||||
url_path = "%s/%s" % (drive, url_path)
|
||||
url = urlunparse(('file', '', url_path, '', '', ''))
|
||||
else:
|
||||
url = "https://www.pygame.org/docs/"
|
||||
webbrowser.open(url)
|
||||
@@ -0,0 +1,44 @@
|
||||
<html> <title>Pygame Logos</title><!--
|
||||
Pygame Logos
|
||||
--><body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111>
|
||||
|
||||
|
||||
<table cellpadding=0 cellspacing=0 border=0 style='border: 3px solid black;' width='100%'>
|
||||
<tr>
|
||||
<td bgcolor='#c2fc20' style='padding: 6px;' align=center valign=center><a href='https://www.pygame.org/'><img src='https://www.pygame.org/docs/pygame_tiny.gif' border=0 width=200 height=60></a><br><b>pygame logos</b></td>
|
||||
<td bgcolor='#6aee28' style='border-left: 3px solid black; padding: 6px;' align=center valign=center>
|
||||
|
||||
These logos are available for use in your own game projects.
|
||||
Please put them up wherever you see fit. The logo was created
|
||||
by TheCorruptor on July 29, 2001.
|
||||
|
||||
|
||||
</td></tr></table>
|
||||
|
||||
<p align=center>
|
||||
There is a higher resolution layered photoshop image
|
||||
available <a href="https://www.pygame.org/ftp/pygame_logo.psd">here</a>.
|
||||
<i>(1.3 MB)</i></p>
|
||||
|
||||
<table width=100%><tr><td colspan=2 align=center>
|
||||
<img src=pygame_logo.gif width=676 height=200><br>
|
||||
<b><a href=pygame_logo.gif>pygame_logo.gif</a></b> - 676 x 200<br>
|
||||
</td></tr><tr><td align=center><br>
|
||||
<img src=pygame_small.gif width=338 height=100><br>
|
||||
<b><a href=pygame_small.gif>pygame_small.gif</a></b> - 338 x 100<br>
|
||||
</td><td align=center><br>
|
||||
<img src=pygame_tiny.gif width=200 height=60><br>
|
||||
<b><a href=pygame_tiny.gif>pygame_tiny.gif</a></b> - 200 x 60<br>
|
||||
</td></tr></table>
|
||||
|
||||
<p align=center>
|
||||
<img src=pygame_powered.gif width=250 height=100><br>
|
||||
<b><a href=pygame_powered.gif>pygame_powered.gif</a></b> - 250 x 100<br>
|
||||
</p><br> <br>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body></html>
|
||||
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 9.9 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
@@ -0,0 +1,83 @@
|
||||
from typing import Union, Optional, Tuple, List, Sequence
|
||||
from pygame.color import Color
|
||||
from pygame.rect import Rect
|
||||
from pygame.surface import Surface
|
||||
from pygame.math import Vector2
|
||||
|
||||
_Coordinate = Union[Tuple[float, float], List[float], Vector2]
|
||||
_ColorValue = Union[
|
||||
Color, Tuple[int, int, int], List[int], int, Tuple[int, int, int, int]
|
||||
]
|
||||
_RectValue = Union[
|
||||
Rect,
|
||||
Union[Tuple[int, int, int, int], List[int]],
|
||||
Union[Tuple[_Coordinate, _Coordinate], List[_Coordinate]],
|
||||
]
|
||||
|
||||
def rect(
|
||||
surface: Surface,
|
||||
color: _ColorValue,
|
||||
rect: _RectValue,
|
||||
width: Optional[int] = 0,
|
||||
border_radius: Optional[int] = -1,
|
||||
border_top_left_radius: Optional[int] = -1,
|
||||
border_top_right_radius: Optional[int] = -1,
|
||||
border_bottom_left_radius: Optional[int] = -1,
|
||||
border_bottom_right_radius: Optional[int] = -1,
|
||||
) -> Rect: ...
|
||||
def polygon(
|
||||
surface: Surface,
|
||||
color: _ColorValue,
|
||||
points: Sequence[_Coordinate],
|
||||
width: Optional[int] = 0,
|
||||
) -> Rect: ...
|
||||
def circle(
|
||||
surface: Surface,
|
||||
color: _ColorValue,
|
||||
center: _Coordinate,
|
||||
radius: float,
|
||||
width: Optional[int] = 0,
|
||||
draw_top_right: Optional[bool] = None,
|
||||
draw_top_left: Optional[bool] = None,
|
||||
draw_bottom_left: Optional[bool] = None,
|
||||
draw_bottom_right: Optional[bool] = None,
|
||||
) -> Rect: ...
|
||||
def ellipse(
|
||||
surface: Surface, color: _ColorValue, rect: _RectValue, width: Optional[int] = 0
|
||||
) -> Rect: ...
|
||||
def arc(
|
||||
surface: Surface,
|
||||
color: _ColorValue,
|
||||
rect: _RectValue,
|
||||
start_angle: float,
|
||||
stop_angle: float,
|
||||
width: Optional[int] = 1,
|
||||
) -> Rect: ...
|
||||
def line(
|
||||
surface: Surface,
|
||||
color: _ColorValue,
|
||||
start_pos: _Coordinate,
|
||||
end_pos: _Coordinate,
|
||||
width: Optional[int] = 1,
|
||||
) -> Rect: ...
|
||||
def lines(
|
||||
surface: Surface,
|
||||
color: _ColorValue,
|
||||
closed: bool,
|
||||
points: Sequence[_Coordinate],
|
||||
width: Optional[int] = 1,
|
||||
) -> Rect: ...
|
||||
def aaline(
|
||||
surface: Surface,
|
||||
color: _ColorValue,
|
||||
start_pos: _Coordinate,
|
||||
end_pos: _Coordinate,
|
||||
blend: Optional[int] = 1,
|
||||
) -> Rect: ...
|
||||
def aalines(
|
||||
surface: Surface,
|
||||
color: _ColorValue,
|
||||
closed: bool,
|
||||
points: Sequence[_Coordinate],
|
||||
blend: Optional[int] = 1,
|
||||
) -> Rect: ...
|
||||
@@ -0,0 +1,540 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''Pygame Drawing algorithms written in Python. (Work in Progress)
|
||||
|
||||
Implement Pygame's Drawing Algorithms in a Python version for testing
|
||||
and debugging.
|
||||
'''
|
||||
from __future__ import absolute_import, division
|
||||
import sys
|
||||
|
||||
if sys.version_info >= (3, 0, 0):
|
||||
from math import floor, ceil
|
||||
else:
|
||||
# Python2.7
|
||||
# FIXME : the import of the builtin math module is broken ...
|
||||
def floor(x):
|
||||
int_x = int(x)
|
||||
return int_x if (x == int_x or x > 0) else int_x - 1
|
||||
|
||||
def ceil(x):
|
||||
int_x = int(x)
|
||||
return int_x if (int_x == x or x < 0) else int_x + 1
|
||||
|
||||
|
||||
# H E L P E R F U N C T I O N S #
|
||||
|
||||
# fractional part of x
|
||||
|
||||
def frac(x):
|
||||
'''return fractional part of x'''
|
||||
return x - floor(x)
|
||||
|
||||
def inv_frac(x):
|
||||
'''return inverse fractional part of x'''
|
||||
return 1 - (x - floor(x)) # eg, 1 - frac(x)
|
||||
|
||||
|
||||
# L O W L E V E L D R A W F U N C T I O N S #
|
||||
# (They are too low-level to be translated into python, right?)
|
||||
|
||||
def set_at(surf, x, y, color):
|
||||
surf.set_at((x, y), color)
|
||||
|
||||
|
||||
def draw_pixel(surf, x, y, color, bright, blend=True):
|
||||
'''draw one blended pixel with given brightness.'''
|
||||
try:
|
||||
other_col = surf.get_at((x, y)) if blend else (0, 0, 0, 0)
|
||||
except IndexError: # pixel outside the surface
|
||||
return
|
||||
new_color = tuple((bright * col + (1 - bright) * pix)
|
||||
for col, pix in zip(color, other_col))
|
||||
# FIXME what should happen if only one, color or surf_col, has alpha?
|
||||
surf.set_at((x, y), new_color)
|
||||
|
||||
|
||||
def _drawhorzline(surf, color, x_from, y, x_to):
|
||||
if x_from == x_to:
|
||||
surf.set_at((x_from, y), color)
|
||||
return
|
||||
|
||||
start, end = (x_from, x_to) if x_from <= x_to else (x_to, x_from)
|
||||
for x in range(start, end + 1):
|
||||
surf.set_at((x, y), color)
|
||||
|
||||
|
||||
def _drawvertline(surf, color, x, y_from, y_to):
|
||||
if y_from == y_to:
|
||||
surf.set_at((x, y_from), color)
|
||||
return
|
||||
|
||||
start, end = (y_from, y_to) if y_from <= y_to else (y_to, y_from)
|
||||
for y in range(start, end + 1):
|
||||
surf.set_at((x, y), color)
|
||||
|
||||
|
||||
# I N T E R N A L D R A W L I N E F U N C T I O N S #
|
||||
|
||||
def _clip_and_draw_horzline(surf, color, x_from, y, x_to):
|
||||
'''draw clipped horizontal line.'''
|
||||
# check Y inside surf
|
||||
clip = surf.get_clip()
|
||||
if y < clip.y or y >= clip.y + clip.h:
|
||||
return
|
||||
|
||||
x_from = max(x_from, clip.x)
|
||||
x_to = min(x_to, clip.x + clip.w - 1)
|
||||
|
||||
# check any x inside surf
|
||||
if x_to < clip.x or x_from >= clip.x + clip.w:
|
||||
return
|
||||
|
||||
_drawhorzline(surf, color, x_from, y, x_to)
|
||||
|
||||
|
||||
def _clip_and_draw_vertline(surf, color, x, y_from, y_to):
|
||||
'''draw clipped vertical line.'''
|
||||
# check X inside surf
|
||||
clip = surf.get_clip()
|
||||
|
||||
if x < clip.x or x >= clip.x + clip.w:
|
||||
return
|
||||
|
||||
y_from = max(y_from, clip.y)
|
||||
y_to = min(y_to, clip.y + clip.h - 1)
|
||||
|
||||
# check any y inside surf
|
||||
if y_to < clip.y or y_from >= clip.y + clip.h:
|
||||
return
|
||||
|
||||
_drawvertline(surf, color, x, y_from, y_to)
|
||||
|
||||
# These constans xxx_EDGE are "outside-the-bounding-box"-flags
|
||||
LEFT_EDGE = 0x1
|
||||
RIGHT_EDGE = 0x2
|
||||
BOTTOM_EDGE = 0x4
|
||||
TOP_EDGE = 0x8
|
||||
|
||||
def encode(x, y, left, top, right, bottom):
|
||||
'''returns a code that defines position with respect to a bounding box'''
|
||||
# we use the fact that python interprets booleans (the inqualities)
|
||||
# as 0/1, and then multiply them with the xxx_EDGE flags
|
||||
return ((x < left) * LEFT_EDGE +
|
||||
(x > right) * RIGHT_EDGE +
|
||||
(y < top) * TOP_EDGE +
|
||||
(y > bottom) * BOTTOM_EDGE)
|
||||
|
||||
|
||||
INSIDE = lambda a: not a
|
||||
ACCEPT = lambda a, b: not (a or b)
|
||||
REJECT = lambda a, b: a and b
|
||||
|
||||
|
||||
def clip_line(line, left, top, right, bottom, use_float=False):
|
||||
'''Algorithm to calculate the clipped line.
|
||||
|
||||
We calculate the coordinates of the part of the line segment within the
|
||||
bounding box (defined by left, top, right, bottom). The we write
|
||||
the coordinates of the line segment into "line", much like the C-algorithm.
|
||||
With `use_float` True, clip_line is usable for float-clipping.
|
||||
|
||||
Returns: true if the line segment cuts the bounding box (false otherwise)
|
||||
'''
|
||||
assert isinstance(line, list)
|
||||
x1, y1, x2, y2 = line
|
||||
dtype = float if use_float else int
|
||||
|
||||
while True:
|
||||
# the coordinates are progressively modified with the codes,
|
||||
# until they are either rejected or correspond to the final result.
|
||||
code1 = encode(x1, y1, left, top, right, bottom)
|
||||
code2 = encode(x2, y2, left, top, right, bottom)
|
||||
|
||||
if ACCEPT(code1, code2):
|
||||
# write coordinates into "line" !
|
||||
line[:] = x1, y1, x2, y2
|
||||
return True
|
||||
if REJECT(code1, code2):
|
||||
return False
|
||||
|
||||
# We operate on the (x1, y1) point, and swap if it is inside the bbox:
|
||||
if INSIDE(code1):
|
||||
x1, x2 = x2, x1
|
||||
y1, y2 = y2, y1
|
||||
code1, code2 = code2, code1
|
||||
if (x2 != x1):
|
||||
m = (y2 - y1) / float(x2 - x1)
|
||||
else:
|
||||
m = 1.0
|
||||
# Each case, if true, means that we are outside the border:
|
||||
# calculate x1 and y1 to be the "first point" inside the bbox...
|
||||
if code1 & LEFT_EDGE:
|
||||
y1 += dtype((left - x1) * m)
|
||||
x1 = left
|
||||
elif code1 & RIGHT_EDGE:
|
||||
y1 += dtype((right - x1) * m)
|
||||
x1 = right
|
||||
elif code1 & BOTTOM_EDGE:
|
||||
if x2 != x1:
|
||||
x1 += dtype((bottom - y1) / m)
|
||||
y1 = bottom
|
||||
elif code1 & TOP_EDGE:
|
||||
if x2 != x1:
|
||||
x1 += dtype((top - y1) / m)
|
||||
y1 = top
|
||||
|
||||
|
||||
def _draw_line(surf, color, x1, y1, x2, y2):
|
||||
'''draw a non-horizontal line (without anti-aliasing).'''
|
||||
# Variant of https://en.wikipedia.org/wiki/Bresenham's_line_algorithm
|
||||
#
|
||||
# This strongly differs from craw.c implementation, because we use a
|
||||
# "slope" variable (instead of delta_x and delta_y) and a "error" variable.
|
||||
# And we can not do pointer-arithmetic with "BytesPerPixel", like in
|
||||
# the C-algorithm.
|
||||
if x1 == x2:
|
||||
# This case should not happen...
|
||||
raise ValueError
|
||||
|
||||
slope = abs((y2 - y1) / (x2 - x1))
|
||||
error = 0.0
|
||||
|
||||
if slope < 1:
|
||||
# Here, it's a rather horizontal line
|
||||
|
||||
# 1. check in which octants we are & set init values
|
||||
if x2 < x1:
|
||||
x1, x2 = x2, x1
|
||||
y1, y2 = y2, y1
|
||||
y = y1
|
||||
dy_sign = 1 if (y1 < y2) else -1
|
||||
|
||||
# 2. step along x coordinate
|
||||
for x in range(x1, x2 + 1):
|
||||
set_at(surf, x, y, color)
|
||||
error += slope
|
||||
if error >= 0.5:
|
||||
y += dy_sign
|
||||
error -= 1
|
||||
else:
|
||||
# Case of a rather vertical line
|
||||
|
||||
# 1. check in which octants we are & set init values
|
||||
if y1 > y2:
|
||||
x1, x2 = x2, x1
|
||||
y1, y2 = y2, y1
|
||||
x = x1
|
||||
slope = 1 / slope
|
||||
dx_sign = 1 if (x1 < x2) else -1
|
||||
|
||||
# 2. step along y coordinate
|
||||
for y in range(y1, y2 + 1):
|
||||
set_at(surf, x, y, color)
|
||||
error += slope
|
||||
if error >= 0.5:
|
||||
x += dx_sign
|
||||
error -= 1
|
||||
|
||||
|
||||
def _draw_aaline(surf, color, from_x, from_y, to_x, to_y, blend):
|
||||
'''draw an anti-aliased line.
|
||||
|
||||
The algorithm yields identical results with _draw_line for horizontal,
|
||||
vertical or diagonal lines, and results changes smoothly when changing
|
||||
any of the endpoint coordinates.
|
||||
|
||||
Note that this yields strange results for very short lines, eg
|
||||
a line from (0, 0) to (0, 1) will draw 2 pixels, and a line from
|
||||
(0, 0) to (0, 1.1) will blend 10 % on the pixel (0, 2).
|
||||
'''
|
||||
# The different requirements that we have on an antialiasing algorithm
|
||||
# implies to make some compromises:
|
||||
# 1. We want smooth evolution wrt to the 4 endpoint coordinates
|
||||
# (this means also that we want a smooth evolution when the angle
|
||||
# passes +/- 45°
|
||||
# 2. We want the same behavior when swapping the endpoints
|
||||
# 3. We want understandable results for the endpoint values
|
||||
# (eg we want to avoid half-integer values to draw a simple plain
|
||||
# horizontal or vertical line between two integer l endpoints)
|
||||
#
|
||||
# This implies to somehow make the line artificially 1 pixel longer
|
||||
# and to draw a full pixel when we have the endpoints are identical.
|
||||
dx = to_x - from_x
|
||||
dy = to_y - from_y
|
||||
|
||||
if dx == 0 and dy == 0:
|
||||
# For smoothness reasons, we could also do some blending here,
|
||||
# but it seems overshoot...
|
||||
set_at(surf, int(from_x), int(from_y), color)
|
||||
return
|
||||
|
||||
if abs(dx) >= abs(dy):
|
||||
if from_x > to_x:
|
||||
from_x, to_x = to_x, from_x
|
||||
from_y, to_y = to_y, from_y
|
||||
dx = -dx
|
||||
dy = -dy
|
||||
|
||||
slope = dy / dx
|
||||
def draw_two_pixel(x, float_y, factor):
|
||||
y = floor(float_y)
|
||||
draw_pixel(surf, x, y, color, factor * inv_frac(float_y), blend)
|
||||
draw_pixel(surf, x, y + 1, color, factor * frac(float_y), blend)
|
||||
|
||||
# A and G are respectively left and right to the "from" point, but
|
||||
# with integer-x-coordinate, (and only if from_x is not integer).
|
||||
# Hence they appear in following order on the line in general case:
|
||||
# A from-pt G . . . to-pt S
|
||||
# |------*-------|--- . . . ---|-----*------|-
|
||||
G_x = ceil(from_x)
|
||||
G_y = from_y + (G_x - from_x) * slope
|
||||
|
||||
# 1. Draw start of the segment if we have a non-integer-part
|
||||
if from_x < G_x:
|
||||
# this corresponds to the point "A"
|
||||
draw_two_pixel(floor(from_x), G_y - slope, inv_frac(from_x))
|
||||
|
||||
# 2. Draw end of the segment: we add one pixel for homogenity reasons
|
||||
rest = frac(to_x)
|
||||
S_x = ceil(to_x)
|
||||
if rest > 0:
|
||||
# Again we draw only if we have a non-integer-part
|
||||
S_y = from_y + slope * (dx + 1 - rest)
|
||||
draw_two_pixel(S_x, S_y, rest)
|
||||
else:
|
||||
S_x += 1
|
||||
|
||||
# 3. loop for other points
|
||||
for x in range(G_x, S_x):
|
||||
y = G_y + slope * (x - G_x)
|
||||
draw_two_pixel(x, y, 1)
|
||||
|
||||
else:
|
||||
if from_y > to_y:
|
||||
from_x, to_x = to_x, from_x
|
||||
from_y, to_y = to_y, from_y
|
||||
dx = -dx
|
||||
dy = -dy
|
||||
|
||||
slope = dx / dy
|
||||
|
||||
def draw_two_pixel(float_x, y, factor):
|
||||
x = floor(float_x)
|
||||
draw_pixel(surf, x, y, color, factor * inv_frac(float_x), blend)
|
||||
draw_pixel(surf, x + 1, y, color, factor * frac(float_x), blend)
|
||||
|
||||
G_y = ceil(from_y)
|
||||
G_x = from_x + (G_y - from_y) * slope
|
||||
|
||||
# 1. Draw start of the segment
|
||||
if from_y < G_y:
|
||||
draw_two_pixel(G_x - slope, floor(from_y), inv_frac(from_y))
|
||||
|
||||
# 2. Draw end of the segment
|
||||
rest = frac(to_y)
|
||||
S_y = ceil(to_y)
|
||||
if rest > 0:
|
||||
S_x = from_x + slope * (dy + 1 - rest)
|
||||
draw_two_pixel(S_x, S_y, rest)
|
||||
else:
|
||||
S_y += 1
|
||||
|
||||
# 3. loop for other points
|
||||
for y in range(G_y, S_y):
|
||||
x = G_x + slope * (y - G_y)
|
||||
draw_two_pixel(x, y, 1)
|
||||
|
||||
|
||||
# C L I P A N D D R A W L I N E F U N C T I O N S #
|
||||
|
||||
def _clip_and_draw_line(surf, rect, color, pts):
|
||||
'''clip the line into the rectangle and draw if needed.
|
||||
|
||||
Returns true if anything has been drawn, else false.'''
|
||||
# "pts" is a list with the four coordinates of the two endpoints
|
||||
# of the line to be drawn : pts = x1, y1, x2, y2.
|
||||
# The data format is like that to stay closer to the C-algorithm.
|
||||
if not clip_line(pts, rect.x, rect.y, rect.x + rect.w - 1,
|
||||
rect.y + rect.h - 1):
|
||||
# The line segment defined by "pts" is not crossing the rectangle
|
||||
return 0
|
||||
if pts[1] == pts[3]: # eg y1 == y2
|
||||
_drawhorzline(surf, color, pts[0], pts[1], pts[2])
|
||||
elif pts[0] == pts[2]: # eg x1 == x2
|
||||
_drawvertline(surf, color, pts[0], pts[1], pts[3])
|
||||
else:
|
||||
_draw_line(surf, color, pts[0], pts[1], pts[2], pts[3])
|
||||
return 1
|
||||
|
||||
def _clip_and_draw_line_width(surf, rect, color, line, width):
|
||||
yinc = xinc = 0
|
||||
if abs(line[0] - line[2]) > abs(line[1] - line[3]):
|
||||
yinc = 1
|
||||
else:
|
||||
xinc = 1
|
||||
newpts = line[:]
|
||||
if _clip_and_draw_line(surf, rect, color, newpts):
|
||||
anydrawn = 1
|
||||
frame = newpts[:]
|
||||
else:
|
||||
anydrawn = 0
|
||||
frame = [10000, 10000, -10000, -10000]
|
||||
|
||||
for loop in range(1, width // 2 + 1):
|
||||
newpts[0] = line[0] + xinc * loop
|
||||
newpts[1] = line[1] + yinc * loop
|
||||
newpts[2] = line[2] + xinc * loop
|
||||
newpts[3] = line[3] + yinc * loop
|
||||
if _clip_and_draw_line(surf, rect, color, newpts):
|
||||
anydrawn = 1
|
||||
frame[0] = min(newpts[0], frame[0])
|
||||
frame[1] = min(newpts[1], frame[1])
|
||||
frame[2] = max(newpts[2], frame[2])
|
||||
frame[3] = max(newpts[3], frame[3])
|
||||
|
||||
if loop * 2 < width:
|
||||
newpts[0] = line[0] - xinc * loop
|
||||
newpts[1] = line[1] - yinc * loop
|
||||
newpts[2] = line[2] - xinc * loop
|
||||
newpts[3] = line[3] - yinc * loop
|
||||
if _clip_and_draw_line(surf, rect, color, newpts):
|
||||
anydrawn = 1
|
||||
frame[0] = min(newpts[0], frame[0])
|
||||
frame[1] = min(newpts[1], frame[1])
|
||||
frame[2] = max(newpts[2], frame[2])
|
||||
frame[3] = max(newpts[3], frame[3])
|
||||
|
||||
return anydrawn
|
||||
|
||||
|
||||
def _clip_and_draw_aaline(surf, rect, color, line, blend):
|
||||
'''draw anti-aliased line between two endpoints.'''
|
||||
if not clip_line(line, rect.x - 1, rect.y -1, rect.x + rect.w,
|
||||
rect.y + rect.h, use_float=True):
|
||||
return # TODO Rect(rect.x, rect.y, 0, 0)
|
||||
_draw_aaline(surf, color, line[0], line[1], line[2], line[3], blend)
|
||||
return # TODO Rect(-- affected area --)
|
||||
|
||||
|
||||
# D R A W L I N E F U N C T I O N S #
|
||||
|
||||
def draw_aaline(surf, color, from_point, to_point, blend=True):
|
||||
'''draw anti-aliased line between two endpoints.'''
|
||||
line = [from_point[0], from_point[1], to_point[0], to_point[1]]
|
||||
return _clip_and_draw_aaline(surf, surf.get_clip(), color, line, blend)
|
||||
|
||||
|
||||
def draw_line(surf, color, from_point, to_point, width=1):
|
||||
'''draw anti-aliased line between two endpoints.'''
|
||||
line = [from_point[0], from_point[1], to_point[0], to_point[1]]
|
||||
return _clip_and_draw_line_width(surf, surf.get_clip(), color, line, width)
|
||||
|
||||
|
||||
# M U L T I L I N E F U N C T I O N S #
|
||||
|
||||
def _multi_lines(surf, color, closed, points, width=1, blend=False, aaline=False):
|
||||
'''draw several lines, either anti-aliased or not.'''
|
||||
# The code for anti-aliased or not is almost identical, so it's factorized
|
||||
length = len(points)
|
||||
if length <= 2:
|
||||
raise TypeError
|
||||
line = [0] * 4 # store x1, y1 & x2, y2 of the lines to be drawn
|
||||
|
||||
xlist = [pt[0] for pt in points]
|
||||
ylist = [pt[1] for pt in points]
|
||||
left = right = line[0] = xlist[0]
|
||||
top = bottom = line[1] = ylist[0]
|
||||
|
||||
for x, y in points[1:]:
|
||||
left = min(left, x)
|
||||
right = max(right, x)
|
||||
top = min(top, y)
|
||||
bottom = max(bottom, x)
|
||||
|
||||
rect = surf.get_clip()
|
||||
for loop in range(1, length):
|
||||
|
||||
line[0] = xlist[loop - 1]
|
||||
line[1] = ylist[loop - 1]
|
||||
line[2] = xlist[loop]
|
||||
line[3] = ylist[loop]
|
||||
if aaline:
|
||||
_clip_and_draw_aaline(surf, rect, color, line, blend)
|
||||
else:
|
||||
_clip_and_draw_line_width(surf, rect, color, line, width)
|
||||
|
||||
if closed:
|
||||
line[0] = xlist[length - 1]
|
||||
line[1] = ylist[length - 1]
|
||||
line[2] = xlist[0]
|
||||
line[3] = ylist[0]
|
||||
if aaline:
|
||||
_clip_and_draw_aaline(surf, rect, color, line, blend)
|
||||
else:
|
||||
_clip_and_draw_line_width(surf, rect, color, line, width)
|
||||
|
||||
return # TODO Rect(...)
|
||||
|
||||
def draw_lines(surf, color, closed, points, width=1):
|
||||
'''draw several lines connected through the points.'''
|
||||
return _multi_lines(surf, color, closed, points, width, aaline=False)
|
||||
|
||||
|
||||
def draw_aalines(surf, color, closed, points, blend=True):
|
||||
'''draw several anti-aliased lines connected through the points.'''
|
||||
return _multi_lines(surf, color, closed, points, blend=blend, aaline=True)
|
||||
|
||||
|
||||
def draw_polygon(surface, color, points, width):
|
||||
if width:
|
||||
draw_lines(surface, color, 1, points, width)
|
||||
return # TODO Rect(...)
|
||||
num_points = len(points)
|
||||
point_x = [x for x, y in points]
|
||||
point_y = [y for x, y in points]
|
||||
|
||||
miny = min(point_y)
|
||||
maxy = max(point_y)
|
||||
|
||||
if miny == maxy:
|
||||
minx = min(point_x)
|
||||
maxx = max(point_x)
|
||||
_clip_and_draw_horzline(surface, color, minx, miny, maxx)
|
||||
return # TODO Rect(...)
|
||||
|
||||
for y in range(miny, maxy + 1):
|
||||
x_intersect = []
|
||||
for i in range(num_points):
|
||||
i_prev = i - 1 if i else num_points - 1
|
||||
|
||||
y1 = point_y[i_prev]
|
||||
y2 = point_y[i]
|
||||
|
||||
if y1 < y2:
|
||||
x1 = point_x[i_prev]
|
||||
x2 = point_x[i]
|
||||
elif y1 > y2:
|
||||
y2 = point_y[i_prev]
|
||||
y1 = point_y[i]
|
||||
x2 = point_x[i_prev]
|
||||
x1 = point_x[i]
|
||||
else: # special case handled below
|
||||
continue
|
||||
|
||||
if ( ((y >= y1) and (y < y2)) or ((y == maxy) and (y <= y2))) :
|
||||
x_sect = (y - y1) * (x2 - x1) // (y2 - y1) + x1
|
||||
x_intersect.append(x_sect)
|
||||
|
||||
x_intersect.sort()
|
||||
for i in range(0, len(x_intersect), 2):
|
||||
_clip_and_draw_horzline(surface, color, x_intersect[i], y,
|
||||
x_intersect[i + 1])
|
||||
|
||||
# special case : horizontal border lines
|
||||
for i in range(num_points):
|
||||
i_prev = i - 1 if i else num_points - 1
|
||||
y = point_y[i]
|
||||
if miny < y == point_y[i_prev] < maxy:
|
||||
_clip_and_draw_horzline(surface, color, point_x[i], y, point_x[i_prev])
|
||||
|
||||
return # TODO Rect(...)
|
||||
@@ -0,0 +1,31 @@
|
||||
from typing import Any, Dict, List, Optional, Union, overload
|
||||
|
||||
class EventType(object):
|
||||
type: int
|
||||
__dict__: Dict[str, Any]
|
||||
@overload
|
||||
def __init__(self, type: int, dict: Dict[str, Any]) -> None: ...
|
||||
@overload
|
||||
def __init__(self, type: int, **attributes: Any) -> None: ...
|
||||
def __getattr__(self, name: str) -> Any: ...
|
||||
|
||||
# Event is actually a function that returns an EventType, but it's often used
|
||||
# as an annotation.
|
||||
Event = EventType
|
||||
|
||||
_EventIds = Union[int, List[int]]
|
||||
|
||||
def pump() -> None: ...
|
||||
def get(type: _EventIds = ...) -> List[EventType]: ...
|
||||
def poll() -> EventType: ...
|
||||
def wait() -> EventType: ...
|
||||
def peak(type: _EventIds) -> bool: ...
|
||||
def clear(type: _EventIds = ...) -> None: ...
|
||||
def event_name(type: int) -> str: ...
|
||||
def set_blocked(type: Optional[_EventIds]) -> None: ...
|
||||
def set_allowed(type: Optional[_EventIds]) -> None: ...
|
||||
def get_blocked(type: int) -> bool: ...
|
||||
def set_grab(grab: bool) -> None: ...
|
||||
def get_grab() -> bool: ...
|
||||
def post(event: EventType) -> None: ...
|
||||
def custom_type() -> int: ...
|
||||
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""Proof of concept gfxdraw example"""
|
||||
|
||||
import pygame
|
||||
import pygame.gfxdraw
|
||||
|
||||
|
||||
def main():
|
||||
pygame.init()
|
||||
screen = pygame.display.set_mode((500, 500))
|
||||
screen.fill((255, 0, 0))
|
||||
s = pygame.Surface(screen.get_size(), pygame.SRCALPHA, 32)
|
||||
pygame.draw.line(s, (0, 0, 0), (250, 250), (250 + 200, 250))
|
||||
|
||||
width = 1
|
||||
for a_radius in range(width):
|
||||
radius = 200
|
||||
pygame.gfxdraw.aacircle(s, 250, 250, radius - a_radius, (0, 0, 0))
|
||||
|
||||
screen.blit(s, (0, 0))
|
||||
|
||||
pygame.draw.circle(screen, pygame.Color("GREEN"), (50, 100), 10)
|
||||
pygame.draw.circle(screen, pygame.Color("BLACK"), (50, 100), 10, 1)
|
||||
|
||||
pygame.display.flip()
|
||||
try:
|
||||
while 1:
|
||||
event = pygame.event.wait()
|
||||
if event.type == pygame.QUIT:
|
||||
break
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_ESCAPE or event.unicode == "q":
|
||||
break
|
||||
pygame.display.flip()
|
||||
finally:
|
||||
pygame.quit()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,410 @@
|
||||
#!/usr/bin/env python
|
||||
""" pygame.examples.aliens
|
||||
|
||||
Shows a mini game where you have to defend against aliens.
|
||||
|
||||
What does it show you about pygame?
|
||||
|
||||
* pg.sprite, the difference between Sprite and Group.
|
||||
* dirty rectangle optimization for processing for speed.
|
||||
* music with pg.mixer.music, including fadeout
|
||||
* sound effects with pg.Sound
|
||||
* event processing, keyboard handling, QUIT handling.
|
||||
* a main loop frame limited with a game clock from pg.time.Clock
|
||||
* fullscreen switching.
|
||||
|
||||
|
||||
Controls
|
||||
--------
|
||||
|
||||
* Left and right arrows to move.
|
||||
* Space bar to shoot
|
||||
* f key to toggle between fullscreen.
|
||||
|
||||
"""
|
||||
|
||||
import random
|
||||
import os
|
||||
|
||||
# import basic pygame modules
|
||||
import pygame as pg
|
||||
|
||||
# see if we can load more than standard BMP
|
||||
if not pg.image.get_extended():
|
||||
raise SystemExit("Sorry, extended image module required")
|
||||
|
||||
|
||||
# game constants
|
||||
MAX_SHOTS = 2 # most player bullets onscreen
|
||||
ALIEN_ODDS = 22 # chances a new alien appears
|
||||
BOMB_ODDS = 60 # chances a new bomb will drop
|
||||
ALIEN_RELOAD = 12 # frames between new aliens
|
||||
SCREENRECT = pg.Rect(0, 0, 640, 480)
|
||||
SCORE = 0
|
||||
|
||||
main_dir = os.path.split(os.path.abspath(__file__))[0]
|
||||
|
||||
|
||||
def load_image(file):
|
||||
""" loads an image, prepares it for play
|
||||
"""
|
||||
file = os.path.join(main_dir, "data", file)
|
||||
try:
|
||||
surface = pg.image.load(file)
|
||||
except pg.error:
|
||||
raise SystemExit('Could not load image "%s" %s' % (file, pg.get_error()))
|
||||
return surface.convert()
|
||||
|
||||
|
||||
def load_sound(file):
|
||||
""" because pygame can be be compiled without mixer.
|
||||
"""
|
||||
if not pg.mixer:
|
||||
return None
|
||||
file = os.path.join(main_dir, "data", file)
|
||||
try:
|
||||
sound = pg.mixer.Sound(file)
|
||||
return sound
|
||||
except pg.error:
|
||||
print("Warning, unable to load, %s" % file)
|
||||
return None
|
||||
|
||||
|
||||
# Each type of game object gets an init and an update function.
|
||||
# The update function is called once per frame, and it is when each object should
|
||||
# change it's current position and state.
|
||||
#
|
||||
# The Player object actually gets a "move" function instead of update,
|
||||
# since it is passed extra information about the keyboard.
|
||||
|
||||
|
||||
class Player(pg.sprite.Sprite):
|
||||
""" Representing the player as a moon buggy type car.
|
||||
"""
|
||||
|
||||
speed = 10
|
||||
bounce = 24
|
||||
gun_offset = -11
|
||||
images = []
|
||||
|
||||
def __init__(self):
|
||||
pg.sprite.Sprite.__init__(self, self.containers)
|
||||
self.image = self.images[0]
|
||||
self.rect = self.image.get_rect(midbottom=SCREENRECT.midbottom)
|
||||
self.reloading = 0
|
||||
self.origtop = self.rect.top
|
||||
self.facing = -1
|
||||
|
||||
def move(self, direction):
|
||||
if direction:
|
||||
self.facing = direction
|
||||
self.rect.move_ip(direction * self.speed, 0)
|
||||
self.rect = self.rect.clamp(SCREENRECT)
|
||||
if direction < 0:
|
||||
self.image = self.images[0]
|
||||
elif direction > 0:
|
||||
self.image = self.images[1]
|
||||
self.rect.top = self.origtop - (self.rect.left // self.bounce % 2)
|
||||
|
||||
def gunpos(self):
|
||||
pos = self.facing * self.gun_offset + self.rect.centerx
|
||||
return pos, self.rect.top
|
||||
|
||||
|
||||
class Alien(pg.sprite.Sprite):
|
||||
""" An alien space ship. That slowly moves down the screen.
|
||||
"""
|
||||
|
||||
speed = 13
|
||||
animcycle = 12
|
||||
images = []
|
||||
|
||||
def __init__(self):
|
||||
pg.sprite.Sprite.__init__(self, self.containers)
|
||||
self.image = self.images[0]
|
||||
self.rect = self.image.get_rect()
|
||||
self.facing = random.choice((-1, 1)) * Alien.speed
|
||||
self.frame = 0
|
||||
if self.facing < 0:
|
||||
self.rect.right = SCREENRECT.right
|
||||
|
||||
def update(self):
|
||||
self.rect.move_ip(self.facing, 0)
|
||||
if not SCREENRECT.contains(self.rect):
|
||||
self.facing = -self.facing
|
||||
self.rect.top = self.rect.bottom + 1
|
||||
self.rect = self.rect.clamp(SCREENRECT)
|
||||
self.frame = self.frame + 1
|
||||
self.image = self.images[self.frame // self.animcycle % 3]
|
||||
|
||||
|
||||
class Explosion(pg.sprite.Sprite):
|
||||
""" An explosion. Hopefully the Alien and not the player!
|
||||
"""
|
||||
|
||||
defaultlife = 12
|
||||
animcycle = 3
|
||||
images = []
|
||||
|
||||
def __init__(self, actor):
|
||||
pg.sprite.Sprite.__init__(self, self.containers)
|
||||
self.image = self.images[0]
|
||||
self.rect = self.image.get_rect(center=actor.rect.center)
|
||||
self.life = self.defaultlife
|
||||
|
||||
def update(self):
|
||||
""" called every time around the game loop.
|
||||
|
||||
Show the explosion surface for 'defaultlife'.
|
||||
Every game tick(update), we decrease the 'life'.
|
||||
|
||||
Also we animate the explosion.
|
||||
"""
|
||||
self.life = self.life - 1
|
||||
self.image = self.images[self.life // self.animcycle % 2]
|
||||
if self.life <= 0:
|
||||
self.kill()
|
||||
|
||||
|
||||
class Shot(pg.sprite.Sprite):
|
||||
""" a bullet the Player sprite fires.
|
||||
"""
|
||||
|
||||
speed = -11
|
||||
images = []
|
||||
|
||||
def __init__(self, pos):
|
||||
pg.sprite.Sprite.__init__(self, self.containers)
|
||||
self.image = self.images[0]
|
||||
self.rect = self.image.get_rect(midbottom=pos)
|
||||
|
||||
def update(self):
|
||||
""" called every time around the game loop.
|
||||
|
||||
Every tick we move the shot upwards.
|
||||
"""
|
||||
self.rect.move_ip(0, self.speed)
|
||||
if self.rect.top <= 0:
|
||||
self.kill()
|
||||
|
||||
|
||||
class Bomb(pg.sprite.Sprite):
|
||||
""" A bomb the aliens drop.
|
||||
"""
|
||||
|
||||
speed = 9
|
||||
images = []
|
||||
|
||||
def __init__(self, alien):
|
||||
pg.sprite.Sprite.__init__(self, self.containers)
|
||||
self.image = self.images[0]
|
||||
self.rect = self.image.get_rect(midbottom=alien.rect.move(0, 5).midbottom)
|
||||
|
||||
def update(self):
|
||||
""" called every time around the game loop.
|
||||
|
||||
Every frame we move the sprite 'rect' down.
|
||||
When it reaches the bottom we:
|
||||
|
||||
- make an explosion.
|
||||
- remove the Bomb.
|
||||
"""
|
||||
self.rect.move_ip(0, self.speed)
|
||||
if self.rect.bottom >= 470:
|
||||
Explosion(self)
|
||||
self.kill()
|
||||
|
||||
|
||||
class Score(pg.sprite.Sprite):
|
||||
""" to keep track of the score.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
pg.sprite.Sprite.__init__(self)
|
||||
self.font = pg.font.Font(None, 20)
|
||||
self.font.set_italic(1)
|
||||
self.color = pg.Color("white")
|
||||
self.lastscore = -1
|
||||
self.update()
|
||||
self.rect = self.image.get_rect().move(10, 450)
|
||||
|
||||
def update(self):
|
||||
""" We only update the score in update() when it has changed.
|
||||
"""
|
||||
if SCORE != self.lastscore:
|
||||
self.lastscore = SCORE
|
||||
msg = "Score: %d" % SCORE
|
||||
self.image = self.font.render(msg, 0, self.color)
|
||||
|
||||
|
||||
def main(winstyle=0):
|
||||
# Initialize pygame
|
||||
if pg.get_sdl_version()[0] == 2:
|
||||
pg.mixer.pre_init(44100, 32, 2, 1024)
|
||||
pg.init()
|
||||
if pg.mixer and not pg.mixer.get_init():
|
||||
print("Warning, no sound")
|
||||
pg.mixer = None
|
||||
|
||||
fullscreen = False
|
||||
# Set the display mode
|
||||
winstyle = 0 # |FULLSCREEN
|
||||
bestdepth = pg.display.mode_ok(SCREENRECT.size, winstyle, 32)
|
||||
screen = pg.display.set_mode(SCREENRECT.size, winstyle, bestdepth)
|
||||
|
||||
# Load images, assign to sprite classes
|
||||
# (do this before the classes are used, after screen setup)
|
||||
img = load_image("player1.gif")
|
||||
Player.images = [img, pg.transform.flip(img, 1, 0)]
|
||||
img = load_image("explosion1.gif")
|
||||
Explosion.images = [img, pg.transform.flip(img, 1, 1)]
|
||||
Alien.images = [load_image(im) for im in ("alien1.gif", "alien2.gif", "alien3.gif")]
|
||||
Bomb.images = [load_image("bomb.gif")]
|
||||
Shot.images = [load_image("shot.gif")]
|
||||
|
||||
# decorate the game window
|
||||
icon = pg.transform.scale(Alien.images[0], (32, 32))
|
||||
pg.display.set_icon(icon)
|
||||
pg.display.set_caption("Pygame Aliens")
|
||||
pg.mouse.set_visible(0)
|
||||
|
||||
# create the background, tile the bgd image
|
||||
bgdtile = load_image("background.gif")
|
||||
background = pg.Surface(SCREENRECT.size)
|
||||
for x in range(0, SCREENRECT.width, bgdtile.get_width()):
|
||||
background.blit(bgdtile, (x, 0))
|
||||
screen.blit(background, (0, 0))
|
||||
pg.display.flip()
|
||||
|
||||
# load the sound effects
|
||||
boom_sound = load_sound("boom.wav")
|
||||
shoot_sound = load_sound("car_door.wav")
|
||||
if pg.mixer:
|
||||
music = os.path.join(main_dir, "data", "house_lo.wav")
|
||||
pg.mixer.music.load(music)
|
||||
pg.mixer.music.play(-1)
|
||||
|
||||
# Initialize Game Groups
|
||||
aliens = pg.sprite.Group()
|
||||
shots = pg.sprite.Group()
|
||||
bombs = pg.sprite.Group()
|
||||
all = pg.sprite.RenderUpdates()
|
||||
lastalien = pg.sprite.GroupSingle()
|
||||
|
||||
# assign default groups to each sprite class
|
||||
Player.containers = all
|
||||
Alien.containers = aliens, all, lastalien
|
||||
Shot.containers = shots, all
|
||||
Bomb.containers = bombs, all
|
||||
Explosion.containers = all
|
||||
Score.containers = all
|
||||
|
||||
# Create Some Starting Values
|
||||
global score
|
||||
alienreload = ALIEN_RELOAD
|
||||
clock = pg.time.Clock()
|
||||
|
||||
# initialize our starting sprites
|
||||
global SCORE
|
||||
player = Player()
|
||||
Alien() # note, this 'lives' because it goes into a sprite group
|
||||
if pg.font:
|
||||
all.add(Score())
|
||||
|
||||
# Run our main loop whilst the player is alive.
|
||||
while player.alive():
|
||||
|
||||
# get input
|
||||
for event in pg.event.get():
|
||||
if event.type == pg.QUIT:
|
||||
return
|
||||
if event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE:
|
||||
return
|
||||
elif event.type == pg.KEYDOWN:
|
||||
if event.key == pg.K_f:
|
||||
if not fullscreen:
|
||||
print("Changing to FULLSCREEN")
|
||||
screen_backup = screen.copy()
|
||||
screen = pg.display.set_mode(
|
||||
SCREENRECT.size, winstyle | pg.FULLSCREEN, bestdepth
|
||||
)
|
||||
screen.blit(screen_backup, (0, 0))
|
||||
else:
|
||||
print("Changing to windowed mode")
|
||||
screen_backup = screen.copy()
|
||||
screen = pg.display.set_mode(
|
||||
SCREENRECT.size, winstyle, bestdepth
|
||||
)
|
||||
screen.blit(screen_backup, (0, 0))
|
||||
pg.display.flip()
|
||||
fullscreen = not fullscreen
|
||||
|
||||
keystate = pg.key.get_pressed()
|
||||
|
||||
# clear/erase the last drawn sprites
|
||||
all.clear(screen, background)
|
||||
|
||||
# update all the sprites
|
||||
all.update()
|
||||
|
||||
# handle player input
|
||||
direction = keystate[pg.K_RIGHT] - keystate[pg.K_LEFT]
|
||||
player.move(direction)
|
||||
firing = keystate[pg.K_SPACE]
|
||||
if not player.reloading and firing and len(shots) < MAX_SHOTS:
|
||||
Shot(player.gunpos())
|
||||
if pg.mixer:
|
||||
shoot_sound.play()
|
||||
player.reloading = firing
|
||||
|
||||
# Create new alien
|
||||
if alienreload:
|
||||
alienreload = alienreload - 1
|
||||
elif not int(random.random() * ALIEN_ODDS):
|
||||
Alien()
|
||||
alienreload = ALIEN_RELOAD
|
||||
|
||||
# Drop bombs
|
||||
if lastalien and not int(random.random() * BOMB_ODDS):
|
||||
Bomb(lastalien.sprite)
|
||||
|
||||
# Detect collisions between aliens and players.
|
||||
for alien in pg.sprite.spritecollide(player, aliens, 1):
|
||||
if pg.mixer:
|
||||
boom_sound.play()
|
||||
Explosion(alien)
|
||||
Explosion(player)
|
||||
SCORE = SCORE + 1
|
||||
player.kill()
|
||||
|
||||
# See if shots hit the aliens.
|
||||
for alien in pg.sprite.groupcollide(shots, aliens, 1, 1).keys():
|
||||
if pg.mixer:
|
||||
boom_sound.play()
|
||||
Explosion(alien)
|
||||
SCORE = SCORE + 1
|
||||
|
||||
# See if alien boms hit the player.
|
||||
for bomb in pg.sprite.spritecollide(player, bombs, 1):
|
||||
if pg.mixer:
|
||||
boom_sound.play()
|
||||
Explosion(player)
|
||||
Explosion(bomb)
|
||||
player.kill()
|
||||
|
||||
# draw the scene
|
||||
dirty = all.draw(screen)
|
||||
pg.display.update(dirty)
|
||||
|
||||
# cap the framerate at 40fps. Also called 40HZ or 40 times per second.
|
||||
clock.tick(40)
|
||||
|
||||
if pg.mixer:
|
||||
pg.mixer.music.fadeout(1000)
|
||||
pg.time.wait(1000)
|
||||
pg.quit()
|
||||
|
||||
|
||||
# call the "main" function if running this script
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,129 @@
|
||||
#!/usr/bin/env python
|
||||
""" pygame.examples.arraydemo
|
||||
|
||||
Welcome to the arraydemo!
|
||||
|
||||
Use the numpy array package to manipulate pixels.
|
||||
|
||||
This demo will show you a few things:
|
||||
|
||||
* scale up, scale down, flip,
|
||||
* cross fade
|
||||
* soften
|
||||
* put stripes on it!
|
||||
|
||||
"""
|
||||
|
||||
|
||||
import os
|
||||
|
||||
import pygame as pg
|
||||
from pygame import surfarray
|
||||
|
||||
main_dir = os.path.split(os.path.abspath(__file__))[0]
|
||||
|
||||
|
||||
def surfdemo_show(array_img, name):
|
||||
"displays a surface, waits for user to continue"
|
||||
screen = pg.display.set_mode(array_img.shape[:2], 0, 32)
|
||||
surfarray.blit_array(screen, array_img)
|
||||
pg.display.flip()
|
||||
pg.display.set_caption(name)
|
||||
while 1:
|
||||
e = pg.event.wait()
|
||||
if e.type == pg.MOUSEBUTTONDOWN:
|
||||
break
|
||||
elif e.type == pg.KEYDOWN and e.key == pg.K_s:
|
||||
# pg.image.save(screen, name+'.bmp')
|
||||
# s = pg.Surface(screen.get_size(), 0, 32)
|
||||
# s = s.convert_alpha()
|
||||
# s.fill((0,0,0,255))
|
||||
# s.blit(screen, (0,0))
|
||||
# s.fill((222,0,0,50), (0,0,40,40))
|
||||
# pg.image.save_extended(s, name+'.png')
|
||||
# pg.image.save(s, name+'.png')
|
||||
# pg.image.save(screen, name+'_screen.png')
|
||||
# pg.image.save(s, name+'.tga')
|
||||
pg.image.save(screen, name + ".png")
|
||||
elif e.type == pg.QUIT:
|
||||
raise SystemExit()
|
||||
|
||||
|
||||
def main():
|
||||
"""show various surfarray effects
|
||||
"""
|
||||
import numpy as N
|
||||
from numpy import int32, uint8, uint
|
||||
|
||||
pg.init()
|
||||
print("Using %s" % surfarray.get_arraytype().capitalize())
|
||||
print("Press the mouse button to advance image.")
|
||||
print('Press the "s" key to save the current image.')
|
||||
|
||||
# allblack
|
||||
allblack = N.zeros((128, 128), int32)
|
||||
surfdemo_show(allblack, "allblack")
|
||||
|
||||
# striped
|
||||
# the element type is required for N.zeros in numpy else
|
||||
# an array of float is returned.
|
||||
striped = N.zeros((128, 128, 3), int32)
|
||||
striped[:] = (255, 0, 0)
|
||||
striped[:, ::3] = (0, 255, 255)
|
||||
surfdemo_show(striped, "striped")
|
||||
|
||||
# rgbarray
|
||||
imagename = os.path.join(main_dir, "data", "arraydemo.bmp")
|
||||
imgsurface = pg.image.load(imagename)
|
||||
rgbarray = surfarray.array3d(imgsurface)
|
||||
surfdemo_show(rgbarray, "rgbarray")
|
||||
|
||||
# flipped
|
||||
flipped = rgbarray[:, ::-1]
|
||||
surfdemo_show(flipped, "flipped")
|
||||
|
||||
# scaledown
|
||||
scaledown = rgbarray[::2, ::2]
|
||||
surfdemo_show(scaledown, "scaledown")
|
||||
|
||||
# scaleup
|
||||
# the element type is required for N.zeros in numpy else
|
||||
# an #array of floats is returned.
|
||||
shape = rgbarray.shape
|
||||
scaleup = N.zeros((shape[0] * 2, shape[1] * 2, shape[2]), int32)
|
||||
scaleup[::2, ::2, :] = rgbarray
|
||||
scaleup[1::2, ::2, :] = rgbarray
|
||||
scaleup[:, 1::2] = scaleup[:, ::2]
|
||||
surfdemo_show(scaleup, "scaleup")
|
||||
|
||||
# redimg
|
||||
redimg = N.array(rgbarray)
|
||||
redimg[:, :, 1:] = 0
|
||||
surfdemo_show(redimg, "redimg")
|
||||
|
||||
# soften
|
||||
# having factor as an array forces integer upgrade during multiplication
|
||||
# of rgbarray, even for numpy.
|
||||
factor = N.array((8,), int32)
|
||||
soften = N.array(rgbarray, int32)
|
||||
soften[1:, :] += rgbarray[:-1, :] * factor
|
||||
soften[:-1, :] += rgbarray[1:, :] * factor
|
||||
soften[:, 1:] += rgbarray[:, :-1] * factor
|
||||
soften[:, :-1] += rgbarray[:, 1:] * factor
|
||||
soften //= 33
|
||||
surfdemo_show(soften, "soften")
|
||||
|
||||
# crossfade (50%)
|
||||
src = N.array(rgbarray)
|
||||
dest = N.zeros(rgbarray.shape) # dest is float64 by default.
|
||||
dest[:] = 20, 50, 100
|
||||
diff = (dest - src) * 0.50
|
||||
xfade = src + diff.astype(uint)
|
||||
surfdemo_show(xfade, "xfade")
|
||||
|
||||
# alldone
|
||||
pg.quit()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env python
|
||||
""" pygame.examples.audiocapture
|
||||
|
||||
A pygame 2 experiment.
|
||||
|
||||
* record sound from a microphone
|
||||
* play back the recorded sound
|
||||
"""
|
||||
import pygame as pg
|
||||
import time
|
||||
|
||||
if pg.get_sdl_version()[0] < 2:
|
||||
raise SystemExit("This example requires pygame 2 and SDL2.")
|
||||
|
||||
from pygame._sdl2 import (
|
||||
get_audio_device_name,
|
||||
get_num_audio_devices,
|
||||
AudioDevice,
|
||||
AUDIO_F32,
|
||||
AUDIO_ALLOW_FORMAT_CHANGE,
|
||||
)
|
||||
from pygame._sdl2.mixer import set_post_mix
|
||||
|
||||
|
||||
pg.mixer.pre_init(44100, 32, 2, 512)
|
||||
pg.init()
|
||||
|
||||
# init_subsystem(INIT_AUDIO)
|
||||
names = [get_audio_device_name(x, 1) for x in range(get_num_audio_devices(1))]
|
||||
print(names)
|
||||
|
||||
iscapture = 1
|
||||
sounds = []
|
||||
sound_chunks = []
|
||||
|
||||
|
||||
def callback(audiodevice, audiomemoryview):
|
||||
""" This is called in the sound thread.
|
||||
|
||||
Note, that the frequency and such you request may not be what you get.
|
||||
"""
|
||||
# print(type(audiomemoryview), len(audiomemoryview))
|
||||
# print(audiodevice)
|
||||
sound_chunks.append(bytes(audiomemoryview))
|
||||
|
||||
|
||||
def postmix_callback(postmix, audiomemoryview):
|
||||
""" This is called in the sound thread.
|
||||
|
||||
At the end of mixing we get this data.
|
||||
"""
|
||||
print(type(audiomemoryview), len(audiomemoryview))
|
||||
print(postmix)
|
||||
|
||||
|
||||
set_post_mix(postmix_callback)
|
||||
|
||||
audio = AudioDevice(
|
||||
devicename=names[0],
|
||||
iscapture=1,
|
||||
frequency=44100,
|
||||
audioformat=AUDIO_F32,
|
||||
numchannels=2,
|
||||
chunksize=512,
|
||||
allowed_changes=AUDIO_ALLOW_FORMAT_CHANGE,
|
||||
callback=callback,
|
||||
)
|
||||
# start recording.
|
||||
audio.pause(0)
|
||||
|
||||
print("recording with :%s:" % names[0])
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
print("Turning data into a pg.mixer.Sound")
|
||||
sound = pg.mixer.Sound(buffer=b"".join(sound_chunks))
|
||||
|
||||
print("playing back recorded sound")
|
||||
sound.play()
|
||||
time.sleep(5)
|
||||
@@ -0,0 +1,115 @@
|
||||
#!/usr/bin/env python
|
||||
""" pygame.examples.blend_fill
|
||||
|
||||
BLEND_ing colors in different ways with Surface.fill().
|
||||
|
||||
Keyboard Controls:
|
||||
|
||||
* Press R, G, B to increase the color channel values,
|
||||
* 1-9 to set the step range for the increment,
|
||||
* A - ADD, S- SUB, M- MULT, - MIN, + MAX to change the blend modes
|
||||
|
||||
"""
|
||||
import os
|
||||
import pygame as pg
|
||||
from pygame import K_1, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9
|
||||
|
||||
|
||||
def usage():
|
||||
print("Press R, G, B to increase the color channel values,")
|
||||
print("1-9 to set the step range for the increment,")
|
||||
print("A - ADD, S- SUB, M- MULT, - MIN, + MAX")
|
||||
print(" to change the blend modes")
|
||||
|
||||
|
||||
main_dir = os.path.split(os.path.abspath(__file__))[0]
|
||||
data_dir = os.path.join(main_dir, "data")
|
||||
|
||||
|
||||
def main():
|
||||
color = [0, 0, 0]
|
||||
changed = False
|
||||
blendtype = 0
|
||||
step = 5
|
||||
|
||||
pg.init()
|
||||
screen = pg.display.set_mode((640, 480), 0, 32)
|
||||
screen.fill((100, 100, 100))
|
||||
|
||||
image = pg.image.load(os.path.join(data_dir, "liquid.bmp")).convert()
|
||||
blendimage = pg.image.load(os.path.join(data_dir, "liquid.bmp")).convert()
|
||||
screen.blit(image, (10, 10))
|
||||
screen.blit(blendimage, (200, 10))
|
||||
|
||||
pg.display.flip()
|
||||
pg.key.set_repeat(500, 30)
|
||||
usage()
|
||||
|
||||
going = True
|
||||
while going:
|
||||
for event in pg.event.get():
|
||||
if event.type == pg.QUIT:
|
||||
going = False
|
||||
|
||||
if event.type == pg.KEYDOWN:
|
||||
usage()
|
||||
|
||||
if event.key == pg.K_ESCAPE:
|
||||
going = False
|
||||
|
||||
if event.key == pg.K_r:
|
||||
color[0] += step
|
||||
if color[0] > 255:
|
||||
color[0] = 0
|
||||
changed = True
|
||||
|
||||
elif event.key == pg.K_g:
|
||||
color[1] += step
|
||||
if color[1] > 255:
|
||||
color[1] = 0
|
||||
changed = True
|
||||
|
||||
elif event.key == pg.K_b:
|
||||
color[2] += step
|
||||
if color[2] > 255:
|
||||
color[2] = 0
|
||||
changed = True
|
||||
|
||||
elif event.key == pg.K_a:
|
||||
blendtype = pg.BLEND_ADD
|
||||
changed = True
|
||||
elif event.key == pg.K_s:
|
||||
blendtype = pg.BLEND_SUB
|
||||
changed = True
|
||||
elif event.key == pg.K_m:
|
||||
blendtype = pg.BLEND_MULT
|
||||
changed = True
|
||||
elif event.key == pg.K_PLUS:
|
||||
blendtype = pg.BLEND_MAX
|
||||
changed = True
|
||||
elif event.key == pg.K_MINUS:
|
||||
blendtype = pg.BLEND_MIN
|
||||
changed = True
|
||||
|
||||
elif event.key in (K_1, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9):
|
||||
step = int(event.unicode)
|
||||
|
||||
if changed:
|
||||
screen.fill((100, 100, 100))
|
||||
screen.blit(image, (10, 10))
|
||||
blendimage.blit(image, (0, 0))
|
||||
# blendimage.fill (color, (0, 0, 20, 20), blendtype)
|
||||
blendimage.fill(color, None, blendtype)
|
||||
screen.blit(blendimage, (200, 10))
|
||||
print(
|
||||
"Color: %s, Pixel (0,0): %s"
|
||||
% (tuple(color), [blendimage.get_at((0, 0))])
|
||||
)
|
||||
changed = False
|
||||
pg.display.flip()
|
||||
|
||||
pg.quit()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,198 @@
|
||||
#!/usr/bin/env python
|
||||
""" pygame.examples.blit_blends
|
||||
|
||||
Blending colors in different ways with different blend modes.
|
||||
|
||||
It also shows some tricks with the surfarray.
|
||||
Including how to do additive blending.
|
||||
|
||||
|
||||
Keyboard Controls
|
||||
-----------------
|
||||
|
||||
* R, G, B - add a bit of Red, Green, or Blue.
|
||||
* A - Add blend mode
|
||||
* S - Subtractive blend mode
|
||||
* M - Multiply blend mode
|
||||
* = key BLEND_MAX blend mode.
|
||||
* - key BLEND_MIN blend mode.
|
||||
* 1, 2, 3, 4 - use different images.
|
||||
|
||||
"""
|
||||
import os
|
||||
import pygame as pg
|
||||
import time
|
||||
|
||||
main_dir = os.path.split(os.path.abspath(__file__))[0]
|
||||
data_dir = os.path.join(main_dir, "data")
|
||||
|
||||
try:
|
||||
import pygame.surfarray
|
||||
import numpy
|
||||
except ImportError:
|
||||
print("no surfarray for you! install numpy")
|
||||
|
||||
|
||||
def main():
|
||||
pg.init()
|
||||
pg.mixer.quit() # remove ALSA underflow messages for Debian squeeze
|
||||
screen = pg.display.set_mode((640, 480))
|
||||
|
||||
im1 = pg.Surface(screen.get_size())
|
||||
# im1= im1.convert()
|
||||
im1.fill((100, 0, 0))
|
||||
|
||||
im2 = pg.Surface(screen.get_size())
|
||||
im2.fill((0, 50, 0))
|
||||
# we make a srcalpha copy of it.
|
||||
# im3= im2.convert(SRCALPHA)
|
||||
im3 = im2
|
||||
im3.set_alpha(127)
|
||||
|
||||
images = {}
|
||||
images[pg.K_1] = im2
|
||||
images[pg.K_2] = pg.image.load(os.path.join(data_dir, "chimp.bmp"))
|
||||
images[pg.K_3] = pg.image.load(os.path.join(data_dir, "alien3.gif"))
|
||||
images[pg.K_4] = pg.image.load(os.path.join(data_dir, "liquid.bmp"))
|
||||
img_to_blit = im2.convert()
|
||||
iaa = img_to_blit.convert_alpha()
|
||||
|
||||
blits = {}
|
||||
blits[pg.K_a] = pg.BLEND_ADD
|
||||
blits[pg.K_s] = pg.BLEND_SUB
|
||||
blits[pg.K_m] = pg.BLEND_MULT
|
||||
blits[pg.K_EQUALS] = pg.BLEND_MAX
|
||||
blits[pg.K_MINUS] = pg.BLEND_MIN
|
||||
|
||||
blitsn = {}
|
||||
blitsn[pg.K_a] = "BLEND_ADD"
|
||||
blitsn[pg.K_s] = "BLEND_SUB"
|
||||
blitsn[pg.K_m] = "BLEND_MULT"
|
||||
blitsn[pg.K_EQUALS] = "BLEND_MAX"
|
||||
blitsn[pg.K_MINUS] = "BLEND_MIN"
|
||||
|
||||
screen.blit(im1, (0, 0))
|
||||
pg.display.flip()
|
||||
clock = pg.time.Clock()
|
||||
print("one pixel is:%s:" % [im1.get_at((0, 0))])
|
||||
|
||||
going = True
|
||||
while going:
|
||||
clock.tick(60)
|
||||
|
||||
for event in pg.event.get():
|
||||
if event.type == pg.QUIT:
|
||||
going = False
|
||||
if event.type == pg.KEYDOWN:
|
||||
usage()
|
||||
|
||||
if event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE:
|
||||
going = False
|
||||
|
||||
elif event.type == pg.KEYDOWN and event.key in images.keys():
|
||||
img_to_blit = images[event.key]
|
||||
iaa = img_to_blit.convert_alpha()
|
||||
|
||||
elif event.type == pg.KEYDOWN and event.key in blits.keys():
|
||||
t1 = time.time()
|
||||
# blits is a dict keyed with key -> blit flag. eg BLEND_ADD.
|
||||
im1.blit(img_to_blit, (0, 0), None, blits[event.key])
|
||||
t2 = time.time()
|
||||
print("one pixel is:%s:" % [im1.get_at((0, 0))])
|
||||
print("time to do:%s:" % (t2 - t1))
|
||||
|
||||
elif event.type == pg.KEYDOWN and event.key in [pg.K_t]:
|
||||
|
||||
for bkey in blits.keys():
|
||||
t1 = time.time()
|
||||
|
||||
for x in range(300):
|
||||
im1.blit(img_to_blit, (0, 0), None, blits[bkey])
|
||||
|
||||
t2 = time.time()
|
||||
|
||||
# show which key we're doing...
|
||||
onedoing = blitsn[bkey]
|
||||
print("time to do :%s: is :%s:" % (onedoing, t2 - t1))
|
||||
|
||||
elif event.type == pg.KEYDOWN and event.key in [pg.K_o]:
|
||||
t1 = time.time()
|
||||
# blits is a dict keyed with key -> blit flag. eg BLEND_ADD.
|
||||
im1.blit(iaa, (0, 0))
|
||||
t2 = time.time()
|
||||
print("one pixel is:%s:" % [im1.get_at((0, 0))])
|
||||
print("time to do:%s:" % (t2 - t1))
|
||||
|
||||
elif event.type == pg.KEYDOWN and event.key == pg.K_SPACE:
|
||||
# this additive blend without clamp two surfaces.
|
||||
# im1.set_alpha(127)
|
||||
# im1.blit(im1, (0,0))
|
||||
# im1.set_alpha(255)
|
||||
t1 = time.time()
|
||||
|
||||
im1p = pygame.surfarray.pixels2d(im1)
|
||||
im2p = pygame.surfarray.pixels2d(im2)
|
||||
im1p += im2p
|
||||
del im1p
|
||||
del im2p
|
||||
t2 = time.time()
|
||||
print("one pixel is:%s:" % [im1.get_at((0, 0))])
|
||||
print("time to do:%s:" % (t2 - t1))
|
||||
|
||||
elif event.type == pg.KEYDOWN and event.key in [pg.K_z]:
|
||||
t1 = time.time()
|
||||
im1p = pygame.surfarray.pixels3d(im1)
|
||||
im2p = pygame.surfarray.pixels3d(im2)
|
||||
im1p16 = im1p.astype(numpy.uint16)
|
||||
im2p16 = im1p.astype(numpy.uint16)
|
||||
im1p16 += im2p16
|
||||
im1p16 = numpy.minimum(im1p16, 255)
|
||||
pygame.surfarray.blit_array(im1, im1p16)
|
||||
|
||||
del im1p
|
||||
del im2p
|
||||
t2 = time.time()
|
||||
print("one pixel is:%s:" % [im1.get_at((0, 0))])
|
||||
print("time to do:%s:" % (t2 - t1))
|
||||
|
||||
elif event.type == pg.KEYDOWN and event.key in [pg.K_r, pg.K_g, pg.K_b]:
|
||||
# this adds one to each pixel.
|
||||
colmap = {}
|
||||
colmap[pg.K_r] = 0x10000
|
||||
colmap[pg.K_g] = 0x00100
|
||||
colmap[pg.K_b] = 0x00001
|
||||
im1p = pygame.surfarray.pixels2d(im1)
|
||||
im1p += colmap[event.key]
|
||||
del im1p
|
||||
print("one pixel is:%s:" % [im1.get_at((0, 0))])
|
||||
|
||||
elif event.type == pg.KEYDOWN and event.key == pg.K_p:
|
||||
print("one pixel is:%s:" % [im1.get_at((0, 0))])
|
||||
|
||||
elif event.type == pg.KEYDOWN and event.key == pg.K_f:
|
||||
# this additive blend without clamp two surfaces.
|
||||
|
||||
t1 = time.time()
|
||||
im1.set_alpha(127)
|
||||
im1.blit(im2, (0, 0))
|
||||
im1.set_alpha(255)
|
||||
|
||||
t2 = time.time()
|
||||
print("one pixel is:%s:" % [im1.get_at((0, 0))])
|
||||
print("time to do:%s:" % (t2 - t1))
|
||||
|
||||
screen.blit(im1, (0, 0))
|
||||
pg.display.flip()
|
||||
|
||||
pg.quit()
|
||||
|
||||
|
||||
def usage():
|
||||
print("press keys 1-5 to change image to blit.")
|
||||
print("A - ADD, S- SUB, M- MULT, - MIN, + MAX")
|
||||
print("T - timing test for special blend modes.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
usage()
|
||||
main()
|
||||
@@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env python
|
||||
""" pygame.examples.camera
|
||||
|
||||
Basic image capturing and display using pygame.camera
|
||||
|
||||
Keyboard controls
|
||||
-----------------
|
||||
|
||||
- 0, start camera 0.
|
||||
- 1, start camera 1.
|
||||
- 9, start camera 9.
|
||||
- 10, start camera... wait a minute! There's not 10 key!
|
||||
"""
|
||||
import pygame as pg
|
||||
import pygame.camera
|
||||
|
||||
|
||||
class VideoCapturePlayer(object):
|
||||
|
||||
size = (640, 480)
|
||||
|
||||
def __init__(self, **argd):
|
||||
self.__dict__.update(**argd)
|
||||
super(VideoCapturePlayer, self).__init__(**argd)
|
||||
|
||||
# create a display surface. standard pygame stuff
|
||||
self.display = pg.display.set_mode(self.size, 0)
|
||||
self.init_cams(0)
|
||||
|
||||
def init_cams(self, which_cam_idx):
|
||||
|
||||
# gets a list of available cameras.
|
||||
self.clist = pygame.camera.list_cameras()
|
||||
print(self.clist)
|
||||
|
||||
if not self.clist:
|
||||
raise ValueError("Sorry, no cameras detected.")
|
||||
|
||||
try:
|
||||
cam_id = self.clist[which_cam_idx]
|
||||
except IndexError:
|
||||
cam_id = self.clist[0]
|
||||
|
||||
# creates the camera of the specified size and in RGB colorspace
|
||||
self.camera = pygame.camera.Camera(cam_id, self.size, "RGB")
|
||||
|
||||
# starts the camera
|
||||
self.camera.start()
|
||||
|
||||
self.clock = pg.time.Clock()
|
||||
|
||||
# create a surface to capture to. for performance purposes, you want the
|
||||
# bit depth to be the same as that of the display surface.
|
||||
self.snapshot = pg.surface.Surface(self.size, 0, self.display)
|
||||
|
||||
def get_and_flip(self):
|
||||
# if you don't want to tie the framerate to the camera, you can check and
|
||||
# see if the camera has an image ready. note that while this works
|
||||
# on most cameras, some will never return true.
|
||||
|
||||
self.snapshot = self.camera.get_image(self.display)
|
||||
|
||||
# if 0 and self.camera.query_image():
|
||||
# # capture an image
|
||||
|
||||
# self.snapshot = self.camera.get_image(self.snapshot)
|
||||
|
||||
# if 0:
|
||||
# self.snapshot = self.camera.get_image(self.snapshot)
|
||||
# # self.snapshot = self.camera.get_image()
|
||||
|
||||
# # blit it to the display surface. simple!
|
||||
# self.display.blit(self.snapshot, (0, 0))
|
||||
# else:
|
||||
|
||||
# self.snapshot = self.camera.get_image(self.display)
|
||||
# # self.display.blit(self.snapshot, (0,0))
|
||||
|
||||
pg.display.flip()
|
||||
|
||||
def main(self):
|
||||
going = True
|
||||
while going:
|
||||
events = pg.event.get()
|
||||
for e in events:
|
||||
if e.type == pg.QUIT or (e.type == pg.KEYDOWN and e.key == pg.K_ESCAPE):
|
||||
going = False
|
||||
if e.type == pg.KEYDOWN:
|
||||
if e.key in range(pg.K_0, pg.K_0 + 10):
|
||||
self.init_cams(e.key - pg.K_0)
|
||||
|
||||
self.get_and_flip()
|
||||
self.clock.tick()
|
||||
print(self.clock.get_fps())
|
||||
|
||||
|
||||
def main():
|
||||
pg.init()
|
||||
pygame.camera.init()
|
||||
VideoCapturePlayer().main()
|
||||
pg.quit()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,203 @@
|
||||
#!/usr/bin/env python
|
||||
""" pygame.examples.chimp
|
||||
|
||||
This simple example is used for the line-by-line tutorial
|
||||
that comes with pygame. It is based on a 'popular' web banner.
|
||||
Note there are comments here, but for the full explanation,
|
||||
follow along in the tutorial.
|
||||
"""
|
||||
|
||||
|
||||
# Import Modules
|
||||
import os
|
||||
import pygame as pg
|
||||
from pygame.compat import geterror
|
||||
|
||||
if not pg.font:
|
||||
print("Warning, fonts disabled")
|
||||
if not pg.mixer:
|
||||
print("Warning, sound disabled")
|
||||
|
||||
main_dir = os.path.split(os.path.abspath(__file__))[0]
|
||||
data_dir = os.path.join(main_dir, "data")
|
||||
|
||||
|
||||
# functions to create our resources
|
||||
def load_image(name, colorkey=None):
|
||||
fullname = os.path.join(data_dir, name)
|
||||
try:
|
||||
image = pg.image.load(fullname)
|
||||
except pg.error:
|
||||
print("Cannot load image:", fullname)
|
||||
raise SystemExit(str(geterror()))
|
||||
image = image.convert()
|
||||
if colorkey is not None:
|
||||
if colorkey == -1:
|
||||
colorkey = image.get_at((0, 0))
|
||||
image.set_colorkey(colorkey, pg.RLEACCEL)
|
||||
return image, image.get_rect()
|
||||
|
||||
|
||||
def load_sound(name):
|
||||
class NoneSound:
|
||||
def play(self):
|
||||
pass
|
||||
|
||||
if not pg.mixer or not pg.mixer.get_init():
|
||||
return NoneSound()
|
||||
fullname = os.path.join(data_dir, name)
|
||||
try:
|
||||
sound = pg.mixer.Sound(fullname)
|
||||
except pg.error:
|
||||
print("Cannot load sound: %s" % fullname)
|
||||
raise SystemExit(str(geterror()))
|
||||
return sound
|
||||
|
||||
|
||||
# classes for our game objects
|
||||
class Fist(pg.sprite.Sprite):
|
||||
"""moves a clenched fist on the screen, following the mouse"""
|
||||
|
||||
def __init__(self):
|
||||
pg.sprite.Sprite.__init__(self) # call Sprite initializer
|
||||
self.image, self.rect = load_image("fist.bmp", -1)
|
||||
self.punching = 0
|
||||
|
||||
def update(self):
|
||||
"""move the fist based on the mouse position"""
|
||||
pos = pg.mouse.get_pos()
|
||||
self.rect.midtop = pos
|
||||
if self.punching:
|
||||
self.rect.move_ip(5, 10)
|
||||
|
||||
def punch(self, target):
|
||||
"""returns true if the fist collides with the target"""
|
||||
if not self.punching:
|
||||
self.punching = 1
|
||||
hitbox = self.rect.inflate(-5, -5)
|
||||
return hitbox.colliderect(target.rect)
|
||||
|
||||
def unpunch(self):
|
||||
"""called to pull the fist back"""
|
||||
self.punching = 0
|
||||
|
||||
|
||||
class Chimp(pg.sprite.Sprite):
|
||||
"""moves a monkey critter across the screen. it can spin the
|
||||
monkey when it is punched."""
|
||||
|
||||
def __init__(self):
|
||||
pg.sprite.Sprite.__init__(self) # call Sprite intializer
|
||||
self.image, self.rect = load_image("chimp.bmp", -1)
|
||||
screen = pg.display.get_surface()
|
||||
self.area = screen.get_rect()
|
||||
self.rect.topleft = 10, 10
|
||||
self.move = 9
|
||||
self.dizzy = 0
|
||||
|
||||
def update(self):
|
||||
"""walk or spin, depending on the monkeys state"""
|
||||
if self.dizzy:
|
||||
self._spin()
|
||||
else:
|
||||
self._walk()
|
||||
|
||||
def _walk(self):
|
||||
"""move the monkey across the screen, and turn at the ends"""
|
||||
newpos = self.rect.move((self.move, 0))
|
||||
if not self.area.contains(newpos):
|
||||
if self.rect.left < self.area.left or self.rect.right > self.area.right:
|
||||
self.move = -self.move
|
||||
newpos = self.rect.move((self.move, 0))
|
||||
self.image = pg.transform.flip(self.image, 1, 0)
|
||||
self.rect = newpos
|
||||
|
||||
def _spin(self):
|
||||
"""spin the monkey image"""
|
||||
center = self.rect.center
|
||||
self.dizzy = self.dizzy + 12
|
||||
if self.dizzy >= 360:
|
||||
self.dizzy = 0
|
||||
self.image = self.original
|
||||
else:
|
||||
rotate = pg.transform.rotate
|
||||
self.image = rotate(self.original, self.dizzy)
|
||||
self.rect = self.image.get_rect(center=center)
|
||||
|
||||
def punched(self):
|
||||
"""this will cause the monkey to start spinning"""
|
||||
if not self.dizzy:
|
||||
self.dizzy = 1
|
||||
self.original = self.image
|
||||
|
||||
|
||||
def main():
|
||||
"""this function is called when the program starts.
|
||||
it initializes everything it needs, then runs in
|
||||
a loop until the function returns."""
|
||||
# Initialize Everything
|
||||
pg.init()
|
||||
screen = pg.display.set_mode((468, 60))
|
||||
pg.display.set_caption("Monkey Fever")
|
||||
pg.mouse.set_visible(0)
|
||||
|
||||
# Create The Backgound
|
||||
background = pg.Surface(screen.get_size())
|
||||
background = background.convert()
|
||||
background.fill((250, 250, 250))
|
||||
|
||||
# Put Text On The Background, Centered
|
||||
if pg.font:
|
||||
font = pg.font.Font(None, 36)
|
||||
text = font.render("Pummel The Chimp, And Win $$$", 1, (10, 10, 10))
|
||||
textpos = text.get_rect(centerx=background.get_width() / 2)
|
||||
background.blit(text, textpos)
|
||||
|
||||
# Display The Background
|
||||
screen.blit(background, (0, 0))
|
||||
pg.display.flip()
|
||||
|
||||
# Prepare Game Objects
|
||||
clock = pg.time.Clock()
|
||||
whiff_sound = load_sound("whiff.wav")
|
||||
punch_sound = load_sound("punch.wav")
|
||||
chimp = Chimp()
|
||||
fist = Fist()
|
||||
allsprites = pg.sprite.RenderPlain((fist, chimp))
|
||||
|
||||
# Main Loop
|
||||
going = True
|
||||
while going:
|
||||
clock.tick(60)
|
||||
|
||||
# Handle Input Events
|
||||
for event in pg.event.get():
|
||||
if event.type == pg.QUIT:
|
||||
going = False
|
||||
elif event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE:
|
||||
going = False
|
||||
elif event.type == pg.MOUSEBUTTONDOWN:
|
||||
if fist.punch(chimp):
|
||||
punch_sound.play() # punch
|
||||
chimp.punched()
|
||||
else:
|
||||
whiff_sound.play() # miss
|
||||
elif event.type == pg.MOUSEBUTTONUP:
|
||||
fist.unpunch()
|
||||
|
||||
allsprites.update()
|
||||
|
||||
# Draw Everything
|
||||
screen.blit(background, (0, 0))
|
||||
allsprites.draw(screen)
|
||||
pg.display.flip()
|
||||
|
||||
pg.quit()
|
||||
|
||||
|
||||
# Game Over
|
||||
|
||||
|
||||
# this calls the 'main' function when this script is executed
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env python
|
||||
""" pygame.examples.cursors
|
||||
|
||||
Click a mouse button (if you have one!) and the cursor changes.
|
||||
|
||||
"""
|
||||
import pygame as pg
|
||||
|
||||
|
||||
arrow = (
|
||||
"xX ",
|
||||
"X.X ",
|
||||
"X..X ",
|
||||
"X...X ",
|
||||
"X....X ",
|
||||
"X.....X ",
|
||||
"X......X ",
|
||||
"X.......X ",
|
||||
"X........X ",
|
||||
"X.........X ",
|
||||
"X......XXXXX ",
|
||||
"X...X..X ",
|
||||
"X..XX..X ",
|
||||
"X.X XX..X ",
|
||||
"XX X..X ",
|
||||
"X X..X ",
|
||||
" X..X ",
|
||||
" X..X ",
|
||||
" X..X ",
|
||||
" XX ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
)
|
||||
|
||||
|
||||
no = (
|
||||
" ",
|
||||
" ",
|
||||
" XXXXXX ",
|
||||
" XX......XX ",
|
||||
" X..........X ",
|
||||
" X....XXXX....X ",
|
||||
" X...XX XX...X ",
|
||||
" X.....X X...X ",
|
||||
" X..X...X X..X ",
|
||||
" X...XX...X X...X ",
|
||||
" X..X X...X X..X ",
|
||||
" X..X X...X X..X ",
|
||||
" X..X X.,.X X..X ",
|
||||
" X..X X...X X..X ",
|
||||
" X...X X...XX...X ",
|
||||
" X..X X...X..X ",
|
||||
" X...X X.....X ",
|
||||
" X...XX X...X ",
|
||||
" X....XXXXX...X ",
|
||||
" X..........X ",
|
||||
" XX......XX ",
|
||||
" XXXXXX ",
|
||||
" ",
|
||||
" ",
|
||||
)
|
||||
|
||||
|
||||
def TestCursor(arrow):
|
||||
hotspot = None
|
||||
for y in range(len(arrow)):
|
||||
for x in range(len(arrow[y])):
|
||||
if arrow[y][x] in ["x", ",", "O"]:
|
||||
hotspot = x, y
|
||||
break
|
||||
if hotspot is not None:
|
||||
break
|
||||
if hotspot is None:
|
||||
raise Exception("No hotspot specified for cursor '%s'!" % cursorname)
|
||||
s2 = []
|
||||
for line in arrow:
|
||||
s2.append(line.replace("x", "X").replace(",", ".").replace("O", "o"))
|
||||
cursor, mask = pg.cursors.compile(s2, "X", ".", "o")
|
||||
size = len(arrow[0]), len(arrow)
|
||||
pg.mouse.set_cursor(size, hotspot, cursor, mask)
|
||||
|
||||
|
||||
def main():
|
||||
pg.init()
|
||||
pg.font.init()
|
||||
font = pg.font.Font(None, 24)
|
||||
bg = pg.display.set_mode((800, 600), 0, 24)
|
||||
bg.fill((255, 255, 255))
|
||||
bg.blit(font.render("Click to advance", 1, (0, 0, 0)), (0, 0))
|
||||
pg.display.update()
|
||||
for cursor in [no, arrow]:
|
||||
TestCursor(cursor)
|
||||
going = True
|
||||
while going:
|
||||
pg.event.pump()
|
||||
for e in pg.event.get():
|
||||
if e.type == pg.MOUSEBUTTONDOWN:
|
||||
going = False
|
||||
pg.quit()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 578 B |
|
After Width: | Height: | Size: 8.9 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 170 B |
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 143 B |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 6.4 KiB |
|
After Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 1.0 KiB |