Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
51
Task/Draw-a-clock/PureBasic/draw-a-clock.purebasic
Normal file
51
Task/Draw-a-clock/PureBasic/draw-a-clock.purebasic
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#MiddleX = 90 + 1 ;x,y must be odd numbers, minimum width is 67
|
||||
#MiddleY = #MiddleX
|
||||
#len_sh = (#MiddleX - 8) * 0.97 ;length of second-hand
|
||||
#len_mh = (#MiddleX - 8) * 0.88 ;length of minute-hand
|
||||
#len_hh = (#MiddleX - 8) * 0.66 ;length of hour-hand
|
||||
#clockFace_img = 0
|
||||
#clock_gad = 0
|
||||
#clock_win = 0
|
||||
|
||||
Define cx = #MiddleX, cy = #MiddleY, i, ri.f
|
||||
Define c_gray = RGB($CC, $CC, $CC), c_mgray = RGB($99, $99, $99)
|
||||
Define c_white = RGB(255, 255, 255), c_black =RGB(0, 0, 0)
|
||||
Define c_red = RGB(255, 0, 0), c_blue = RGB(0, 0, 255)
|
||||
Define c_dcyan = RGB($27, $BC, $D8), c_lgreen = RGB($60, $E0, $9)
|
||||
Define c_yellow = RGB($F4, $D5, $0B)
|
||||
|
||||
CreateImage(#clockFace_img, cx * 2 - 1, cy * 2 - 1)
|
||||
StartDrawing(ImageOutput(#clockFace_img))
|
||||
Box(0, 0, cx * 2 - 1, cy * 2 - 1, c_mgray)
|
||||
Circle(cx, cy, cx - 2, c_dcyan)
|
||||
For i = 0 To 359 Step 30
|
||||
ri = Radian(i)
|
||||
Circle(cx + Sin(ri) * (cx - 5), cy + Cos(ri) * (cx - 5), 3, c_gray)
|
||||
Next
|
||||
StopDrawing()
|
||||
OpenWindow(#clock_win, 0, 0, cx * 2, cy * 2, "Clock")
|
||||
ImageGadget(#clock_gad, 0, 0, cx * 2, cy * 2, ImageID(#clockFace_img))
|
||||
|
||||
Define x, y, rad_s.f, rad_m.f, rad_h.f, t$
|
||||
Repeat
|
||||
event = WaitWindowEvent(25)
|
||||
If event = 0
|
||||
rad_s = Radian(360 - (Second(Date()) * 6) + 180)
|
||||
rad_m = Radian(360 - (Minute(Date()) * 6) + 180)
|
||||
rad_h = Radian(360 - (((Hour(Date()) - 1) * 30) + 180) - (Minute(Date()) / 2))
|
||||
|
||||
StartDrawing(ImageOutput(#clockFace_img))
|
||||
Circle(cx, cy, cx - 8, c_lgreen)
|
||||
t$ = FormatDate("%mm-%dd-%yyyy", Date())
|
||||
x = cx - (TextWidth(t$) + 2) / 2
|
||||
y = (cy - (TextHeight(t$) + 2) - 4) / 2
|
||||
Box(x, y, TextWidth(t$) + 2, TextHeight(t$) + 2, c_black)
|
||||
DrawText(x + 2, y + 2, t$, c_black, c_yellow)
|
||||
LineXY(cx, cy, cx + Sin(rad_s) * #len_sh, cy + Cos(rad_s) * #len_sh, c_white)
|
||||
LineXY(cx, cy, cx + Sin(rad_m) * #len_mh, cy + Cos(rad_m) * #len_mh, c_red)
|
||||
LineXY(cx, cy, cx + Sin(rad_h) * #len_hh, cy + Cos(rad_h) * #len_hh, c_black)
|
||||
Circle(cx, cy, 4, c_blue)
|
||||
StopDrawing()
|
||||
SetGadgetState(#clock_gad, ImageID(#clockFace_img))
|
||||
EndIf
|
||||
Until event = #PB_Event_CloseWindow
|
||||
Loading…
Add table
Add a link
Reference in a new issue