Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
CS 141 Introduction to CS
Drawing in Java
Sunday, November 4, 2012 1
Drawing on a Picture
What if we want to draw something on a picture? How about drawing a grid of lines on top of the picture?
Drawing in Java
Sunday, November 4, 2012 2
Drawing in Java
Sunday, November 4, 2012 3
How would you draw a circle on a picture? How would you draw a string of characters? You still would need to set the pixel colors of certain pixels
Which pixels?
Drawing in Java
Sunday, November 4, 2012 4
5
5
x,y
height
width
Drawing in Java
Sunday, November 4, 2012 6
Drawing in Java
Sunday, November 4, 2012 7
Polygon
Outlined Polygon
g.drawPolygon(xArray, yArray, numPoints); g.drawPolygon(currPolygon);
Filled Polygon
g.fillPolygon(xArray, yArray, numPoints); g.fillPolygon(currPolygon);
Drawing in Java
Sunday, November 4, 2012 8
Drawing Lines
g.drawLine(x1,y1,x2,y2);
x1,y1 x2,y2
Drawing in Java
Sunday, November 4, 2012 9
Drawing Arcs
Arcs
Outlined Arc
g.drawArc(topLeftX, topLeftY, width, height, startAngle, arcAngle);
Filled Arc
g.fillArc((topLeftX, topLeftY, width, height, startAngle, arcAngle);
Drawing in Java
Sunday, November 4, 2012 10
Drawing Rectangles
Outlined Rectangle
g.drawRect(topLeftX, topLeftY, width, height);
Filled Rectangle
g.fillRect(topLeftX,topLeftY,width,height);
Drawing in Java
Sunday, November 4, 2012 12
pict.write(/Users/jfdooley/Desktop/filename.jpg);
Drawing in Java
Sunday, November 4, 2012
13
13
Precision Drawings
How would you draw a stack of filled rectangles starting from the lightest one at the bottom right and the darkest one at the top left.
With 10 pixels between each Not easy with drawing packages
Drawing in Java
Sunday, November 4, 2012 14
So lets create
drawRectangles(int x, int y, int number);
Drawing in Java
Sunday, November 4, 2012
15
15
Drawing in Java
Sunday, November 4, 2012 16
Drawing in Java
Sunday, November 4, 2012 17