Question: COS 160: Star Sampler- Using Java Needs to look like this: (just the shape) I need help changing my code: public static void fillStar(Graphics2D g,
COS 160: Star Sampler- Using Java
Needs to look like this: (just the shape)
I need help changing my code:
public static void fillStar(Graphics2D g, int ctrX, int ctrY, int radius, int nPoints, double spikiness) {
int xPoints[] = new int[nPoints];
int yPoints[] = new int[nPoints];
for(int i = 0; i
double angle = (270) + (i * 360.0) / (nPoints);
xPoints[i] = (int)(ctrX + radius * Math.cos(Math.toRadians(angle)));
yPoints[i] = (int)(ctrY + radius * Math.sin(Math.toRadians(angle)));
}
g.fillPolygon(xPoints, yPoints, nPoints);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
DrawingPanel panel = new DrawingPanel(500, 500);
Graphics2D g = panel.getGraphics();
g.setColor(Color.PINK);
fillStar(g, 250, 250, 150, 5, 0.618);
}
}
Needs to do this:
Part 3:
public static void fillStar (Graphics2D g, int ctrX, int ctrY, int radius, int points, double spikiness)
It will now have 1 extra parameter spikiness. The diagram shows that stars are polygons with points regularly spaced on 2 circles and, alternating between the outer and inner circles. The spikiness paramater determines the radius of the inner circle using the formula:
innerRadius = radius * (1.0 - spikiness)
The spikiness parameter can range from 0.0 to 1.0 with 0.0 being not spikey (like a soccer ball) and 1.0 being extremely spikey (like a sea urchin).
Part 4:
Modify your main() method to draw lots of different stars. You can do whatever you like as long as there are at least 25 different star shapes with a varying number of points and varying spikiness. Have fun! For a quick and simple star sampler, I recommend that you just make 2 nested loops and draw a grid of stars with varying numbers of points by row and varying spikiness by column.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
