| 39 | } |
| 40 | |
| 41 | public static void main(String[] args) throws Exception { |
| 42 | // This will generate a Sierpinski triangle with a chaos game of n points for an |
| 43 | // initial triangle with three points on the vertices of an equilateral triangle: |
| 44 | // A = (0.0, 0.0) |
| 45 | // B = (0.5, sqrt(0.75)) |
| 46 | // C = (1.0, 0.0) |
| 47 | // It will output the file sierpinski.dat, which can be plotted after |
| 48 | Point[] shapePoints = new Point[]{ |
| 49 | new Point(0.0, 0.0), |
| 50 | new Point(0.5, Math.sqrt(0.75)), |
| 51 | new Point(1.0, 0.0) |
| 52 | }; |
| 53 | Point[] outputPoints = chaosGame(10000, shapePoints); |
| 54 | |
| 55 | FileWriter fw = new FileWriter("sierpinski.dat"); |
| 56 | for (Point p : outputPoints) |
| 57 | fw.write(p.x + "\t" + p.y + "\n"); |
| 58 | fw.close(); |
| 59 | } |
| 60 | |
| 61 | } |