This assignment gives the student more practice using fillPolygon.
| EXAMPLE: The student will create an applet like the one shown here. This activity provides the student with practice using fillPolygon. |
| x |
ASSIGNMENT:
Here's a method that will create a tree when passed the proper
parameters:
public void tree(Graphics g, int a, int b, int s){
g.setColor(Color.green);
int x[]=new int[11];
int y[]=new int[11];
x[0]=a; y[0]=b;
x[1]=a+s; y[1]=b+s*4/3;
x[2]=a+s/2; y[2]=b+s*4/3;
x[3]=a+s*3/2; y[3]=b+s*8/3;
x[4]=a+s*2/3; y[4]=b+s*8/3;
x[5]=a+2*s; y[5]=b+s*4;
x[6]=a-2*s; y[6]=b+s*4;
x[7]=a-s*2/3; y[7]=b+s*8/3;
x[8]=a-s*3/2; y[8]=b+s*8/3;
x[9]=a-s/2; y[9]=b+s*4/3;
x[10]=a-s; y[10]=b+s*4/3;
g.fillPolygon(x,y,x.length);
g.setColor(brown);
g.fillRect(a-s/4, b+s*4, s/2,s/2);
}
tree(g, 150, 50, 30);