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://commons.wikimedia.org/wiki/File:Turtle_Graphics_Spiral.svg 013*/ 014public class SpiralTurtle extends Turtle 015{ 016 /** 017 @param model a reference to the {@link Model} that this {@code Turtle} is builing 018 @param n number of spirals 019 */ 020 public SpiralTurtle(final Model model, final int n) 021 { 022 this(model, n, 0.0, 0.0, 0.0); 023 } 024 025 026 /** 027 @param model a reference to the {@link Model} that this {@code Turtle} is builing 028 @param n number of spirals 029 @param xPos the intial x-coordinate for this {@link Turtle} 030 @param yPos the intial y-coordinate for this {@link Turtle} 031 */ 032 public SpiralTurtle(final Model model, final int n, 033 final double xPos, final double yPos) 034 { 035 this(model, n, xPos, yPos, 0.0); 036 } 037 038 039 /** 040 @param model a reference to the {@link Model} that this {@code Turtle} is builing 041 @param n number of spirals 042 @param xPos the intial x-coordinate for this {@link Turtle} 043 @param yPos the intial y-coordinate for this {@link Turtle} 044 @param z the z-plane for this {@code Turtle} 045 */ 046 public SpiralTurtle(final Model model, final int n, 047 final double xPos, final double yPos, double z) 048 { 049 super(model, xPos, yPos, z); 050 spiral(n); 051 } 052 053 054 private void spiral(final int n) 055 { 056 for (int i = 0; i < n; ++i) 057 { 058 forward( 1.0 - ((double)i/(double)n) ); 059 turn(121); 060 } 061 } 062 063}//NinjaTurtle