net.returnvoid.graphics.grid

## Class SpiralGrid

- java.lang.Object
- - net.returnvoid.graphics.grid.SpiralGrid

- All Implemented Interfaces:
    RGrid

      public class SpiralGrid
      extends java.lang.Object
      implements RGrid

  This class helps to build an spiral grid. The elements of this grid will be located on a spiral with a given start and end radius. The elements will be distributed not visually evenly. This means, the elements will be closer to each other in the center of the spiral than the ones at the bounds.
  Author:
    Diana Lange

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SpiralGrid(float x, float y, float angleSteps, float startAngle, float rotations, java.lang.Integer dir, float startRadius, float endRadius)` Builds a new grid.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.Float` | `elementSize(java.lang.Integer index)` Calculates and returns the size of an element of the grid.
    `java.lang.Float` | `getAngle(java.lang.Integer index)` Returns the angle of an element with the given index.
    `java.lang.Float` | `getAngleSteps()` Returns the angle distance for each element.
    `processing.core.PVector[]` | `getCoordinates()` Returns all positions of all elements in the grid.
    `java.lang.Float` | `getEndRadius()` Returns the radius which describes the position of the last element of this grid.
    `java.lang.Float` | `getHeight()` Returns the current height of the grid.
    `java.lang.Float` | `getHeight(java.lang.Integer i)` Returns the current height of the grid.
    `java.lang.Float` | `getPadding()` Returns the space between the elements of the grid.
    `java.lang.Float` | `getRadius(java.lang.Integer index)` Returns the the radius (= distance from center) of an element with the given index.
    `java.lang.Integer` | `getRotationDirection()` Returns the direction of rotation for this grid. 1=clockwise, -1=anti-clockwise.
    `java.lang.Float` | `getRotations()` Returns the number of rotations of this spiral.
    `java.lang.Float` | `getStartAngle()` Returns the angle that describes the position of the first element of this grid.
    `java.lang.Float` | `getStartRadius()` Returns the radius which describes the position of the first element of this grid.
    `java.lang.Float` | `getWidth()` Returns the width of the element at the given index.
    `java.lang.Float` | `getWidth(java.lang.Integer i)` Returns the current width of the grid.
    `java.lang.Float` | `getX()` Returns the current x-position of the grid.
    `java.lang.Float` | `getX(java.lang.Integer index)` Returns the x-position of the element at the given index.
    `java.lang.Float` | `getY()` Returns the current y-position of the grid.
    `java.lang.Float` | `getY(java.lang.Integer index)` Returns the y-position of the element at the given index.
    `SpiralGrid` | `setAngleSteps(float radians)` Sets the angle distance between each element (in radians).
    `SpiralGrid` | `setAngleStepsDeg(float degrees)` Sets the angle distance between each element (in degrees).
    `SpiralGrid` | `setEndRadius(float r)` Sets the radius where the spiral ends.
    `SpiralGrid` | `setPadding(float padding)` Sets the padding (space between elements of the grid).
    `SpiralGrid` | `setRotationDirection(java.lang.Integer dir)` Sets the direction of the rotation.
    `SpiralGrid` | `setRotations(float r)` Sets the number of rotations the spiral should make.
    `SpiralGrid` | `setSize(java.lang.Integer size)` Sets the number of elements which will be placed on the grid.
    `SpiralGrid` | `setStartAngle(float radians)` Set the position of the first element of the grid.
    `SpiralGrid` | `setStartAngleDeg(float degrees)` Set the position of the first element of the grid.
    `SpiralGrid` | `setStartRadius(float r)` Sets the radius where the spiral starts.
    `SpiralGrid` | `setX(float x)` Set to x-position of the grid.
    `SpiralGrid` | `setY(float y)` Set to y-position of the grid.
    `java.lang.Integer` | `size()` Returns the number of elements in the grid.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SpiralGrid

          public SpiralGrid(float x,
                            float y,
                            float angleSteps,
                            float startAngle,
                            float rotations,
                            java.lang.Integer dir,
                            float startRadius,
                            float endRadius)

      Builds a new grid. Please provide reasonable value for each parameter or use the GridMaker.
      Parameters:
        `x` - The center x-location of this grid.
        `y` - The center y-location of this grid.
        `angleSteps` - The angle distance for each element (in radians).
        `startAngle` - The angle where the grid starts (in radians). The startAngle defines where the first element will positioned.
        `rotations` - The number of rotations of this spiral.
        `dir` - The direction of the rotation of the spiral. For dir=1 the spiral will rotate clockwise, for dir -1 anti-clockwise.
        `startRadius` - The radius where the spiral starts.
        `endRadius` - The radius where the spiral ends.

  - ### Method Detail

    - #### setRotations

          public SpiralGrid setRotations(float r)

      Sets the number of rotations the spiral should make. If you want to set up the number of elements for this grid, you have to call setSize() after this.
      Parameters:
        `r` - The number of rotations (>= 0.01)
      Returns:
        The current grid object.

    - #### setStartAngle

          public SpiralGrid setStartAngle(float radians)

      Set the position of the first element of the grid.
      Parameters:
        `radians` - The angle which describes the position of the first element (in radian).
      Returns:
        The current grid object.

    - #### setStartAngleDeg

          public SpiralGrid setStartAngleDeg(float degrees)

      Set the position of the first element of the grid.
      Parameters:
        `degrees` - The angle which describes the position of the first element (in degrees).
      Returns:
        The current grid object.

    - #### setRotationDirection

          public SpiralGrid setRotationDirection(java.lang.Integer dir)

      Sets the direction of the rotation.
      Parameters:
        `dir` - Clockwise for dir >= 0, anti-clockwise for dir < 0.
      Returns:
        The current grid object.

    - #### setAngleSteps

          public SpiralGrid setAngleSteps(float radians)

      Sets the angle distance between each element (in radians).
      Parameters:
        `radians` - The angle.
      Returns:
        The current grid object.

    - #### setAngleStepsDeg

          public SpiralGrid setAngleStepsDeg(float degrees)

      Sets the angle distance between each element (in degrees).
      Parameters:
        `degrees` - The angle.
      Returns:
        The current grid object.

    - #### setX

          public SpiralGrid setX(float x)

      Description copied from interface: `RGrid`
      Set to x-position of the grid.
      Specified by:
        `setX` in interface `RGrid`
      Parameters:
        `x` - The new x-position of the grid.
      Returns:
        The current grid object.

    - #### setY

          public SpiralGrid setY(float y)

      Description copied from interface: `RGrid`
      Set to y-position of the grid.
      Specified by:
        `setY` in interface `RGrid`
      Parameters:
        `y` - The new y-position of the grid.
      Returns:
        The current grid object.

    - #### setEndRadius

          public SpiralGrid setEndRadius(float r)

      Sets the radius where the spiral ends. The last element of this grid will be positioned on that radius.
      Parameters:
        `r` - The ending radius.
      Returns:
        The grid object.

    - #### setStartRadius

          public SpiralGrid setStartRadius(float r)

      Sets the radius where the spiral starts. The first element of this grid will be positioned on that radius.
      Parameters:
        `r` - The starting radius.
      Returns:
        The grid object.

    - #### setSize

          public SpiralGrid setSize(java.lang.Integer size)

      Sets the number of elements which will be placed on the grid. This function should be called after the number of rotations is set.
      Parameters:
        `size` - The number of elements for this grid.
      Returns:
        The current grid object.

    - #### setPadding

          public SpiralGrid setPadding(float padding)

      Sets the padding (space between elements of the grid).
      Specified by:
        `setPadding` in interface `RGrid`
      Parameters:
        `padding` - The new padding of this grid (percentage based on elementSize(Integer)) [0, 1].
      Returns:
        The current grid object.

    - #### getCoordinates

          public processing.core.PVector[] getCoordinates()

      Description copied from interface: `RGrid`
      Returns all positions of all elements in the grid.
      Specified by:
        `getCoordinates` in interface `RGrid`
      Returns:
        The positions.

    - #### size

          public java.lang.Integer size()

      Description copied from interface: `RGrid`
      Returns the number of elements in the grid. This is usefull if you want to iterate over all elements of the grid. Example:

           for (int i = 0; i < myGrid.size(); i++) {
                          float x = myGrid.getX(i);
                          float y = myGrid.getY(i):
           }

      Specified by:
        `size` in interface `RGrid`
      Returns:
        The number of elements of the grid.

    - #### getRotations

          public java.lang.Float getRotations()

      Returns the number of rotations of this spiral.
      Returns:
        The number of rotations.

    - #### getStartAngle

          public java.lang.Float getStartAngle()

      Returns the angle that describes the position of the first element of this grid.
      Returns:
        The angle.

    - #### getRotationDirection

          public java.lang.Integer getRotationDirection()

      Returns the direction of rotation for this grid. 1=clockwise, -1=anti-clockwise.
      Returns:
        The direction of rotation.

    - #### getAngleSteps

          public java.lang.Float getAngleSteps()

      Returns the angle distance for each element.
      Returns:
        The angle (in radians).

    - #### getX

          public java.lang.Float getX()

      Description copied from interface: `RGrid`
      Returns the current x-position of the grid.
      Specified by:
        `getX` in interface `RGrid`
      Returns:
        The x-position.

    - #### getY

          public java.lang.Float getY()

      Description copied from interface: `RGrid`
      Returns the current y-position of the grid.
      Specified by:
        `getY` in interface `RGrid`
      Returns:
        The y-position.

    - #### getWidth

          public java.lang.Float getWidth()

      Description copied from interface: `RGrid`
      Returns the width of the element at the given index.
      Specified by:
        `getWidth` in interface `RGrid`
      Returns:
        The width.

    - #### getHeight

          public java.lang.Float getHeight()

      Description copied from interface: `RGrid`
      Returns the current height of the grid.
      Specified by:
        `getHeight` in interface `RGrid`
      Returns:
        The height.

    - #### getEndRadius

          public java.lang.Float getEndRadius()

      Returns the radius which describes the position of the last element of this grid.
      Returns:
        The ending radius.

    - #### getStartRadius

          public java.lang.Float getStartRadius()

      Returns the radius which describes the position of the first element of this grid.
      Returns:
        The starting radius.

    - #### getAngle

          public java.lang.Float getAngle(java.lang.Integer index)

      Returns the angle of an element with the given index.
      Parameters:
        `index` - The index of the element [0, size()]
      Returns:
        The angle the element with that index.

    - #### getRadius

          public java.lang.Float getRadius(java.lang.Integer index)

      Returns the the radius (= distance from center) of an element with the given index.
      Parameters:
        `index` - The index of the element [0, size()]
      Returns:
        The distance to the center of the element with that index.

    - #### getX

          public java.lang.Float getX(java.lang.Integer index)

      Description copied from interface: `RGrid`
      Returns the x-position of the element at the given index. index should be in the range of this grid [0, myGrid.size()], otherwise the call of this function might produce strange results or will produce an ArrayIndexOutOfBoundsException. Usage:

           for (int i = 0; i < myGrid.size(); i++) {
                          float x = myGrid.getX(i);
                          float y = myGrid.getY(i):
           }

      Specified by:
        `getX` in interface `RGrid`
      Parameters:
        `index` - The index of the element.
      Returns:
        The x-position of the element.

    - #### getY

          public java.lang.Float getY(java.lang.Integer index)

      Description copied from interface: `RGrid`
      Returns the y-position of the element at the given index. index should be in the range of this grid [0, myGrid.size()], otherwise the call of this function might produce strange results or will produce an ArrayIndexOutOfBoundsException. Usage:

           for (int i = 0; i < myGrid.size(); i++) {
                          float x = myGrid.getX(i);
                          float y = myGrid.getY(i):
           }

      Specified by:
        `getY` in interface `RGrid`
      Parameters:
        `index` - The index of the element.
      Returns:
        The y-position of the element.

    - #### getPadding

          public java.lang.Float getPadding()

      Returns the space between the elements of the grid.
      Specified by:
        `getPadding` in interface `RGrid`
      Returns:
        The padding.

    - #### elementSize

          public java.lang.Float elementSize(java.lang.Integer index)

      Calculates and returns the size of an element of the grid. The size equals to the distance of the element to its neighbors.
      Parameters:
        `index` - The index of the element [0, size()]
      Returns:
        The size of the element at the given index.

    - #### getWidth

          public java.lang.Float getWidth(java.lang.Integer i)

      Description copied from interface: `RGrid`
      Returns the current width of the grid.
      Specified by:
        `getWidth` in interface `RGrid`
      Parameters:
        `i` - The index of the element.
      Returns:
        The width.

    - #### getHeight

          public java.lang.Float getHeight(java.lang.Integer i)

      Description copied from interface: `RGrid`
      Returns the current height of the grid.
      Specified by:
        `getHeight` in interface `RGrid`
      Parameters:
        `i` - The index of the element.
      Returns:
        The height.