QUICK REFERENCE
Color & Location
Use pyDraw's small value objects for readable colors and reusable coordinates.Creating colors
Create a Color from a readable name, RGB values, or a hexadecimal value. The same Color can be reused by any object, line, text label, or Screen.
Color(name)Create a Color from a supported name such as "red" or "light blue".
Color(red, green, blue)Create a Color from three integer RGB channels.
Color((red, green, blue))Create the same RGB Color from a tuple.
Color("#RGB") · Color("#RRGGBB")Create a Color from short or full hexadecimal notation.
sky = Color("light blue")
screen.color(sky)coral = Color(255, 110, 90)
navy = Color((18, 32, 64))
gold = Color("#F4C542")Reading & comparing colors
Read a Color's resolved RGB channels or inspect the name or hex value that was originally used to create it.
color.red() · color.green() · color.blue()Return one resolved RGB channel.
color.rgb()Return all three resolved channels as an (R, G, B) tuple.
color.name()Return the original name, or None if the Color was not name-based.
color.hex()Return the original hex string, or None if the Color was not hex-based.
color == other_colorCompare Colors by their resolved RGB values.
blue = Color("blue")
print(blue.rgb()) # (0, 0, 255)
print(blue.name()) # blue
print(blue.hex()) # Nonenamed = Color("red")
rgb = Color(255, 0, 0)
print(named == rgb) # TrueColor helpers
Use the built-in collection when a program needs variety, or use Color.NONE to intentionally remove an optional color.
Color.random()Return a new randomly selected named Color.
Color.all()Return an immutable tuple containing every built-in named Color.
Color.NONERepresent no color for properties such as an object's border.
color.clone()Return an equivalent independent Color.
box.color(Color.random())
box.border(Color.NONE)colors = Color.all()
print(len(colors))
first = colors[0]Creating locations
A Location stores an x and y coordinate together. Most pyDraw methods accept a Location anywhere they accept separate coordinates.
Location(x, y)Create a Location from two numeric coordinates.
Location((x, y))Create a Location from a coordinate tuple.
Location(other_location)Create a new Location with another Location's coordinates.
Location(x=value, y=value)Create a Location with named coordinates.
start = Location(40, 80)
player = Rectangle(screen, start, 60, 40, Color("blue"))point = Location((120, 90))
copy = Location(point)Reading & changing coordinates
Read either coordinate, replace one coordinate, or update both through the same Location object.
location.x(value=None) · location.y(value=None)Read one coordinate, or pass a number to replace it.
location.moveto(x, y)Replace both coordinates and return the same Location.
location.moveto(other_location) · location.moveto((x, y))Replace both coordinates from another coordinate value.
location.moveto(x=value, y=value)Replace either named coordinate while preserving the other.
point = Location(20, 30)
point.x(50)
point.moveto(y=100)
print(point) # (X: 50, Y: 100)Relative movement
Use move() when values represent an offset from the current point rather than a new absolute position.
location.move(dx, dy)Add horizontal and vertical offsets and return the same Location.
location.move(offset_location) · location.move((dx, dy))Add offsets stored in a Location or tuple.
location.move(dx=value, dy=value)Move along either named axis while leaving the other unchanged.
target = Location(100, 100)
target.move(20, -10)
player.moveto(target)target.move(dx=5)
target.move(dy=12)Distance, copies & tuples
Locations work naturally in geometry calculations and can also be read like two-item coordinate tuples.
location.distance(other_location)Return the straight-line distance to another Location.
location.clone()Return an independent Location with the same coordinates.
x, y = locationUnpack a Location into its two coordinates.
location[0] · location[1]Read x or y by index.
location == other_location · location == (x, y)Compare coordinates with a Location or tuple.
start = Location(20, 30)
end = Location(80, 110)
print(start.distance(end))
x, y = endoriginal = Location(10, 10)
copy = original.clone()
copy.move(5, 0)
print(original) # (X: 10, Y: 10)