QUICK Tutorial Part 3 - By Dean Garraghty
(c)1994 Dean Garraghty
Quick is still available from us: www.dgs.clara.net
Last time we looked at string handling and ARRAYs. This time we will
look at some simple graphics programming.
Producing graphics in QUICK is just as simple as it is in Basic. In
fact it is easier in QUICK because of QUICK's built-in advanced
techniques, such as the very useful Blitter, which will be demonstrated
later in this tutorial.
QUICK contains all the graphics commands found in Basic, along with
quite a few more. The commands are nearly the same as in Basic, except
that the syntax is usually slightly different to fit in with QUICK's
way of doing things. Most commands are already available, but some have
to be INCLUDEd in from the GRAPH.LIB library.
Let's jump straight in and look at some simple code in Basic and QUICK:
Basic QUICK
5 GRAPHICS 8 MAIN
7 COLOR 1 CLOSE(6)
10 PLOT 5,5 OPEN(6,28,8,"S:")
20 DRAWTO 20,20 COLOR(1)
30 DRAWTO 10,100 POS(5,5)
40 DRAWTO 150,0 DRAW(20,20)
DRAW(10,100)
DRAW(150,0)
ENDMAIN
The Basic program should be quite obvious. We simply change to graphics
mode 8, set the colour register to 1 (so that we can actually see
something happen!), plot a point at 5,5, and then draw some lines to
various parts of the screen. Not the most stunning of programs! The
QUICK program is very similar. There is one major difference here
between Basic and QUICK. In Basic you can simply change the graphics
mode with the GRAPHICS command. In QUICK it isn't quite as easy. This
is because QUICK's GRAPHICS command is not actually part of the QUICK
language. It is, however, available in the GRAPH.LIB library. Normally
we would have to INCLUDE this library and use the command from there.
But, we only need one command from it, and in order to speed things up
and to save memory, I have simply done it the way that the library
would do it. All we need to do is to open the screen as channel 6, with
some parameters to tell the computer which mode we want. The 28 and 8
were simply calculated by going through the code for GRAPHICS in the
library file, and working out the numbers from there. You don't have to
worry where the 28 and 8 come from. So, this line in the QUICK code
effectively changes to mode 8. We CLOSE the channel before OPENing it
again as another graphics mode. When you write some graphics programs
of your own, you may find it easier to just use the GRAPHICS function
in the library file.
You should now know how to actually get some graphics on the screen.
Now I'll show you how to move parts of the screen around using Blitter!
This isn't as hard as it sounds, and you should have no problems using
it yourself! For this example I will only give an example in QUICK,
because these features go way beyond anything Basic can handle! In this
example, I will show you how to draw a set of concentric circles using
the CIRCLE function found in GRAPH.LIB, then how to "cut" it out into
memory, and then how to "paste" it back on the screen in a number of
positions. This is made trivial by the built-in commands CUT and PASTE.
Here's the program:
INCLUDE
[
D1:GRAPH.LIB
]
BYTE
[
R
]
MAIN
.GRAPHICS(24) ;GRAPHICS 8+16 FOR NO TEXT WINDOW
COLOR(1) ;SO WE CAN SEE SOMETHING HAPPEN!
R=1 ;FIRST RADIUS HAS VALUE 1
REPEAT
.CIRCLE(100,50,R) ;DRAW LOTS OF CIRCLES WITH SAME CENTRE
ADD(R,3,R) ;ADD 3 TO VALUE OF R (RADIUS)
UNTIL R=40
CUT(60,10,140,90,30000) ;CUT OUT OUR CIRCLES
PASTE(0,150,100,30000) ;PASTE CIRCLES BACK TO VARIOUS
PASTE(0,150,0,30000) ;PARTS OF THE SCREEN
PASTE(0,20,100,30000)
ENDMAIN
I have put some comments in the program to give you some idea as to
what each line is doing. When you type in the program, you can miss out
all the comments (everything after the ;) if you want to. Also, you can
change the INCLUDE to be D8:GRAPH.LIB if you have a RAMdisk and first
copy the GRAPH.LIB file to it. The best way to do this is to load the
LIB file from the editor. Select save (control S), and then do SHIFT 8.
Then just press return and it's copied! Having the LIB file in the
RAMdisk will speed up compilation enormously!
Now let's break the program down and look at each bit in turn. This
time we are using more facilities offered by GRAPH.LIB so we may as
well use the GRAPHICS function. In this case we set the mode to 24,
which is mode 8 with no text window. Next we set the colour register to
1 so that we can actually see something happen! I have set up a BYTE
variable R, which will be used to hold the radius. This first gets set
to 1. Now we draw a series of concentric circles from a point 100,50.
It will first do this with a radius of 1, which will draw a tiny circle
in the middle. The next line adds 3 to the value of R. Here we are
saying add 3 to R and put the result back in R. The equivalent Basic
code would be R=R+3. So, the next circle will have a radius of 4, the
next 7, then 10 and so on. I have used a REPEAT...UNTIL loop which
stops when R gets to 40.
Now the fun bit comes! The next line cuts out a section of the screen
and copies it into memory. CUT only works by cutting out a rectangular
section of the screen, so I have chosen 60,10 for the upper left of the
section to cut, and 140,90 for the lower right point. I chose these
numbers to represent the maximum and minimum X,Y points with the
maximum radius of 40. Don't worry if you can't work this out! We have
to give CUT a memory address where it can start storing the part of the
screen we have cut. Decimal 30000 is usually a safe bet. Next we PASTE
the cut part of the screen to three other parts of the screen by just
giving an upper-left X,Y point to paste back to, along with the memory
address where we have it stored. The first number (0) simply means copy
as normal. A 1 would do an OR-mode copy. Check page 19 of the QUICK
manual for details of this.
This article should have given you some idea of how to produce graphics
in QUICK. Next time I'll be back with more, but I'm not sure what
exactly!
Originally published in The Atari 8-bit News-Paper.
Click here to Return to the Articles Main Menu