Download presentation
Presentation is loading. Please wait.
1
Making a Smile Face Pepper
2
Code you have DrawingPanel panel = new DrawingPanel (300, 200); Graphics g = panel.getGraphics ( ); //first smiley face g.setColor (Color.YELLOW); g.fillOval (20, 10, 50, 50); g.setColor (Color.BLACK); g.fillOval (32, 25, 7, 7); g.fillOval (50, 25, 7, 7); g.drawOval (30, 37, 30, 15); // drawOval instead of fill to get a line g.setColor (Color.YELLOW);// draw the blackout box g.fillRect (30, 33, 30, 10); //second smiley face g.setColor (Color.YELLOW); g.fillOval (230, 10, 50,50); g.setColor (Color.BLACK); g.fillOval (242, 25, 7, 7); g.fillOval (260, 25, 7, 7); g.drawOval (240, 37, 30, 15); g.setColor (Color.YELLOW); g.fillRect (240, 33, 30, 10);
3
Graphics methods Method name Description drawLine(x1, y1, x2, y2)
line between points (x1, y1), (x2, y2) drawOval(x, y, width, height) draws outline of largest oval that fits in a box of size width * height with top-left corner at (x, y) drawRect(x, y, width, height) draws outline of rectangle of size width * height with top-left corner at (x, y) drawString(text, x, y) writes text with bottom-left corner at (x, y) fillOval(x, y, width, height) fills largest oval that fits in a box of size width * height with top-left corner at (x,y) fillRect(x, y, width, height) fills rectangle of size width * height with top-left corner at (x, y) setColor(Color) Sets Graphics to paint subsequent shapes in the given color
4
Finding relationships
DrawingPanel panel = new DrawingPanel (300, 200); Graphics g = panel.getGraphics ( ); //first smiley face g.setColor (Color.YELLOW); g.fillOval (20, 10, 50, 50); g.setColor (Color.BLACK); g.fillOval (32, 25, 7, 7); g.fillOval (50, 25, 7, 7); g.drawOval (30, 37, 30, 15); // drawOval instead of fill to get a line g.setColor (Color.YELLOW);// draw the blackout box g.fillRect (30, 33, 30, 10); //second smiley face g.setColor (Color.YELLOW); g.fillOval (230, 10, 50,50); g.setColor (Color.BLACK); g.fillOval (242, 25, 7, 7); g.fillOval (260, 25, 7, 7); g.drawOval (240, 37, 30, 15); g.setColor (Color.YELLOW); g.fillRect (240, 33, 30, 10); What is the relationship between the 20,10 Big Circle start and the 32,25 eyes? 32 is 12 over and 15 down, so You can set x = 20 and y = 10 And make the big circle with g.fillOval(x,y,50,50) And make the eye with g.fillOval(x+12,y+15,7,7)
5
Coded with relationships
DrawingPanel panel = new DrawingPanel (300, 200); Graphics g = panel.getGraphics ( ); int x = 20; int y = 10; //first smiley face g.setColor (Color.YELLOW); g.fillOval (x, y, 50, 50); g.setColor (Color.BLACK); g.fillOval (x+12, y+15, 7, 7); g.fillOval (x+30, y+15, 7, 7); g.drawOval (x+10, y+17, 30, 15); // drawOval instead of fill to get a line g.setColor (Color.YELLOW);// draw the blackout box g.fillRect (x+10, y+23, 30, 10); x = 230; y = 10; //second smiley face g.setColor (Color.YELLOW); g.fillOval (x, y, 50, 50); g.setColor (Color.BLACK); g.fillOval (x+12, y+15, 7, 7); g.fillOval (x+30, y+15, 7, 7); g.drawOval (x+10, y+17, 30, 15); // drawOval instead of fill to get a line g.setColor (Color.YELLOW);// draw the blackout box g.fillRect (x+10, y+23, 30, 10);
6
Coded with Methods DrawingPanel panel = new DrawingPanel (300, 200); Graphics g = panel.getGraphics ( ); smile(10,20); //first smiley face smile (230,10); // second face public static void smile(int x, int y){ g.setColor (Color.YELLOW); g.fillOval (x, y, 50, 50); g.setColor (Color.BLACK); g.fillOval (x+12, y+15, 7, 7); g.fillOval (x+30, y+15, 7, 7); g.drawOval (x+10, y+17, 30, 15); // drawOval instead of fill to get a line g.setColor (Color.YELLOW);// draw the blackout box g.fillRect (x+10, y+23, 30, 10); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.