Simple Clock (Source Included)
BlitzMax Forums/BlitzMax Programming/Simple Clock (Source Included)
| ||
Looking at Birdie's massive calculations and CLOCK program for BlitzPLUS ...;Draw Seconds Hand sec=get[2] Line x+(x*.01)*Cos(-90+(sec*6)),y+(y*.01)*Sin(-90+(sec*6)),x+(x*.95)*Cos(-90+(sec*6)),y+(y*.95)*Sin(-90+(sec*6)) ;Draw Minute Hand min#=get[1] min=min+(Float(sec)/Float(60)) Line x+(x*.01)*Cos(-90+(min*6)),y+(y*.01)*Sin(-90+(min*6)),x+(x*.80)*Cos(-90+(min*6)),y+(y*.80)*Sin(-90+(min*6)) ;Draw Hour hour#=get[0] hour=hour+(min/Float(60)) Line x+(x*.01)*Cos(-90+(hour*Float(30))),y+(y*.01)*Sin(-90+(hour*Float(30))),x+(x*.60)*Cos(-90+(hour*Float(30))),y+(y*.60)*Sin(-90+(hour*Float(30))) I endeavored to write a far simpler one with less code and less confusion. So - here you go. Enjoi ! ' Simple Clock by David W (dw817) 12-18-15 Strict Global t$,h,m,s Graphics 640,480 SetBlend solidblend SetLineWidth 6 Repeat SetScale 3,3 DrawText CurrentTime$(),10,10 SetScale 1,1 SetColor 64,128,192 DrawOval 320-200,240-200,400,400 t$=CurrentTime$() h=Left$(t$,2).toint() m=Mid$(t$,4,2).toint() s=Right$(t$,2).toint() SetRotation ((h Mod 12)*3600+m*60+s)/120.0 SetColor 200,150,250 DrawLine 320,240,320,120 SetRotation (m*60+s)/10.0 SetColor 150,200,250 DrawLine 320,240,320,100 SetRotation s*6 SetColor 255,255,255 DrawLine 320,240,320,50 SetRotation 0 Flip Flip Until KeyDown(27) |
| ||
Nice. Here's a modified version. It uses String.Split() to split the time elements into an array. It also uses DrawPoly instad of DrawLine for a more stylized hands.'Simple Clock II by TomToad 'based on: ' Simple Clock by David W (dw817) 12-18-15 SuperStrict Graphics 640,480 Local Hourhand:Float[] = [-10.0,0.0,0.0,-180.0,10.0,0.0,0.0,10.0] Local MinuteHand:Float[] = [-10.0,0.0,0.0,-220.0,10.0,0.0,0.0,10.0] Local SecondHand:Float[] = [-3.0,0.0,0.0,-230.0,3.0,0.0,0.0,10.0] Local t:String[] Local Hour:Float, Minute:Float, Second:Float SetOrigin 320,240 While Not KeyHit(KEY_ESCAPE) And Not AppTerminate() Cls 'Print the current time SetRotation 0 SetScale 3,3 DrawText CurrentTime$(),-310,-230 SetScale 1,1 'Split the time into the t array t = CurrentTime().Split(":") Second = t[2].ToFloat() Minute = t[1].ToFloat() + Second/60.0 Hour = t[0].ToFloat() + Minute/60.0 'draw face SetColor 64,128,192 DrawOval -240,-240,480,480 'Draw Minute hand SetColor 150,200,250 SetRotation Minute*6.0 DrawPoly MinuteHand 'Draw Hour Hand SetColor 200,150,250 SetRotation Hour*30.0 DrawPoly HourHand 'Draw second hand SetColor 255,255,255 SetRotation Second*6.0 DrawPoly SecondHand Flip Wend |
| ||
Ooh ! Yours is LOVELY, TomToad. :D Very stylized hands indeed ! BTW, your SPLIT TIME method is interesting. I'm wondering if that words with commas as I have this routine I use when handling virtual variables.global yankch$ Function yank$(a$ Var) Local b$ If yankch$="" yankch$="," EndIf If fnz$(a$)<>yankch$ a$:+yankch$ EndIf b$=Left$(a$,Instr(a$,yankch$)-1) a$=Mid$(a$,Instr(a$,yankch$)+ 1) If fnz$(a$)=yankch$ Or fnz$(a$)="," a$=fnd$(a$) EndIf yankch$="," Return b$ EndFunction Function fnz$(a$) Return Right$(a$,1) EndFunction Now here's a question. Is it possible to do one of the following ? [1] Use GLGRAPHICS and read and write pixels ? or [2] Create true 3D graphics using the standard GRAPHICS mode ? |
| ||
Try this exampleSuperStrict 'A comma seperated value string "First Name, Last Name, Subject, Grade" Local CSV:String = "Tom,Jones,Math,A" 'A string seperated by :-) Local SSV:String = "Mary:-)Smith:-)Science:-)B+" Local Student:String[] = CSV.Split(",") Print "~nComma Seperated Values" For Local i:Int = 0 Until Student.Length Print Student[i] Next Student = SSV.Split(":-)") Print "~nSmiley Seperated Values" For Local i:Int = 0 Until Student.Length Print Student[i] Next |
| ||
This is intriguing what you wrote, Tom. But it does not "take out" the data from the line in question. I'm using this routine to extract my current "," system data. Definitely not as elegant as your code above. ' Yank Text Functions by David W (dw817) 12-21-15 Global yankch$ Global a$="apple,banana,cucumber",b$ Repeat b$=yank$(a$) ' not only pulls the next item but removes it Print b$ Until b$="" Function yank$(a$ Var) Local b$ If yankch$="" yankch$="," EndIf If fnz$(a$)<>yankch$ a$:+yankch$ EndIf b$=Left$(a$,Instr(a$,yankch$)-1) a$=Mid$(a$,Instr(a$,yankch$)+ 1) If fnz$(a$)=yankch$ Or fnz$(a$)="," a$=fnd$(a$) EndIf yankch$="," Return b$ EndFunction Function yankno(a$ Var) Return val(yank$(a$)) EndFunction Function fnd$(a$) Return Left$(a$,Len(a$)-1) EndFunction Function fnz$(a$) Return Right$(a$,1) EndFunction Function val(t$) Return t$.toint() EndFunction You are using, "For (varaiable) UNTIL" instead of TO. What is the difference of the two, TomToad ? |
| ||
Hiya, There's no need to reinvent the wheel ;-) CSV = CSV.Replace(",","") will remove all instances of a comma in the original CSV string. You can think of Until as '<' and To as '<='. |
| ||
Until will loop to the terminating, but not include it. To will include the terminating value. So For i = 0 to 10 will loop through the numbers 0-10, while For i = 0 Until 10 will loop through the numbers 0-9. It is helpful because an array with 10 elements will be indexed Array[0] - Array[9], and you will not need to add a -1 to the end of the loop For i = 0 To Array.Length - 1 |
| ||
I tell ya, TomToad. BASIC has come a long way. You can tell my coding methods are very strongly steeped in it. I'm definitely interested in learning all these amazing short-cuts you guys have, but it may take some time for them to actually sink in, where I can see the merit in them. |