HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Graphs ?

04-27-2009, 07:47 AM#1
Chocobo
Originally from there : http://www.thehelper.net/forums/showthread.php?t=125344

And here : http://www.thehelper.net/forums/showthread.php?t=124870 (very old thing I made 1 year ago through)


If you do not know what it does, here is a video showing what it can do :

(credits to LauraeLc2 who made the video for me)
http://www.youtube.com/watch?v=O0nd0fK2-JQ

this is what I try to reproduce :

http://www.youtube.com/watch?v=ryHYO7HP9p8



This is the (ugly) code I'm using for that :
(source code in second post)


Is there anyway to "shorten" the code or to make the code more efficient (or more readable at least)?


Collapse JASS:
function Calculate takes integer degree, real duration, integer which, real delay, string s, integer precision, boolean additive, boolean delayed, boolean last returns nothing

is the function that does almost everything : pick degree of the parametric functions, the duration, which graph you want (normal or bezier), the delay between lightnings, the lightning you want, the precision of lightnings (use more or less lightnings), if it's an "additive" (that doesn't reset lightning count), if it has to delay the lightning destroy (so they destroy all together when it's false), and if it's the last lightning you are doing (used for "GetTime").

I guess that's too long to explicit everything. Would there be a shorter way of doing what I'm trying to do?

Another question : How would I make it multi instanceable? (could not perform two graphs at same time, or "not able to draw a graph while another graph is being graphed") and without making it slow? (I start to have small problems when delay is set to 0.0, sometimes my computer freezes for 0.5s but I think it depends on the lightning effect I use, I wrote if it's "laggy" or not in the function "LightningList")


source code : http://www.thehelper.net/forums/showthread.php?t=125497 (post 2)


Anothing thing : where does those magic numbers come from when you have to calculate each constant of the graph?


note : can't use vjass
04-30-2009, 10:48 AM#2
Chocobo
bump
05-03-2009, 02:39 AM#3
Silvenon
Well, it's kinda hard to solve your problem since you're the only one who understands the code. I have no time checking all those udg_Lists. Though I think the problem is more simple than that. Try to fill your code with BJDebugMsg functions to check where the error appears (that's what that function is for).

For example:

Collapse JASS:
if degree == 2 then
    set Lightning[i] = AddLightning("CLPB", true, udg_List3[1]*T*T+udg_List3[2]*T+udg_List3[3] ,udg_List4[1]*T*T+udg_List4[2]*T+udg_List4[3], udg_List3[1]*Tmax*Tmax+udg_List3[2]*Tmax+udg_List3[3] ,udg_List4[1]*Tmax*Tmax+udg_List4[2]*Tmax+udg_List4[3])
    if Lightning[i] == null then
        call BJDebugMsg("no lightning")
    else
        call BJDebugMsg("lightning created")
    endif
endif

This is just an example how you can play with it and slowly figure out what's wrong. If the message "no lightning" pops out in map testing, it means that the lightning wasn't created properly, if the message "lighting created" pops out, then the lightning was created and the variable has a value. If no message pops at all, that means degree wasn't equal to 2 in the first place. Get it?

Also, the whole loop construction is pretty weird:

Collapse JASS:
    loop
        exitwhen T >= 1
        set i = i + 1
        set T = T + Tpitch
        set Tmax = T + Tpitch
        if T+Tmax < 1 then
            set Tmax = 1
        endif
        if degree == 2 then
            set Lightning[i] = AddLightning("CLPB", true, udg_List3[1]*T*T+udg_List3[2]*T+udg_List3[3] ,udg_List4[1]*T*T+udg_List4[2]*T+udg_List4[3], udg_List3[1]*Tmax*Tmax+udg_List3[2]*Tmax+udg_List3[3] ,udg_List4[1]*Tmax*Tmax+udg_List4[2]*Tmax+udg_List4[3])
        endif
    endloop

In this case, Tpich will be 36, then T will also be 36, which is far greater then 1. Why does exitwhen have such a low limit?

Quote:
Another question : How would I make it multi instanceable? (could not perform two graphs at same time, or "not able to draw a graph while another graph is being graphed") and without making it slow? (I start to have small problems when delay is set to 0.0, sometimes my computer freezes for 0.5s but I think it depends on the lightning effect I use, I wrote if it's "laggy" or not in the function "LightningList")

Well, first of all, get rid of the TriggerSleepAction functions, because they are really bad and they are probably the ones screwing up the code (lagging, halting etc.). It's best to avoid them either way (especially in a loop, lol :D), I suggest you start using timers.


Ok, I'm done, I'm sorry I wasn't helpful much, but we'll see if you can manage to find the problems, maybe use the advices I gave you (though I still got a hunch the problem are those TriggerSleepAction functions).
05-03-2009, 07:02 AM#4
Chocobo
well, I think that's the "a bit" old code (ListGraphing2), I'm currently using LG5 (LG4 is source code).

it's where i wrote "source code : http://www.thehelper.net/forums/showthread.php?t=125497 (post 2)"

however I'll try to explain more what it does :
- assign to 3 lists coordinates of points you want to link
- select a graph of degree "n" to work with (normal=2~7, bezier=2~5)
- get a 3d parametric function that matches the following condition : passes by "(2+n)" points no matter the way it has to be (it can't be a function since you can have for instance 2 "y" for 1 "x") ; it shorts it passes by the following points : List1~3[Z], List1~3[Z+1], List1~3[Z+2]. Z is a constant that increases by 1 (and starts from 1) until it reaches the number "(DimList-n)".
- (multi instanced) create the graph by surperposing lightnings (where Tpitch defines the accuracy of lightnings, however in warcraft 3 locations have an accuracy of 0.250)
- (multi instanced) remove the lightning over time
- restart all over from step 3 but adds 1 to Z.

but the cons of it :
- can't be multi instanced
- too much parameters to input
- too much thing to prepare before using it
- idk where those magic numbers come from
- code is too long (LG5 is already 1000 lines long for the script and a library of 8 letters of 52)


currently it's using Timers (LG4~5), TriggerSleepAction was not doing much problems in LG2 and over, there was a problem in the timing of graphs and the formula I was using.



>In this case, Tpich will be 36, then T will also be 36, which is far greater then 1. Why does exitwhen have such a low limit?

hmm yea, I think you did read my second link ("http://www.thehelper.net/forums/showthread.php?t=124870 (very old thing I made 1 year ago through)"). there was a big problem between integers and reals in my code, resulting in bugland in my graph (causing a crash for unknown reasons).


the "true" source code I'm using : http://www.thehelper.net/forums/showthread.php?t=125497 (LG4, however I'm already using LG5 which has small improvement on List utilities like sum/add/factor/divide/scale/median/avg.. so perhaps in the future it will do regression graphs.)



there are small parts in the code which are easily improvable, such as :

Collapse JASS:
function CollectData takes real T, real Tmax, integer i returns nothing
    if udg_degree == 2 then
        //degree 2 parametric : at^2 + bt + c
        set udg_RD[1] = udg_List4[1]*T*T + udg_List4[2]*T + udg_List4[3]
        set udg_RD[2] = udg_List5[1]*T*T + udg_List5[2]*T + udg_List5[3]
        set udg_RD[3] = udg_List6[1]*T*T + udg_List6[2]*T + udg_List6[3]
        set udg_RD[4] = udg_List4[1]*Tmax*Tmax + udg_List4[2]*Tmax + udg_List4[3]
        set udg_RD[5] = udg_List5[1]*Tmax*Tmax + udg_List5[2]*Tmax + udg_List5[3]
        set udg_RD[6] = udg_List6[1]*Tmax*Tmax + udg_List6[2]*Tmax + udg_List6[3]
        set udg_Lightnings[i] = CreateLightning()
    endif
    if udg_degree == 3 then
        //degree 3 parametric : at^3 + bt^2 + ct + d
        set udg_RD[1] = udg_List4[1]*T*T*T + udg_List4[2]*T*T + udg_List4[3]*T + udg_List4[4]
        set udg_RD[2] = udg_List5[1]*T*T*T + udg_List5[2]*T*T + udg_List5[3]*T + udg_List5[4]
        set udg_RD[3] = udg_List6[1]*T*T*T + udg_List6[2]*T*T + udg_List6[3]*T + udg_List6[4]
        set udg_RD[4] = udg_List4[1]*Tmax*Tmax*Tmax + udg_List4[2]*Tmax*Tmax + udg_List4[3]*Tmax + udg_List4[4]
        set udg_RD[5] = udg_List5[1]*Tmax*Tmax*Tmax + udg_List5[2]*Tmax*Tmax + udg_List5[3]*Tmax + udg_List5[4]
        set udg_RD[6] = udg_List6[1]*Tmax*Tmax*Tmax + udg_List6[2]*Tmax*Tmax + udg_List6[3]*Tmax + udg_List6[4]
        set udg_Lightnings[i] = CreateLightning()
    endif
    if udg_degree == 4 then
        //degree 4 parametric : at^4 + bt^3 + ct^2 + dt + e
        set udg_RD[1] = udg_List4[1]*T*T*T*T + udg_List4[2]*T*T*T + udg_List4[3]*T*T + udg_List4[4]*T + udg_List4[5]
        set udg_RD[2] = udg_List5[1]*T*T*T*T + udg_List5[2]*T*T*T + udg_List5[3]*T*T + udg_List5[4]*T + udg_List5[5]
        set udg_RD[3] = udg_List6[1]*T*T*T*T + udg_List6[2]*T*T*T + udg_List6[3]*T*T + udg_List6[4]*T + udg_List6[5]
        set udg_RD[4] = udg_List4[1]*Tmax*Tmax*Tmax*Tmax + udg_List4[2]*Tmax*Tmax*Tmax + udg_List4[3]*Tmax*Tmax + udg_List4[4]*Tmax + udg_List4[5]
        set udg_RD[5] = udg_List5[1]*Tmax*Tmax*Tmax*Tmax + udg_List5[2]*Tmax*Tmax*Tmax + udg_List5[3]*Tmax*Tmax + udg_List5[4]*Tmax + udg_List5[5]
        set udg_RD[6] = udg_List6[1]*Tmax*Tmax*Tmax*Tmax + udg_List6[2]*Tmax*Tmax*Tmax + udg_List6[3]*Tmax*Tmax + udg_List6[4]*Tmax + udg_List6[5]
        set udg_Lightnings[i] = CreateLightning()
    endif
    if udg_degree == 5 then
        //degree 5 parametric : at^5 + bt^4 + ct^3 + dt^2 + et + f, a bit long xd
        set udg_RD[1] = udg_List4[1]*T*T*T*T*T + udg_List4[2]*T*T*T*T + udg_List4[3]*T*T*T + udg_List4[4]*T*T + udg_List4[5]*T + udg_List4[6]
        set udg_RD[2] = udg_List5[1]*T*T*T*T*T + udg_List5[2]*T*T*T*T + udg_List5[3]*T*T*T + udg_List5[4]*T*T + udg_List5[5]*T + udg_List5[6]
        set udg_RD[3] = udg_List6[1]*T*T*T*T*T + udg_List6[2]*T*T*T*T + udg_List6[3]*T*T*T + udg_List6[4]*T*T + udg_List6[5]*T + udg_List6[6]
        set udg_RD[4] = udg_List4[1]*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List4[2]*Tmax*Tmax*Tmax*Tmax + udg_List4[3]*Tmax*Tmax*Tmax + udg_List4[4]*Tmax*Tmax + udg_List4[5]*Tmax + udg_List4[6]
        set udg_RD[5] = udg_List5[1]*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List5[2]*Tmax*Tmax*Tmax*Tmax + udg_List5[3]*Tmax*Tmax*Tmax + udg_List5[4]*Tmax*Tmax + udg_List5[5]*Tmax + udg_List5[6]
        set udg_RD[6] = udg_List6[1]*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List6[2]*Tmax*Tmax*Tmax*Tmax + udg_List6[3]*Tmax*Tmax*Tmax + udg_List6[4]*Tmax*Tmax + udg_List6[5]*Tmax + udg_List6[6]
        set udg_Lightnings[i] = CreateLightning()
    endif
    if udg_degree == 6 then
        //degree 6 parametric : at^6 + bt^5 + ct^4 + dt^3 + et^2 + ft + g, that's long :D
        set udg_RD[1] = udg_List4[1]*T*T*T*T*T*T + udg_List4[2]*T*T*T*T*T + udg_List4[3]*T*T*T*T + udg_List4[4]*T*T*T + udg_List4[5]*T*T + udg_List4[6]*T + udg_List4[7]
        set udg_RD[2] = udg_List5[1]*T*T*T*T*T*T + udg_List5[2]*T*T*T*T*T + udg_List5[3]*T*T*T*T + udg_List5[4]*T*T*T + udg_List5[5]*T*T + udg_List5[6]*T + udg_List5[7]
        set udg_RD[3] = udg_List6[1]*T*T*T*T*T*T + udg_List6[2]*T*T*T*T*T + udg_List6[3]*T*T*T*T + udg_List6[4]*T*T*T + udg_List6[5]*T*T + udg_List6[6]*T + udg_List6[7]
        set udg_RD[4] = udg_List4[1]*Tmax*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List4[2]*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List4[3]*Tmax*Tmax*Tmax*Tmax + udg_List4[4]*Tmax*Tmax*Tmax + udg_List4[5]*Tmax*Tmax + udg_List4[6]*Tmax + udg_List4[7]
        set udg_RD[5] = udg_List5[1]*Tmax*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List5[2]*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List5[3]*Tmax*Tmax*Tmax*Tmax + udg_List5[4]*Tmax*Tmax*Tmax + udg_List5[5]*Tmax*Tmax + udg_List5[6]*Tmax + udg_List5[7]
        set udg_RD[6] = udg_List6[1]*Tmax*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List6[2]*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List6[3]*Tmax*Tmax*Tmax*Tmax + udg_List6[4]*Tmax*Tmax*Tmax + udg_List6[5]*Tmax*Tmax + udg_List6[6]*Tmax + udg_List6[7]
        set udg_Lightnings[i] = CreateLightning()
    endif
    if udg_degree == 7 then
        //degree 7 parametric : at^7 + bt^6 + ct^5 + dt^4 + et^3 + ft^2 + gt + h, who would calculate this anyway??
        set udg_RD[1] = udg_List4[1]*T*T*T*T*T*T*T + udg_List4[2]*T*T*T*T*T*T + udg_List4[3]*T*T*T*T*T + udg_List4[4]*T*T*T*T + udg_List4[5]*T*T*T + udg_List4[6]*T*T + udg_List4[7]*T + udg_List4[8]
        set udg_RD[2] = udg_List5[1]*T*T*T*T*T*T*T + udg_List5[2]*T*T*T*T*T*T + udg_List5[3]*T*T*T*T*T + udg_List5[4]*T*T*T*T + udg_List5[5]*T*T*T + udg_List5[6]*T*T + udg_List5[7]*T + udg_List5[8]
        set udg_RD[3] = udg_List6[1]*T*T*T*T*T*T*T + udg_List6[2]*T*T*T*T*T*T + udg_List6[3]*T*T*T*T*T + udg_List6[4]*T*T*T*T + udg_List6[5]*T*T*T + udg_List6[6]*T*T + udg_List6[7]*T + udg_List6[8]
        set udg_RD[4] = udg_List4[1]*Tmax*Tmax*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List4[2]*Tmax*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List4[3]*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List4[4]*Tmax*Tmax*Tmax*Tmax + udg_List4[5]*Tmax*Tmax*Tmax + udg_List4[6]*Tmax*Tmax + udg_List4[7]*Tmax + udg_List4[8]
        set udg_RD[5] = udg_List5[1]*Tmax*Tmax*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List5[2]*Tmax*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List5[3]*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List5[4]*Tmax*Tmax*Tmax*Tmax + udg_List5[5]*Tmax*Tmax*Tmax + udg_List5[6]*Tmax*Tmax + udg_List5[7]*Tmax + udg_List5[8]
        set udg_RD[6] = udg_List6[1]*Tmax*Tmax*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List6[2]*Tmax*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List6[3]*Tmax*Tmax*Tmax*Tmax*Tmax + udg_List6[4]*Tmax*Tmax*Tmax*Tmax + udg_List6[5]*Tmax*Tmax*Tmax + udg_List6[6]*Tmax*Tmax + udg_List6[7]*Tmax + udg_List6[8]
        set udg_Lightnings[i] = CreateLightning()
    endif
endfunction

however, I don't think it will become smaller with a loop (currently I stay at using that because it's safe and understandable)


the script in action :

05-03-2009, 12:03 PM#5
Rising_Dusk
I feel like a cubic spline method would look better.
05-03-2009, 12:11 PM#6
MaD[Lion]
u can make it look smooth by using acceleration, and also require less points