Sign in to follow this  
Followers 0
MrPink

Clean graph because of old data

7 posts in this topic

Hello,

i want to clean a graph that i filled with dots. It should show a dot that is moving within a graph but at the moment i see all dots that were drawn. I take the x and y values from different panels.

Here is my script:

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

GUICreate("", 340, 330)
GUISetOnEvent($GUI_EVENT_CLOSE,"close")


$GraphWidth = 273
$GraphHeight = 273

$graph = GUICtrlCreateGraphic(48, 15, $GraphWidth, $GraphHeight)
GUICtrlSetBkColor(-1,0xFFFFFF)
GUICtrlSetColor(-1,0x000000)


$yMax = 100         ;this is the upper label for y axis
$yMin = 0               ;this is the lower label for y axis

$xMax = 100        ;this is the upper label for x axis
$xMin = 0               ;this is the lower label for x axis

GUICtrlCreateLabel($yMax,15,10,20,15,$SS_RIGHT)
GUICtrlCreateLabel($yMin,15,280,20,15,$SS_RIGHT)

GUICtrlCreateLabel($xMax,307,295,20,15,$SS_CENTER)
GUICtrlCreateLabel($xMin,38,295,20,15,$SS_CENTER)

GUISetState()

While 1
    
;---------- GET THE X,Y VALUES -----------------------------------
    If WinExists("x-coords") Then
        $fXcoord = Number(ControlGetText("x-coords", "", "Edit1"))
        $fYcoord = Number(ControlGetText("y-coords", "", "Edit1"))
;~  MsgBox(64, "Text", $sText)
    EndIf
;-----------------------------------------------------------------

;---------- PLOT THE POINTS ----------
    GUICtrlSetGraphic ($graph,$GUI_GR_DOT,Gen_Abs_Pix_x($fXcoord,$xMin,$xMax,$GraphWidth), Gen_Abs_Pix_y($fYcoord,$yMin,$yMax,$GraphHeight))
    GUICtrlSetGraphic ($graph,$GUI_GR_REFRESH)
;-----------------------------------------------------------------

;~  MsgBox(0,"hallo",$sText)
    
    Sleep(100)
WEnd

func Gen_Abs_Pix_x($x,$low,$high,$width)
    $out = (($width/($high-$low))*(($high-$low)*(($x-$low)/($high-$low))))
    Return $out
EndFunc

func Gen_Abs_Pix_y($y,$low,$high,$height)
    $out = ($height - (($height/($high-$low))*(($high-$low)*(($y-$low)/($high-$low)))))
    Return $out
EndFunc


func close()
    Exit
EndFunc

Can someone give me a hint how i can possibly clear the GUI from the old points ??

Share this post


Link to post
Share on other sites



Set the previous graphic dot to white before drawing the next graphic dot. There's probably a better way to do it, but I'm not to good with graphic controls.

Opt("GUIOnEventMode", 1)

GUICreate("", 340, 330)
GUISetOnEvent($GUI_EVENT_CLOSE,"close")


$GraphWidth = 273
$GraphHeight = 273

$graph = GUICtrlCreateGraphic(48, 15, $GraphWidth, $GraphHeight)
GUICtrlSetBkColor(-1,0xFFFFFF)
GUICtrlSetColor(-1,0x000000)


$yMax = 100            ;this is the upper label for y axis
$yMin = 0                ;this is the lower label for y axis

$xMax = 100           ;this is the upper label for x axis
$xMin = 0                ;this is the lower label for x axis

GUICtrlCreateLabel($yMax,15,10,20,15,$SS_RIGHT)
GUICtrlCreateLabel($yMin,15,280,20,15,$SS_RIGHT)

GUICtrlCreateLabel($xMax,307,295,20,15,$SS_CENTER)
GUICtrlCreateLabel($xMin,38,295,20,15,$SS_CENTER)

GUISetState()
$fXcoord = 2
$fYcoord = 2
While 1
    If $fXcoord = 98 Then $fXcoord = 2
    If $fYcoord = 98 Then $fYcoord = 2
    $fXcoord += 2 
    $fYcoord += 2  
;---------- GET THE X,Y VALUES -----------------------------------
;~     If WinExists("x-coords") Then
;~         $fXcoord = Number(ControlGetText("x-coords", "", "Edit1"))
;~         $fYcoord = Number(ControlGetText("y-coords", "", "Edit1"))
;~     MsgBox(64, "Text", $sText)
;~     EndIf
;-----------------------------------------------------------------

;---------- PLOT THE POINTS ----------
    GUICtrlSetGraphic($graph, $GUI_GR_COLOR, 0xffffff)
    GUICtrlSetGraphic ($graph,$GUI_GR_DOT,Gen_Abs_Pix_x($fXcoord - 2,$xMin,$xMax,$GraphWidth), Gen_Abs_Pix_y($fYcoord - 2,$yMin,$yMax,$GraphHeight))
    GUICtrlSetGraphic($graph, $GUI_GR_COLOR, 0x000000)
    GUICtrlSetGraphic ($graph,$GUI_GR_DOT,Gen_Abs_Pix_x($fXcoord,$xMin,$xMax,$GraphWidth), Gen_Abs_Pix_y($fYcoord,$yMin,$yMax,$GraphHeight))
    GUICtrlSetGraphic ($graph,$GUI_GR_REFRESH)
;-----------------------------------------------------------------

;~     MsgBox(0,"hallo",$sText)
    
    Sleep(100)
WEnd

func Gen_Abs_Pix_x($x,$low,$high,$width)
    $out = (($width/($high-$low))*(($high-$low)*(($x-$low)/($high-$low))))
    Return $out
EndFunc

func Gen_Abs_Pix_y($y,$low,$high,$height)
    $out = ($height - (($height/($high-$low))*(($high-$low)*(($y-$low)/($high-$low)))))
    Return $out
EndFunc


func close()
    Exit
EndFunc
I notice GUICtrlSetGraphic() in a loop seems to flicker alot, but that's probably just something I'm doing wrong with GUICtrlSetGraphic()

I think I'd do it with GDI+ and win api invalidte region if I was going to approach something like this myself.

Cheers

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

thats what i thought too .. but then you will still see the black dots because of the flickering (it is updated every 100ms). so it draws white dots over the black dots, but the black dots are still there and will show up once in a while ;o) BTW i couldn't find out how to stop the flickering either. what i read was that it is because of renewed everything at the refresh.

Edited by MrPink

Share this post


Link to post
Share on other sites

i found at least the solution for erasing the old points. easily delete the GUI and create a new one ;o)

here is the working code (the flickering is still not solved):

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

GUICreate("", 340, 330)
GUISetOnEvent($GUI_EVENT_CLOSE,"close")


$GraphWidth = 273
$GraphHeight = 273

$graph = GUICtrlCreateGraphic(48, 15, $GraphWidth, $GraphHeight)
GUICtrlSetBkColor(-1,0xFFFFFF)
GUICtrlSetColor(-1,0x000000)


$yMax = 1024            ;this is the upper label for y axis
$yMin = 0               ;this is the lower label for y axis

$xMax = 1024           ;this is the upper label for x axis
$xMin = 0               ;this is the lower label for x axis

GUICtrlCreateLabel($yMax,15,10,20,15,$SS_RIGHT)
GUICtrlCreateLabel($yMin,15,280,20,15,$SS_RIGHT)

GUICtrlCreateLabel($xMax,307,295,20,15,$SS_CENTER)
GUICtrlCreateLabel($xMin,38,295,20,15,$SS_CENTER)

GUISetState()

$fXcoordold=1
$fYcoordold=1

While 1

    $graph = GUICtrlCreateGraphic(48, 15, $GraphWidth, $GraphHeight)
    
;---------- GET THE X,Y VALUES -----------------------------------
    If WinExists("x-coords") Then
        $fXcoord = Number(ControlGetText("x-coords", "", "Edit1"))
        $fYcoord = Number(ControlGetText("y-coords", "", "Edit1"))
    EndIf
;-----------------------------------------------------------------

;---------- PLOT THE POINTS --------------------------------------
    GUICtrlSetGraphic ($graph,$GUI_GR_DOT,Gen_Abs_Pix_x($fXcoord,$xMin,$xMax,$GraphWidth), Gen_Abs_Pix_y($fYcoord,$yMin,$yMax,$GraphHeight))
    GUICtrlSetGraphic ($graph,$GUI_GR_REFRESH)
;-----------------------------------------------------------------
    
    Sleep(50)
    GUICtrlDelete($graph)
WEnd

func Gen_Abs_Pix_x($x,$low,$high,$width)
    $out = (($width/($high-$low))*(($high-$low)*(($x-$low)/($high-$low))))
    Return $out
EndFunc

func Gen_Abs_Pix_y($y,$low,$high,$height)
    $out = ($height - (($height/($high-$low))*(($high-$low)*(($y-$low)/($high-$low)))))
    Return $out
EndFunc


func close()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hi,

Try deleting/recreating the graphics control after the sleep(100)

It won't solve the flickering though.

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

GUICreate("", 340, 330)
GUISetOnEvent($GUI_EVENT_CLOSE,"close")


$GraphWidth = 273
$GraphHeight = 273

$graph = GUICtrlCreateGraphic(48, 15, $GraphWidth, $GraphHeight)
GUICtrlSetBkColor(-1,0xFFFFFF)
GUICtrlSetColor(-1,0x000000)


$yMax = 100            ;this is the upper label for y axis
$yMin = 0                ;this is the lower label for y axis

$xMax = 100           ;this is the upper label for x axis
$xMin = 0                ;this is the lower label for x axis

GUICtrlCreateLabel($yMax,15,10,20,15,$SS_RIGHT)
GUICtrlCreateLabel($yMin,15,280,20,15,$SS_RIGHT)

GUICtrlCreateLabel($xMax,307,295,20,15,$SS_CENTER)
GUICtrlCreateLabel($xMin,38,295,20,15,$SS_CENTER)

GUISetState()
$fXcoord = 2
$fYcoord = 2
While 1
    If $fXcoord = 98 Then $fXcoord = 2
    If $fYcoord = 98 Then $fYcoord = 2
    $fXcoord += 2 
    $fYcoord += 2  
;---------- GET THE X,Y VALUES -----------------------------------
;~     If WinExists("x-coords") Then
;~         $fXcoord = Number(ControlGetText("x-coords", "", "Edit1"))
;~         $fYcoord = Number(ControlGetText("y-coords", "", "Edit1"))
;~     MsgBox(64, "Text", $sText)
;~     EndIf
;-----------------------------------------------------------------

;---------- PLOT THE POINTS ----------
    GUICtrlSetGraphic ($graph,$GUI_GR_DOT,Gen_Abs_Pix_x($fXcoord,$xMin,$xMax,$GraphWidth), Gen_Abs_Pix_y($fYcoord,$yMin,$yMax,$GraphHeight))
    GUICtrlSetGraphic ($graph,$GUI_GR_REFRESH)
;-----------------------------------------------------------------

;~     MsgBox(0,"hallo",$sText)
    
    Sleep(100)
    
    GUICtrlDelete ($graph)
    $graph = GUICtrlCreateGraphic(48, 15, $GraphWidth, $GraphHeight)
    GUICtrlSetBkColor(-1,0xFFFFFF)
    GUICtrlSetColor(-1,0x000000)    
WEnd

func Gen_Abs_Pix_x($x,$low,$high,$width)
    $out = (($width/($high-$low))*(($high-$low)*(($x-$low)/($high-$low))))
    Return $out
EndFunc

func Gen_Abs_Pix_y($y,$low,$high,$height)
    $out = ($height - (($height/($high-$low))*(($high-$low)*(($y-$low)/($high-$low)))))
    Return $out
EndFunc


func close()
    Exit
EndFunc

Cheers

Edit: I was to slow to post.. doh

Edited by smashly

Share this post


Link to post
Share on other sites

but its funny that we both found 2 solutions almost at the same time ;o) thank you anyway for your effort !!

Share this post


Link to post
Share on other sites

Has anyone come up with a solution to this? Do Graphics controls just not support $GUI_HIDE?

I haven't played with AutoIt for a long time, so pardon me if this is a stupid question.

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  
Followers 0