Help! My QL has entered the Matrix !!!

A place to discuss general QL issues.
User avatar
tofro
Font of All Knowledge
Posts: 2688
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Help! My QL has entered the Matrix !!!

Post by tofro »

pjw wrote:I guess I could do with some cheering up having just watched the fourth instalment of the Matrix trilogy :?
Ok, it wasnt that bad, but nothing like the first lot. Perhaps a second viewing will do it better justice.

One thing became obvious: None of my programs look as good as the real thing! But then again, if it had been important I might have tried harder. For this exercise, a cursory nod in that direction will have to suffice. And for my amusement, doing it in as few instructions as possible seemed like a nice challenge. So heres the latest, 142 bytes:

Code: Select all

x=scr_xlim:y=scr_ylim:window x,y,0,0:cls:g%=x/12-1:open#1;scr:rep:window 10,y,rnd(g%)*12,0:scroll s:if rnd(1):bput#1;rnd(31,99):s=5:else:s=15
No refinements or sophistication. EX to start, CTRL 5 to pause, <BREAK> followed by QUIT to quit. SBASIC only.
Per,

runs nicely on QDOS/MGG/suqlx when you add an initialization to s before usage and some loop names.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Help! My QL has entered the Matrix !!!

Post by pjw »

tofro wrote:<>
Per,
runs nicely on QDOS/MGG/suqlx when you add an initialization to s before usage and some loop names.
Great! I suppose you need a line number as well and then LRUN it? Or can one just DO it?
Anyway, I found a way to shave off two more bytes: Just sack the %s in g%!


Per
dont be happy. worry
- ?
Tinyfpga
Gold Card
Posts: 252
Joined: Thu Sep 27, 2018 1:59 am

Re: Help! My QL has entered the Matrix !!!

Post by Tinyfpga »

I managed to compile pjw's last posted Matrix!!! code on my system as follows:-

x=scr_xlim:y=scr_ylim
window x,y,0,0:cls:g%=x/12-1
open #1,scr_

rep p
window 10,y,rnd(g%)*12,0:ink#1,rnd(1000):scroll s/5
if rnd(1):bput#1;rnd(31,99):s=5:else:s=15
end rep p

I still don't fully understand the program but was able to add random colours to the raining text to see what it would look like. To slow the rain I divided s by 5.

I tested SELECT ON an array and found that SELECT ON is fine with a variable but not a variable within an array. (it is rejected by my parser)

The Matrix!!! code will not run whilst it is overlapped by another window. I guess this is because you can't resize a window whilst it is covered by another application's window.
As a background, the fact that Matrix!!! stops raining when covered by applications is actually rather useful. One can freeze the display at an appropriate point.
Matrix3.jpg
Last edited by Tinyfpga on Mon Dec 27, 2021 10:00 pm, edited 1 time in total.


User avatar
tofro
Font of All Knowledge
Posts: 2688
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Help! My QL has entered the Matrix !!!

Post by tofro »

pjw wrote:
tofro wrote:<>
Per,
runs nicely on QDOS/MGG/suqlx when you add an initialization to s before usage and some loop names.
Great! I suppose you need a line number as well and then LRUN it? Or can one just DO it?
Anyway, I found a way to shave off two more bytes: Just sack the %s in g%!
I was grateful and provided a line number (after all, it's still around Christmas) ;)


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Help! My QL has entered the Matrix !!!

Post by pjw »

Tinyfpga wrote:I managed to compile pjw's last posted Matrix!!! code on my system as
follows:-
It looks, er, interesting :)
x=scr_xlim:y=scr_ylim
window x,y,0,0:cls:g%=x/12-1
open #1,scr_
Since you appear to be interested to get to grips with SBASIC, I can
try to explain (although there clearly are some differences between
SMS2 SBASIC and up-to-date SMSQ/E SBASIC, so beware!):

When you start a new interpreter instance (SBASIC daughter job), eg
with EX <program>_bas, any attempt to access the screen causes a
console to be opened. This weird console is described in various
places, including a document by Tony Tebby called DIFFER.DOC. He
explains:
To use the facility to create SBASIC daughter jobs with just
window #0 open, all the standard commands which default to window #1
or #2 will default to window #0 if channel #1 or #2 is not open. This
may not apply to extension commands.
Since SCR_XLIM/SCR_YLIM both require a channel (default #0) using them
opens the default console, thus immediately providing channel #0. The
next two screen calls, window and cls, act on this channel.

g%=x/12-1 just creates an index of the screen columns, starting from
0. (I found that g= works just as well as g%=)

But now we need a real window to operate on, so we open a new screen
as channel #1.
rep p
window 10,y,rnd(g%)*12,0:ink#1,rnd(1000):scroll s/5
if rnd(1):bput#1;rnd(31,99):s=5:else:s=15
end rep p
SCROLL moves the contents of a given window down (or up) and replaces
the displaced pixel lines with the paper colour. You can scroll only
part of a window, but here we want to scroll the whole window down by
<s> pixels. So we make window#1 the width of the column, and the
height of the whole screen. The column to operate on is chosen
randomly for effect ( rnd(g)*12 ). This becomes the x-offset of the
window and column.

Perhaps ideally, we'd print the character into our randomly selected
column and then scroll the column, but to avoid an extra endif, it was
done like the above. Its so fast the difference wont be noticed anyway.

Now we print the character, some random character between ASCII 31 and
99 (99 was chosen simply to save a byte. It could just as well have
been 191.) (I see you added the random ink colour here: You could have
dispensed with the #1, as INK defaults to channel #1 anyway. You could
also have limited yourself to ink rnd(1,7), or just ink rnd(7).. )

Initially I randomly printed spaces, but they are not needed as the
scrolling takes care of that. Hence the s=5 (normal character) and s=
15
(space).

Normally, you want loops to be as efficient as possible, so all
calculations where the answer is known in advance are done outside the
loop. Thus it would make more sense to change the clauses :s=5:else:s=
15
to :s=1:else:s=3, and the clause scroll s/5 to scroll s, as this
has the exact same meaning and shaves a few micro seconds of a any
loop that has to do real work! (However, you may be attempting to slow
the loop down a fraction by adding the extra calculation..?)
I still don't fully understand the program but was able to add
random colours to the raining text to see what it would look like. To
slow the rain I divided s by 5.
I hope the workings of the code has become clearer now. Of course,
this was exceptionally terse and a little convoluted. But often I feel
that reams of beautifully formatted code with long, descriptive names
dont necessarily make things clearer; they just obscure bad
programming! (IMHO) There has to be a balance.

PS: To slow the loop it would make more sense to make a sub routine,
W, that does some complicated math in a FOR loop, or something..
def proc W: for i=0 to 999: x = 3^3
And put the W after scroll s.


Per
dont be happy. worry
- ?
User avatar
QLvsJAGUAR
Gold Card
Posts: 455
Joined: Tue Feb 15, 2011 8:42 am
Location: Lucerne, Switzerland
Contact:

Re: Help! My QL has entered the Matrix !!!

Post by QLvsJAGUAR »

After having enjoyed Christmas with my family, I have to work this week. During lunch break I copied all Matrix code snippets from this thread to files and ran them under QPC2. Nice tries. :geek:


QL forever!
https://www.sinclairql.net/ - Go and get THE DISTRIBUTION & QL/E!
https://www.youtube.com/QLvsJAGUAR/community - Blog
https://www.youtube.com/QLvsJAGUAR - Dedicated QL videos
Sinclair, QL, ATARI, JAGUAR, NUON, APPLE, NeXT, MiST & much more...
Videos, pictures & information
User avatar
QLvsJAGUAR
Gold Card
Posts: 455
Joined: Tue Feb 15, 2011 8:42 am
Location: Lucerne, Switzerland
Contact:

Re: Help! My QL has entered the Matrix !!!

Post by QLvsJAGUAR »

But...

Psst. Now I tell you a secret if you don't already know! That The Matrix is already built in in every QL! It only needs two statements (REPeat and COPY or SPL).

Drum roll...

Here's the SBASIC code what I call MiniMatrYX (85 bytes):

Code: Select all

REP:SPL WIN1_,"SCR_6x"&RND(SCR_YLIM/2TO SCR_YLIM)&"a"&(RND(0TO(SCR_XLIM-6)/2)*2)&"x0"
Here's the rather spartanic but even shorter 68 bytes version called MiniMatriX:

Code: Select all

REP:SPL WIN1_,"SCR_6x"&SCR_YLIM&"a"&(RND(0TO(SCR_XLIM-6)/2)*2)&"x0"
MiniMatrYX under QLE v3.21 (wip) on QPC2 v5.02
MiniMatrYX under QLE v3.21 (wip) on QPC2 v5.02
:ugeek: Just call me Neo.

P.S. 1: SuperBASIC needs a variable name after REPeat.
P.S. 2: In case your machine is too fast, try a bigger file instead of just the WIN1_ FAT, e.g. QL/E's WIN1_boot_verbose.


QL forever!
https://www.sinclairql.net/ - Go and get THE DISTRIBUTION & QL/E!
https://www.youtube.com/QLvsJAGUAR/community - Blog
https://www.youtube.com/QLvsJAGUAR - Dedicated QL videos
Sinclair, QL, ATARI, JAGUAR, NUON, APPLE, NeXT, MiST & much more...
Videos, pictures & information
Tinyfpga
Gold Card
Posts: 252
Joined: Thu Sep 27, 2018 1:59 am

Re: Help! My QL has entered the Matrix !!!

Post by Tinyfpga »

pjw posted
"Since you appear to be interested to get to grips with SBASIC......."

Yes, I really am interested. I have no idea why, but I enjoy programming for fun on/in SMS. There is something about SMS that is completely absent on various other hobby or learner systems. I find that writing a program in my SBASIC, as in SmsBASIC, setup is a kind of artistic endeavour.
For this activity to become more fluid I need to better understand how the whole thing works.

Your reply was very informative but will take me some time to digest. I have played with your program to produce varied and very attractive results. I am amazed by how much can be achieved with so little code. Inspired by your program, I am going to try and write a MATRIX!!! program that runs in the background and looks more like the ones found on YouTube.

Sadly I am not an accomplished,or not even an unaccomplished author but I intend (therefor it might never happen) to write an SBASIC programming manual for people who think like me. For example, I have been following the PE for dummies thread but have very little understanding of the topic being discussed. So you see I am even dumber than a dummy. I suppose I could try harder but I am not very keen on using EasyPtr.

There are a number of limitations that become apparent when writing animation programs. These are probably a reflection of the very low power of the machines on which SMS was developed.

The first, concerning the pjw MATRIX!!! program, is that the WINDOW #n,x,y,xp,yp instruction does not seem to work in the background.

The second is that if you let a program write to the screen "flat out" and "on top" the performance of the system is affected, such that no other program is useable. If the animation window is even partially covered by another window, system performance is restored. Why is this?

The problem I have with animation is that the only real control I have on animation speed is the WAIT instruction which has a minimum delay of 20 msecs. This is far too long. I can delay animation by wasting time doing a calculation but this is affects the system's performance.
Is there no way of creating a DELAY instruction to control programs in micro seconds? Lots of NO OPERATIONs (what ever they are) perhaps. Is there not a clock that controls the processor that could be used somehow?

The third, fourth and fifth limitations are really all the same and can probably only be solved in hardware.
Animation stops if you move the pointer over the animation.
Animation stops if you move or resize a window.
Most problematic is that even programs that are not writing to screen appear to stop when moving or resizing.


User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Help! My QL has entered the Matrix !!!

Post by pjw »

QLvsJAGUAR wrote:But...
Psst. Now I tell you a secret if you don't already know! That The Matrix is already built in in every QL!
Haha! What I enjoy with these little challenges is that one tries
one's damndest to refine an idea to its barest essentials. And then,
just as one thinks ones reached its purest form, someone comes along
and flips the conventional thinking to come up with some amazing new
way of doing it.

With the FIZZBUZZ episode on ql-users back in 2010 there was a clear
task:
Rich Mellor wrote: I was just reading that 99/100 job applicants for programming
jobs apparently cannot write a short "fizzbuzz" program when given 10
minutes to do so in an interview.

Code: Select all

The rules are simple -
write out the values 1 to 100 on screen
If the value is divisble by 3 write 'FIZZ' after the number
If the value is divisble by 5 write 'BUZZ' after the number
If the value is divisble by 3 and 5 write 'FIZZBUZZ' after the
number
It started off with people on ql-users submitting code in Assembler,
S*BASIC, C, Java, etc. Later, even for different computers, like ZX,
Jupiter Ace, and SAM Coupé.

Most contributors claimed 2-3 minutes for the S*BASIC versions (but
unsurprisingly, more than the allotted time for the assembler ones).
However, as it is impossible to check times on an email list, what
became more interesting was how terse the code could be made. I wont
go through all the tricks, "cheats", and shenanigans that were tried,
nor reveal the winning entry. They are part of a journey that would
take up too much room to describe here.

The Matrix "challenge" is slightly different in that there is no clear
definition of the task and also a highly subjective element - hence my
Miss World analogy.

So if I may be permitted to voice my personal opinion regarding the
last two entries, Id have to say, continuing with the MW metaphor:
The bikini was certainly tiny enough to leave nothing to the
imagination. The contestant is original and has brains aplenty.
However, she is not pretty; she might have a chance as Mrs Zion, but
not as Ms World.

- Smith.


Per
dont be happy. worry
- ?
User avatar
dilwyn
Mr QL
Posts: 2753
Joined: Wed Dec 01, 2010 10:39 pm

Re: Help! My QL has entered the Matrix !!!

Post by dilwyn »

pjw wrote: With the FIZZBUZZ episode on ql-users back in 2010 there was a clear
task:
Rich Mellor wrote: I was just reading that 99/100 job applicants for programming
jobs apparently cannot write a short "fizzbuzz" program when given 10
minutes to do so in an interview.

Code: Select all

The rules are simple -
write out the values 1 to 100 on screen
If the value is divisble by 3 write 'FIZZ' after the number
If the value is divisble by 5 write 'BUZZ' after the number
If the value is divisble by 3 and 5 write 'FIZZBUZZ' after the
number
I don't remember that one (maybe I did try and made a fool of myself - I'm sure you can find the evidence in the archive if I did). Out of interest, and wanting something to pass a few minutes just now, I had a go and it's certainly possible in S*BASIC in a very few lines in a couple of minutes, which for me included writing it out on paper and typing it in and correcting a minor typo (one letter in different case to the rest). I'm sure that with a little rewrite it would, like the Matrix ones, go down to just a line or two with a little thought.

But back on topic, I haven't tried writing a Matrix one as plenty of good attempts have been listed here, so a bit pointless me trying to go further!

I do agree with what you say, though, that often in cases like this it's about lateral thinking rather than pure programming knowledge or which language you try to use, or whatever. After all, many a QL program program over the years has successfully shown that a hell of a lot can be achieved just from S*BASIC. I'm thinking of those short programs in Quanta mag by people like Steve Poole who write a whole working game or utility in just a page or so of BASIC code. While S*BASIC is often good enough for very large programs, it's also easy to write short, simple programs for your own use in minutes. Assembler, C, etc all have their places, but as we've seen here you can achieve a lot with a few lines of BASIC too.


Post Reply