MXL Magazine Online
HOMELATEST ISSUEARTICLESBINARY BINGEJAVA JNUKYGUI LABLINKSSHOPABOUT CONTACT  
Home > Issue 003 > Coding Showdown > Draw your weapon

Draw your weapon

Requirements: .Chris Module Studio

Wow, finally I get a title that fits in with the column title. Now we really have got a show down. However away from shooting the hell out of each other this months column looks at how to draw shapes, create shapes, etc. I'll also be using the blank move technique that I discussed in my last article, "pick a point." You might want to read up on that first.

Below is the code you should start with and we will expand of it from their:

10 Screen 7
20 CLS
30 DRAW = "
(code goes here)"

1) What you should always do

The first thing you would always do when drawing in a graphic is set the point of origin. This as i metioned earlier is a blank move ("BM") which is fllowed by the co-ordinates. If your working in screen 7 you will have about 320 wide by 180 height so lets start with something simple

30 DRAW "C9 BM100,100"

To draw graphics you place all the instructions inside speech marks after the word draw. I have also added C9 at the start of the draw instructions to tell it to draw the line in blue. This is actually a light blue. For more information on color in screen 7 see Color under C in the .Chris Module Studio Refrence section.

2) Drawing the graghics

Now you can begin to add different lines, etc. There are two ways to do this:

A. Using the standard commands which are listed under refrence in the .Chris Module Studio section. These are keys such as up, down, left right, eg:

U10 R10 D10 L10

This would draw a simple square.

B. Using the move command. Think about it. If BM makes a blank move, removing the B must produce a move where it does draw a line. For instance, if you wanted to draw a horizontal line you could use the following:

DRAW "C9 BM100,100 M200,100"

This would make a blank move to the co-ordinates 100,100 and then move across 100 pixles to 200,100.

There are different reasons for using each one. Personally I almost aways use the first one as if say I draw a square and I want to move it futher accross the screen, all I need to do is alter the BM I used as the point of origin and the whole thing moves rather than me having to change every co-ordinate by using the second method.

However the second method is a lot easier to understand as it tells you the exact co-orindate it is going to so you can easily match it up with the co-ordinate you want it to arrive at. No more working it out with a calculator.

Conclusion

The method you use for drawing graphics is down to your personal prefrence and what you need it for. If you know where you want to go it can save a lot of messing about by using M. However it can sometimes be far easier to use the tried and tested method of using the standard single letter commands followed by the value.

If your looking for extra refrence on drawing in .Chris Module Studio then you might want to check out Dot Chris Development > Dot Chris Module Studio > Documenation > Graphics (in the Worfolk Developers Library if your not already there). There you can find an introduction to drawing graghics and a sample application that draws graphics. Plus for refrence of what does what check out D under Dot Chris Module Studio Refrence.