Значок ресурса

Turtle Graphics

Нет прав на скачивание
Автор: Ian M. Collier
Год: 1985
Издатели: Your Computer
Производитель: Your Computer
Языки: 🇬🇧 Английский
Формат: 📼 TZX лента
Требования: 🖥️ ZX Spectrum 16K

Ссылки:
Страница на ZXArt
Страница на World Of Spectrum
Страница на Spectrum Computing

Скриншоты:
turtlegd.png


turtlegd.png
Turtle





Ian Collier with a Logo graphics


program for the Spectrum.





This is an implementation of the turtle graphics part of


Logo, adapted into about 15 commands.


To set up the machine code the listing of data must be


entered and run. The data will be read and Poked in by the


Basic program.


After creating the graphics code it should be ready for


use at 30000. It may, however, need to be moved, for


example to a higher address in a 48K Spectrum. Having saved


the code with


SAVE "logo"CODE 30000,1600


the relocate program will move the code, first by loading


it in at the new address, if this has not already be done,


then changing the absolute addresses. A copy of the code at


30000 should be retained for the demonstration program.


Program 1 [which also expects the code to be at 30000]


allows you to use the turtle graphics without writing a


prgoram. It incorporates one loop using the control varia-


ble a, which can be set up. Commands are as follows:


DIR x - Points turtle in a direction x degrees


anticlockwise from horizontal right.


CIR x - Draws a circle around the turtle,


radius x pixels.


BOX x,y - Draws a box with two diagonally opposite


corners at the turtle and (x,y).


FOR x - Moves the turtle forward, leaving a trail.


BOR x - =BORDER x


FIL x,y,z - Fills in any enclosed area in ink z, starting


at (x,y). If filling starts at the edge of the


area, then it is possible that only half will


be filled, so aim for the middle.


POL x,y,z - Draws a polygon with x sides, moving first to


(x,y) and going anticlockwise.


INK x - Any further drawing will be in ink x; this only


lasts to the end of the line of instructions.


JUM x - Moves the turtle forward x pixels without


changing the screen (Jump).


ROT x - Rotates the turtle x degrees anticlockwise.


MOV x,y - Moves the turtle to (x,y).


PLO x,y - Moves the turtle to (x,y) and plots a pixel.


SCR x,y - Changes the screen colours to paper x and ink y


without erasing the patterns.


REP x - Marks the start of a set of instructions to be


repeated x times. Also sets up the Basic


variable Rep which is equal to the counter of


the innermost loop. Note Rep starts at x and


goes down to 1.


END - Marks the end of the repeated instructions.


The instructions can be in upper or lower case.


The prompt Instructions will appear and the instructions


must be typed in (I have printed out some examples [which


seem to have gone missing somewhere between author and


printer]). Then the prompt For a= will appear and you must


set up the loop as in Basic by typing three numbers fol-


lowed by Enter, e.g.





FOR a=1 TO 50 STEP 1





If a loop is not required, three 1s can be entered.


If a mistake has been entered in the instructions, the


program will stop with a report. Otherwise, the instruc-


tions will be carried out and you may then enter some more.


Each time a set of instructions is entered, the screen is


cleared and the turtle is moved to the centre of the screen


and pointed horizontally right.


To use the commands in a program they must be initia-


lised. If the code is still in its original position, this


is done by:





RANDOMIZE USR 30000





The syntax checker will now accept the new commands, but to


use the commands, they must be re-initialised if the pro-


gram has been altered. This is so that the new position of


the variables is recognised, and the new defined procedures


are found. The commands need to be initialised after Clear


and Run, as these reset the machine stack. If Interface 1


is connected, this adds complications. [He's not joking;


with the Interface 1 attached, the Demo won't even work


when loaded normally. One solution I've found is to _first_


use a Microdrive command, such as CAT 1 - there does not


have to be a Microdrive loaded, getting the error message


is OK - and only then to load the program.]


The new commands are regarded by the program as syntax


errors unless followed by a turtle graphics command, but


they work within a program. Also, when one of the new error


reports - e.g. Microdrive not present - is caused, this


resets the machine stack and the graphics commands need to


be re-initialised.


To enter the new commands, they must be placed inside


quotes, but at the end of a line, the final quotes may be


omitted. For use in a program, there is one more command -


Cal.


It calls instructions at the address given. If these in-


structions are in a string, the address of the instructions


needs to be found and the string needs to be prepared by


inserting the hidden floating point forms after the numbers


- these will not be hidden in a string and will appear as


question marks and other characters. This is done by the


routine at 31500 and is demonstrated in program one in


lines 145,9510.


New commands are like definable procedures. For an exam-


ple see the command .sta in the demo program. To define a


procedure, open quotes as usual and type a full stop fol-


lowed by the three-letter name, then a colon. The commands


following this will be executed every time the new command


is encountered. The end of the defined command is at the


first close quotes encountered in the definition, or at the


end of the line.





[ And now a bit about the TZX. This starts with the machine


code loader, followed by the code relocator. A note about


this last one: it does not check for overlaps, so you


can't relocate the code to anywhere between 30001 and


31599. This should not be a major limitation.


After these come first the Demo program, and then the one


which the article only ever refers to as "Program 1".


I've decided to call it "Shell", as it is, in essence, a


command shell for this system. These both auto-run to


load the machine code at 30000, which follows them on the


TZX, at that address. All these programs, by the way,


will run on the 16K Spectrum as well.





Finally, let's repair a lacuna in the article. The author


promised some samples for the shell program, but they got


lost along the way. Therefore, here are a few I've


adapted (i.e., nicked) from some other Logo implementa-


tions for the Spectrum. Where the values for FOR a are


relevant, I've given them; otherwise, just enter 1,1,1.





The basic (NPI) Logo demonstration: a square.


rep4:for40:rot90:end





mov80,60:rep8:for40:rot45:end:rot45:rep8:for96:rot135:end





This one demonstrates that loops can be nested. Even if


the value of the variable "rep" for the outer loop is


not available within the inner loop, the system does


remember correctly where it left off.


rep12:rot30:rep8:rot45:for20:end:end





A few spirals, using the loop facility:


fora:rot70 for a=3 to 100 step 1


An odd one, but still a spiral:


fora:rot177 for a=1 to 177 step 1


Another spiral, demonstrating that you can use expres-


sions as well as plain variables:


fora*2:rot123 for a=3 to 76 step 1


Note that these could just as well have been written to


use rep, in which case the loop is inside the string


rather than outside it. This does require a bit of


adaptation. For example:


rep177:for178-rep:rot177:end





mov100,0:pola,150,0 for a=3 to 11 step 1





Don't forget that it is also instructive to check how


the Demo program uses the various commands.





Richard Bos, april 2012 ]
Автор
Verter_bot
Загрузки
0
Просмотры
13
Расширение
zip
Размер
4.8 КБ
Хэш
b51c2bf828edd1e792ea921e3fc24704
Первый выпуск
Последнее обновление

Оценки

0.00 звезд(ы) 0 оценок
Назад
Вверх