Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Polygon Generate(int seed)
- {
- Random generator = new Random(seed);
- // Set points using a min and max range
- int numPoints = (int)Math.floor(generator.nextDouble() * (maxPts-minPts)) + minPts;
- int[] yPolyPoints = new int[numPoints];
- int[] xPolyPoints = new int[numPoints];
- // Set the radius using min and max range as well
- radius = (int)Math.floor(generator.nextDouble() * (maxRad - minRad)) + minRad;
- double crAng = 0,
- // Angle between each point
- angDiff = Math.toRadians(360.0 / numPoints),
- // Arbitrary radJitter range; notice I subtract each by the jitter / 2.0 to get a +/- jitter with this range
- radJitter = radius / 3.0,
- angJitter = angDiff * .9;
- for (int i=0; i<numPoints; i++)
- {
- double tRadius = radius + (generator.nextDouble() * radJitter - radJitter / 2.0);
- double tAng = crAng + (generator.nextDouble() * angJitter - angJitter / 2.0);
- int nx = (int)(Math.sin(tAng) * tRadius),
- ny = (int)(Math.cos(tAng) * tRadius);
- yPolyPoints[i] = ny;
- xPolyPoints[i] = nx;
- crAng += angDiff;
- }
- return new Polygon(xPolyPoints, yPolyPoints, numPoints);
- }
Advertisement
Add Comment
Please, Sign In to add comment