generativedesign
Class GenerativeDesign

java.lang.Object
  extended by generativedesign.GenerativeDesign

public class GenerativeDesign
extends Object

This class collects static methods that are used in several sketches of the book. 'Static' means, that you don't need to create an instance of this class to use one of the methods. For example, if you want to print the version number of this library just type: println(GenerativeDesign.version());


Field Summary
static String ALPHA
          Constant to be used with the function sortColors.
static String BLUE
          Constant to be used with the function sortColors.
static String BRIGHTNESS
          Constant to be used with the function sortColors.
static String GRAYSCALE
          Constant to be used with the function sortColors.
static String GREEN
          Constant to be used with the function sortColors.
static int HTML_CONTENT
          Constant to be used as a mode with the class AsyncHTMLLoader.
static int HTML_PLAIN
          Constant to be used as a mode with the class AsyncHTMLLoader.
static String HUE
          Constant to be used with the function sortColors.
static String RED
          Constant to be used with the function sortColors.
static String SATURATION
          Constant to be used with the function sortColors.
static String VERSION
           
 
Constructor Summary
GenerativeDesign()
           
 
Method Summary
static float angleDifference(float theAngle1, float theAngle2)
          Calculates the minimal difference of two angles given in radians.
static float[] cartesianToPolar(float theX, float theY)
          Converts 2D cartesian coordinates to polar coordinates
static float[] cartesianToPolar(float theX, float theY, float theZ)
          Converts 3D cartesian coordinates to polar coordinates
static PVector cartesianToPolar(PVector theVector)
          Converts 3D cartesian coordinates to polar coordinates
static float[] HSBtoRGB(float theH, float theS, float theB)
          Converts a HSB color to RGB.
static ArrayList<String> loadHTMLAsync(PApplet theParent, String theURL)
          Loads a HTML-File asynchronously
static ArrayList<String> loadHTMLAsync(PApplet theParent, String theURL, int theMode)
          Loads a HTML-File asynchronously
static PImage loadImageAsync(PApplet theParent, String thePath)
          Loads an image file asynchronously
static XMLElement loadXMLAsync(PApplet theParent, String theURL)
          Loads a XML-File asynchronously.
static XML loadXMLAsync2(PApplet theParent, String theURL)
          Loads a XML-File asynchronously
static float[] polarToCartesian(float theLength, float theAngle)
          Converts 2D polar coordinates to cartesian coordinates
static float[] polarToCartesian(float theLength, float theAngleY, float theAngleZ)
          Converts 3D polar coordinates to cartesian coordinates
static PVector polarToCartesian(PVector theVector)
          Converts 3D polar coordinates to cartesian coordinates
static float[] RGBtoHSB(float theR, float theG, float theB)
          Converts a RGB color to HSB.
static void saveASE(PApplet theParent, int[] theColors, String theFileName)
          Exports an .ase (Adobe Swatch Echange) file with default names
static void saveASE(PApplet theParent, int[] theColors, String[] theNames, String theFileName)
          Exports an .ase (Adobe Swatch Echange) file
static int[] sortColors(PApplet theParent, int[] theColors, String theMethod)
          Sorts a list of colors
static String timestamp()
           
static void unsort(ArrayList<Object> theList)
          Takes an ArrayList and reorders the elements randomly.
static String version()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static String VERSION

RED

public static String RED
Constant to be used with the function sortColors.


GREEN

public static String GREEN
Constant to be used with the function sortColors.


BLUE

public static String BLUE
Constant to be used with the function sortColors.


HUE

public static String HUE
Constant to be used with the function sortColors.


SATURATION

public static String SATURATION
Constant to be used with the function sortColors.


BRIGHTNESS

public static String BRIGHTNESS
Constant to be used with the function sortColors.


GRAYSCALE

public static String GRAYSCALE
Constant to be used with the function sortColors.


ALPHA

public static String ALPHA
Constant to be used with the function sortColors.


HTML_PLAIN

public static int HTML_PLAIN
Constant to be used as a mode with the class AsyncHTMLLoader. Using the mode HTML_PLAIN will return the plain html code, including the header and all other tags.


HTML_CONTENT

public static int HTML_CONTENT
Constant to be used as a mode with the class AsyncHTMLLoader. Using the mode HTML_CONTENT will return just the text that is shown on the website.

Constructor Detail

GenerativeDesign

public GenerativeDesign()
Method Detail

version

public static String version()
Returns:
Actual version of the generativedesign library.

timestamp

public static String timestamp()
Returns:
String with the current date and time in the format YYMMDD_HHMMSS (year, month, day, hours, minutes, seconds)

RGBtoHSB

public static float[] RGBtoHSB(float theR,
                               float theG,
                               float theB)
Converts a RGB color to HSB. Uses the built in java function Color.RGBtoHSB for the conversions.

Parameters:
theR - Red value (0-255)
theG - Green value (0-255)
theB - Blue value (0-255)
Returns:
Array of three float values representing hue (0-366), saturation (0-100) and brightness (0-100)

HSBtoRGB

public static float[] HSBtoRGB(float theH,
                               float theS,
                               float theB)
Converts a HSB color to RGB. Uses the built in java function Color.HSBtoRGB for the conversions.

Parameters:
theH - Hue value (0-360)
theS - Saturation value (0-100)
theB - Brightness value (0-100)
Returns:
Array of three float values between 0-255 representing red, green and blue

sortColors

public static int[] sortColors(PApplet theParent,
                               int[] theColors,
                               String theMethod)
Sorts a list of colors

Parameters:
theParent - Reference to a PApplet. Typically use "this"
theColors - Array of colors to sort
theMethod - Sorting method: one of the constants RED, GREEN, BLUE, HUE, SATURATION, BRIGHTNESS, ALPHA, GRAYSCALE
Returns:
Sorted color array

saveASE

public static void saveASE(PApplet theParent,
                           int[] theColors,
                           String theFileName)
Exports an .ase (Adobe Swatch Echange) file with default names

Parameters:
theParent - Reference to a PApplet. Typically use "this"
theColors - color values (rgb 0-255) of the swatches
theFileName - filename of the .ase file

saveASE

public static void saveASE(PApplet theParent,
                           int[] theColors,
                           String[] theNames,
                           String theFileName)
Exports an .ase (Adobe Swatch Echange) file

Parameters:
theParent - Reference to a PApplet. Typically use "this"
theColors - color values (rgb 0-255) of the swatches
theNames - names of the swatches
theFileName - filename of the .ase file

loadImageAsync

public static PImage loadImageAsync(PApplet theParent,
                                    String thePath)
Loads an image file asynchronously

Parameters:
theParent - Reference to a PApplet. Typically use "this"
thePath - Path/filename to load
Returns:
Empty XMLElement in which the data is loaded

loadXMLAsync2

public static XML loadXMLAsync2(PApplet theParent,
                                String theURL)
Loads a XML-File asynchronously

Parameters:
theParent - Reference to a PApplet. Typically use "this"
theURL - URL or filename to load
Returns:
Empty XMLElement in which the data is loaded

loadXMLAsync

public static XMLElement loadXMLAsync(PApplet theParent,
                                      String theURL)
Loads a XML-File asynchronously. This function is using the old (before processing 2.0) XMLElement, because we wanted the library to still work with processing 1.X.

Parameters:
theParent - Reference to a PApplet. Typically use "this"
theURL - URL or filename to load
Returns:
Empty XMLElement in which the data is loaded

loadHTMLAsync

public static ArrayList<String> loadHTMLAsync(PApplet theParent,
                                              String theURL)
Loads a HTML-File asynchronously

Parameters:
theParent - Reference to a PApplet. Typically use "this"
theURL - URL or filename to load
Returns:
Empty String array in which the data is loaded

loadHTMLAsync

public static ArrayList<String> loadHTMLAsync(PApplet theParent,
                                              String theURL,
                                              int theMode)
Loads a HTML-File asynchronously

Parameters:
theParent - Reference to a PApplet. Typically use "this"
theURL - URL or filename to load
theMode - The mode for the text that will be returned. Either HTML_PLAIN (plain html code with all tags) or HTML_CONTENT (just the text that is shown on the website)
Returns:
Empty String array in which the data is loaded

angleDifference

public static float angleDifference(float theAngle1,
                                    float theAngle2)
Calculates the minimal difference of two angles given in radians.

Parameters:
theAngle1 - Angle to subtract from
theAngle2 - Angle to subtract
Returns:
Angle between -PI and PI (-180 deg and 180 deg)

cartesianToPolar

public static float[] cartesianToPolar(float theX,
                                       float theY)
Converts 2D cartesian coordinates to polar coordinates

Parameters:
theX - X-coordinate
theY - Y-coordinate
Returns:
Array containing 'length' and 'angle', so that rotating a point (length, 0) around the origin with angle relults in point (theX, theY)

cartesianToPolar

public static float[] cartesianToPolar(float theX,
                                       float theY,
                                       float theZ)
Converts 3D cartesian coordinates to polar coordinates

Parameters:
theX - X-coordinate
theY - Y-coordinate
theZ - Z-coordinate
Returns:
Array containing 'length', 'angleY' and 'angleZ', so that rotating a point (length, 0, 0) first around the y-axis with angleY and then around the z-axis with angleZ results in point (theX, theY, theZ)

cartesianToPolar

public static PVector cartesianToPolar(PVector theVector)
Converts 3D cartesian coordinates to polar coordinates

Parameters:
theVector - vector to convert
Returns:
Vector containing 'length', 'angleY' and 'angleZ', so that rotating a point (length, 0, 0) first around the y-axis with angleY and then around the z-axis with angleZ results in point (theX, theY, theZ)

polarToCartesian

public static float[] polarToCartesian(float theLength,
                                       float theAngle)
Converts 2D polar coordinates to cartesian coordinates

Parameters:
theLength - Distance of the point to the origin
theAngle - Angle
Returns:
Array containing 'x' and 'y'

polarToCartesian

public static float[] polarToCartesian(float theLength,
                                       float theAngleY,
                                       float theAngleZ)
Converts 3D polar coordinates to cartesian coordinates

Parameters:
theLength - Distance of the point to the origin
theAngleY - Angle for rotation around y-axis
theAngleZ - Angle for rotation around z-axis
Returns:
Array containing 'x', 'y' and 'z'

polarToCartesian

public static PVector polarToCartesian(PVector theVector)
Converts 3D polar coordinates to cartesian coordinates

Parameters:
theVector - Vector containing (length, angleY, angleZ), where 'length' is distance of the point to the origin, 'angleY' is the angle for rotation around y-axis and 'angleZ' is the angle for rotation around z-axis
Returns:
PVector

unsort

public static void unsort(ArrayList<Object> theList)
Takes an ArrayList and reorders the elements randomly.

Parameters:
theList - ArrayList to unsort


Processing library GenerativeDesign by Benedikt Gross, Hartmut Bohnacker. (C) 2009