Artikel Binäruhr auf Wikipedia entdeckt und ich konnte nicht widerstehen
BlitzMax: [AUSKLAPPEN] [EINKLAPPEN] Type TBinaryClock Field mPosX:Float , mPosY:Float , mLEDX:Float , mLEDY:Float Field mHours:Int[2] , mMinutes:Int[2] , mSeconds:Int[2] Field mBG_R:Int , mBG_G:Int , mBG_B:Int, mDrawBG:Int Field mON_R:Int , mON_G:Int , mON_B:Int Field mOFF_R:Int , mOFF_G:Int , mOFF_B:Int Method UpdateTime() mHours[0] = Int(Mid(CurrentTime() , 1 , 1) ) mHours[1] = Int(Mid(CurrentTime() , 2 , 1) ) mMinutes[0] = Int(Mid(CurrentTime() , 4 , 1) ) mMinutes[1] = Int(Mid(CurrentTime() , 5 , 1) ) mSeconds[0] = Int(Mid(CurrentTime() , 7 , 1) ) mSeconds[1] = Int(Mid(CurrentTime() , 8 , 1) ) EndMethod Method DrawDigital() SetColor 255 , 255 , 255 DrawText mHours[0] + "" + mHours[1] , mPosX + mLEDX + 10 , mPosY + mLEDY - 40 DrawText mMinutes[0] + "" + mMinutes[1] , mPosX + mLEDX + 60 , mPosY + mLEDY - 40 DrawText mSeconds[0] + "" + mSeconds[1] , mPosX + mLEDX + 110 , mPosY + mLEDY - 40 EndMethod Method DrawBinary() If mDrawBG = 1 SetColor mBG_R , mBG_G , mBG_B DrawRect mPosX , mPosY , 150 , 150 EndIf SetColor mOFF_R , mOFF_G , mOFF_B If mHours[0] = 2 SetColor mON_R , mON_G , mON_B DrawOval mPosX + mLEDX , mPosY + mLEDY + 40 , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B If mHours[0] = 1 SetColor mON_R , mON_G , mON_B DrawOval mPosX + mLEDX , mPosY + mLEDY + 60, 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B If mHours[1] >= 8 If mHours[1] Mod 8 = 0 Or mHours[1] Mod 8 = 1 SetColor mON_R , mON_G , mON_B EndIf DrawOval mPosX + mLEDX + 20 , mPosY + mLEDY , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B
If mHours[1] >= 4 And mHours[1] < 8 SetColor mON_R , mON_G , mON_B EndIf DrawOval mPosX + mLEDX + 20 , mPosY + mLEDY + 20 , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B
If mHours[1] >= 2 And mHours[1] < 4 If mHours[1] Mod 2 < 2 SetColor mON_R , mON_G , mON_B ElseIf mHours[1] > 4 And mHours[1] <> 5 And mHours[1] < 8 SetColor mON_R , mON_G , mON_B EndIf DrawOval mPosX + mLEDX + 20 , mPosY + mLEDY + 40 , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B
If mHours[1] Mod 2 = 1 SetColor mON_R , mON_G , mON_B DrawOval mPosX + mLEDX + 20 , mPosY + mLEDY + 60 , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B
If mMinutes[0] >= 4 SetColor mON_R , mON_G , mON_B EndIf DrawOval mPosX + mLEDX + 50 , mPosY + mLEDY + 20 , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B If mMinutes[0] >= 2 And mMinutes[0] < 4 If mMinutes[0] Mod 2 < 2 SetColor mON_R , mON_G , mON_B ElseIf mMinutes[0] > 4 And mMinutes[0] <> 5 And mMinutes[0] < 8 SetColor mON_R , mON_G , mON_B EndIf DrawOval mPosX + mLEDX + 50 , mPosY + mLEDY + 40 , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B If mMinutes[0] Mod 2 = 1 SetColor mON_R , mON_G , mON_B DrawOval mPosX + mLEDX + 50 , mPosY + mLEDY + 60 , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B
If mMinutes[1] >= 8 If mMinutes[1] Mod 8 = 0 Or mMinutes[1] Mod 8 = 1 SetColor mON_R , mON_G , mON_B EndIf DrawOval mPosX + mLEDX + 70 , mPosY + mLEDY , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B
If mMinutes[1] >= 4 And mMinutes[1] < 8 SetColor mON_R , mON_G , mON_B EndIf DrawOval mPosX + mLEDX + 70 , mPosY + mLEDY + 20 , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B
If mMinutes[1] >= 2 And mMinutes[1] < 4 If mMinutes[1] Mod 2 < 2 SetColor mON_R , mON_G , mON_B ElseIf mMinutes[1] > 4 And mMinutes[1] <> 5 And mMinutes[1] < 8 SetColor mON_R , mON_G , mON_B EndIf DrawOval mPosX + mLEDX + 70 , mPosY + mLEDY + 40 , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B
If mMinutes[1] Mod 2 = 1 SetColor mON_R , mON_G , mON_B DrawOval mPosX + mLEDX + 70 , mPosY + mLEDY + 60 , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B
If mSeconds[0] >= 4 SetColor mON_R , mON_G , mON_B EndIf DrawOval mPosX + mLEDX + 100 , mPosY + mLEDY + 20 , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B If mSeconds[0] >= 2 And mSeconds[0] < 4 If mSeconds[0] Mod 2 < 2 SetColor mON_R , mON_G , mON_B ElseIf mSeconds[0] > 4 And mSeconds[0] <> 5 And mSeconds[0] < 8 SetColor mON_R , mON_G , mON_B EndIf DrawOval mPosX + mLEDX + 100 , mPosY + mLEDY + 40 , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B
If mSeconds[0] Mod 2 = 1 SetColor mON_R , mON_G , mON_B DrawOval mPosX + mLEDX + 100 , mPosY + mLEDY + 60 , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B If mSeconds[1] >= 8 If mSeconds[1] Mod 8 = 0 Or mSeconds[1] Mod 8 = 1 SetColor mON_R , mON_G , mON_B EndIf DrawOval mPosX + mLEDX + 120 , mPosY + mLEDY , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B If mSeconds[1] >= 4 And mSeconds[1] < 8 SetColor mON_R , mON_G , mON_B EndIf DrawOval mPosX + mLEDX + 120 , mPosY + mLEDY + 20 , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B If mSeconds[1] >= 2 And mSeconds[1] < 4 If mSeconds[1] Mod 2 < 2 SetColor mON_R , mON_G , mON_B ElseIf mSeconds[1] > 4 And mSeconds[1] <> 5 And mSeconds[1] < 8 SetColor mON_R , mON_G , mON_B EndIf DrawOval mPosX + mLEDX + 120 , mPosY + mLEDY + 40 , 10 , 10 SetColor mOFF_R , mOFF_G ,mOFF_B If mSeconds[1] Mod 2 = 1 SetColor mON_R , mON_G , mON_B DrawOval mPosX + mLEDX + 120 , mPosY + mLEDY + 60 , 10 , 10 SetColor mOFF_R , mOFF_G , mOFF_B EndMethod Method SetLEDPos(_x:Float , _y:Float) mLEDX = _x mLEDY = _y EndMethod Method SetClockColor(_color:Int , _r:Int , _g:Int , _b:Int) Select _color Case 0 mBG_R = _r mBG_G = _g mBG_B = _b
Case 1 mOFF_R = _r mOFF_G = _g mOFF_B = _b Case 2 mON_R = _r mON_G = _g mON_B = _b
EndSelect EndMethod Method SwitchBG() If mDrawBG = 1 mDrawBG = 0 Else mDrawBG = 1 EndIf EndMethod EndType
Hier noch ein Beispiel:
BlitzMax: [AUSKLAPPEN] [EINKLAPPEN] Include "TBinaryClock.bmx"
Graphics 150 , 150 , 0 , 60
Global myBinaryClock:TBinaryClock = New TBinaryClock
myBinaryClock.mPosX = 0 myBinaryClock.mPosY = 0
myBinaryClock.SetLEDPos(10 , 70)
myBinaryClock.SetClockColor(0 , 100 , 100 , 100) myBinaryClock.SetClockColor(1 , 120 , 0 , 0) myBinaryClock.SetClockColor(2 , 200 , 0 , 0)
Repeat Cls If KeyHit(key_f1) myBinaryClock.SwitchBG() myBinaryClock.UpdateTime() myBinaryClock.DrawBinary() myBinaryClock.DrawDigital() Flip Until KeyHit(key_escape) Or AppTerminate()
|