Binäre Uhr

Übersicht BlitzMax, BlitzMax NG Codearchiv & Module

Neue Antwort erstellen

DaysShadow

Betreff: Binäre Uhr

BeitragDi, Jan 27, 2009 12:38
Antworten mit Zitat
Benutzer-Profile anzeigen
Artikel Binäruhr auf Wikipedia entdeckt und ich konnte nicht widerstehen Wink

BlitzMax: [AUSKLAPPEN]
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

' HOUR: tens digit

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


' HOUR: units digit

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


' MINUTES: tens digit

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


' MINUTES: units digit

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


' SECONDS: tens digit

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


' SECONDS: units digit
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]
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) ' Farbe für Hintergrund einstellen
myBinaryClock.SetClockColor(1 , 120 , 0 , 0) ' Farbe für LEDs die aus sind einstellen
myBinaryClock.SetClockColor(2 , 200 , 0 , 0) ' Farbe für LEDs die an sind einstellen

Repeat

Cls

If KeyHit(key_f1) myBinaryClock.SwitchBG()

myBinaryClock.UpdateTime()
myBinaryClock.DrawBinary()
myBinaryClock.DrawDigital()

Flip

Until KeyHit(key_escape) Or AppTerminate()
  • Zuletzt bearbeitet von DaysShadow am Do, Mai 21, 2009 19:27, insgesamt einmal bearbeitet

Bura.Tino

BeitragSo, März 01, 2009 3:17
Antworten mit Zitat
Benutzer-Profile anzeigen
Habe ich auch schon programmiert, da diese Uhren einfach kultig sind. Smile
Rolling Eyes <- Ich liebe dieses Smilie ! Very Happy

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Codearchiv & Module

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group