Package net.paulhertz.pixelaudio

# Class Argosy

java.lang.Object
net.paulhertz.pixelaudio.Argosy

public class Argosy extends Object

Author:
  Paul Hertz

  Argosy provides tools for shifting pixel patterns along the signal path of an image. One way to generate the pixel patterns is with the Lindenmayer class. The patterns are generated by arrays of numbers ("argosy patterns") and arrays of colors, with a gap in between each repeated pattern. The patterns could also be interpreted as rhythmic values in music, and the colors as timbre or instrumentation. Both music and visual patterns can be generated by a Lindenmayer pattern or "L-system."

  The Argosy class create pixel patterns ordered by the signal path of a PixelAudioMapper. Argosy patterns consist of an array of numbers (argosyArray), an array of colors (argosyColors), a gap between patterns (unitSize * argosyGapScale) and a color for the gap (argosyGapColor). Each number in the pattern array determines the length of a run of pixels in a color specified by the color array. The Argosy pattern maker steps through the pattern, scaling it by unitSize, and assigns it the current color in the argosyColors, which it also steps through. The arrays do not have to be the same size.

  TODO implement pixel offset TODO interpolating version of Argosy patterns, with floating point pattern values TODO dynamic functional version of patterns and other parameters TODO perhaps filling should permit one less gap than repetitions of pattern -- the first and last pattern will abut more precisely, we should provide conditions for partial filling (but not in version 1).

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `(package private) float`
  `animStepDivisor`
  subunit divisor for animStep
  `static final int[]`
  `argosy55`
  `(package private) int[]`
  `argosyArray`
  Array of color values used for animation by rotating the array left or right
  `(package private) int[]`
  `argosyColors`
  default colors for argosy units
  `(package private) int`
  `argosyGap`
  number of pixels in the gap between argosy patterns
  `(package private) int`
  `argosyGapColor`
  color of pixels in the gap
  `(package private) float`
  `argosyGapScale`
  scaling for number of units in gap between argosies
  `(package private) int[]`
  `argosyIntervals`
  array of number of pixels in each element of the expanded argosy pattern
  `(package private) int`
  `argosyMargin`
  margin on either side of the argosy patterns
  `(package private) int`
  `argosyOffset`
  pixel count by which to shift the argosy pixels at initialization
  `(package private) int[]`
  `argosyPattern`
  current pattern to fill bigArray
  `(package private) int`
  `argosyPixelShift`
  the number of pixels the array has shifted from its initial state
  `(package private) int`
  `argosyReps`
  how many times to repeat the pattern, 0 to fill array
  `(package private) int`
  `argosyShiftStep`
  count the number of unit shifts
  `(package private) int`
  `argosySize`
  sum of values in argosy pattern
  `(package private) int`
  `argosyStep`
  number of pixels in a shiftLeft animation Step
  `(package private) int`
  `argosyUnitSize`
  the number of pixels in an argosy unit
  `(package private) int`
  `bgColor`
  background color, fills the argosy array before colors are added
  `(package private) boolean`
  `isCentered`
  center the argosy patterns in the big array
  `(package private) boolean`
  `isCountShift`
  do we count the shift or not?
  `(package private) PixelAudioMapper`
  `mapper`
  PixelAudioMapper that provides values for several variables and maps bigArray to bitmaps or audio signals
  `(package private) int`
  `maxReps`
  maximum number of repetitions, used internally

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Argosy(PixelAudioMapper mapper, int[] pattern, int unitSize, int reps, boolean isCentered, int[] colors, int gap, int gapColor, int animStep)`
  `Argosy(PixelAudioMapper mapper, int unitSize, int reps, boolean isCentered)`
  `Argosy(PixelAudioMapper mapper, int unitSize, int reps, boolean isCentered, int[] colors, int gapColor, float gapScale, int[] pattern)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `argosyFill()`
  Fills `argosyArray` with colors from argosyColors following the argosy pattern stored in argosyIntervals.
  `static ArrayList<String>`
  `fibo(int depth, boolean verbose)`
  An L-System generator for Fibonacci trees represented as a sequence of 0s and 1s.
  `static int[]`
  `fibonacciPattern(int depth, int v1, int v2, boolean verbose)`
  Generates an argosy pattern based on a Fibonacci tree.
  `float`
  `getAnimStepDivisor()`
  `int[]`
  `getArgosyArray()`
  `int[]`
  `getArgosyArrayCopy()`
  `int[]`
  `getArgosyColors()`
  `int`
  `getArgosyGap()`
  `int`
  `getArgosyGapColor()`
  `float`
  `getArgosyGapScale()`
  `int`
  `getArgosyMargin()`
  `int`
  `getArgosyOffset()`
  `int[]`
  `getArgosyPattern()`
  `int`
  `getArgosyPixelShift()`
  `int`
  `getArgosyReps()`
  `float[]`
  `getArgosySignal()`
  `float[]`
  `getArgosySignal(float scale)`
  `float[]`
  `getArgosySignal(PixelAudioMapper.ChannelNames chan)`
  `float[]`
  `getArgosySignal(PixelAudioMapper.ChannelNames chan, float scale)`
  `int`
  `getArgosySize()`
  `int`
  `getArgosyStep()`
  `int`
  `getBgColor()`
  `PixelAudioMapper`
  `getMapper()`
  `int`
  `getMaxReps()`
  `int`
  `getUnitSize()`
  `void`
  `initArgosy()`
  Sets up the argosy array and fills it with colors using the argosy pattern.
  `private void`
  `reverseArray(int[] arr, int l, int r)`
  Reverses an arbitrary subset of an array.
  `void`
  `rotateLeft(int d)`
  Rotates bigArray left by d values.
  `void`
  `setAnimStepDivisor(float animStepDivisor)`
  `void`
  `setArgosyArray(int[] newArgosyArray)`
  `void`
  `setArgosyColors(int[] argosyColors)`
  Sets new argosyColors and triggers a call to initArgosy() to reset the pattern in argosyArray.
  `void`
  `setArgosyGap(int argosyGap)`
  Sets argosyGap and triggers a call to initArgosy() to reset the pattern in argosyArray.
  `void`
  `setArgosyGapColor(int argosyGapColor)`
  Sets argosyGapColor and triggers a call to argosyFill() to reset the pattern in bigArray.
  `void`
  `setArgosyGapScale(float argosyGapScale)`
  Sets argosyGapScale and triggers a call to initArgosy() to reset the pattern in argosyArray.
  `void`
  `setArgosyOffset(int argosyOffset)`
  `void`
  `setArgosyPattern(int[] pattern)`
  Sets a new argosy pattern and triggers a call to argosyFill() to reset the pattern in bigArray.
  `void`
  `setArgosyPixelShift(int newShift)`
  `void`
  `setArgosyReps(int newReps)`
  `void`
  `setArgosyStep(int argoStep)`
  Set the animStep, with no side effects (but animation calls will use the new value)
  `void`
  `setBgColor(int bgColor)`
  `void`
  `setNewColors(int[] argosyColors, int argosyGapColor)`
  Sets new argosy colors and argosy gap color, triggers a call to argosyFill().
  `void`
  `setUnitSize(int unitSize)`
  Sets unitSize and triggers a call to initArgosy() to reset the pattern in argosyArray.
  `void`
  `shift(int pixelShift, boolean isCounted)`
  Shifts left by a specified number of pixels, summing them to argosyPixelShift if isCounted is true.
  `void`
  `shiftLeft()`
  basic animation, rotate left by animStep pixels, increment the step counter argosyShiftStep
  `void`
  `shiftRight()`
  basic animation, rotate right by animStep pixels, decrement the step counter argosyShiftStep
  `void`
  `zeroArgosyPixelShift()`

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

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

- ## Field Details

  - ### mapper

    PixelAudioMapper mapper
    PixelAudioMapper that provides values for several variables and maps bigArray to bitmaps or audio signals

  - ### argosyArray

    int[] argosyArray
    Array of color values used for animation by rotating the array left or right

  - ### argosyUnitSize

    int argosyUnitSize
    the number of pixels in an argosy unit

  - ### argosyStep

    int argosyStep
    number of pixels in a shiftLeft animation Step

  - ### animStepDivisor

    float animStepDivisor
    subunit divisor for animStep

  - ### bgColor

    int bgColor
    background color, fills the argosy array before colors are added

  - ### argosyColors

    int[] argosyColors
    default colors for argosy units

  - ### argosyGapScale

    float argosyGapScale
    scaling for number of units in gap between argosies

  - ### argosyGap

    int argosyGap
    number of pixels in the gap between argosy patterns

  - ### argosyGapColor

    int argosyGapColor
    color of pixels in the gap

  - ### argosyReps

    int argosyReps
    how many times to repeat the pattern, 0 to fill array

  - ### maxReps

    int maxReps
    maximum number of repetitions, used internally

  - ### argosyMargin

    int argosyMargin
    margin on either side of the argosy patterns

  - ### argosyPattern

    int[] argosyPattern
    current pattern to fill bigArray

  - ### argosySize

    int argosySize
    sum of values in argosy pattern

  - ### isCentered

    boolean isCentered
    center the argosy patterns in the big array

  - ### argosyIntervals

    int[] argosyIntervals
    array of number of pixels in each element of the expanded argosy pattern

  - ### argosyPixelShift

    int argosyPixelShift
    the number of pixels the array has shifted from its initial state

  - ### isCountShift

    boolean isCountShift
    do we count the shift or not?

  - ### argosyShiftStep

    int argosyShiftStep
    count the number of unit shifts

  - ### argosyOffset

    int argosyOffset
    pixel count by which to shift the argosy pixels at initialization

  - ### argosy55

    public static final int[] argosy55

- ## Constructor Details

  - ### Argosy

    public Argosy(PixelAudioMapper mapper, int unitSize, int reps, boolean isCentered)
    Parameters:
      `mapper` - PixelAudioMapper
      `unitSize` - size of a unit of the argosy -- powers of 2 or 4 are a good fit for the Hilbert PixelMapGen
      `reps` - number of repetitions of the argosy pattern, pass in 0 for maximum that fit
      `isCentered` - true if argosy array should be centered in bigArray

  - ### Argosy

    public Argosy(PixelAudioMapper mapper, int unitSize, int reps, boolean isCentered, int[] colors, int gapColor, float gapScale, int[] pattern)
    Parameters:
      `mapper` - PixelAudioMapper
      `unitSize` - size of a unit of the argosy
      `reps` - number of repetitions of the argosy pattern, pass in 0 for maximum that fit
      `isCentered` - true if argosy array should be centered in bigArray
      `colors` - an array of colors for the argosy patterns
      `gapColor` - a color for the spaces between argosy patterns
      `gapScale` - scaling for number of units in gap between argosies
      `pattern` - a pattern of numbers, will be copied to argosyPattern

  - ### Argosy

    public Argosy(PixelAudioMapper mapper, int[] pattern, int unitSize, int reps, boolean isCentered, int[] colors, int gap, int gapColor, int animStep)
    Parameters:
      `mapper` - PixelAudioMapper
      `pattern` - a pattern of numbers, will be copied to argosyPattern
      `unitSize` - size of a unit of the argosy
      `reps` - number of repetitions of the argosy pattern, pass in 0 for maximum that fit
      `isCentered` - true if argosy array should be centered in bigArray
      `colors` - an array of colors for the argosy patterns
      `gap` - number of pixels in gap between pattern repeats (argosyGapScale * argosyUnitSize)
      `gapColor` - a color for the spaces between argosy patterns
      `animStep` - number of pixels on each animation step, when calling shiftLeft() or shiftRight()

- ## Method Details

  - ### initArgosy

    public void initArgosy()
    Sets up the argosy array and fills it with colors using the argosy pattern.

  - ### argosyFill

    public void argosyFill()
    Fills `argosyArray` with colors from argosyColors following the argosy pattern stored in argosyIntervals. Tbis method is generally called from initArgosy(), which fills argosyArray with the bgColor pixels.

  - ### rotateLeft

    public void rotateLeft(int d)
    Rotates bigArray left by d values. Uses efficient "Three Rotation" algorithm.
    Parameters:
      `d` - number of elements to shift

  - ### reverseArray

    private void reverseArray(int[] arr, int l, int r)
    Reverses an arbitrary subset of an array.
    Parameters:
      `arr` - array to modify
      `l` - left bound of subset to reverse
      `r` - right bound of subset to reverse

  - ### shiftRight

    public void shiftRight()
    basic animation, rotate right by animStep pixels, decrement the step counter argosyShiftStep

  - ### shiftLeft

    public void shiftLeft()
    basic animation, rotate left by animStep pixels, increment the step counter argosyShiftStep

  - ### getArgosyPixelShift

    public int getArgosyPixelShift()
    Returns:
      the argosyPixelShift, save this if you want to reshift

  - ### setArgosyPixelShift

    public void setArgosyPixelShift(int newShift)

  - ### zeroArgosyPixelShift

    public void zeroArgosyPixelShift()

  - ### shift

    public void shift(int pixelShift, boolean isCounted)
    Shifts left by a specified number of pixels, summing them to argosyPixelShift if isCounted is true. This is the most flexible animation method with animation steps set externally. The other methods, shiftLeft() and shiftRight(), use this.animStep to determine pixel shift.
    Parameters:
      `pixelShift` -
      `isCounted` -

  - ### getArgosyArray

    public int[] getArgosyArray()
    Returns:
      argosyArray, not a copy

  - ### getArgosyArrayCopy

    public int[] getArgosyArrayCopy()
    Returns:
      a copy of argosyArray

  - ### setArgosyArray

    public void setArgosyArray(int[] newArgosyArray)
    Parameters:
      `newArgosyArray` - the int[] array to set, must be same length as this.argosyArray.

  - ### getArgosySignal

    public float[] getArgosySignal()

  - ### getArgosySignal

    public float[] getArgosySignal(PixelAudioMapper.ChannelNames chan)

  - ### getArgosySignal

    public float[] getArgosySignal(float scale)

  - ### getArgosySignal

    public float[] getArgosySignal(PixelAudioMapper.ChannelNames chan, float scale)

  - ### getArgosySize

    public int getArgosySize()
    Returns:
      argosySize, the number of argsoyUnits in argosyPattern

  - ### getUnitSize

    public int getUnitSize()
    Returns:
      the unitSize

  - ### setUnitSize

    public void setUnitSize(int unitSize)
    Sets unitSize and triggers a call to initArgosy() to reset the pattern in argosyArray.
    Parameters:
      `unitSize` - the new unitSize

  - ### getArgosyStep

    public int getArgosyStep()
    Returns:
      the animStep, number of pixels to shift in an animation

  - ### setArgosyStep

    public void setArgosyStep(int argoStep)
    Set the animStep, with no side effects (but animation calls will use the new value)
    Parameters:
      `argoStep` -

  - ### getArgosyColors

    public int[] getArgosyColors()
    Returns:
      the array of colors for the argosy pattern elements

  - ### setArgosyColors

    public void setArgosyColors(int[] argosyColors)
    Sets new argosyColors and triggers a call to initArgosy() to reset the pattern in argosyArray.
    Parameters:
      `argosyColors` -

  - ### getArgosyGapScale

    public float getArgosyGapScale()
    Returns:
      the argosyGapScale

  - ### setArgosyGapScale

    public void setArgosyGapScale(float argosyGapScale)
    Sets argosyGapScale and triggers a call to initArgosy() to reset the pattern in argosyArray.
    Parameters:
      `argosyGapScale` -

  - ### getArgosyGap

    public int getArgosyGap()
    Returns:
      the argosyGap, number of pixels between iterations of the argosy pattern

  - ### setArgosyGap

    public void setArgosyGap(int argosyGap)
    Sets argosyGap and triggers a call to initArgosy() to reset the pattern in argosyArray. Usually it's better to set the argosyGapScale, but if you want a gap that isn't a multiple of unitSize, this is the way to do it.
    Parameters:
      `argosyGap` -

  - ### getArgosyGapColor

    public int getArgosyGapColor()
    Returns:
      the argosyGapColor

  - ### setArgosyGapColor

    public void setArgosyGapColor(int argosyGapColor)
    Sets argosyGapColor and triggers a call to argosyFill() to reset the pattern in bigArray.
    Parameters:
      `argosyGapColor` -

  - ### getArgosyReps

    public int getArgosyReps()
    Returns:
      argosyReps, the number of repetitions of the argosy pattern in the array, set by argosyFill().

  - ### setArgosyReps

    public void setArgosyReps(int newReps)

  - ### getMapper

    public PixelAudioMapper getMapper()
    Returns:
      the PixelAudioMapper associated with this Argosy

  - ### getArgosyMargin

    public int getArgosyMargin()
    Returns:
      argosyMargin, the left and right margin to argosy patterns in the array, set by argosyFill().

  - ### getArgosyOffset

    public int getArgosyOffset()

  - ### setArgosyOffset

    public void setArgosyOffset(int argosyOffset)

  - ### getMaxReps

    public int getMaxReps()

  - ### getArgosyPattern

    public int[] getArgosyPattern()
    Returns:
      the argosyPattern, an array with a numeric pattern.

  - ### setArgosyPattern

    public void setArgosyPattern(int[] pattern)
    Sets a new argosy pattern and triggers a call to argosyFill() to reset the pattern in bigArray.
    Parameters:
      `pattern` -

  - ### setNewColors

    public void setNewColors(int[] argosyColors, int argosyGapColor)
    Sets new argosy colors and argosy gap color, triggers a call to argosyFill().
    Parameters:
      `argosyColors` -
      `argosyGapColor` -

  - ### getAnimStepDivisor

    public float getAnimStepDivisor()

  - ### setAnimStepDivisor

    public void setAnimStepDivisor(float animStepDivisor)

  - ### getBgColor

    public int getBgColor()

  - ### setBgColor

    public void setBgColor(int bgColor)

  - ### fibo

    public static ArrayList<String> fibo(int depth, boolean verbose)
    An L-System generator for Fibonacci trees represented as a sequence of 0s and 1s. There are two generation rules: 0 -> 1; 1 -> 01. The initial state is 0.
    Parameters:
      `depth` - depth of iteration of the L-System. A depth of 8 gets you an ArrayList with 34 elements.
      `verbose` - Keep me informed. Or not.
    Returns:
      an ArrayList of String values "1" and "0".

  - ### fibonacciPattern

    public static int[] fibonacciPattern(int depth, int v1, int v2, boolean verbose)
    Generates an argosy pattern based on a Fibonacci tree. Depth 8 gets you a 34 element sequence, and so Fibonacci forth. For example: int[] testPattern = argosyGen(8, 5, 8, true);
    Parameters:
      `depth` - depth of iteration of the L-System. A depth of 8 gets you an array with 34 elements.
      `v1` - value to substitute for a "0" in the ArrayList returned by fibo()
      `v2` - value to substitute for a "1" in the ArrayList return by fibo()
      `verbose` - if true, tells the console what's up
    Returns:
      an array of ints determined by a Fibonacci tree generator and your inputs v1 and v2