Jump to content
Sign in to follow this  

Scripting a graph drawer

Recommended Posts

I have been scripting on a script that simple draws a curve in a GUI window, it's pretty sweet, but I have some problems.

First I just draw each pixel with the GUI_GR_PIXEL but that turned out ugly when there was very high difference between the y coordinates. So I used the GUI_GR_LINE instead but I don't get it, it works great when the curve is just a straight line, but when for example using a y = x^2 ekvation there is a line from the top edge of the screen to the curve, my drawing code looks like this:

Global $width=850
Global $height=650
Global $prec=0.015

;some code

Dim $oldx, $oldy
For $x=-($width/2) to $width/2 Step $prec
$y = $x^2 ; Ekvationen som ska ritas
$tcoord = translate($x,$y)
$oldx = $tcoord[0]
$oldy = $tcoord[1]
;~ GUICtrlSetGraphic($graph,$GUI_GR_PIXEL,$tcoord[0],$tcoord[1])

; Some code

Func translate ($x, $y)
    Dim $answer[2]
    $answer[0] = $width/2-$x*-1
    $answer[1] = $height/2-$y
    Return $answer

That was my graphical problem, my next is that I need a function that returns the answer of an expression, for example:

_expression("2^3*sin(0)+5") would return 5

So my question is: Has made a function like, cause I really don't know how I would script it myself.

Thanks in advance!

Broken link? PM me and I'll send you the file!

Share this post

Link to post
Share on other sites

I had the same problem with the graphic thing. Maybe the link in my sig can help (Sin, Cos, Tan drawer).

I changed $GUI_GR_LINE with $GUI_GR_DOT and it looks good. The higher the value of $prec is, the uglier it will look and the faster it will be drawn, of course.

Share this post

Link to post
Share on other sites

The problem with drawing each pixel is that it's going to be super ugly if you use for example tan(), and I know there is someway to do the $GUI_GR_LINE thing right, (read in the help file about something named $GUI_GR_CLOSE but I didn't understand it.)

Does anybody know about the function? I could maybe do it but it would be alot of ugly code and ALOT of StringInstr()

Broken link? PM me and I'll send you the file!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...