E N D
Making a Smile Face Pepper
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);
Finding relationships What is the relationship between the 20,10 Big Circle start and the 32,25 eyes? • 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); 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)
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);
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); }