Jump to content

Lines drawn with GUICtrlSetGraphic drop


navajo
 Share

Recommended Posts

Sorry if an anser to this problem has been posted before, I could not find an answer with the forum search

The code below draws a few lines, 200 of them, if you watch close, some of the lines drop from view after they have been drawn.

any suggestions why those lines are dropping? :whistle:

#include <GuiConstants.au3>

$linecount = 0

$Form1 = GUICreate("Lines", 705, 805, 220, 116)
$canvas = GUICtrlCreateGraphic(10, 10, 700, 700)

GUISetState(@SW_SHOW)



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
    EndSwitch
    
    if $linecount <= 200 Then
        sleep(150)      
        rndline($canvas, rndcolor())
        $linecount = $linecount + 1
    EndIf
    
WEnd



Func rndcolor()
    $_c = random(0x000000, 0xffffff, 1)
    return $_c
EndFunc

Func rndline($_canvas, $color = 0x000000) 
    $t_x = Random(10, 600, 1)
    $t_y = random(10, 600, 1)
    
    GUICtrlSetGraphic($_canvas, $GUI_GR_COLOR, $color, $color)
    GUICtrlSetGraphic($canvas, $GUI_GR_LINE, $t_x, $t_y)
    GUICtrlSetGraphic($_canvas, $GUI_GR_REFRESH)
    
EndFunc
Edited by navajo
Link to comment
Share on other sites

any suggestions why those lines are dropping? ;)

Probably because the $GUI_GR_LINE is a "draw-to command, which is probably terminated and re-started from a last-set (not by you) point by the $GUI_GR_REFRESH command.

Suggestion : createa random starting-point, use $GUI_GR_MOVE to get there, than generate a random ending-point, and draw your line. Than refresh the display :

Func rndline($_canvas, $color = 0x000000)
   
    GUICtrlSetGraphic($_canvas, $GUI_GR_COLOR, $color, $color)

            $t_x = Random(10, 600, 1)
            $t_y = random(10, 600, 1)
            GUICtrlSetGraphic($canvas, $GUI_GR_MOVE, $t_x, $t_y)

            $t_x = Random(10, 600, 1)
            $t_y = random(10, 600, 1)
            GUICtrlSetGraphic($canvas, $GUI_GR_LINE, $t_x, $t_y)

    GUICtrlSetGraphic($_canvas, $GUI_GR_REFRESH)
   
EndFunc
Hope that helps. :P

[edit]

It looks like that placing a simple "GUICtrlSetGraphic($canvas, $GUI_GR_MOVE, 20,20)" just above the "while 1" will allso do the job ... No real idea why though. :whistle:

Edited by BitRot
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...