找回密码
 加入
搜索
查看: 1824|回复: 3

[网络通信] 已解决 虚心求教 用GUI 怎么画圆(一个点的运动轨迹是圆)

[复制链接]
发表于 2021-1-10 22:10:57 | 显示全部楼层 |阅读模式
本帖最后由 itzyx 于 2021-1-11 14:09 编辑

各位大佬,我想用GUI 画一个圆(一个点的运动轨迹是圆),备注:是从原点开始的 像素点,第一,轨迹是不连贯的,不会连在一起;   第二, 可以调节像素点的运动速度;
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIGdi.au3>
#include <StaticConstants.au3>

Global $hDC, $hPen_Background, $hPen_Progress, $obj_orig
Global Const $_color_Background = 0x000000 ; 画线进度条的底色
Global Const $_color_Progress = 0x0000ff ; 画线进度条的前景色
Global Const $start_x = 920 ; 圆心x
Global Const $start_y = 500 ; 圆心y
Global Const $length = 400 ; 半径
Global Const $width = 5 ; 宽度
Global Const $Label1_l = 60 ; $Label1 的宽度
Global Const $Label1_h = 17 ; $Label1 的高度
Global Const $Label1_x = $start_x - Int($Label1_l / 2) - 2 ; $Label1 的位置x
Global Const $Label1_y = $start_y - 15 ; $Label1 的位置y

$Form1 = GUICreate('曝光测试',1840,960,-1,-1)
$button1 = GUICtrlCreateButton("开始", 20, 920, 130, 30)
$button2 = GUICtrlCreateButton("停止", 200, 920, 130, 30)
$Label1 = GUICtrlCreateLabel("0/0", $Label1_x, $Label1_y, $Label1_l, $Label1_h, $SS_CENTER)
GUISetBkColor(0x000000)
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $button1
                        _Main()


        EndSwitch
WEnd

Func _Main()
        _LineProgress_prep() ; 准备
        Local $i_num = 10; 总个数
        Local $i_progress
        For $i = 1 To $i_num
                ; 代码
                Sleep(100)
                $i_progress = Int($i / $i_num * 360)
                _LineProgress_draw($i_progress) ;画进度线
                GUICtrlSetData($Label1, $i & "/" & $i_num)
        Next
        _LineProgress_clean() ; 清除画线
EndFunc   ;==>_Main

Func _LineProgress_prep() ; 准备
        $hDC = _WinAPI_GetWindowDC($Form1) ; 场景
        $hPen_Background = _WinAPI_CreatePen($PS_SOLID, $width, $_color_Background)
        $hPen_Progress = _WinAPI_CreatePen($PS_SOLID, $width, $_color_Progress)
        $obj_orig = _WinAPI_SelectObject($hDC, $hPen_Background) ; 使用画底色的笔。
        _WinAPI_MoveTo($hDC, $start_x, $start_y - $length)
        $obj_orig = _WinAPI_SelectObject($hDC, $hPen_Progress) ; 使用画前景色的笔
EndFunc   ;==>_LineProgress_prep

Func _LineProgress_draw($_progress) ;画进度线
;~         $_progress 范围: 0-360
                _WinAPI_MoveTo($hDC, $start_x, $start_y - $length)
        _WinAPI_AngleArc($hDC, $start_x, $start_y, $length, 90, -$_progress)
EndFunc   ;==>_LineProgress_draw

Func _LineProgress_clean() ; 清除资源
        ; 清除画线
        _WinAPI_RedrawWindow($Form1)
        ; 清除资源
        _WinAPI_SelectObject($hDC, $obj_orig)
        _WinAPI_DeleteObject($hPen_Background)
        _WinAPI_DeleteObject($hPen_Progress)
        _WinAPI_ReleaseDC(0, $hDC)
EndFunc   ;==>_LineProgress_clean
这个代码能画出实线,我想改成 一个点的运动,不连成线,  不按停止会一直运动, 如果按停止 会在一个固定的位置,呈现的是一个像素点。   这方面的知识我是一点不懂,希望各位大佬能指点一二,感谢(自己摸索了一下,实现了基本的功能)
发表于 2021-1-11 20:43:49 | 显示全部楼层
标题为已解决的主题,一定要附上解决方法,否则就是无意义问题。
 楼主| 发表于 2021-1-12 09:45:56 | 显示全部楼层
afan 发表于 2021-1-11 20:43
标题为已解决的主题,一定要附上解决方法,否则就是无意义问题。

好的  A大  之前不知道,下次一定注意
 楼主| 发表于 2021-1-12 09:47:28 | 显示全部楼层
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>



$pi = 3.14159265358979
Local $iCount = 0


$Form1 = GUICreate("圆", 1840,960,-1,-1,BitOR($WS_MINIMIZEBOX,$WS_SYSMENU,$WS_POPUP,$WS_GROUP,$WS_CLIPSIBLINGS))


$Label1 = GUICtrlCreateLabel('。', 920, 500, 10, 10)
GUISetBkColor(0x000000)
GUICtrlSetColor($Label1, 0xff0000)

$Label = GUICtrlCreateLabel("。", 920, 500, 10, 10)
$x = 400 * sin( 20 * $pi / 180)

AdlibRegister('_TimerProc',5)
;_TimerProc()
GUISetState(@SW_SHOW)


Func _TimerProc()
        $iCount = $iCount + 1
        $x = 400* cos(0.15 * $iCount * $pi / 180)
        $y = 400* sin(0.15 * $iCount * $pi / 180)

GUICtrlSetPos($Label, 920+ $x, 500+ $y)

        GUICtrlSetColor(-1, 0xFFFFFF)
EndFunc

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        AdlibUnRegister('_TimerProc')
                        Exit

        EndSwitch
WEnd

换种思维,用角度去画圆就方便点了,速度是在代码里面调的,就没设置 按钮了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-18 17:06 , Processed in 0.069449 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表