Page 1 of 1

fill canvas easy script.

PostPosted: Mon May 16, 2011 5:54 pm
by savvy
here, i was bored and made a script for a fill canvas function. just use..
Code: Select all
fill(R,G,B);

in order to fill the canvas its put into.

Code: Select all
void fill (int R, int G, int B)
{
    int i,j;
    for(j=0;j<height;j++)
    {
    for(i=0;i<width;i++)
    {
        setpen(R,G,B,0,1);
        putpixel(i,j);
    }
    }
}

its very simple, the j loop scans along the canvas, and everytime it moves 1 pixel its filled the height also (the i loop) placing a pixel at point i,j.
then i have a simple setpen to mark out the colour indicated in the function.

have fun :)

savvy

Re: fill canvas easy script.

PostPosted: Mon May 16, 2011 5:55 pm
by Hblade
cool :D

Re: fill canvas easy script.

PostPosted: Mon May 16, 2011 6:16 pm
by Kodo
Nice, there is also an even easier way to do this that is already built in to GE. You can use the Erase funciton:

erase(0, 0, 0, .5);

erase(int r, int g, int b, double transp)
-r: red component (0 - 255)
-g: green component (0 - 255)
-b: blue component (0 - 255)
-transparency: (0.0 - 1.0)

This function will have the effect of clearing the canvas to the specified color and transparency, very useful :) You might have missed this increadaibly useful script reference that tells you about all of the built in functions: http://game-editor.com/docs/script_reference.htm

Re: fill canvas easy script.

PostPosted: Mon May 16, 2011 8:42 pm
by Game A Gogo
Savvy, not that I want to bash your code and your attempts... but this method is very cpu costly (Especially on big canvas) while erase() will run about the same speed for any size