IPTSCRAE SCRIPTING LESSON THREE
Picasso Revisited - Painting Guide

Painting is one of the most popular entertainments on Palace. The routines produce results that are seen by everyone in the room, and many of them are quite clever. However, although these routines are fun, they can also be annoying. Drawing on the screen can lag other users because they must wait for their screens to update. Keep your drawing routines to a minimum, and use routines that paint a limited number of lines. If your routine is excessive, you will see "Tone down the drawing" messages and may even be logged off the server for flooding!

On the Canvas
The basis of every drawing routine is a line. There are two basic line-drawing commands.

<startX> <startY> <endX> <endY> LINE
This command draws a line from point <startX> <startY> to point <endX> <endY>. The line is drawn in the current PENSIZE and PENCOLOR. When the line has finished drawing, the pen is positioned at the ending coordinates.

<X> <Y> LINETO
This command draws a line from the current position of the pen to the <X> <Y> coordinates. The line is drawn in the current PENSIZE and PENCOLOR. To draw up or to the left, use negative numbers. When the line has finished drawing, the pen is positioned at the ending coordinates:

/-10 -10 LINETO

draws up and to the left 10 pixels, while

/10 10 LINETO

draws down and to the right 10 pixels. (If you try these commands, one right after the other, you may not be able to see the results because the two lines will be on top of each other. You will need to reposition your pen between the commands to see anything meaningful.)

These two commands are the basis of ALL drawing routines. They are the only two commands that actually produce visible results on the screen. All of the other painting commands set up the state of the pen for these commands.

If you are getting confused with X and Y, try thinking of it this way: The X coordinate is the horizontal position. The Y coordinate is the vertical position. The X can be thought of as the screen's "column" and the Y as the screen's "row". (If you've used a spreadsheet, these terms should be familiar.)

Also, remember: Position arguments in Iptscrae are always in X-Y order. If your results are not what you expected, double-check that you have your arguments in the proper order.

Location, Location, Location
Before you begin drawing, you need to place your pen in the correct starting position. The way to do this is with the command:

<X> <Y> PENPOS
This command positions your pen to the <X> <Y> coordinates without drawing anything on the screen. For instance:

/WHOME WHOPOS POSX 10 + POSY 10 + LINE
/WHOME WHOPOS PENPOS -100 -50 LINETO

The first command draws a line from you down and to the right 10 pixels (though you probably won't see it unless your AV is transparent in the middle, or unless it is drawing on top of you), but the pen's position is left at the end of the line. The PENPOS command in the second line resets back to you before drawing the second line with LINETO.

During a routine, you may want to move your pen to a new position, but without drawing anything on the screen. The command to do this is:

<X> <Y> PENTO
No, it's not a new game. :) The PENTO command simply sets your pen's position relative to the current pen position. PENPOS requires you to give the position in absolute terms, but this uses the type of relative move that LINETO does. If you want to use a LINETO to adjust your position without leaving that line, use PENTO instead. Just like the LINETO command, you use negative numbers to move up or left.

Art Supplies
Before drawing a line, a variety of commands are used to set up the attributes of your pen. If these are not done before your line commands, the settings will be whatever was last used.

PENFRONT and PENBACK
These commands are complimentary, and they work the same way as the button in your paint menu when you do it manually. If you're not sure which button I mean, open it up. The icon shows a guest- green ball- with a brick wall bisecting him. Click on it, and he disappears behind the wall. Click on him again, and he is in front of the wall. This is what the paint does to people's avatars. If the wall is in front of him, your paint will be on top of their AVs. (It is never in front of their name, though that may disappear momentarily until it is automatically redisplayed). Use PENFRONT to do that in a script. Use PENBACK to make your lines go behind their avatar. PENBACK is the default.

<number> PENSIZE
This command sets the size of the lines drawn to <number> pixels. Legal values are 1 to 8. You can draw much thicker lines than that with the client's paint menu, but I've never had any success in scripts with numbers larger than 8. If anyone does, let me know.

The ends of your lines are square. (This is an important concept! Especially if you are trying to place lines "inside" of each other!) So, if you say:

/3 PENSIZE

You will set the ENDs of the lines to a 3-pixel square. When you are drawing a line larger than one pixel in size, the beginning coordinates will be the upper left of the beginning square, and the ending coordinates will be the upper left of the ending square.

<red> <green> <blue> PENCOLOR
This one changes the color you are drawing, using three numbers for the red, green, and blue values. The numbers can be from 0 to 255. Mix and match for what you want, here are some examples:

255 255 255 white
0 0 0 black
0 0 128 medium/dark blue
255 255 0 bright yellow
128 0 128 medium purple

Yes, Red and Green make yellow in this scheme.

Experiment with this to get an idea of what to expect from different combinations. Note that the Palace uses a 256 color palette, and that this method theoretically allows 256 * 256 * 256 colors. It doesn't, really. The nearest color in the 256-color palette to what you describe is what will be used. (Ok, only 236 colors of the 256-color palette are used. So sue me. Or better yet, sue Jim Bumgardner, or whoever thought that not using 20 colors was a good idea. :)

Janitorial Services
Now that you've scribbled all over the screen, and you can't see what you're doing any more, let's talk about the commands that ERASE what you've drawn. Remembering to clean up after yourself is an important attribute of Proper Palace Etiquette!

PAINTUNDO
This command is the same as pressing the 'dynamite trigger box' in the paint menu. It erases the last line you draw. Saying PAINTUNDO "x" number of times erases the last "x" number of lines you drew. It takes as long to do a PAINTUNDO as it did to draw the original line. Lag is bad enough without that. Try the next command instead:

PAINTCLEAR
This one command cleans off all painting on the screen. This will usually suffice for your needs, since most routines draw a figure that is then erased. Of course, a lot of them don't bother erasing anything, in which case you might want to do it manually by saying:

/PAINTCLEAR

(If you have your original cyborg.ipt, saying 'clean' will achieve the same results, except that it clears off all loose props, too. If you take a look at the script, you will see that it uses the PAINTCLEAR command.)

The Calculating User
(Note: If you do not understand the stack in Iptscrae, go back and review the beginning of Lesson 1 before you read this.)
As you recall, in Lesson 1 we talked about the stack, and the way mathematical computations are performed. Basically, two values are placed on the stack, and then the mathematical operator ("+" in the example) was used to take them off the stack, add them together and place the results back on the stack. In the end, THE RESULT is what is now on the stack. There are 5 basic mathematical operators in Iptscrae:

<numberA> <numberB> +
Adds the two numbers and pushes the result onto the stack. When done correctly, the following example will cause you to "say" the number 8:

/3 5 + ITOA SAY

<numberA> <numberB> -
Subtracts <numberB> from <numberA> and pushes the result onto the stack. For example:

/6 2 - ITOA SAY

will cause you to "say" the number 4. It IS possible to subtract a large value from a smaller one. The result will be a negative number. For example:

/2 6 - ITOA SAY

will cause you to "say" the number -4.

<numberA> <numberB> *
This symbol is the asterisk, or "star". It multiplies the two numbers and pushes the result onto the stack. The following example will cause you to "say" the number 6:

/3 2 * ITOA SAY

<numberA> <numberB> /
Divides <numberA> by <numberB> and pushes the result onto the stack. Only the integer portion is put on the stack. Any remainder is discarded. For example:

/25 5 / ITOA SAY

will cause you to "say" the number 5.

Because the remainder is discarded:

/235 10 / ITOA SAY

will cause you to "say" the number 23. In Iptscrae, dividing 0 by a number will return 0. Dividing a valid number by 0 will also return 0. It will not produce an error.

<numberA> <numberB> %
Divides <numberA> by <numberB> and puts the remainder (modulo) onto the stack. The following example will cause you to "say" the number 3:

/23 5 % ITOA SAY

Using the addition and subtraction techniques along with the painting commands, you will be able to draw just about anything that can be done. For example:

/POSX 50 - POSY 40 + WHOME WHOPOS LINE

will draw a line to you from a position 50 pixels to the left and 40 pixels down.

You give it the data:

POSX (your horizontal position)
-50, the offset value to the location you want to start at

and then tell it to subtract the second value from the first. This pushes the desired <startX> for the LINE command on the stack.

You describe the <startY> argument by saying: POSY 40 +.

WHOME WHOPOS pushes two more values, your current horizontal and vertical position, onto the stack.

Now, you have your 4 arguments (<startX> <startY> <endX> <endY>) placed on the stack, which the LINE command needs to operate.

At this point, I can't stress experimentation enough. This is a programming language- and just like any language, the best way to learn it is to use it. Play with the commands, try new things, and find what limits are there- and what aren't.

HOMEWORK:
1. Make a routine that will draw a thin green line around the outside of your avatar area when you say "square". Remember that avatars are 132 by 132 pixels, and that your position is the middle of that area.

2. Make a routine that will draw six lines that are 8 pixels wide. The lines are to be drawn from the left side of the screen to the right, and are to start at your row and work down. The colors, from top to bottom are: purple, blue, green, yellow, orange, and red. The routine is run when you say "rainbow".

3. Make a routine that will draw four lines to you- one from each corner of the screen. Make them any size and color. The routine is run when you say "diagonal".

4. Copy the zap routine, and change it so that the line is drawn from the person you are whispering to to your mouse position, not from you. The routine is run when you say "zapspoof". (Note that this won't fool anti-zap routines, but it should look interesting.)

5. Make a routine that will draw a red line through the person you are whispering to. Use the commands to make it look like it comes in the front, and goes out the back, and put an arrow point on the end. The routine is run when you say "cupid".

6. Make a routine that draws a line from the bottom center of the screen to you, regardless of where you are standing on the screen. Use multiple commands so that it is a thick red line which then gets bright yellow in the middle. This routine is run when you say "laser".

CHALLENGE:
Write a routine that draws a circle.

NOTES:
Your screen size is 512 pixels wide and 383 pixels high. 0,0 is the upper left corner. (Remember, you start counting with 0... NOT 1!)

Use a room, like the Iptscrae Classroom to test your drawing routines. You may not be able to see what's going on if the background of the room is a complex or dark picture. If you don't see visible results on the screen, move your AV to another location. It is possible that you are "sitting" on your results.

To be sure that a combination of multiple lines (such as the "laser" routine above) is properly coordinated, try them at different screen positions. Something that looks like it is working when you are centered on the screen, may NOT be correct when you stand in the upper left corner, or on the extreme right side of the screen.

If you run into any problems with homework assignment #6, there is a tutorial on the Class Information page. Go back to that page and select the "Speical Java Demo". Please note: this tutorial is a Java applet. You're browser must be able to handle Java applets for this to work!

<Previous> <Iptscrae> <Next>