SetHexColor will nicht so richtig

Übersicht BlitzMax, BlitzMax NG Allgemein

Neue Antwort erstellen

Ratchet

Betreff: SetHexColor will nicht so richtig

BeitragFr, Aug 19, 2011 15:08
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich wollte mir eine Funktion schreiben die mir aus einem Hexwert die Farbe setzt. Dazu habe ich die Berechnung der RGB Werte von https://www.blitzforum.de/help/ReadPixel benutzt. Aber ich bekomme immer 255,255,255 also weiß heraus. Was mache ich falsch?

Beispiel:
BlitzMax: [AUSKLAPPEN]
SuperStrict

Const COLOR_LIGHT: String = $557FAA
Const COLOR_NORMAL: String = $406080
Const COLOR_DARK: String = $203040

Function SetHexColor(HexColor: String)
Local r: Int
Local g: Int
Local b: Int
r = (HexColor And $FF0000)/$10000
g = (HexColor And $FF00)/$100
b = HexColor And $FF
SetColor(r, g, b)
End Function

Graphics 640,480,0
While Not KeyHit(KEY_ESCAPE)
Cls
DrawRect(0,0,100,100)
Flip
If KeyHit(KEY_1) Then SetHexColor(COLOR_LIGHT)
If KeyHit(KEY_2) Then SetHexColor(COLOR_NORMAL)
If KeyHit(KEY_3) Then SetHexColor(COLOR_DARK)
Wend
[iMac 27"] [3,4GHz Intel Core i5 ] [8GB Ram] [NVIDIA GeForce GTX 775M 2GB] [MacOS X Yosemite] [BlitzMax + MaxGui] [Monkey X Pro]

Xeres

Moderator

BeitragFr, Aug 19, 2011 15:11
Antworten mit Zitat
Benutzer-Profile anzeigen
Du benutzt ein logisches AND wo du ein Bit-And "&" bräuchtest. Sind zwei verschiedene Dinge in BlitzMax.
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)

Ratchet

BeitragFr, Aug 19, 2011 15:24
Antworten mit Zitat
Benutzer-Profile anzeigen
Ach stimmt, da war ja was XD
Vielen Dank!

BlitzMax: [AUSKLAPPEN]
Function SetHexColor(HexColor: String)
Local r: Int
Local g: Int
Local b: Int
r = (Int(HexColor) & $FF0000)/$10000
g = (Int(HexColor) & $FF00)/$100
b = Int(HexColor) & $FF
SetColor(r, g, b)
End Function
[iMac 27"] [3,4GHz Intel Core i5 ] [8GB Ram] [NVIDIA GeForce GTX 775M 2GB] [MacOS X Yosemite] [BlitzMax + MaxGui] [Monkey X Pro]

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group