Halcon 画一个时钟

直接上代码:

dev_update_off()
dev_close_window()
dev_open_window(0, 0, 512, 512, 'white', WindowHandle)
set_display_font(WindowHandle, 16, 'mono', 'true', 'false')
dev_set_draw('margin')
dev_set_color('black')
CenterX := 512 / 2
CenterY := 512 / 2
while(true)
    dev_clear_window()    
    dev_set_line_width(5)
    disp_circle(WindowHandle, CenterY, CenterX, 2)
    disp_circle(WindowHandle, CenterY, CenterX, 100)
    dev_set_line_width(2)
    disp_circle(WindowHandle, CenterY, CenterX, 105)
    for I := 1 to 12 by 1
        MarkAngle := 360 / 12 * I - 90
        MarkX1 := CenterX + 100 * cos(rad(MarkAngle))        
        MarkY1 := CenterY + 100 * sin(rad(MarkAngle))
        MarkX2 := CenterX + 90 * cos(rad(MarkAngle))
        MarkY2 := CenterY + 90 * sin(rad(MarkAngle))
        Text := '' + I
        get_string_extents(WindowHandle, Text, Ascent, Descent, Width, Height)
        TextX := CenterX + 80 * cos(rad(MarkAngle)) - Width / 2
        TextY := CenterY + 80 * sin(rad(MarkAngle)) - Height / 2
        disp_line(WindowHandle, MarkY1, MarkX1, MarkY2, MarkX2)
        disp_text(WindowHandle, '' + I, 'image', TextY, TextX, 'black', ['box'], ['false'])
    endfor    
    get_system_time(MSecond, Second, Minute, Hour, Day, YDay, Month, Year)
    if (Hour > 12)
        Hour := Hour - 12
    endif
    dev_set_line_width(3)
    HourAngle := 360 / 12 * Hour - 90
    HourX := CenterX + 50 * cos(rad(HourAngle))
    HourY := CenterY + 50 * sin(rad(HourAngle))
    disp_line(WindowHandle, CenterY, CenterX, HourY, HourX)
    dev_set_line_width(2)
    MinuteAngle := 360 / 60 * Minute - 90
    MinuteX := CenterX + 60 * cos(rad(MinuteAngle))
    MinuteY := CenterY + 60 * sin(rad(MinuteAngle))
    disp_line(WindowHandle, CenterY, CenterX, MinuteY, MinuteX)
    dev_set_line_width(1)
    SecondAngle := 360 / 60 * Second - 90
    SecondX := CenterX + 70 * cos(rad(SecondAngle))
    SecondY := CenterY + 70 * sin(rad(SecondAngle))
    disp_line(WindowHandle, CenterY, CenterX, SecondY, SecondX)
    wait_seconds(1)
endwhile

效果:

 

posted @ 2023-02-05 22:38  广阔之海  阅读(83)  评论(0编辑  收藏  举报