CS1 Graphics
To use the graphics functions, make sure you import
them in your notebook or
your program:
from cs1.graphics import *
-
open_canvas(width, height)
Opens a new canvas with the given size and displays it. It will be filled with the current background color. -
set_color(color_name)
Given a string likeblack
,blue
, etc., will set the current drawing color. -
set_background_color(color_name)
Given a string likeblack
,blue
, etc., will set the current background color. -
set_color_rgb(red, blue, green)
Given red, blue, and green between 0 and 255, will set the current drawing color to that value. -
set_background_color_rgb(red, blue, green)
Given red, blue, and green between 0 and 255, will set the current background color to that value. -
set_line_thickness(thickness)
Sets the thickness of the lines that are drawn. -
clear_canvas()
Clears the canvas with the current background color. -
draw_line(x0, y0, x1, y1)
Draws a line betwen (x0, y0) and (x1, y1). -
draw_polyline(x0, y0, x1, y1, ...)
Draws a sequence of lines where each point is connected to the previous. -
draw_circle(centerx, centery, radius)
Draws a circle at the given point, with the given radius. -
draw_filled_circle(centerx, centery, radius)
Likedraw_circle
but fills the circle. -
draw_oval(centerx, centery, radiusx, radiusy)
Draws an ellipse at the given center point with the provided radii. -
draw_filled_oval(centerx, centery, radiusx, radiusy)
Likedraw_oval
but fills the oval. -
draw_rect(x, y, width, height)
Draws a rectangle with upper corner at x, y. -
draw_filled_rect(x, y, width, height)
Likedraw_rect
but fills the rectangle. -
draw_polygon(x1, y1, x2, y2, ...)
Likedraw_polyline
but connects the last point to the first. -
draw_filled_polygon(x1, y1, x2, y2, ...)
Likedraw_polygon
but fills the polygon. -
draw_string(message, x, y, text_size)
Draws the given string centered at x, y with the given text size.