Advertisement
LilFrostay

Untitled

Oct 3rd, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1.  
  2.  
  3. public class Koch {
  4. private static int startingn;
  5. // plot Koch curve of order n, with given step size
  6.  
  7.  
  8. private static double getArea(int n) {
  9. //Output Variable
  10. int output = 0;
  11. //Times the Koch Snowflake has progressed
  12. int timesran = startingn-n;
  13. //Amount of sides on the Koch Snowflake
  14. int sides = 3;
  15. //Number of bases for each traignle on each snowflake
  16. int s = 3;
  17.  
  18. //The loop runs x amount of times per progressions in the snowflake.
  19. for(int i = 1; i <= timesran; i++) {
  20.  
  21. //Calculating the area of each progression per triangle.
  22. if(i == 1) {
  23. output +=
  24. (Math.sqrt(3) * Math.pow(sides,2)) / 4;
  25. } else {
  26. sides = sides*4;
  27. output +=
  28. sides * ((Math.sqrt(3) * Math.pow((sides/s),2)) / 4);
  29. s = s*3;
  30. }
  31.  
  32. }
  33.  
  34. //Returning the total area.
  35. return output;
  36. }
  37.  
  38. public static void main(String[] args) {
  39. startingn = 5;
  40. double step = 1.0 / Math.pow(3.0, startingn);
  41. System.out.println(getArea(3));
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement