The type of colors
The type of colors
There are a few predefined colors in the cmpsci220.graphics package. You can also use the cmpsci220.graphics.rgb function to create your own colors.
The type of images
The type of images
There are several functions in the cmpsci220.graphics package to create simple shapes, such as cmpsci220.graphics.rect, cmpsci220.graphics.oval, etc. You can make more complex images by manipulating and composing simpler shapes. E.g., see the functions cmpsci220.graphics.move and cmpsci220.graphics.overlay.
Draws a line at an angle.
Draws a line at an angle.
Draws a line from (length,length)
of length length
. The
angle between the x-axis and the line is given by degrees
.
Examples
angle(0, 10)
draws a horizontal line from (10, 10) to (20, 10)
angle(90, 10)
draws a vertical line from (10, 10) to (10, 20)
the angle of the line, specified in degrees
the length of the line
(optional) the color; black by default
(optional) the width; 1 by default
Starts the program
Starts the program
Starts the program in the init
state and draws the state using
the draw
argument. There are many optional arguments that you can
provide to customize the behavior of the program. For example, you can use
the tick
argument to update the state to build an animation.
the initial state of the program
a function from states to Images, which is called on each tick
(optional) the width of the window; 400 by default
(optional) the height of the window; 400 by default
(optional) a function to update the state; the default value is the identity function
(optional) the number of times per second that
draw
and tick
will be applied; the
default value is 35 tickes per second
the last value of the state before the window is closed
The color black
A blank image
A blank image
This image does not appear. But, it is often useful as a base-case when writing image-building functions.
The color blue
Draws a filled rectangle
Draws a filled rectangle
Draws a filled rectangle with width width
and height height
.
Examples:
fillRect(100, 30, red)
draws a short, red rectangle
fillRect(100, 100, blue)
draws a blue square
the width of the rectangle
the height of the rectangle
(optional) the color of the line; black by default
The color green
Ignores pressed keys
Draws a line
Draws a line
Draws a line from (0,0)
to (x,y)
.
Examples:
line(100, 0, red)
draws a horizonal, red line.
line(0, 100, blue, 10)
draws a thick, vertical, blue line.
the x-coordinate of the end-point
the y-coordinate of the end-point
(optional) the color of the line; black by default
(optional) the width of the line; 1 by default
Moves an image
Moves an image
Moves an image x
pixels horizontally and y
pixels
vertically.
Examples:
overlay(move(rect(10, 10, blue), 5, 5), rect(20, 20, red))
draws
a blue square centered inside a red square.
the image to draw
the x offset of the image
the y offset of the image
Draws an oval
Draws an oval
Draws an oval with width width
and height height
.
Examples:
oval(10, 100, blue)
draws a tall and thin blue oval
oval(100, 100, red)
draws a red circle with diameter 100
the height of the oval
(optional) the color of the oval; black by default
Overlays one image on top of another.
Overlays one image on top of another.
Draws the top
image on top of bot
.
Examples:
overlay(rect(10, 10, blue), rect(20, 20, red))
draws
a blue square inside a red square.
the image to draw on top
the image to draw on the bottom
Draws a rectangle
Draws a rectangle
Draws a rectangle with width width
and height height
.
Examples:
rect(100, 30, red)
draws a short, red rectangle
rect(100, 100, blue)
draws a blue square
the width of the rectangle
the height of the rectangle
(optional) the color of the line; black by default
The color red
A color defined by its red, green, and blue values
A color defined by its red, green, and blue values
the amount of red, in the range 0.0-1.0
the amount of green, in the range 0.0-1.0
the amount of blue, in the range 0.0-1.0
Save an image to a file
Shows an image
Shows an image
Shows an image in a window.
the image to draw
(optional) the width of the window; 400 by default
(optional) the height of the window; 400 by default
Draws a solid oval
Draws a solid oval
Draws an oval with width width
and height height
.
Examples:
solidOval(10, 100, blue)
draws a tall and thin blue oval
solidOval(100, 100, red)
draws a red circle with diameter 100
the width of the oval
the height of the oval
(optional) the color; black by default
An API for drawing 2D images and animations.