Color cycling in the QL with RECOL

Anything QL Software or Programming Related.
User avatar
badaman
Chuggy Microdrive
Posts: 56
Joined: Sun Jan 12, 2020 12:18 pm
Location: Spain
Contact:

Color cycling in the QL with RECOL

Postby badaman » Sun Mar 15, 2020 7:18 pm

This article is written for new users of the QL or users who are learning SuperBASIC, but the described technique can be useful for advanced users. My English is not very accurate, so I have used the Google translator for this post. Please excuse the inconvenience.

Color cycling

The color cycling technique allows you to define an image whose color palette has the characteristic that part of it can be defined as a cycle of consecutive colors, resulting in an effect of movement or animation.

The example par excellence is “Waterfall” file that came as a demo in NEOCrhome, one of the first programs that allowed this effect that was common in Atari ST and Commodore Amiga.

Image

In the QL we have a very limited color palette in the classic 4 and 8 color modes, and this does not allow us very realistic effects, but something can be done. Without a doubt in other color modes, with some machine code, the effect would be much better than what I show here as a result:

Image

Using RECOL

To achieve this effect, we must start from two premises:

1.- SuperBASIC has a command called RECOL that changes the screen colors that we indicate. For the default colors from 0 to 7 we can decide that these will be replaced on the screen by another color from 0 to 7. For example, we can change the color blue from white, as seen below, with 'n' being the chosen channel.

Code: Select all

RECOL #n, 0,7,2,3,4,5,6,1


What it does is swap colors on the screen. For animations, we must make sure that, when using RECOL, we exchange colors, as in this case, color 1 for color 7, and color 7 for color 1. Otherwise it may happen that different colors on the screen end up being the same.

2.- SuperBASIC allows defining windows that we can associate with a channel. In this way we can define rectangular areas on which to apply RECOL. In this example two areas have been used as seen in the image. In this way we can save the rest of the image and act only on the area on which we are going to use RECOL.

Image

Those areas of the screen with irregular edges must be worked in such a way that the colors used are not affected by the RECOL, as is the case with the edges of the waterfall. This is the starting image.

Image

Surely using the FLASH command other interesting effects can be achieved, but this would mean creating a more accurate mask for changing colors.

The program

This is the code that allows this color change.

Code: Select all

 100 MODE 8
 110 LBYTES mdv1_scrs_cascada_scr, 131072
 120 ch1 = 3: ch2 = 4
 130 OPEN #ch1, scr_148x145a232x29
 140 OPEN #ch2, scr_512x82a0x174
 150 REPeat loop
 160 RECOL #ch1,0,7,2,3,4,5,6,1
 170 RECOL #ch2,0,7,2,3,4,5,6,1
 180 IF INKEY$ <> "": EXIT loop
 190 PAUSE 10
 200 END REPeat loop
 210 CLOSE #ch1: CLOSE #ch2


Other uses of RECOL

In this other example, RECOL is used to simulate a trail on the screen. a bouncing ball is shown, leaving a colored tail behind it.

Image

This is the program:

Code: Select all

100 MODE 8: ch = 3
 110 OPEN #ch, scr_
 120 axw = 400: ayw = 200
 130 WINDOW #ch, 512,256,0,0
 140 PAPER #ch, 1: CLS #ch
 150 WINDOW #ch, axw, ayw, INT ((512-axw) / 2), INT ((256-ayw) / 2)
 160 PAPER #ch, 0: CLS #ch
 170 INK #ch, 7
 180 SCALE #ch, ayw, 0.0
 190 axw = INT (X_Scale (ayw, axw, ayw))
 200 r = 6: d = 4
 210 x = INT (axw / 2)
 220 y = INT (ayw / 2)
 230 iz = 0: ab = 0
 240 ix = 1: iy = 1
 250:
 260 REPeat loop
 270 RECOL #ch, 0,0,1,2,3,4,5,6
 280 FILL #ch, 1
 290 CIRCLE #ch, x, y, r
 300 FILL #ch, 0
 310 x = x + (d * ix): y = y + (d * iy)
 320 IF x> axw OR x <0 THEN ix = -ix
 330 IF y> ayw OR y <0 THEN iy = -iy
 340 REMark PAUSE
 350 END REPeat loop
 360:
 370 DEFine FuNction X_Scale (y_scale, wide, high)
 380 RETurn .7411765 * y_scale * wide / high
 390 END DEFine X_Scale


I don't know if this technique has been used in the QL at any time, but it can be a starting point for a cover or basic game.
Last edited by badaman on Mon Apr 06, 2020 8:31 pm, edited 3 times in total.


martyn_hill
Super Gold Card
Posts: 564
Joined: Sat Oct 25, 2014 9:53 am

Re: Color cycling in the QL with RECOL

Postby martyn_hill » Sun Mar 15, 2020 10:07 pm

Thanks Badaman - what an interesting use of the otherwise oft-neglected RECOL procedure!


User avatar
badaman
Chuggy Microdrive
Posts: 56
Joined: Sun Jan 12, 2020 12:18 pm
Location: Spain
Contact:

Re: Color cycling in the QL with RECOL

Postby badaman » Thu Apr 02, 2020 8:21 pm

Another example: Psicodelia

Image

Code: Select all

100 MODE 8
110 LBYTES mdv1_scrs_psicodelia_scr,131072
120 ch1=3
130 OPEN #ch1,scr_512x256a0x0
140 REPeat loop
150   RECOL #ch1,0,3,6,2,5,1,4,7
160   IF INKEY$ <> "": EXIT loop
170   PAUSE 10
180 END REPeat loop
190 CLOSE #ch1


The images:

Image

Image
Last edited by badaman on Mon Apr 06, 2020 8:30 pm, edited 1 time in total.


User avatar
Sparrowhawk
Gold Card
Posts: 280
Joined: Wed Dec 15, 2010 12:33 pm
Location: @131072
Contact:

Re: Color cycling in the QL with RECOL

Postby Sparrowhawk » Sat Apr 04, 2020 5:59 pm

Brilliant! thank you for sharing :)


a.k.a. Jean-Yves !
User avatar
badaman
Chuggy Microdrive
Posts: 56
Joined: Sun Jan 12, 2020 12:18 pm
Location: Spain
Contact:

Re: Color cycling in the QL with RECOL

Postby badaman » Mon Apr 06, 2020 8:29 pm

martyn_hill wrote:Thanks Badaman - what an interesting use of the otherwise oft-neglected RECOL procedure!


Sparrowhawk wrote:Brilliant! thank you for sharing :)


Thank you.


User avatar
Cristian
Super Gold Card
Posts: 730
Joined: Mon Feb 16, 2015 1:40 pm
Location: Veneto

Re: Color cycling in the QL with RECOL

Postby Cristian » Wed Apr 08, 2020 6:58 pm

Thank you for sharing your interesting concept. I had a similar idea some time ago, but then I abandoned it because RECOL is really slow on real hardware, even with Supergoldcard.
Has anyone tried with other machines (Aurora, Q68...)? Does the program run smoothly?


User avatar
badaman
Chuggy Microdrive
Posts: 56
Joined: Sun Jan 12, 2020 12:18 pm
Location: Spain
Contact:

Re: Color cycling in the QL with RECOL

Postby badaman » Thu Apr 09, 2020 7:38 pm

Cristian wrote:Thank you for sharing your interesting concept. I had a similar idea some time ago, but then I abandoned it because RECOL is really slow on real hardware, even with Supergoldcard.
Has anyone tried with other machines (Aurora, Q68...)? Does the program run smoothly?


That you say is important. I have not yet tried this method in the real QL. I think that it can be useful not in large windows, but for small areas of the screen where you want to apply some effect.

I can think of, for example, a torch whose fire changes colors red and yellow... a light bulb that turns on or off, a starry sky that clinks between cyan, blue and white, a small Christmas tree, or a neon sign...

On the other hand, perhaps a machine code routine can be optimized to make it work faster, for example, using long words to exchange two or more colors.



Who is online

Users browsing this forum: No registered users and 5 guests