Page 1 of 1

This code

PostPosted: Fri Sep 26, 2008 2:10 am
by segwego12
I'm trying to make a plasma effect, what should I do to this code so Game Editor can handle it?
Code: Select all
int main(int argc, char *argv[])
{
    screen(256, 256, 0, "Plasma");

    for(int x = 0; x < w; x++)
    for(int y = 0; y < h; y++)
    {
        int color = int(128.0 + (128.0 * sin(x / 8.0)));
        pset(x, y, ColorRGB(color, color, color));
    }
    redraw();
    sleep();
    return(0);
}

Re: This code

PostPosted: Fri Sep 26, 2008 12:31 pm
by segwego12
hello?

Re: This code

PostPosted: Fri Sep 26, 2008 3:17 pm
by Spidy
maybe makslane will help ya

Re: This code

PostPosted: Fri Sep 26, 2008 4:43 pm
by segwego12
ok.

Re: This code

PostPosted: Sat Sep 27, 2008 1:01 am
by makslane
1) Create a canvas actor
2) In the 'Draw Actor' event of the canvas, put the code:

Code: Select all
int x1, y1;

for(x1 = 0; x1 < width; x1++)
{
    for(y1 = 0; y1 < height; y1++)
    {
        int color = 128.0 + (128.0 * sin(x1 / 8.0));
 
        setpen(color, color, color, 0, 1);
        putpixel(x1, y1);
    }
}


The result will be:

Re: This code

PostPosted: Sat Sep 27, 2008 1:08 am
by makslane
With little changes, we ca have other patterns:

Code: Select all
int x1, y1;


for(x1 = 0; x1 < width; x1++)
{
    for(y1 = 0; y1 < height; y1++)
    {
        int color = 128.0 + (128.0 * sin(x1*y1/32.0));
 
        setpen(color, color, color, 0, 1);
        putpixel(x1, y1);
    }
}

Re: This code

PostPosted: Sat Sep 27, 2008 1:21 am
by makslane
Now, an animated color effect:

Code: Select all
int x1, y1;

for(x1 = 0; x1 < width; x1++)
{
    for(y1 = 0; y1 < height; y1++)
    {
        int red = 128.0 + (128 * sin((1/(float)frame)*x1*y1/10.0));
        int green = 128.0 + (128 * sin((1/(float)frame)*x1*y1/5.0));
        int blue = 128.0 + (128 * sin((1/(float)frame)*x1*y1/2.0));
 
        setpen(red, green, blue, 0, 1);
        putpixel(x1, y1);
    }
}


plasma3.jpg


And the ged file
plasma.zip
(1 KiB) Downloaded 95 times

Re: This code

PostPosted: Sat Sep 27, 2008 2:06 am
by segwego12
makslane wrote:Now, an animated color effect:

Code: Select all
int x1, y1;

for(x1 = 0; x1 < width; x1++)
{
    for(y1 = 0; y1 < height; y1++)
    {
        int red = 128.0 + (128 * sin((1/(float)frame)*x1*y1/10.0));
        int green = 128.0 + (128 * sin((1/(float)frame)*x1*y1/5.0));
        int blue = 128.0 + (128 * sin((1/(float)frame)*x1*y1/2.0));
 
        setpen(red, green, blue, 0, 1);
        putpixel(x1, y1);
    }
}


plasma3.jpg


And the ged file
plasma.zip

Thank you makslane, Now, when can I learn to make fire?

Re: This code

PostPosted: Sat Sep 27, 2008 8:09 pm
by edh
+1 point for makslane, this is something new I learned.