Page 1 of 1

drawing a lightning! how to?

PostPosted: Thu Jan 27, 2011 7:23 pm
by sonicfire
so for example i have this:
Image
no problem using lineto.

but, what if i want to do this ?
Image

i´m simply not sure about the maths here. anyone could guide me?
i always have source and target coordinates but how would i go about "dividing" this
line into lets say 8 [img]lineto[/img]´s with slight random variations but still point to the target? :)

anybody could help me? would be much appreciated :) thanks!!

Re: drawing a lightning! how to?

PostPosted: Thu Jan 27, 2011 7:27 pm
by Hblade
Hmm, thats a hard one.

You can always try:
Code: Select all
for(i=0;i<(distance(x,y,target.x,target.y)/2);i++) {
moveto(x, y);
lineto(i, i);
lineto(i, i);
lineto(target.x, target.y);
}


Untested, but might create a stagger in th emiddle.


There is another method but it's a long rout to take.

Re: drawing a lightning! how to?

PostPosted: Thu Jan 27, 2011 8:07 pm
by sonicfire
Thank you :) Will give it a try!

Re: drawing a lightning! how to?

PostPosted: Thu Jan 27, 2011 10:03 pm
by Game A Gogo
Here's my version :)
Code: Select all
int i,rx,ry;
int Crack=25,Force=25;
setpen(0,127,255,0,3);
moveto(0,0);
for(i=0;i<Crack;i++)
{
    rx=(rand(2)-1)*((float)i/Crack)*Force;
    ry=(rand(2)-1)*((float)i/Crack)*Force;
    lineto(((float)i/Crack)*width+rx,((float)i/Crack)*height+ry);
}

variable Crack is how many segment should crack and Force is the intensity of the cracking.
note, the cracking intensity is graduate, so it starts smoothly to more and more

Re: drawing a lightning! how to?

PostPosted: Thu Jan 27, 2011 10:09 pm
by Game A Gogo
exemple that follows the mouse (put in draw actor)
Code: Select all
int i,rx,ry;
int Crack=25,Force=25;
erase(0,0,0,1);
setpen(0,127,255,0,3);
moveto(320,240);
for(i=0;i<Crack;i++)
{
    rx=(rand(2)-1)*((float)i/Crack)*Force;
    ry=(rand(2)-1)*((float)i/Crack)*Force;
    lineto((((float)i/Crack)*(xmouse-320)+rx)+320,(((float)i/Crack)*(ymouse-240)+ry)+240);
}

or
Code: Select all
int i,rx,ry;
int Crack=10,Force=10;
erase(0,0,0,1);
setpen(0,127,255,0,3);
moveto(320,240);
for(i=0;i<Crack;i++)
{
    rx=(rand(2)-1)*min(1,((float)i/Crack)*3)*Force;
    ry=(rand(2)-1)*min(1,((float)i/Crack)*3)*Force;
    lineto((((float)i/Crack)*(xmouse-320)+rx)+320,(((float)i/Crack)*(ymouse-240)+ry)+240);
}

Re: drawing a lightning! how to?

PostPosted: Fri Jan 28, 2011 1:55 am
by sonicfire
:shock: amazing, thanks very much!
thank you both :D