module documentation

dudraw.py

The dudraw module defines functions that allow the user to create a drawing. A drawing appears on the canvas. The canvas appears in the window. As a convenience, the module also imports the commonly used Color objects defined in the color module.

Function annulus Draw an annulus centered at (x, y) with outer radius r1, and inner radius r2.
Function arc Draw an arc portion between angle1 and angle2, of the circumference of a circle centered at (x, y) with a radius r.
Function circle Draw on the background canvas a circle of radius r centered on (x, y).
Function clear Clear the background canvas to color c, where c is an object of class Color. c defaults to dudraw.WHITE.
Function clear_rgb Clear the background canvas to color c, where c is an object of class Color. c defaults to dudraw.WHITE.
Function ellipse Draw on the background canvas an ellipse centered at (x, y) with a width of 2.0 * half_width, and a height of 2.0 * half_height.
Function elliptical_arc Draw an arc portion between angle1 and angle2, of the circumference of an ellipse centered at (x, y) with a width of half_width, and a height of 2.0 * half_height.
Function elliptical_sector Draw a sector portion between angle1 and angle2, of the interior of an ellipse centered at (x, y) with a width of half_width, and a height of 2.0 * half_height.
Function filled_annulus Draw a filled annulus centered at (x, y) with outer radius r1, and inner radius r2.
Function filled_circle Draw on the background canvas a filled circle of radius r centered on (x, y).
Function filled_ellipse Draw on the background canvas a filled ellipse centered at (x, y) with a width of 2.0 * half_width, and a height of 2.0 * half_height.
Function filled_elliptical_sector Draw a filled sector portion between angle1 and angle2, of the interior of an ellipse centered at (x, y) with a width of half_width, and a height of 2.0 * half_height.
Function filled_polygon Draw on the background canvas a filled polygon with coordinates (x[i], y[i]).
Function filled_quadrilateral Draw a filled quadrilateral on the canvas with corners at (x0, y0), (x1, y1), (x2, y2), and (x3, y3).
Function filled_rectangle Draw on the background canvas a rectangle of width (2 * halfWidth and height (2 * halfHeight) centered at point (x, y).
Function filled_sector Draw a filled sector portion between angle1 and angle2, of the interior of a circle centered at (x, y) with a radius r.
Function filled_square Draw on the background canvas a filled square whose sides are of length 2r, centered on (x, y).
Function filled_triangle Draw a filled triangle on the canvas with corners at (x0, y0), (x1, y1), and (x2, y2).
Function get_canvas_height Return the height of the current canvas
Function get_canvas_width Return the width of the current canvas
Function get_pen_color Returns the value of _penColor as an object of class Color.
Function get_pixel_color Return the color of the pixel at the given user coordinates
Function has_next_key_typed Return True if the queue of keys the user typed is not empty. Otherwise return False.
Function line Draw on the background canvas a line from (x0, y0) to (x1, y1).
Function mouse_pressed Return True if the mouse has been left-clicked since the last time mousePressed was called, and False otherwise.
Function mouse_x Return the x coordinate in user space of the location at which the mouse was most recently left-clicked. If a left-click hasn't happened yet, raise an exception, since mouseX() shouldn't be called until mousePressed() returns True.
Function mouse_y Return the y coordinate in user space of the location at which the mouse was most recently left-clicked. If a left-click hasn't happened yet, raise an exception, since mouseY() shouldn't be called until mousePressed() returns True.
Function next_key_typed Remove the first key from the queue of keys that the the user typed, and return that key.
Function picture Draw pic on the background canvas centered at (x, y). pic is an object of class picture.Picture. x and y default to the midpoint of the background canvas.
Function point Draw on the background canvas a point at (x, y).
Function polygon Draw on the background canvas a polygon with coordinates (x[i], y[i]).
Function polyline Draw on the background canvas a polyline with coordinates (x[i], y[i]).
Function quadrilateral Draw a quadrilateral on the canvas with corners at (x0, y0), (x1, y1), (x2, y2), and (x3, y3).
Function rectangle Draw on the background canvas a rectangle of width (2 * halfWidth and height (2 * halfHeight) centered at point (x, y).
Function save Save the window canvas to file f.
Function sector Draw a sector portion between angle1 and angle2, of the interior of a circle centered at (x, y) with a radius r.
Function set_canvas_size Set the size of the canvas to w pixels wide and h pixels high. Calling this function is optional. If you call it, you must do so before calling any drawing function.
Function set_font_family Set the font family to f (e.g. 'Helvetica' or 'Courier').
Function set_font_size Set the font size to s (e.g. 12 or 16).
Function set_pen_color Set the pen color to c, where c is an object of class Color. c defaults to dudraw.BLACK.
Function set_pen_color_rgb Set the pen color to c, where c is an object of class Color. c defaults to dudraw.BLACK.
Function set_pen_width Set the pen radius to r, thus affecting the subsequent drawing of points and lines. If r is 0.0, then points will be drawn with the minimum possible radius and lines with the minimum possible width.
Function set_scale Undocumented
Function set_x_scale Set the x-scale of the canvas such that the minimum x value is min and the maximum x value is max.
Function set_y_scale Set the y-scale of the canvas such that the minimum y value is min and the maximum y value is max.
Function show Copy the background canvas to the window canvas, and then wait for msec milliseconds. msec defaults to infinity.
Function square Draw on the background canvas a square whose sides are of length 2r, centered on (x, y).
Function text Draw string s on the background canvas centered at (x, y).
Function triangle Draw a triangle on the canvas with corners at (x0, y0), (x1, y1), and (x2, y2).
Function _ccw Undocumented
Function _check_for_events Check if any new event has occured (such as a key typed or button pressed). If a key has been typed, then put that key in a queue.
Function _factor_x Undocumented
Function _factor_y Undocumented
Function _intersect Undocumented
Function _line_width_pixels Undocumented
Function _main Dispatch to a function that does regression testing, or to a dialog-box-handling function.
Function _make_sure_window_created Undocumented
Function _pen_width_pixels Undocumented
Function _pixel Draw on the background canvas a pixel at (x, y).
Function _pygame_color Convert c, an object of type Color, to an equivalent object of type pygame.Color. Return the result.
Function _regression_test Perform regression testing.
Function _scale_point Undocumented
Function _scale_x Undocumented
Function _scale_y Undocumented
Function _show Copy the background canvas to the window canvas.
Function _show_and_wait_forever Copy the background canvas to the window canvas. Then wait forever, that is, until the user closes the dudraw window.
Function _thick_line Draw on the background canvas a line from (x0, y0) to (x1, y1). Draw the line with a pen whose radius is r.
Function _user_x Undocumented
Function _user_y Undocumented
Constant _BORDER Undocumented
Constant _DEFAULT_CANVAS_SIZE Undocumented
Constant _DEFAULT_FONT_FAMILY Undocumented
Constant _DEFAULT_FONT_SIZE Undocumented
Constant _DEFAULT_PEN_WIDTH Undocumented
Constant _DEFAULT_XMAX Undocumented
Constant _DEFAULT_XMIN Undocumented
Constant _DEFAULT_YMAX Undocumented
Constant _DEFAULT_YMIN Undocumented
Variable _canvas_height Undocumented
Variable _canvas_width Undocumented
Variable _keys_typed Undocumented
Variable _mouse_pos Undocumented
Variable _mouse_pressed Undocumented
Variable _pen_width Undocumented
Variable _window_created Undocumented
Variable _xmax Undocumented
Variable _xmin Undocumented
Variable _ymax Undocumented
Variable _ymin Undocumented
def annulus(x, y, r1, r2):

Draw an annulus centered at (x, y) with outer radius r1, and inner radius r2.

Parameters
x:floatUndocumented
y:floatUndocumented
r1:floatUndocumented
r2:floatUndocumented
def arc(x, y, r, angle1, angle2):

Draw an arc portion between angle1 and angle2, of the circumference of a circle centered at (x, y) with a radius r.

Parameters
x:floatUndocumented
y:floatUndocumented
r:floatUndocumented
angle1:floatUndocumented
angle2:floatUndocumented
def circle(x, y, r):

Draw on the background canvas a circle of radius r centered on (x, y).

Parameters
x:floatUndocumented
y:floatUndocumented
r:floatUndocumented
def clear(c=WHITE):

Clear the background canvas to color c, where c is an object of class Color. c defaults to dudraw.WHITE.

Parameters
c:ColorUndocumented
def clear_rgb(r=255, g=255, b=255):

Clear the background canvas to color c, where c is an object of class Color. c defaults to dudraw.WHITE.

Parameters
r:floatUndocumented
g:floatUndocumented
b:floatUndocumented
def ellipse(x, y, half_width, half_height):

Draw on the background canvas an ellipse centered at (x, y) with a width of 2.0 * half_width, and a height of 2.0 * half_height.

Parameters
x:floatUndocumented
y:floatUndocumented
half_width:floatUndocumented
half_height:floatUndocumented
def elliptical_arc(x, y, half_width, half_height, angle1, angle2):

Draw an arc portion between angle1 and angle2, of the circumference of an ellipse centered at (x, y) with a width of half_width, and a height of 2.0 * half_height.

Parameters
x:floatUndocumented
y:floatUndocumented
half_width:floatUndocumented
half_height:floatUndocumented
angle1:floatUndocumented
angle2:floatUndocumented
def elliptical_sector(x, y, half_width, half_height, angle1, angle2):

Draw a sector portion between angle1 and angle2, of the interior of an ellipse centered at (x, y) with a width of half_width, and a height of 2.0 * half_height.

Parameters
x:floatUndocumented
y:floatUndocumented
half_width:floatUndocumented
half_height:floatUndocumented
angle1:floatUndocumented
angle2:floatUndocumented
def filled_annulus(x, y, r1, r2):

Draw a filled annulus centered at (x, y) with outer radius r1, and inner radius r2.

Parameters
x:floatUndocumented
y:floatUndocumented
r1:floatUndocumented
r2:floatUndocumented
def filled_circle(x, y, r):

Draw on the background canvas a filled circle of radius r centered on (x, y).

Parameters
x:floatUndocumented
y:floatUndocumented
r:floatUndocumented
def filled_ellipse(x, y, half_width, half_height):

Draw on the background canvas a filled ellipse centered at (x, y) with a width of 2.0 * half_width, and a height of 2.0 * half_height.

Parameters
x:floatUndocumented
y:floatUndocumented
half_width:floatUndocumented
half_height:floatUndocumented
def filled_elliptical_sector(x, y, half_width, half_height, angle1, angle2):

Draw a filled sector portion between angle1 and angle2, of the interior of an ellipse centered at (x, y) with a width of half_width, and a height of 2.0 * half_height.

Parameters
x:floatUndocumented
y:floatUndocumented
half_width:floatUndocumented
half_height:floatUndocumented
angle1:floatUndocumented
angle2:floatUndocumented
def filled_polygon(x, y):

Draw on the background canvas a filled polygon with coordinates (x[i], y[i]).

Parameters
x:Sequence[float]Undocumented
y:Sequence[float]Undocumented
def filled_quadrilateral(x0, y0, x1, y1, x2, y2, x3, y3):

Draw a filled quadrilateral on the canvas with corners at (x0, y0), (x1, y1), (x2, y2), and (x3, y3).

Parameters
x0:floatUndocumented
y0:floatUndocumented
x1:floatUndocumented
y1:floatUndocumented
x2:floatUndocumented
y2:floatUndocumented
x3:floatUndocumented
y3:floatUndocumented
def filled_rectangle(x, y, half_width, half_height):

Draw on the background canvas a rectangle of width (2 * halfWidth and height (2 * halfHeight) centered at point (x, y).

Parameters
x:floatUndocumented
y:floatUndocumented
half_width:floatUndocumented
half_height:floatUndocumented
def filled_sector(x, y, r, angle1, angle2):

Draw a filled sector portion between angle1 and angle2, of the interior of a circle centered at (x, y) with a radius r.

Parameters
x:floatUndocumented
y:floatUndocumented
r:floatUndocumented
angle1:floatUndocumented
angle2:floatUndocumented
def filled_square(x, y, r):

Draw on the background canvas a filled square whose sides are of length 2r, centered on (x, y).

Parameters
x:floatUndocumented
y:floatUndocumented
r:floatUndocumented
def filled_triangle(x0, y0, x1, y1, x2, y2):

Draw a filled triangle on the canvas with corners at (x0, y0), (x1, y1), and (x2, y2).

Parameters
x0:floatUndocumented
y0:floatUndocumented
x1:floatUndocumented
y1:floatUndocumented
x2:floatUndocumented
y2:floatUndocumented
def get_canvas_height():

Return the height of the current canvas

Returns
floatUndocumented
def get_canvas_width():

Return the width of the current canvas

Returns
floatUndocumented
def get_pen_color():

Returns the value of _penColor as an object of class Color.

def get_pixel_color(x, y):

Return the color of the pixel at the given user coordinates

Parameters
x:floatUndocumented
y:floatUndocumented
Returns
pygame.ColorUndocumented
def has_next_key_typed():

Return True if the queue of keys the user typed is not empty. Otherwise return False.

Returns
boolUndocumented
def line(x0, y0, x1, y1):

Draw on the background canvas a line from (x0, y0) to (x1, y1).

Parameters
x0:floatUndocumented
y0:floatUndocumented
x1:floatUndocumented
y1:floatUndocumented
def mouse_pressed():

Return True if the mouse has been left-clicked since the last time mousePressed was called, and False otherwise.

Returns
boolUndocumented
def mouse_x():

Return the x coordinate in user space of the location at which the mouse was most recently left-clicked. If a left-click hasn't happened yet, raise an exception, since mouseX() shouldn't be called until mousePressed() returns True.

Returns
floatUndocumented
def mouse_y():

Return the y coordinate in user space of the location at which the mouse was most recently left-clicked. If a left-click hasn't happened yet, raise an exception, since mouseY() shouldn't be called until mousePressed() returns True.

Returns
floatUndocumented
def next_key_typed():

Remove the first key from the queue of keys that the the user typed, and return that key.

Returns
strUndocumented
def picture(pic_path, x=None, y=None):

Draw pic on the background canvas centered at (x, y). pic is an object of class picture.Picture. x and y default to the midpoint of the background canvas.

Parameters
pic_path:strUndocumented
x:floatUndocumented
y:floatUndocumented
def point(x, y):

Draw on the background canvas a point at (x, y).

Parameters
x:floatUndocumented
y:floatUndocumented
def polygon(x, y):

Draw on the background canvas a polygon with coordinates (x[i], y[i]).

Parameters
x:Sequence[float]Undocumented
y:Sequence[float]Undocumented
def polyline(x, y):

Draw on the background canvas a polyline with coordinates (x[i], y[i]).

Parameters
x:Sequence[float]Undocumented
y:Sequence[float]Undocumented
def quadrilateral(x0, y0, x1, y1, x2, y2, x3, y3):

Draw a quadrilateral on the canvas with corners at (x0, y0), (x1, y1), (x2, y2), and (x3, y3).

Parameters
x0:floatUndocumented
y0:floatUndocumented
x1:floatUndocumented
y1:floatUndocumented
x2:floatUndocumented
y2:floatUndocumented
x3:floatUndocumented
y3:floatUndocumented
def rectangle(x, y, half_width, half_height):

Draw on the background canvas a rectangle of width (2 * halfWidth and height (2 * halfHeight) centered at point (x, y).

Parameters
x:floatUndocumented
y:floatUndocumented
half_width:floatUndocumented
half_height:floatUndocumented
def save(f):

Save the window canvas to file f.

Parameters
f:strUndocumented
def sector(x, y, r, angle1, angle2):

Draw a sector portion between angle1 and angle2, of the interior of a circle centered at (x, y) with a radius r.

Parameters
x:floatUndocumented
y:floatUndocumented
r:floatUndocumented
angle1:floatUndocumented
angle2:floatUndocumented
def set_canvas_size(w=_DEFAULT_CANVAS_SIZE, h=_DEFAULT_CANVAS_SIZE):

Set the size of the canvas to w pixels wide and h pixels high. Calling this function is optional. If you call it, you must do so before calling any drawing function.

Parameters
w:floatUndocumented
h:floatUndocumented
def set_font_family(f=_DEFAULT_FONT_FAMILY):

Set the font family to f (e.g. 'Helvetica' or 'Courier').

Parameters
f:strUndocumented
def set_font_size(s=_DEFAULT_FONT_SIZE):

Set the font size to s (e.g. 12 or 16).

Parameters
s:intUndocumented
def set_pen_color(c=_DEFAULT_PEN_COLOR):

Set the pen color to c, where c is an object of class Color. c defaults to dudraw.BLACK.

Parameters
c:ColorUndocumented
def set_pen_color_rgb(r=255, g=255, b=255):

Set the pen color to c, where c is an object of class Color. c defaults to dudraw.BLACK.

Parameters
r:intUndocumented
g:intUndocumented
b:intUndocumented
def set_pen_width(w=_DEFAULT_PEN_WIDTH):

Set the pen radius to r, thus affecting the subsequent drawing of points and lines. If r is 0.0, then points will be drawn with the minimum possible radius and lines with the minimum possible width.

Parameters
w:floatUndocumented
def set_scale(min, max):

Undocumented

Parameters
min:floatUndocumented
max:floatUndocumented
def set_x_scale(min=_DEFAULT_XMIN, max=_DEFAULT_XMAX):

Set the x-scale of the canvas such that the minimum x value is min and the maximum x value is max.

Parameters
min:floatUndocumented
max:floatUndocumented
def set_y_scale(min=_DEFAULT_YMIN, max=_DEFAULT_YMAX):

Set the y-scale of the canvas such that the minimum y value is min and the maximum y value is max.

Parameters
min:floatUndocumented
max:floatUndocumented
def show(msec=0.0):

Copy the background canvas to the window canvas, and then wait for msec milliseconds. msec defaults to infinity.

Parameters
msec:floatUndocumented
def square(x, y, r):

Draw on the background canvas a square whose sides are of length 2r, centered on (x, y).

Parameters
x:floatUndocumented
y:floatUndocumented
r:floatUndocumented
def text(x, y, s):

Draw string s on the background canvas centered at (x, y).

Parameters
x:floatUndocumented
y:floatUndocumented
s:strUndocumented
def triangle(x0, y0, x1, y1, x2, y2):

Draw a triangle on the canvas with corners at (x0, y0), (x1, y1), and (x2, y2).

Parameters
x0:floatUndocumented
y0:floatUndocumented
x1:floatUndocumented
y1:floatUndocumented
x2:floatUndocumented
y2:floatUndocumented
def _ccw(a, b, c):

Undocumented

def _check_for_events():

Check if any new event has occured (such as a key typed or button pressed). If a key has been typed, then put that key in a queue.

def _factor_x(w):

Undocumented

Parameters
w:floatUndocumented
Returns
floatUndocumented
def _factor_y(h):

Undocumented

Parameters
h:floatUndocumented
Returns
floatUndocumented
def _intersect(a, b, c, d):

Undocumented

def _line_width_pixels():

Undocumented

Returns
floatUndocumented
def _main():

Dispatch to a function that does regression testing, or to a dialog-box-handling function.

def _make_sure_window_created():

Undocumented

def _pen_width_pixels():

Undocumented

Returns
floatUndocumented
def _pixel(x, y):

Draw on the background canvas a pixel at (x, y).

Parameters
x:floatUndocumented
y:floatUndocumented
def _pygame_color(c):

Convert c, an object of type Color, to an equivalent object of type pygame.Color. Return the result.

Parameters
c:ColorUndocumented
Returns
pygame.ColorUndocumented
def _regression_test():

Perform regression testing.

def _scale_point(p):

Undocumented

Parameters
p:Sequence[float]Undocumented
Returns
Sequence[float]Undocumented
def _scale_x(x):

Undocumented

Parameters
x:floatUndocumented
Returns
floatUndocumented
def _scale_y(y):

Undocumented

Parameters
y:floatUndocumented
Returns
floatUndocumented
def _show():

Copy the background canvas to the window canvas.

def _show_and_wait_forever():

Copy the background canvas to the window canvas. Then wait forever, that is, until the user closes the dudraw window.

def _thick_line(x0, y0, x1, y1, r):

Draw on the background canvas a line from (x0, y0) to (x1, y1). Draw the line with a pen whose radius is r.

Parameters
x0:floatUndocumented
y0:floatUndocumented
x1:floatUndocumented
y1:floatUndocumented
r:floatUndocumented
def _user_x(x):

Undocumented

Parameters
x:floatUndocumented
Returns
floatUndocumented
def _user_y(y):

Undocumented

Parameters
y:floatUndocumented
Returns
floatUndocumented
_BORDER: float =

Undocumented

Value
0.0
_DEFAULT_CANVAS_SIZE: int =

Undocumented

Value
512
_DEFAULT_FONT_FAMILY: str =

Undocumented

Value
'Helvetica'
_DEFAULT_FONT_SIZE: int =

Undocumented

Value
12
_DEFAULT_PEN_WIDTH: float =

Undocumented

Value
0.0
_DEFAULT_XMAX: float =

Undocumented

Value
1.0
_DEFAULT_XMIN: float =

Undocumented

Value
0.0
_DEFAULT_YMAX: float =

Undocumented

Value
1.0
_DEFAULT_YMIN: float =

Undocumented

Value
0.0
_canvas_height =

Undocumented

_canvas_width =

Undocumented

_keys_typed: list =

Undocumented

_mouse_pos =

Undocumented

_mouse_pressed: bool =

Undocumented

_pen_width =

Undocumented

_window_created: bool =

Undocumented

_xmax =

Undocumented

_xmin =

Undocumented

_ymax =

Undocumented

_ymin =

Undocumented