forums

TNT Basic Forums > Programming Q&A
colour code
< Last Thread     Next Thread >
Author
Thread        Post A Reply

02-26-2003 10:57

Posted by:
mark_667

Location:
England

Click Here to Email mark_667   Find more posts by mark_667

Hi,
I made this to test the default RGB colours in TNT and also to see what sort of random colours it is capable of producing. However, when I try to run it, I get some strange results, firstly, all the component colour values are identical for each colour on screen Red = 247, Green = 191, Blue = 7. I put these values in the RGB colour picker in Photoshop and it is a dark orange colour(?). Also, the yellow appears green, and the red appears black? I tried using the ‘Make pen colour’ command to do the same: pen colour random(0-255),random(0-255),random(0-255), but this is also highlighted as an error. The code is included below.

graphics mode 640,480
frame rect 0,0 to 640,480

set pen colour green
Paint Canvas
Draw Frame
print ""
print "Current colour Green:"
print "Red =",red component (0-255)
print "Green =",green component (0-255)
print "Blue =",blue component (0-255)
Delay 2000
'One of these for each default colour

repeat
int r= Random (0,255), g= Random (0,255), b= Random (0,255) 'colour' would end up being a random RGB colour...
int colour=r,g,b

set pen colour colour
paint canvas
draw frame
print ""
print "Current colour:"
print "Red =",red component (0-255)
print "Green =",green component (0-255)
print "Blue =",blue component (0-255)
forever

if mouse button
End
end if

Any opinions appreciated,
Mark_667

02-26-2003 13:52

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

YEAH!!!

Crazy, I was just thinking of posting a thread to complain on this but you got here before...

Yeah, this thread should stay in the bugs section...

TNT is absolutely off with colo(u)rs!!!!
CHECK IT!!
There is really nothin that works with the make colo(u)r stuff.

Also it would be very nice if you added some more colours callable such as white, red... but before this check that terrible "make colour"!! I need it now!

cheers

M@tt€ř

02-26-2003 14:13

Posted by:
John Treece-Birch

Click Here to Email John Treece-Birch   Find more posts by John Treece-Birch

Make Colour

Are you using version 1.12? I know we had some bugs in Make Colour but I thought they were all resolved in the latest version. I'll check it soon and make sure it works.

Also, we already have colour functions for White and Red don't we?

Thanks,
John

02-26-2003 19:54

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

I' m on Os 9.2.2 with the new Hieroglyph.

I thought I' d like other "easy-call" colours (other than the ones there already are) such as, dunno, purple, orange... but it really does not matter once the "make colour" works, so don' t waste your time...

Cheers

µ@TT€ř

02-26-2003 20:47

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

Make Colour works?!

Hi there,

Mark, I got your email last week, I looked into it and I thought I'd already replied to you but I must have forgot. As far as I could see, the problem wasn't that 'Make Colour' didn't work, it was more that you weren't actually using it! ;)


graphics mode 640,480
frame rect 0,0 to 640,480

set pen colour green
Paint Canvas
Draw Frame
print ""
print "Current colour Green:"
print "Red =",red component (0-255)
print "Green =",green component (0-255)
print "Blue =",blue component (0-255)
Delay 2000
'One of these for each default colour


The commands 'red component', 'green component' and 'blue component' take a composite colour and return the respective components from it. So you pass it a colour you've made with the 'make colour' command, or a preset colour such as 'red', 'green', 'blue' etc, and it will return a value between 0 and 255 indicating the colour value for that component.
However, in your example, the colour you are passing it is '0-255', or -255. This is probably not what you meant and is why you're getting strange results.


repeat
int r= Random (0,255), g= Random (0,255), b= Random (0,255) 'colour' would end up being a random RGB colour...
int colour=r,g,b


Another slip here I'm afraid, you are declaring a variable colour, and setting it equal to 'r'. Then you are declaring two more variables called g and b. (You already have these defined as integers and so TNT Basic doesn't mind you doing it again.)
So your code sets 'colour' to a random value between 0 and 255, this is not going to be the colour you expect!
Your code should read:

int colour = make colour (r,g,b)

This is how you should make colours from their components. You can also make them using the 'set red component', 'set green component' and 'set blue component' commands.

For example:
int colour=0
colour = set red component(colour,r)
colour = set green component(colour,g)
colour = set blue component(colour,b)


set pen colour colour
paint canvas
draw frame
print ""
print "Current colour:"
print "Red =",red component (0-255)
print "Green =",green component (0-255)
print "Blue =",blue component (0-255)
forever


Again, the colour you are printing out to screen is not the colour you are using. You should pass colour into them, as such:

print "Current colour:"
print "Red =",red component (colour)
print "Green =",green component (colour)
print "Blue =",blue component (colour)

Hope this helps!

Matteo,

Could you send me some concrete examples of TNT Basic's colour commands going wrong, because I don't know of any problems with them other than a minor rounding error.

The rounding error I know of is that if you set a colour component to 255, then get it back again it will come back as 247. This is just a rounding error produced due to the fact that the component is an 8 bit number when it goes in, but must be reduced to a 5 bit number so that 3 of them can fit in a 16 bit colour. Then when you pull it out again it has to be expanded from 5 bit to 8 bit and the quick method TNT Basic uses doesn't produce the original value again. It has no effect on the colour produced at all, it just returns a slightly rounded number when you extract it out again.

If this isn't the problem you're referring to then please let us know or post here the problems you've found with the colour commands!

As for more colour constants, we'e already got 'white' and 'red', as well as 'green', 'blue', 'black' and 'yellow'. You can make more with the 'make colour' function and store them in global variables for use throughout your program.

Cheers,

Mark

02-27-2003 12:29

Posted by:
mark_667

Location:
England

Click Here to Email mark_667   Find more posts by mark_667

Ooops!

Hi,
Mark, don't panic, you did reply to my e-mail, I just had some additional questions and wondered what everyone else thought. As for the Make Colour command, I wasn't sure how to implement it, so ended up with some badly syntaxed code I thought would work anyway, thanks for clearing this up.

02-27-2003 19:12

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

It' s set sprite colour that does not work

I found out that it' s not make colour that does not work, instead it' s set sprite colour, a function that nobody maybe ever used, but I need it.

Just try it with this code (or any other...)


graphics mode hardware 800,600
load images 128
set pen colour make colour(100,100,100)
fill rect 0,0 to 100,100
repeat
set sprite colour 0,make colour(100,100,100)
sprite 0,200,200,0
draw frame
until space

they are not the same colour...

cheers

Matteo

02-28-2003 11:48

Posted by:
John Treece-Birch

Click Here to Email John Treece-Birch   Find more posts by John Treece-Birch

Colour Bug

There was a bug in the Set Sprite Colour function under Hardware Mode. I've fixed it now and it will be in the next release.

Thanks for the bug report,
John

02-28-2003 12:14

Posted by:
mark_667

Location:
England

Click Here to Email mark_667   Find more posts by mark_667

Fixed!

Talking of bugs, after a little experimentation with Mark's sugestions, the code now works as it should. - Thanks!

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.