Documente Academic
Documente Profesional
Documente Cultură
// by Tje Bouma
// Beginning Java, Ventura College, March 26, 2009
// Notes: drawing of a pentagon...colored along the slope of each
side...resizes...with text.
import javax.swing.*;
import java.awt.*;
import java.applet.*;
String S;
FontMetrics measure;
int typesize;
Dimension rowcol;
rowcol = getSize();
row = rowcol.width;
col = rowcol.height;
if (col>row)
{
offset = row/32;
height = (row - 2* offset)/2;
typesize = row/16;
}
else
{
offset = row/32;
height = ( col - 2 * offset) / 2;
typesize = col/16;
}
centerx = row/2;
centery = col/2;
r = height;
shiftA = (int) (r * Math.sin(Math.toRadians(36)));
drop = (int) (r * Math.cos(Math.toRadians(36)));
shiftB = (int) (r * Math.sin(Math.toRadians(72)));
lift = (int) (r * Math.cos(Math.toRadians(72)));
side = shiftA * 2;
x[0] = centerx;
y[0] = centery - r;
x[1] = centerx + shiftB;
y[1] = centery - lift;
x[2] = centerx + shiftA;
y[2] = centery + drop;
x[3] = centerx - shiftA;
y[3] = y[2];
x[4] = centerx - shiftB;
y[4] = y[1];
x[5] = x[0];
y[5] = y[0];
Draw.setColor(new Color(20,20,20));
Draw.fillRect(0,0,row,col);
Draw.setColor(new Color(200,200,200));
Draw.drawOval(centerx-r, centery-r, r*2, r*2);
Draw.setColor(new Color(250,250,200));
Draw.setFont(new Font("sansserif",Font.ITALIC,typesize));
S = "PENTAGON";
measure = Draw.getFontMetrics();
Draw.drawString(S,centerx - (measure.stringWidth(S)/2), centery +
typesize/2);
}
}