/* This is the anti snowflake class for the Kosh Simulation */ import java.lang.*; public class AntiTriangle{ int n; //this is the number of permutation double length; //length of origonal side // constructor public AntiTriangle(int z, double l){ n = z; length = l; } // calculates the permiter just like in the Triangle class public double Permiter(){ double ans; ans = NumSides() * SideLength(n); return ans; } // calculates sidelength for the nth side public double SideLength(int n){ double ans; ans = length/(Math.pow(3, n-1)); return ans; } // calculates the number of sides in the nth permutation public int NumSides(){ int ans = 0; ans = (int)(3 * Math.pow(4, n-1)); return ans; } // calculates the area of the nth triangle public double Area(int a){ double area; double height; area = Math.pow(SideLength(a),2) * Math.sqrt(3)/4 * NumTriangles(a); return area; } // calculates the number of triangles in the nth permutation public double NumTriangles(int a){ double ans = 0; if(a == 1){ ans = 1; }else if(a == 2){ ans = 3; }else { ans = 3 * Math.pow(4, a-2); } return ans; } // this works by takeing initial area and subtracting the subsiquent // areas public double TotalArea(){ double ans = Area(1); for(int i = 2; i <= n; i++){ ans -= Area(i); } return ans; } }