Professional Documents
Culture Documents
JBonus Pagan 1
JBonus Pagan 1
// by Tje Bouma
// Beginning Java, Ventura College, March 26, 2009
// Notes: drawing of a star...colored with slope, resizes, with text.
import javax.swing.*;
import java.awt.*;
import java.applet.*;
Dimension rowcol;
rowcol = getSize();
row = rowcol.width;
col = rowcol.height;
String S;
FontMetrics measure;
int typesize;
if (col>row)
{
offset = row/32;
height = (row - 2 * offset)/2;
typesize = row/16;
}
else
{
offset = col/32;
height = ( col - 2 * offset) / 2;
typesize = col/16;
}
centerx = row/2;
centery = col/2;
X[0] = centerx;
Y[0] = centery - r;
X[1] = centerx + shiftA;
Y[1] = centery + drop;
X[2] = centerx - shiftB;
Y[2] = centery - lift;
X[3] = centerx + shiftB;
Y[3] = Y[2];
X[4] = centerx - shiftA;
Y[4] = Y[1];
X[5] = X[0];
Y[5] = Y[0];
x[0]= centerx;
y[0]= centery + smallr;
x[1]= centerx - smallshiftB;
y[1]= centery + smalllift;
x[2]= centerx - smallshiftA;
y[2]= centery - smalldrop;
x[3]= centerx + smallshiftA;
y[3]= y[2];
x[4]= centerx + smallshiftB;
y[4]= y[1];
x[5]= x[0];
y[5]= y[0];
//lower L spike
n=0;
Q=200;
for(n=0; n < smallshiftB; n++)
{
Q = Q + 5;
if(Q>240) Q=200;
Draw.setColor(new Color(Q,250,Q) );
Draw.drawLine(X[4],Y[4],x[1] + n, y[1] + (int)( n /
Math.tan(Math.toRadians(54)))) ;
Draw.drawLine(X[4],Y[4],x[1] + n + 1, y[1] +(int)( n /
Math.tan(Math.toRadians(54)))) ;
}
//upper L spike
n=0;
Q=200;
for(n=0; n < smalllift + smalldrop; n++)
{
Q = Q + 5;
if(Q>240) Q=200;
Draw.setColor(new Color(Q,Q,112) );
Draw.drawLine(X[2], Y[2], x[2] - (int)( n /
Math.tan(Math.toRadians(72)) ), y[2] + n ) ;
Draw.drawLine(X[2], Y[2], x[2] - (int)( n /
Math.tan(Math.toRadians(72)) ) - 1, y[2] + n ) ;
}
//upper R spike
n=0;
Q=200;
for(n=0; n < smalllift + smalldrop; n++)
{
Q = Q + 5;
if(Q>245) Q=200;
Draw.setColor(new Color(Q,100,85) );
Draw.drawLine(X[3], Y[3], x[3] + (int)( n /
Math.tan(Math.toRadians(72)) ), y[3] + n ) ;
Draw.drawLine(X[3], Y[3], x[3] + (int)( n /
Math.tan(Math.toRadians(72)) ) + 1, y[3] + n ) ;
}
//top spike
n=0;
Q=200;
for(n=0; n < smallside; n++)
{
Q = Q + 5;
if(Q>245) Q=200;
Draw.setColor(new Color(245,Q,0) );
Draw.drawLine(X[0], Y[0], x[2] + n, y[2] ) ;
}
// lower left, inner pentagon.
n=0;
Q=200;
for(n=0; n < smallshiftB; n++)
{
Q = Q + 5;
if(Q>210) Q=150;
Draw.setColor(new Color(98,Q,Q) );
Draw.drawLine(centerx,centery,x[0] - n, y[0] - (int)( n /
Math.tan(Math.toRadians(54)))) ;
Draw.drawLine(centerx,centery,x[0] - n - 1, y[0] - (int)( n /
Math.tan(Math.toRadians(54))) ) ;
}
//lower right
n=0;
Q=200;
for(n=0; n < smallshiftB; n++)
{
Q = Q + 5;
if(Q>210) Q=150;
Draw.setColor(new Color(Q,Q,Q) );
Draw.drawLine(centerx,centery,x[0] + n, y[0] - (int)( n /
Math.tan(Math.toRadians(54)))) ;
Draw.drawLine(centerx,centery,x[0] + n + 1, y[0] - (int)( n /
Math.tan(Math.toRadians(54))) ) ;
}
//upperL
n=0;
Q=200;
for(n=0; n < smalllift + smalldrop; n++)
{
Q = Q + 5;
if(Q>210) Q=150;
Draw.setColor(new Color(Q,Q,75) );
Draw.drawLine(centerx, centery, x[2] - (int)( n /
Math.tan(Math.toRadians(72)) ), y[2] + n ) ;
Draw.drawLine(centerx, centery, x[2] - (int)( n /
Math.tan(Math.toRadians(72)) ) - 1, y[2] + n ) ;
}
//upper R
n=0;
Q=200;
for(n=0; n < smalllift + smalldrop; n++)
{
Q = Q + 5;
if(Q>210) Q=150;
Draw.setColor(new Color(Q,100,60) );
Draw.drawLine(centerx, centery, x[3] + (int)( n /
Math.tan(Math.toRadians(72)) ), y[3] + n ) ;
Draw.drawLine(centerx, centery, x[3] + (int)( n /
Math.tan(Math.toRadians(72)) ) + 1, y[3] + n ) ;
}
//top
n=0;
Q=200;
for(n=0; n < smallside; n++)
{
Q = Q + 5;
if(Q>210) Q=150;
Draw.setColor(new Color(255,Q,0) );
Draw.drawLine(centerx, centery, x[2] + n, y[2] ) ;
}
Draw.setColor(new Color(70,70,70));
Draw.drawPolyline(X,Y,6);
Draw.drawOval(centerx-r, centery-r, r*2, r*2);
Draw.setColor(Color.white);
Draw.setFont(new Font("sansserif",Font.ITALIC,typesize));
S = "I AM STAR";
measure = Draw.getFontMetrics();
Draw.drawString(S,centerx - (measure.stringWidth(S)/2), centery +
typesize/2);
}
}