Spirals Sample
Description
This sample illustrates the usage of some common Phantom
language functions and procedures. The script opens the
PhantomTarget application and draws a series of spirals
in the drawing dialog. At the end, it captures and saves
a bitmap of the drawing area. Some of the Phantom features
used are:
- Mouse Functions
- Math Functions
- User Functions
- Loops
- Window Size Functions
To use this sample, simply copy and paste
it into a new script and save it where the PhantomTarget application
is located.
[ Back to Samples
]
Spirals |
# Spirals.psc
# This is a sample script that draws
spirals in the
# PhantomTarget application. It
is intended as a fun
# example of what Phantom can do.
# The function to draw the spiral
# x_ctr is the x center of the spiral
(pixel)
# y_ctr is the y center of the spiral
(pixel)
function void
DrawSpiral(real x_ctr, real
y_ctr){
# Click at the outer-edge
of the spiral. The fourth parameter is
# '1', so the button
is pressed, but not released.
Drawing.Static9.MouseClick(0, int(r+x_ctr),
int(y_ctr), 1);
real R = r; #
Copy the global spiral radius to a local value
real T = 0.0; #
This is the angle of spiral rotation
real x; #
A holder for the current x-position of the pen
real y; #
A holder for the current y-position of the pen
# While the radius is
> 10 pixels, loop the spiral
while(R > 10){
R = R - dr; #
Decrease the spiral radius by the global dr
x = R*cos(T); #
Compute the x position of the pen
y = R*sin(T); #
Compute the y position of the pen
T = T + dtheta; #
Increment the spiral angle
x = x + x_ctr + 0.5;
# Add the spiral center x-coordinate
+ 0.5 for rounding
y = y + y_ctr + 0.5;
# Add the spiral center y-coordinate
+ 0.5 for rounding
# Move the
mouse to the new point in the spiral. Since
the mouse
# button
is 'held' down, this will draw a line to the new point.
Drawing.Static9.MouseMove(int(x),
int(y));
}
# The spiral drawing
is finished, so release the mouse button
Drawing.Static9.MouseClick(0, int(x), int(y),
2);
}
# This function sets the pen color
for drawing
function void
SetPen(int R, int
G, int B, int
S){
# Edit1 is the red (R)
pen color
Drawing.Edit1.SetText(string(R));
# Edit2 is the green
(G) pen color
Drawing.Edit2.SetText(string(G));
# Edit3 is the blue
(B) pen color
Drawing.Edit3.SetText(string(B));
# Edit7 is the pen pixel
width
Drawing.Edit7.SetText(string(S));
# Apply the new values
Drawing._Set.Click();
}
######## The Main Script #############################
# Include Phantom Target Declarations
use "PhantomTarget.dec";
# Start Phantom Target
System("..\\PhantomTarget.exe");
# Open the drawing window
PhantomTarget._Controls._Drawing.Select();
# Declare globals
# Compute the spiral radius as ~1/2
the drawing window height
real r = Drawing.Static9.GetWindowHeight()/2
- 5;
# Set the delta radius for each
spiral step
real dr = 0.2;
# Compute the default center-x position
as 1/2 the drawing window width
real XX = Drawing.Static9.GetWindowWidth()/2;
# Compute the default center-y position
as 1/2 the drawing window height
real YY = Drawing.Static9.GetWindowHeight()/2;
# Set the angle between spiral steps
to 5 degrees
real dtheta = 5.0*3.14159/180.0;
# Set the default pen size (2 pixels)
int PenSize = 2;
# Reduce the automatic delay for
fast drawing
SetDelay(0);
# Draw the spirals
SetPen(255, 0, 0, PenSize); #
Set the pen to red
DrawSpiral(XX + 90, YY);
# Draw a spiral to the right of
center
SetPen(255, 0, 255, PenSize); #
Set the pen to magenta
DrawSpiral(XX - 90, YY);
# Draw a spiral to the left of center
SetPen(0, 255, 0, PenSize); #
Set the pen to green
DrawSpiral(XX + 60, YY);
# Draw a spiral to the right of
center
SetPen(0, 255, 255, PenSize); #
Set the pen to cyan
DrawSpiral(XX - 60, YY);
# Draw a spiral to the left of center
SetPen(0, 0, 255, PenSize); #
Set the pen to blue
DrawSpiral(XX + 30, YY);
# Draw a spiral to the right of
center
SetPen(255, 255, 0, PenSize); #
Set the pen to yellow
DrawSpiral(XX - 30, YY);
# Draw a spiral to the left of center
SetPen(0, 0, 0, PenSize); #
Set the pen to black
DrawSpiral(XX, YY); #
Draw a spiral at the center
# Capture and save the drawing as
a bitmap
bitmap b = Drawing.Static9.CaptureBitmap();
b.Save("spiral.bmp");
# Un-comment this to close PhantomTarget
#PhantomTarget.Close();
|
|
Copyright
© 2000-2009 Phantom Automated Solutions, Inc.
[ Home ] [ Contact
] [ Privacy Policy ] [System
Requirements]
|