001/*
002 * Renderer Models. The MIT License.
003 * Copyright (c) 2022 rlkraft@pnw.edu
004 * See LICENSE for details.
005*/
006
007package renderer.models_L.turtlegraphics;
008
009import renderer.scene.Model;
010
011/**
012   https://www.clear.rice.edu/comp360/lectures/fall2008/TurtleFractalsL2New.pdf#page=6
013*/
014public class PolygasketTurtle extends Turtle
015{
016   /**
017      @param model  a reference to the {@link Model} that this {@code Turtle} is builing
018      @param n      number of sides in the N-gon
019      @param m      number of levels for the Polygasket
020   */
021   public PolygasketTurtle(final Model model, final int n, final int m)
022   {
023      this(model, n, m, 0.0, 0.0, 0.0);
024   }
025
026
027   /**
028      @param model  a reference to the {@link Model} that this {@code Turtle} is builing
029      @param n      number of sides in the N-gon
030      @param m      number of levels for the Polygasket
031      @param xPos   the intial x-coordinate for this {@link Turtle}
032      @param yPos   the intial y-coordinate for this {@link Turtle}
033   */
034   public PolygasketTurtle(final Model model, final int n, final int m,
035                           final double xPos, final double yPos)
036   {
037      this(model, n, m, xPos, yPos, 0.0);
038   }
039
040
041   /**
042      @param model  a reference to the {@link Model} that this {@code Turtle} is builing
043      @param n      number of sides in the N-gon
044      @param m      number of levels for the Polygasket
045      @param xPos   the intial x-coordinate for this {@link Turtle}
046      @param yPos   the intial y-coordinate for this {@link Turtle}
047      @param z      the z-plane for this {@code Turtle}
048   */
049   public PolygasketTurtle(final Model model, final int n, final int m,
050                           final double xPos, final double yPos, final double z)
051   {
052      super(model, xPos, yPos, z);
053      polygasket(n, m);
054   }
055
056
057   private void polygasket(final int n, final int level)
058   {
059      if (0 == level)
060      {
061         // draw a N-gon
062         for (int i = 0; i < n; ++i)
063         {
064            forward(1);
065            turn(360.0/n);
066         }
067      }
068      else
069      {
070         for (int i = 0; i < n; ++i)
071         {
072            resize(0.5);
073            polygasket(n, level - 1);
074            resize(2.0);
075            move(1);
076            turn(360.0/n);
077         }
078      }
079   }
080
081}//PolygasketTurtle