cs111 Wellesley Edu Reference Cs1graphics
cs111 Wellesley Edu Reference Cs1graphics
objects (an 'object' in Computer Science is just a generic term for a value in a program that can
Home be manipulated using attached functions).
Schedule
For each object, it lists how to create it and what you can do with it.
Instructors & Tutors
Drop-in Hours
Course info...
Reference...
cs1graphics Objects
Canvas
A canvas is a special object that represents the drawing window. You will only create one Canvas
in your program.
How to create one: Canvas(200, 200, "white", "Title") supply the width, height,
background color, and title for the canvas.
What can you do with it:
add(drawable)--Add something to the canvas. Note that when you create a shape, you
need to add it to the canvas, or it will not appear.
remove(drawable)--Remove something from the canvas.
Drawable
Any kind of thing you can draw (everything on this list counts as a Drawable).
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
What you can do with it:
move(dx, dy)--move it relative to its current position.
moveTo(x, y)--move to a specific position.
Home setDepth(depth)--set depth to put it in front of or behind other objects.
Schedule
rotate(angle)--rotate it around its reference point by the given angle (degrees
Instructors & Tutors
Drop-in Hours
clockwise).
Course info... scale(factor)--scale it by the given scale factor (1.0 does nothing).
Reference... flip(angle)--mirror it across a line with the given angle that goes through the object's
center point.
adjustReference(dx, dy)--move the reference point relative to its current location
without moving the object.
Layer
Contains other objects so that they can be manipulated as a group.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
clear()--Remove everything from this layer.
Home Text
Schedule
Draws words on the canvas.
Instructors & Tutors
Drop-in Hours How to make one: Text("message", 12, Point(0, 0)) provide a message (the text to
Course info... display), a font size, and a center point.
Reference... What you can do with it:
setMessage(text)--change what the text is.
setFontSize(size)--change the font size.
setFontColor(color)--change the font color.
Shape
Any kind of shape (applies to the rest of the objects listed here). A Shape is a kind of Drawable, so
you can do things like rotate it or use getReferencePoint on it.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
setBorderWidth()--Sets the width of the shape border.
setFillColor()--Sets the color of the interior of the shape (if it has one).
Path
A series of lines connecting specific points.
How to make one: Path(Point(0, 0), Point(50, 0), Point(0, 50), Point(50, 50),
...) (You can supply as many points as you want.)
What you can do with it:
addPoint(point, index)--Adds a new point to the path.
setPoint(point, index)--Replaces a point in the path.
deletePoint(index)--Removes a point from the path.
clearPoints()--Removes all of the points from the path.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Circle
A circle with a specific radius. A Circle is a Shape and also a Drawable, so you can do things with
it like scale or setFillColor.
Home
Schedule How to make one: Circle(50, Point(0, 0)) provide a radius and a center point.
Instructors & Tutors What you can do with it:
Drop-in Hours
setRadius(r)--Sets a new radius for the circle.
Course info...
Reference... What you can ask it:
getRadius()--Returns the radius of the circle.
Ellipse
An ellipse with a specific width and height. An Ellipse is a Shape and also a Drawable, so you can
do things with it like scale or setFillColor.
How to make one: Ellipse(50, 80, Point(0, 0)) provide width first, then height and
finally a center point.
What you can do with it:
setWidth(w)--Sets a new width for the ellipse.
setHeight(h)--Sets a new height for the ellipse.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Rectangle
A rectangle with a width, height, and center point. A Rectangle is a Shape and also a Drawable,
so you can do things with it like scale or setFillColor.
Home
Schedule How to make one: Rectangle(50, 80, Point(0, 0)) provide width first, then height, and
Instructors & Tutors finally a center point.
Drop-in Hours
What you can do with it:
Course info...
setWidth(w)--Sets a new width for the rectangle.
Reference...
setHeight(h)--Sets a new height for the rectangle.
Polygon
A polygon has some points that define an outside and a filled in inside. A Polygon is a Shape and
also a Drawable, so you can do things with it like scale or setFillColor.
How to make one: Polygon(Point(0, 0), Point(50, 0), Point(25, 50), ...) provide a
series of points. The last point will be connected back to the first point to complete the shape.
What you can do with it:
addPoint(point, index)--Adds a new point to the polygon.
setPoint(point, index)--Replaces a point in the polygon.
deletePoint(index)--Removes a point from the polygon.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
clearPoints()--Removes all of the points from the polygon.
How to make one: Image("filename.gif") provide the filename as a string. Make sure the
file is in the same directory as your code.
What you can ask it:
getWidth()--Returns the width of the image.
getHeight()--Returns the height of the image.
getPixel(x, y)--Returns the color of the pixel at the given location in the image.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD