Dr. Jim's QL Dumping Ground

Anything QL Software or Programming Related.
User avatar
Andrew
Aurora
Posts: 793
Joined: Tue Jul 17, 2018 9:10 pm

Re: Dr. Jim's QL Dumping Ground

Post by Andrew »

Derek_Stewart wrote: Mot sure what RANDOMISE (DATE) is doing.
It generates a new start value for RND. Without it the RND will generate the same values at each run and program would create the same image.

A color Kaleidoscope

64x64

Code: Select all

100 REMark COLOR Kaleidoscope 64x64
110 :
120 setup_screen
130 :
140 REPeat loop
150  FOR w = 3 TO 50
160    FOR i = 1 TO 32
170      FOR j = 0 TO 31
180        k = i + j
190        IK = INT((j * 3) / (i + 3) + i * w / 12): IK=IK MOD 12
200        fmi = 64 - i: fmk = 64 - k
210        Plot i, k : Plot k, i
220        Plot fmi, fmk: Plot fmk, fmi
230        Plot k, fmi: Plot fmi, k
240        Plot i, fmk: Plot fmk, i
250        IF KEYROW(1) && 64 THEN EXIT loop
260      NEXT j
270    NEXT i
280  BLOCK#ch, 8,4, 252,126, 0
290  NEXT w
300 END REPeat loop
310 CLOSE#ch
320 MODE 4
330 :
340 REMark Emulate ZX81 PLOT command
350 :
360 DEFine PROCedure Plot(x,y)
370   BLOCK#ch, 8,4, (x-1)*8+4,(y-1)*4+2, IK
380 END DEFine Plot
390 :
400 REMark setup screen
410 :
420 DEFine PROCedure setup_screen
430   MODE 8
440   ch=FOPEN("scr_512x256a0x0")
450   PAPER #ch;7
460   IK=0: INK #ch,IK
470   CLS #ch
480 END DEFine setup_screen
128x128

Code: Select all

100 REMark COLOR Kaleidoscope 128x128
110 :
120 setup_screen
130 :
140 REPeat loop
150  FOR w=3 TO 50
160  p=INT(RND(1 TO 12))
170    FOR i = 1 TO 63
180      FOR j = 0 TO 63
190        k = i + j
200        IK = INT((j * 3) / (i + 3) + i * w / 12): IK=IK MOD 12
210        fmi = 128 - i: fmk = 128 - k
220        Plot i, k : Plot k, i
230        Plot fmi, fmk: Plot fmk, fmi
240        Plot k, fmi: Plot fmi, k
250        Plot i, fmk: Plot fmk, i
260        IF KEYROW(1) && 64 THEN EXIT loop
270      NEXT j
280    NEXT i
290    BLOCK#ch, 4,2, 254,127, 0
300   NEXT w
310 END REPeat loop
320 CLOSE#ch
330 MODE 4
340 :
350 DEFine PROCedure Plot(x,y)
360   BLOCK#ch, 4,2, (x-1)*4+2,(y-1)*2+1, IK
370 END DEFine Plot
380 :
390 REMark setup screen
400 :
410 DEFine PROCedure setup_screen
420   MODE 8
430   ch=FOPEN("scr_512x256a0x0")
440   PAPER #ch;7
450   IK=0: INK #ch,IK
460   CLS #ch
470 END DEFine setup_screen


stevepoole
Super Gold Card
Posts: 714
Joined: Mon Nov 24, 2014 2:03 pm

Re: Dr. Jim's QL Dumping Ground

Post by stevepoole »

Hi Folks,

Here is an old Kaleidoscope program for QL systems that runs well :
kaleidoscope4_bas.zip
(906 Bytes) Downloaded 93 times
Regards,
Steve.


User avatar
TMD2003
Trump Card
Posts: 168
Joined: Sat Oct 10, 2020 12:18 pm

Re: Dr. Jim's QL Dumping Ground

Post by TMD2003 »

Mine's looking rather nice now - and is pretty much the way I intended it to be. I was going to add a feature to SBYTES the pattern, but I figured that CTRL+F11 to make a bitmap was all I'd ever need.

There are seven different colour schemes - plus you can define your own colours, or have a continuously randomised series of all seven inbuilt schemes. The ZX81 pixels are 8×6 BLOCKs so that they appear square on QemuLator. If you're determined to stick with QPC2, adjustments can be made to use 8×8 BLOCKs, or any other proportion, provided WINDOW #1 is also adjusted to a multiple of the BLOCK dimensions. It's 512×252 to fit the dimensions I've used.

This isn't a QL ZIP below, it's a regular Windows ZIP with a solitary _bas file in it.
Attachments
qaleid_bas.zip
(2.3 KiB) Downloaded 92 times


Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
User avatar
TMD2003
Trump Card
Posts: 168
Joined: Sat Oct 10, 2020 12:18 pm

Re: Dr. Jim's QL Dumping Ground

Post by TMD2003 »

Since my tenure of the comp.sys.sinclair Crap Games Competition ended on 17th December, I bet you all thought you'd seen the last of me. You did, didn't you? Well, think again, because I've been flinging myself at some slightly tricky maths programs recently, and yet again, the QL and its very wide screen are a great help. Even more so than the banner-ad-shaped Z88.

A few years ago, I tried to write a cubic equation solver for the Spectrum using Wikipedia's explanation - but I didn't get far, so I moved on to other projects. Part of the problem was, working out what was valid and what wasn't; I was presented with a formula that had a cube root (three potential solutions) with a square root under it (two potential solutions), minus another cube root (three potential solutions) with another square root under that (two potential solutions). This is where I completely lost the cubic plot.

But I've recently revisited it, with the help of a video from Mathologer that's simple enough for anyone with A-level maths to follow (even the bit that involves complex numbers), and by careful calculation of the values that I actually need (including how to evaluate the cube root of a complex number, which I didn't previously know), I've cracked it. The Spectrum version needed a few tweaks, and but for one example I've found where a root that's supposed to be 5 is calculated at 5.00000001, I've found it's accurate. This is despite having to convert a complex number x+iy into its polar form re^(iθ) - which means squaring the x and the y, adding them and taking a square root, then taking arctan(y/x) to find θ, adding 2π/3 and 4π/3 to θ to find the second and third roots, and taking cosine of all three. I've made some test cases such as (x-3)(x-6)(x-8)=0 in which I expect the roots to be exactly 3, 6 and 8 - and despite all the calculations that involve irrational numbers and rounding errors, bar that one example with the 5.00000001, the exact roots have been produced.

So, flushed with success, I moved onto the QL, and rewrote the Cubic Equation Solver to take advantage of the wide screen. I've kept it using two side-by-side windows, where the window on the left (#2) displays the results and the window on the right (#1) acts as a sketch pad, showing the interim values that are calculated to solve the equation. It will work with three roots (and that 5.00000001 comes out at exactly 5 this time), two roots where one is a duplicate, one real root and two complex conjugate roots, and one triplicate root.

Also, anyone tempted to start screaming about me using "Wild West" user-defined graphics - I haven't, anything that appears to be that is actually a procedure that draws it line by line with BLOCK statements, so it should work on any QL system from PM ROM to the latest SMSQ/E. And if I ever need the symbols again, I can copy the procedures.

Image Image


That was a roaring success. And earlier today, I thought it might be possible to calculate factorials exactly, using the QL's 85-column display. I've used much the same principle as I did with the base converter earlier in this thread: store each digit of the number we're looking for in an array, multiply each digit, and then scan through them and carry if required. In the end I found I could keep the standard two-pixel border that cuts the window down to 84 characters, because 61! is 84 digits and 62! is 86 digits. I've checked with my calculator and - even though it shows 61! as 5.075802138×10^83, I can see the full value printed on the QL's screen is correct (as is 60! in the screenshot). It takes around two seconds to evaluate the smallest factorials and six and a half seconds for the last few, on a standard black box QL - though anyone who tries this will probably use QPC2 where the calculation will be effectively instant.

So if you've ever wondered what all the digits are in 61!, you can find out with this program.

Image


I've got a grand plan to see if I can make an RPN calculator for the QL. The Spectrum versions I made in 2017 are all well and good, but the QL's screen brings up the enticing prospect of a complex RPN calculator - which will have four stacks for real, imaginary, magnitude and argument, and I'll need all four. Addition and subtraction are easy, multiplication is relatively straightforward, division is a tad more complicated, but taking a square root? That involves taking the positive square root of the magnitude, and halving the argument; it can't be done (easily) on the real and imaginary parts. Anyway, that's probably one for when I've got an enormous amount of time on my hands...

A reminder: these are regular PC zips, not QL zips - unzip them to reveal the _bas files inside.
Attachments
cubic_bas.zip
(2.79 KiB) Downloaded 61 times
fact_bas.zip
(1.44 KiB) Downloaded 64 times


Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
User avatar
TMD2003
Trump Card
Posts: 168
Joined: Sat Oct 10, 2020 12:18 pm

Re: Dr. Jim's QL Dumping Ground

Post by TMD2003 »

Achtung! I found some mistakes in the cubic equation solver (overwriting the variables k1 and k2, which I'd used for ink colours, while solving one-root equations). This has now been fixed.

Anyone with any suggestions for more QL maths programs? I reckon there's a ton of potential here.


Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
Post Reply