Types (Studio)

Top  Previous  Next

 

 

In PixelScript, each variable must be explicitly declared to be of a given type.  Once a variable is declared, it can only hold values of that type.  For example, a real can only hold numbers, while a color can only hold colors.

 

 

 

real

 

Variables of this type can hold numbers with a fractional component (also known as floating-point values), such as 3.4, -21.782, or 2.0.  Floating-point values are very important in graphics programming, making real the most important number type.

 

 

real myReal = 10.0 / 4.0;

debug(myReal);

Outputs "2.5".

 

 

 

int

 

Variables of this type hold whole numbers only (values without a fractional component).  If a floating-point value is assigned to an int, the fractional component will be lost.

 

 

int myReal = 10 / 4;

debug(myReal);

 

Outputs "2" because ints don't store fractional components.

int myReal = 10.0 / 4.0;

debug(myReal);

 

Produces an error because floating-point values can't be stored directly to ints.

int myReal = (int)(10.0 / 4.0);

debug(myReal);

 

Outputs "2".  This notation "casts", or converts, the floating-point value into an int.

for (int i = 0; i < 3; i++)

{

  debug("Current value of i is " + i);

}

Because ints don't retain the fractional component of numbers, in PixelScript they are most commonly used as control variables for loops, where only whole numbers are needed.

 

 

 

color

 

Variables of this type hold colors.

 

 

result = color(0.3, 1.0, 0.6);

 

Creates an image with a green-blue color.  Specifically, the image will have a red component of 0.3, a green component of 1.0, and a blue component of 0.6.  If you would like the color to have an alpha component as well, supply a fourth number to the color function.

 

color myColor = color(0.3, 1.0, 0.6);

result = myColor;

 

A more long-winded way of achieving the same result.

 

color myColor = color(0.3, 1.0, 0.6);

myColor.R = 1.0;

result = myColor;

 

After being declared, the components of the color can be individually read and modified through R, G, B, and A components.

color myColor = color(0.3, 1.0, 0.6);

debug(myColor.Hue);

 

The hue, saturation, and brightness of a color can be read through its read-only Hue, Saturation, and Brightness components.

result.R = 0.2;

result.G = 0.4;

result.B = 0.6;

result.A = 0.8;

The special result variable is itself of type color, so it can be manipulated like any other color.

 

 

 

complex

 

Complex numbers are two-dimensional values with "real" and "imaginary" parts.  They are useful for creating fractals, which are usually represented by complex-number equations.

 

 

complex myComplex = complex(1, 2);

debug(myComplex);

 

Outputs "1 + 2i", a number with a real component of 1 and an imaginary component of 2.

debug(myComplex.Re);

 

Outputs "1", which is the real component of the complex number.

 

debug(myComplex.Im);

Outputs "2", which is the imaginary component of the complex number.

 

 

 

bool

 

Variables of type bool store true-false values, which are produced by comparisons or logic statements.

 

 

bool correct = 4 < 3;

 

if (correct)

  debug("The statement was correct!");

else

  debug("The statement was incorrect!");

Outputs "The statement was incorrect!".

 

 

Next, learn about the various functions and constants available in PixelScript.

 

 

 


Page URL: http://www.spiralgraphics.biz/genetica/help/index.htm?pixelscript_types.htm