Sign in to follow this  
Followers 0
navajo

Lines drawn with GUICtrlSetGraphic drop

2 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

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