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.






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;


Outputs "2.5".






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;



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

int myReal = 10.0 / 4.0;



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

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



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.






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);



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 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);



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



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



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






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!");


  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