Constants Statement

Home • Gallery • Tutorials • Download • Purchase • Site Map
 

Constants Statement Syntax

The Fractal Science Kit fractal generator constants statement is 1 of the statements used in the properties section of the program instructions to define the program's Properties.

The constants statement is used to define a set of complex constants available to the program instructions. The format of the constants statement is:

constants [ <Name> ] {
  <Identifier> = <Expression>
  <Identifier> = <Expression>
  ...
}

<Name> and each <Identifier> must be a valid identifier. Each <Expression> must be a valid complex expression. The <Expression>  may use any of the defined options or enums. OptionArray statements may reference these constants.  Option definitions may not use these constants in their enabled expressions, however. Finally, the <Expression> must evaluate to a complex (non-object) value.

The name of the constant is <Name> followed by a period (.) and then the <Identifier>. <Name> is optional when you define the set of constants, and if it is not given, the name of each constant is simply the <Identifier>.

Example:

option Angle {
  type = Float
  caption = "Angle"
  details = "Angle of rotation"
  default = 0
  range = [-360,360]
}
constants {
  Rotation = Cis(DegreeToRadian(Angle))
}

This example defines a complex constant named Rotation that can be used to rotate a number. Remember that the value of the expression z*Cis(A) is equal to the point z rotated about the origin by A radians if A is a floating point number. Using this fact and the above definitions, we can rotate a point z by Angle degrees about the origin using the expression z*Rotation.

Example:

constants Math {
  TwoPI = 2 * Math.PI
  Cos0  = 1
  Cos30 = Sqrt(3)/2
  Cos45 = Sqrt(2)/2
  Cos60 = 0.5
  Cos90 = 0
  Sin0  = 0
  Sin30 = 0.5
  Sin45 = Sqrt(2)/2
  Sin60 = Sqrt(3)/2
  Sin90 = 1
}

This example creates several math related constants. These are accessed in your code as Math.TwoPI, Math.Cos0, etc.

 

Copyright © 2004-2017 Hilbert, LLC
All rights reserved