Understanding RGB by MikeS2nd Mar 2005 8:07
|
---|
Summary Learn what RGB is all about, and how to use it in your 2D and 3D programs. Description Learn what RGB is all about, and how to use it in your 2D and 3D programs. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com `3-2-05 Ink RGB tutorial `By MikeS of CurvedBasic `What exactly does RGB stand for? `RGB means Red,Green,Blue. different combinations of these values will give you millions(~16) `of colors at your disposal. You can specify a value of between 0-255 for each color. sync on : sync rate 60 `Setup our refresh rate for the screen. set display mode 1024,768,32 `This is our resolution for our window. do `Intialize our main loop cls `Since we're doing lots of drawing and 2D work, it works well to clear the screen first. ink rgb(255,0,0),1 `This command sets the ink for any lines, text, boxes, etc. that we use. text 0,0,"This is red" `Heres use of the text command to show us the red text. `As you may have noticed, the higher value you put in the 'R' or red value, the more influence `of that color you get. What happens when you balance them all out though? ink rgb(255,255,255),1 text 0,30,"This will be white" ink rgb(128,128,128),1 text 0,60,"This will be gray" ink rgb(0,0,0),1 text 0,90,"This is black, though you can't see it because the screen is black!" `This little for-next routine is really going to slow down your computer. `It's not a good idea to put it into your main loop normally, but it's okay for this example. lock pixels `Locking the pixels will help speed up the draw speed here. for x=0 to 255 for y=0 to 255 dot x,y+120,rgb(x,0,0) `This makes dots at the specified x and y co-ordinates. `We add 120 to the y value, so it will be positioned lower than our `previous text. next x next y `Here are the color gradiants for green and blue for x=0 to 255 for y=0 to 255 dot x,y+375,rgb(0,x,0) next x next y for x=0 to 255 for y=0 to 255 dot x,y+630,rgb(0,0,x) next x next y unlock pixels `Unlock the pixels, since we're done with the drawing. `You may be interested in returning the colors currently on screen. To do this `we can use some neat pixel commands. `This returns the pixel color value from our mouse position. `It's a big number, so we'll break it down more. pixelcolor=point(mousex(),mousey()) `These next 3 commands return the red(rgbr), green(rgbg), and blue(rgbb) values) of the `pixel color. red=rgbr(pixelcolor) green=rgbg(pixelcolor) blue=rgbb(pixelcolor) `Now lets just print a simple text statement to show us the values. ink rgb(255,255,255),1 text 400,0,"red="+str$(red)+" green="+str$(green)+" blue="+str$(blue) sync `refresh the screen loop `Send us back to the loop `Hope this tutorial is helps you fully understand RGB and even some of the drawing commands `better. `CurvedBasic 2005 `Mike |