fill canvas easy script.

Talk about making games.

fill canvas easy script.

Postby savvy » Mon May 16, 2011 5:54 pm

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
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: fill canvas easy script.

Postby Hblade » Mon May 16, 2011 5:55 pm

cool :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: fill canvas easy script.

Postby Kodo » Mon May 16, 2011 6:16 pm

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
Inogames: http://www.inogames.com iOS gaming
Firetop Adventure (app store): http://itunes.apple.com/us/app/firetop- ... ?mt=8&ls=1
User avatar
Kodo
 
Posts: 449
Joined: Thu Oct 20, 2005 8:20 pm
Location: UK
Score: 23 Give a positive score

Re: fill canvas easy script.

Postby Game A Gogo » Mon May 16, 2011 8:42 pm

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
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron