matherp Guru
 Joined: 11/12/2012 Location: United KingdomPosts: 11174 |
| Posted: 02:09pm 09 May 2020 |
|
|
|
In this post we look more at the Colour LookUp Table (CLUT) and the MAP command and function and use them to create a rotating colour disk

As explained earlier, 8-bit colour modes use a lookup table to convert from a single byte of information to the RGB565 pixel that will be displayed. In the CMM2 firmware the 8-bits are treated as a RGB332 pixel and are mapped to the most appropriate RGB565 value.
However, we can override this using the MAP command.
Normally a pixel that is set to zero would mean that it would be black on the screen but if we use the commands
MAP(0)=RGB(RED) MAP SET
Then every "black" pixel on the display will instantly turn red. Actually it isn't quite instant as the MAP SET command waits for the next frame blanking period before making the change. So MAP(n)=colour primes the colour change and MAP SET enacts it. This allows us to change a number of colours simultaneously by using multiple MAP(n)=colour commands and then a single MAP SET.
To use our new colours in a drawing command we use the MAP(n) function. So for example if we type MAP(134)=RGB(148,73,66) to get some particular shade then to use that colour we would reference it as MAP(134) e.g.
MAP(134)=RGB(149,73,66) MAP SET TEXT MM.HRES\2, MM.VRES\2,"Hello",CM,,5,map(134)
This would display the text in a dark brown colour. If we then typed
MAP(134)=RGB(BLUE) MAP SET
The text would immediately turn blue as would any other pixels on the display set to 134.
There a couple of other MAP commands
MAP MAXIMITE sets the CLUT to mimic the colours of the original Colour Maximite. i.e. 0-7 are the Maximite primary colours.
MAP RESET restores the original RGB332 mapping
Now lets look at using the MAP command to create the colour wheel above
' Set up an array to hold the colour mappings we are going to use Dim integer cmap(6)
'Clear the screen CLS
'Set up 6 colours in the array cmap(1)=RGB(red) cmap(2)=RGB(green) cmap(3)=RGB(blue) cmap(4)=RGB(yellow) cmap(5)=RGB(magenta) cmap(6)=RGB(cyan)
' Do an initial update of the CLUT to set up our colours mapclut
'Display an outer circle in white Circle MM.HRes/2,MM.VRes/2,MM.VRes/2-1,0,,RGB(white),RGB(white)
' Now draw a simple colour pie chart using our new colours with the ARC command Arc MM.HRes/2,MM.VRes/2,0,MM.VRes/2-10,0,60,map(1) Arc MM.HRes/2,MM.VRes/2,0,MM.VRes/2-10,60,120,map(2) Arc MM.HRes/2,MM.VRes/2,0,MM.VRes/2-10,120,180,map(3) Arc MM.HRes/2,MM.VRes/2,0,MM.VRes/2-10,180,240,map(4) Arc MM.HRes/2,MM.VRes/2,0,MM.VRes/2-10,240,300,map(5) Arc MM.HRes/2,MM.VRes/2,0,MM.VRes/2-10,300,360,map(6)
' Start a never ending loop Do
'each time round the loop move the colours in our array one place to the left ' Use array element 0 to store the first element that is going to be at the end cmap(0)=cmap(1) cmap(1)=cmap(2) cmap(2)=cmap(3) cmap(3)=cmap(4) cmap(4)=cmap(5) cmap(5)=cmap(6) cmap(6)=cmap(0)
' reset the colour map mapclut
' pause so we can see the change Pause 200 Loop
'This subroutine updates the colour map for the colours we are using ' set map positions 1 to 6 to the new colours ' then apply the change Sub mapclut map(1)=cmap(1) map(2)=cmap(2) map(3)=cmap(3) map(4)=cmap(4) map(5)=cmap(5) map(6)=cmap(6) map set End Sub >
Next post we are going to look at BLIT. Sounds complex? Actually all it is is a memory to memory copy - nothing more, but perhaps the most powerful tool in the graphics arsenal. Edited 2020-05-10 00:19 by matherp |