0% found this document useful (0 votes)
24 views

cs111 Wellesley Edu Reference Cs1graphics

The document describes different types of objects that can be used in computer graphics programs, including Canvas, Drawable, Layer, Text, Shape, Path, Circle, Ellipse, Rectangle, and Polygon. It explains how to create each object and common operations that can be performed on each object type.

Uploaded by

chaosofdoomx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

cs111 Wellesley Edu Reference Cs1graphics

The document describes different types of objects that can be used in computer graphics programs, including Canvas, Drawable, Layer, Text, Shape, Path, Circle, Ellipse, Rectangle, and Polygon. It explains how to create each object and common operations that can be performed on each object type.

Uploaded by

chaosofdoomx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

This is a cheat-sheet page for the cs1graphics module, detailing the most important types of

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.

What you can ask it:


getDepth()--tells you the current depth.
getReferencePoint()--tells you the current reference point.

Layer
Contains other objects so that they can be manipulated as a group.

How to make one: Layer() (no need to supply any arguments).


What you can do with it:
add(drawable)--Add any kind of drawable to the layer (including another layer).
remove(drawable)--Remove something you added before.

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.

What you can ask it:


getMessage()--tells you what the message text is.
getFontSize()--tells you what the font size is.
getFontColor()--tells you what the font color is.

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.

What you can do with it:


setBorderColor()--Sets the color of the border of the shape.

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).

What you can ask it:


Home
getBorderColor()--Returns the current border color.
Schedule
Instructors & Tutors getBorderWidth()--Returns the current border width.
Drop-in Hours getFillColor()--Returns the color of the interior of the shape (if it has one).
Course info...
Reference...

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.

What you can ask it:


getPoint(index)--Looks up a point in the path and gives you that point.
getNumberOfPoints()--Returns the number of points in 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.

What you can ask it:


getWidth()--Returns the width of the ellipse.
getHeight()--Returns the height of 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.

What you can ask it:


getWidth(w)--Returns the width.
getHeight(h)--Returns the height.

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.

What you can ask it:


getPoint(index)--Looks up a point in the polygon and gives it to you.
Home
Schedule
getNumberOfPoints()--Returns the number of points in the polygon.

Instructors & Tutors


Drop-in Hours
Course info... Image
Reference...
An Image object draws an image that's stored in a file. The .gif format should always be
supported, other images might or might not work. .gif animations will only show the first frame
of the animation.

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

You might also like