Unit 1: Using Easy Draw Objects
In this unit students learn to create objects and call methods by drawing with Easy Draw. Every shape is an object, which makes classes, constructors, references, and methods visible on the screen.
Learning Objectives
Students will be able to:
Explain the difference between a class and an object.
Create objects with
newand a constructor, passing arguments in the right order.Store a reference to an object in a variable of the class's type.
Call
voidmethods (setters) and non-void methods (getters) on an object and use the returned value.Use
intanddoublevariables and arithmetic expressions to place shapes.Use
Math.random()andMath.sqrt()in a drawing.
Lesson 1.1: Classes and Objects
A class is a blueprint. An object is one thing built from that blueprint. EasyDraw.Circle is a class. Each circle on the canvas is an object.
Break the line EasyDraw.Circle sun = new EasyDraw.Circle(300, 300, 100); into parts:
EasyDraw.Circle- the type of the variable (the class).sun- the variable that stores a reference to the object.new- creates a new object.EasyDraw.Circle(300, 300, 100)- calls the constructor with arguments: center x, center y, and radius.
Discussion: We made two objects from one class. What is the same about them? What is different?
Lesson 1.2: The Coordinate Plane and Constructors
The canvas is 600 x 600 pixels. (0, 0) is the top-left corner and y grows down. Turn on the Grid button on the Easy Draw page and hover over the canvas to see coordinates.
Each constructor expects its arguments in a certain order:
new EasyDraw.Rectangle(x, y, width, height)
top-left corner, then size
new EasyDraw.Circle(centerX, centerY, radius)
center, then radius
new EasyDraw.Oval(centerX, centerY, width, height)
center, then size
new EasyDraw.RegPolygon(nsides, centerX, centerY, radius)
number of sides, center, radius
new EasyDraw.Polygon(x1, y1, x2, y2, x3, y3, ...)
each point
new EasyDraw.Line(x1, y1, x2, y2)
start point, end point
new EasyDraw.Text(centerX, centerY, text)
center, then the text
Practice: Swap the order of two arguments in a constructor call. What happens? What happens if you leave one out? (The compiler error is the lesson!)
Lesson 1.3: Calling Methods
Methods are what an object can do. Setters are void methods: they change the object and do not return anything.
Getters are non-void methods: they return a value we can store or use.
Discussion: ball.setRadius(ball.getRadius() * 2); uses a non-void method call as the argument of a void method call. Which method runs first?
Practice: Draw a square, then use its getters to place a circle exactly on its top-right corner.
Lesson 1.4: Variables and Expressions
Variables and arithmetic let shapes be placed relative to each other. Change x, y, or size and the whole snowman moves and resizes together.
Discussion: What happens with int size = 80; and size / 3? Compare it with double size = 80;. (Integer division!)
Lesson 1.5: Colors and Strings
Colors can be a String (a name or a hex value) or three int values for red, green, and blue.
Use the Color Picker button on the Easy Draw page to find RGB and hex values.
Text objects hold a String, and + builds new strings:
Lesson 1.6: The Math Class
Math.random() returns a double from 0.0 up to (not including) 1.0. Multiply and cast it to get a random whole number.
Practice: Run the program several times. Then draw a line from the center of the canvas to the star.
Unit Project: Object Portrait
Students draw a portrait (of themselves, a character, an animal, or a robot) built only from Easy Draw objects.
Requirements:
At least 12 objects using at least 5 different classes (
Rectangle,Circle,Oval,RegPolygon,Polygon,Line,Arc,Text).Every shape is placed using
x,y, andsizevariables, so changing those three values moves and resizes the whole portrait.At least 3 different setters and at least 2 getters are used.
At least one color is RGB and one is hex.
Uses
Math.random()for at least one detail (like a random shirt color).A
Textobject shows a title built with string concatenation.
Objects
15+ objects, 6+ classes
12+ objects, 5+ classes
Fewer objects or classes
Very few objects
Methods
Setters and getters used together in expressions
3+ setters and 2+ getters
Only setters
No methods called
Relative position
Whole portrait scales correctly with size
Portrait moves with x and y
Some shapes use fixed numbers
All fixed numbers
Code quality
Clear names, comments, and organization
Comments explain each part
Few comments
Hard to read
Design
Original, detailed, and polished
Complete and recognizable
Unfinished
Hard to recognize
Last updated
Was this helpful?