The ColorMixer Basics

I've never attempted to use the color mixer statements in my TB Bronze before because it was not listed in my manual and as far as I can tell I haven't really had a need for it until now but I have no idea how to make it work. I would really appreciate any help that could give me information on the below items. Any other helpful information would also be greatly appreciated. thanks!
-Can TB Bronze use this statement?
-What does the statement look like?
-What other statements/values are need to make it work?
-How and for what can it be used?
-Are there any advantages to using it over the basic colors?

-Thanks again to anyone who offers tips and info!!

Comments

Colors in True Basic Bronze

I do not know if TB Bronze can use this statement, but it can use the SET COLOR "color" and SET BACKGROUND COLOR "color" statements SET COLOR sets the font color and SET BACKGROUND COLOR sets the background color (not to hard). SET COLOR has 16 colors, some one's you can use by name include red, green, black, white, blue, cyan, and I think there is one other, but I don't remember right now, otherwise look through the forum, I think there is one there, you can also use SET COLOR {num} minus the brackets. 0-16 work I do not know which is which but there is a red, blue, cyan, green, black, grey, purple/pink, white, and 8 more.

-grouchi

ColorMix

Hi,

Nothing beats reading the manual. You can REDIM variables at any time to allow for continuously expanding arrays.

The real question here is the rather complicated way you have approached the problem. Basically there is no reason to do any color changes if you are merely interested in the intersection point of two lines, you don't need to plot any lines at all - you just inspect the color of each pixel along a virtual line until you meet a color that is different to the background - this must be the target line that your virtual line has intersected.

Regards
Big John

Still Having problems...

I tried removing the empty sub which I figured was the problem, but when I remove it and try and run it I get an error saying that there's an undefined routine in my program...I'm not sure what to do any more

VERSION

Hi,

What version of TrueBASIC are you using - type VER on the command line. Versions 5.31 up to the present version (5.5b19) have all got the built in routine CALL getCpixel.

Comment out CALL getCpixel and see if you still get the error message about undefined routines.

Regards
Big John

Still Nothing

Ok so I tried commenting out the call statement...no more error...so i know that it's the call getcpixel that's causing the error...I also checked my version jst incase I had it wrong, I was right and I still have the VER 5.5b19 of gold which im using until the bug free 6.0 comes out...I think I have an idea as to why it work though...is it possible that the main program simply cannot find the file or lib or something associated with the GetCPixel command? and if it isn't finding it because of that then should it be telling me that it can't find the file?

GetCPixel

Hi,

OK, I confess, it is all my fault - I put it down to age. The last time I used this routine was 2005. I just checked my old program and the correct name for the routine is:

ReadCPixel(x,y,red,green,blue)

Not GetCPixel.

It is certainly built into version 5.5b19

Sorry about that.

Regards
Big John

Oh ok-But...

Yea I know...problem should be fixed by now right? But it's not...although the now "Call ReadCPixel" command works it has brought up yet another issue...If we use the code that I posted earlier on this topic it's clear that it DOES work, but not as I had hoped...it seems that when I use the code it now erases all of the colored pixels EXCEPT the few pixels that match the IF THEN statement...the line shows up when the ReadCPixel commands are commented out, but it does not appear when the commands are included...I'm not really sure why it does this other than a theory...does the ReadCPixel command simply lay a "mask" over the area defined by the x,y variables to "Read" them? Or is my program just horribly flawed? Really sorry for having so many issues with this and I thank you for taking so much time to help me. Thanks a lot!

SET COLOR

Hi,

Your program has a number of SET COLOR statements that use a color that you have defined with SET COLOR MIX. The point that you have missed about SET COLOR MIX (n) is that whatever color (n) happened to be before is now changed to another color.

For example: suppose n=31 and let us suppose that you detect a rose red color with ReadCpixel and you SET COLOR MIX (31) as rose red, and then you SET COLOR 31 which means every time you click the mouse it will paint a rose red pixel. OK so far.
The next time ReadCpixel is used let us suppose it detects a sky blue color. You then use SET COLOR MIX followed by SET COLOR in order to paint sky blue pixels. Seems logical?
Unfortunately, in reseting color 31 to be sky blue, all the previous pixels which were also color 31 (red rose) will now be sky blue too. To avoid this happening you need to use a different number (or variable) each time you SET COLOR MIX.

Regards
Big John

If I understand correctly...

So am I correct by assuming that in order to "set color brush" inside the loop I have that I must now dimension that variable? ie: brush(1),brush(2),brush(3) etc?

If I must now use DIMs:
-----What would the appropriate DIM be? Is there a way to make DIMs infinite or possibly continously growing? (I'm not an avid user of Arrays/Matrices/DIMs so I'm not quite as informed here).

If I do NOT use DIMSor the like:
-----If we're not using DIMs then I'm afraid I may not have any idea what I'm doing. Is it possible to turn that variable into a string and then "add" a defining number to it such as a 1,2,3, or 4 etc. and then returning the newly named string to a variable and then using "set color brush1,2,3,4 etc"? Or would that not work and/or be to much effort for it's worth?

-I swear that someday the posts on this forum topic will cease =)....maybe

One More Question

Ok so I tried using just the CALL GetCPixel(x,y,r,g,b)

What I want this program to do (for now) is simply stop the drawing of a line when the color of the line reaches a destination of which is not the same color as the line itself. EX: the line color is blue and the the destination line is grey, I want the blue line to stop "drawing" itself when it hit the destination line. I know that I could to this by simply setting parameters as the coordinates of the grey line, but my main program has so many lines that I would much rather NOT type all of those coordinates and instead have it stop based on color...kind of like Pac-Man I guess.

Here's my code so far :
*Keep in mind that I'm aware of the extra external do loop (this is for other directions when I add them which you can see based on the value of "direction" below.)*

SET WINDOW 0,50,0,50

RANDOMIZE

LET x=25
LET y=25
LET x1=40
LET y1=0
LET rBox=.3
LET gBox=.3
LET bBox=.3
LET rBrush=.2
LET gBrush=.2
LET bBrush=.8

SET COLOR MIX(box) rBox,gBox,bBox
PRINT rBox,gBox,bBox
SET COLOR box
PLOT AREA:0,0;0,5;5,5;5,0

SET COLOR MIX(brush) rBrush,gBrush,bBrush
PRINT rBrush,gBrush,bBrush
SET COLOR brush
PLOT AREA:5,5;10,5;10,10;5,10

GET KEY null

DO
SET COLOR MIX(box) rBox,gBox,bBox
SET COLOR box
PLOT x1,y1;x1,y1+49
LET direction=int(rnd*4)+1
IF direction=1 then
DO
SET COLOR MIX(brush) rBrush,gBrush,bBrush
SET COLOR brush
PLOT x,y;
LET x=x+.1

CALL GetCPixel(x,y,rBrush,gBrush,bBrush)
CALL GetCPixel(x1,y1,rBox,gBox,bBox)
! the next line has rBoxrBrush...it should have a does not equal sign there...
IF x1=x and rBox<>rBrush then
PRINT "Brush and Border colors don't match but X coor's do"
STOP
END IF
PAUSE .01
LOOP until key input
END IF
LOOP until key input

SUB GetCPixel(x,y,r,g,b)
END SUB

END

When lines intersect

Hi,

The code line:
IF x1=x and rBox<>rBrush then........
can never be true if x1=x because 5 lines earlier you have just colored the pixel x,y rbrush,gbrush,bbrush and you have used getCpixel(x1,y1) to define the point x (the same as x1) as rbox,gbox,bbox. What you need to do is use getpixel(x1,y1) to define the color of point x1 BEFORE you plot x,y over the top of the same point.

Regards
Big John

Perhaps I'm just slow...

ok so at first I tried simply the command "getpixel(x1,y1)"
I couldn't seem to make that work, so I thought perhaps you ment CALL GetCPixel(x,y,r,g,b) so I tried that to no avial...have I done something wrong? or is it still possible that my CALL GetCPixel statements are overiding each other? Sorry for the continuing questions, but I'm very curious as to how this works exactly...Thanks a lot in advance too

CALL getCpixel(x,y,r,g,b)

Hi,

If you are using your earlier code then you must remove the empty sub-routine

SUB getCpixel
END sub

from your code.

Regards
Big John

SET COLORMIX

Hi,

The default color palette only has the first 16 colors defined (color numbers 0 to 15)- same as the DOS default colors.

You can find out what these colors are with:
ASK COLOR MIX (2) r,g,b
The computer will tell you what the "red", "green" and "blue" components are for color number two. The component values are given as decimal values between 0 and 1.
The r,g,b values for BLACK (color number 0) are 0,0,0
The r,g,b values for WHITE (color number 15) are 1,1,1

The whole palette contains 255 colors so you can use:
SET COLOR MIX (n) r,g,b to set any of the remaining colors in the palette. For example:
SET COLOR MIX (24)1,.50,0
will set color number 24 to orange.
SET COLOR MIX (25) .76,.38,0
will set color number 25 to brown

Regards

Big John

Thanks!!

That worked great and it's already been very useful to me! There are a few more things I would like to know if it isn't to much trouble. I've seen/glanced at a few other commands a while back that are also not listed in my manual and that I can't seem to find much help with but here's what they are:
-I've heard of something similar to ASK COLOR MIX etc... but in this particular case they were using the colors as perimeters. For example lets say my square is blue and the edges of the empty square it's in are green. Is there a command that does something like...if Color Blue touches Color Green then stop... or if the blue square was moving randomly around the screen and if it hits a red line it can keep going but if it hits a green line it will stop moving. Is there anyway to set those limits on movement without using the coordinates of the lines and just use the colors?
-Also another command I've heard of is something like GET COLOR where the program obtains the Red,Green,and Blue values of the specific pixel that you click on. I'm fairly positive that it works. Is it simply the get mouse a,b,c command or is it something more complicated or lie a hybrid between get mouse and set color mix?
-Finally, and sorry for all the questions but I just like to expand my knowledge base quickly and productively =), but I really wanted to know if there's a command or equation for redimentioning a screen while a program is running? Say the user moves an object across the screen, can you redimention the screen to simulate zooming in without erasing or otherwise distoring the background images/coordinate pictures? And can we redimention the screen around the moving object so that we not only zoom in on it but follow it?
-P.S. I know that this algorithm exists, but where can I find the one that redimentions your screen to make squares actually appear square on monitors like mine?(1920x1080res)? *This question is seperate from the previous question by the way.*
---THANKS A LOT!!! Sorry for all the questions, feel free to negate/ignore some of them if there's too many at the moment or if you would rather reply via email let me know! Once again, Thanks!

COLOR

Hi,

When dealing with color you need to distinguish between "global" colors and "local" colors.
ASK COLOR x and SET COLOR x both affect the "pen" or drawing color for the whole screen.
ASK BACKGROUND COLOR y and SET BACKGROUND COLOR y affect the "brush" or background color for the whole screen.
In the above cases the color is defined by a number represented by the numeric variables x or y.
You can change what color is displayed by any color number with:
SET COLOR MIX (n) red,green,blue
and
ASK COLOR MIX (n) red,green,blue

On the local level you can find out what color any screen pixel is with:
CALL GetCPixel(x,y,red,green,blue)
where x and y are screen co-ordinates.
You can set any pixel color with:
SET COLOR n
PLOT x,y

You can set the screen co-ordinates at any time with:
SET WINDOW x1,x2,y1,y2

If you wish to keep an object in the "sights" of the screen, you just need to use the above statement each time the target moves to keep the target in the screen sights.

The shape of screen pixels are controlled by the aspect ratio. With the right aspect ratio, the length of say 5 pixels vertically will be the same as the length of 5 pixels horizontally. This is normally true for screen sizes 640x480, 800x600, 1024x768.

Regards
Big John

Big John

Ok, so just one more question...

I noticed when you answered my last question that you referred to a library or subroutine with the statement:

CALL GetCPixel(x,y,red,green,blue)

I'm curious to know which SUB or LIB is being CALLed into action with this command so that I can actually use it. I've tried a few libraries, but I can't seem to get the right one...is there a chance I don't have the library? I'm using a few versions of TB...TB BRONZE 5.30 and TB GOLD 5.5b19 and TB GOLD 6.001 the bronze I use as a mostly bug free way of programming and the 5.5b19 gold is used as a way to familiarize myself with how gold works and the 6.001 gold is more to look pretty than anything as it seems to have issues at the moment. So between those three do you think I can find this library if it's gone missing?

If not would it be to much trouble for you to email it to me?

---Thank you so much by the way

SUB GetCPixel(x,y,r,g,b)

Hi,

The sub-routine GetCPixel(x,y,r,g,b) is a built in routine like the built-in routine Read_Image. It is not in any library. As I recall it is not documented either.

Regards
Big John