Spider
Applet Name: spider.class
Description: Looks like
a twelve-sided spider web.
Assignment: Draw an eight-sided spider web with all the
concentric lines one color and all the radiating lines
another color.
---------------------------------------------------------------------
import java.applet.*;
import java.awt.*;
public class spider extends Applet {
double x1,y1,x2,y2;
int x,y,t,L2,t2;
Dimension dim;
public void init() {
dim=size();
}
public void paint(Graphics g) {
g.setColor(Color.yellow);
g.fillRect(0,0,dim.width,dim.height);
g.setColor(Color.black); //CENTER
for(t=30;t< 361;t+=30)
{
t2=30+t;
for(x=0;x< 10;x++)
{
x1=x*Math.cos(t*Math.PI/180);
y1=x*Math.sin(t*Math.PI/180);
x2=x*Math.cos(t2*Math.PI/180);
y2=x*Math.sin(t2*Math.PI/180);
x1*=10; //scaling to larger area
y1*=10;
x2*=10;
y2*=10;
g.drawLine((int)x1+100,(int)y1+100,(int)x2+100,(int)y2+100);
g.drawLine((int)x1+100,(int)y1+100,100,100);
}
}
}
}
---------------------------------------------------------------------
Easy assignment... but good practice working with trig functions.