#Graph Preview on the Inspector like Curve class

19 messages · Page 1 of 1 (latest)

surreal pine
#

I would like a graph preview from the parameter that I have exported,

But if I extended from Curve class.
I would have to plot f(x) as y right??? then the only way curve class allow us to manipulate graph was to add point to it

therefore, I would have to plot many (x,f(x)) point in the curve as much as possible with more than 100 point which doesn't give that much accurate graph. The graph became unintuitive line of square( because the each point represented as a big square in the graph)

This is an example that I plotted the sin graph. as can be seen in the small preview it just a sin graph with some frequency but the editor show each point as square and becoming a very confusing picture.

red elbow
#

Can you show the code for this?

surreal pine
#

let me recreate it a bit

#

it should goes along these line

#

sry I couldn't post the exact one caz the @tool stop working

#

but the idea is that I wanted to preview some function as a graph, but don't know which module would help or could we turn off the point visual

red elbow
#

well you have a curve range from 0 to 1, so if you want to have a full run of the sine function with a resolution of 1/1000th of a unit, i'd probably go with something like:

for i in 1000:
   var x = float(i)/1000.0   # float division!
   preview_graph.add_point(Vector2(x, polynom(x))

and then for polynom:

func polynom(x:float) -> float:
    # we have an x range of 0 to 1 and we want to show one full run of the sine function, so lets 
    # multiply x with TAU (2*PI) for a full run..
    return sin (TAU * x)  
surreal pine
#

well I didn't mean to replicate the sine function. I still haven't figure hot my actual function will be scale to 0,1 yet but it a polynomial so I use the above function as the example

#

as u can see I +1/2 the above function so the scale could fit in the first quadrant

#

but u see the problem is that when it come to complex polynomial graph it could show to preview nicely @red elbow

red elbow
#

I did this with a custom control and a custom inspector plugin.

#

its basicalyl the same approach just that there is more control over the drawing process this way

surreal pine
#

Oh thanks this is what I'm looking for. I still haven't been familiar with the Control and Inspector plugin script. Are there any suggestion on the related docs. I have go through the Curve classes but found nothing

red elbow
#

well not really i collected this from a lot of random stuff on the web and some experimentation