Making a Smile Face - PowerPoint PPT Presentation

About This Presentation
Title:

Making a Smile Face

Description:

... (Color.YELLOW);// draw the blackout box g.fillRect (30, 33, 30, 10); //second smiley face g.setColor (Color.YELLOW); g.fillOval (230, 10, 50 ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 7
Provided by: KristinPe6
Learn more at: https://home.adelphi.edu
Category:
Tags: blackout | face | making | smile

less

Transcript and Presenter's Notes

Title: Making a Smile Face


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.fi
    llOval (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.fi
    llOval (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.fi
    llRect (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.fi
    llOval (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.fi
    llOval (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.fi
    llRect (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(x12,y15,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.fi
    llOval (x, y, 50, 50)       g.setColor
    (Color.BLACK)       g.fillOval (x12, y15, 7,
    7)       g.fillOval (x30, y15, 7, 7)
                g.drawOval (x10, y17, 30, 15) //
    drawOval instead of fill to get a
    line       g.setColor (Color.YELLOW)// draw the
    blackout box       g.fillRect (x10, y23, 30,
    10)      x 230
  • y 10        //second smiley
    face       g.setColor (Color.YELLOW)       g.fi
    llOval (x, y, 50, 50)       g.setColor
    (Color.BLACK)       g.fillOval (x12, y15, 7,
    7)       g.fillOval (x30, y15, 7, 7)
                g.drawOval (x10, y17, 30, 15) //
    drawOval instead of fill to get a
    line       g.setColor (Color.YELLOW)// draw the
    blackout box       g.fillRect (x10, y23, 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.f
    illOval (x, y, 50, 50)       g.setColor
    (Color.BLACK)       g.fillOval (x12, y15, 7,
    7)       g.fillOval (x30, y15, 7, 7)
                g.drawOval (x10, y17, 30, 15)
  • // drawOval instead of
    fill to get a line       g.setColor
    (Color.YELLOW)// draw the blackout
    box       g.fillRect (x10, y23, 30, 10)     
Write a Comment
User Comments (0)
About PowerShow.com