Forth Hints & Tips: Kaleidoscope
Posted: Mon Mar 04, 2024 11:40 pm
In the old days, some magazines had a tips section where interesting little programs were presented for the reader to type on their computer. Under this influence and aiming to demystify Forth a little, I open this topic with small fragments of code in Forth for the reader to type on their ZX81, rescuing a little of the spirit of that time.
I invite all forth enthusiasts to also contribute in order to enrich the topic.
Programs can target Toddy Forth-79, FIF Forth and also Husband Forth (H4TH).
I just ask that you maintain the following standard in your posts:
- When replying with your contribution edit the subject in this format:
Forth hints & Tips: title
- In the body of the message, specify the Forth variant for which it is intended:
Forth variant: TF79 / FIF / H4TH
So let's go to the first entry, a program originally in BASIC published in the magazine Sinclair Programs nr. 5 and converted to TF79:
Forth variant: TF79
Two versions are presented: the first passes the arguments via values/variables; the second only uses the stack to pass the arguments.
After the picture is finished, use the "C" key to continue and any other key to end the program.
I invite all forth enthusiasts to also contribute in order to enrich the topic.
Programs can target Toddy Forth-79, FIF Forth and also Husband Forth (H4TH).
I just ask that you maintain the following standard in your posts:
- When replying with your contribution edit the subject in this format:
Forth hints & Tips: title
- In the body of the message, specify the Forth variant for which it is intended:
Forth variant: TF79 / FIF / H4TH
So let's go to the first entry, a program originally in BASIC published in the magazine Sinclair Programs nr. 5 and converted to TF79:
Forth variant: TF79
Two versions are presented: the first passes the arguments via values/variables; the second only uses the stack to pass the arguments.
Code: Select all
\ KALEIDOSCOPE
VALUE H VALUE V
VALUE RH VALUE RV
: KALEIDOSCOPE
BEGIN PAGE
250 RND 200 + 1 DO
24 RND TO V 32 RND TO H
23 24 V - + TO RV
31 32 H - + TO RH
H V 1 PLOT
RH V 1 PLOT
RH RV 1 PLOT
H RV 1 PLOT
LOOP KEY ASCII C = NOT
UNTIL ;
Code: Select all
\ KALEIDOSCOPE
: KALEIDOSCOPE
BEGIN PAGE
250 RND 200 + 1 DO
32 RND 24 RND
OVER 32 SWAP - 31 +
OVER 24 SWAP - 23 +
2OVER 1 PLOT
2DUP 1 PLOT
-ROT SWAP 1 PLOT
1 PLOT
LOOP KEY ASCII C = NOT
UNTIL ;
After the picture is finished, use the "C" key to continue and any other key to end the program.