///////////////////////////////////////////////////////////////////// // (c) Gatan Inc. ///////////////////////////////////////////////////////////////////// // This scripts generates an image using the "sin" function. // In addition, use of the icol and irow intrinsic variables are demonstrated. // Finally, the image is displayed using the temperature color look-up table. ////////////////////////////////////////////////////////////////////// // last modified 08-July-2014 BS (comments only) // Create constants to define the x and y size (in pixels) of the generated image number sizeX = 400, sizeY = 400 // Create the 2D image sinePattern, of data type Real 4-byte // with dimensions sizeX by sizeY and title "Sine pattern" image sinePattern := RealImage("Sine Pattern", 4, sizeX, sizeY) // Define the values of the constants spacingX and spacingY, // whose purpose will be clear in the next step // Also, set a value for pi number spacingX = sizeX/2., spacingY = sizeY/2. number pi = 3.1415926 // Now, create the sine pattern using the function below // The intrinsic variables icol and irow are extremely useful. // They take on context specific values // icol refers to the image column number (for N columns this ranges from 0 to N-1) // and irow refers to the image row number. Hence one can use icol and irow as running // "X" and "Y" variable in an equation. // Use of these varaibles avoids use of FOR loops, and, as a result of the way // DM performs calculations, image size operations can be performed far more efficiently this way sinePattern = sin( 2*pi*(icol/spacingX + irow/spacingY) ) * sin(pi*icol/sizeX) * sin(pi*irow/sizeY) // Set the color mode to use when displaying the image // The possible values for mode are 1=greyscale, 3=rainbow, 4=temperature. // Note the use of dot notation - the expression could also be written as // SetColorMode( SinePattern, 4 ) SinePattern.SetColorMode( 4 ) //Finally, display the image 'SinePattern' ShowImage(SinePattern) /* Note the use of the := operator when creating the image. This operator denotes that the image 'sinePattern' refers implicitly to the image created on the right hand side of the expression. If the = operator had been used, SinePattern would have been a copy of the defined image. As a result, the image title information would have been lost and the image would have been displayed as "Untitled". */