Rubiko hat geschrieben:also:
voll = grün ; fast voll = helleres grün ; irgendwann gelb, gelb wird immer dumkler; bei 20 % z.B rot... das rot wird immer dunkler
Sollen diese Farben alle in der 'Lifebar' sein, oder soll sich
der ganze Balken so färben?
Code: Alles auswählen
Dim lifebar_colors(100)
f.f = 255/25
For i = 0 To 25 : lifebar_colors(100-i)=RGB($00,$80+f*i/2,00) : Next
For i = 0 To 25 : lifebar_colors( 75-i)=RGB(i*f,$FF ,00) : Next
For i = 0 To 25 : lifebar_colors( 50-i)=RGB($FF,$FF-f*i ,00) : Next
For i = 0 To 25 : lifebar_colors( 25-i)=RGB($FF-f*i/2,$00,00) : Next
Procedure DrawBar(Index)
If Index<=100 And Index>=1 And StartDrawing(ImageOutput())
Box(0,0,50,400,lifebar_colors(Index))
StopDrawing()
SetGadgetState(0,ImageID())
EndIf
EndProcedure
Procedure DrawColors(y_start,width,height,color1,color2)
red = Red(color1)
green = Green(color1)
blue = Blue(color1)
r.f = (Red(color2) -red )/ height
g.f = (Green(color2) -green )/ height
b.f = (Blue(color2) -blue )/ height
For a = 0 To height
Line(0,a+y_start,width,0,RGB(red+a*r,green+a*g,blue+a*b))
Next a
EndProcedure
power = 100
CreateImage(0,50,400)
If StartDrawing(ImageOutput())
DrawColors( 0,50,100,RGB($00,$80,$00),RGB($00,$FF,$00))
DrawColors(100,50,100,RGB($00,$FF,$00),RGB($FF,$FF,$00))
DrawColors(200,50,100,RGB($FF,$FF,$00),RGB($FF,$00,$00))
DrawColors(300,50,100,RGB($FF,$00,$00),RGB($80,$00,$00))
StopDrawing()
EndIf
OpenWindow(0,0,0,160,420,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Lifebar")
CreateGadgetList(WindowID())
ImageGadget(2,100,10,50,400,ImageID())
ImageGadget(0,10,10,50,400,CreateImage(1,50,400))
TrackBarGadget(1,70,10,20,400,1,100,#PB_TrackBar_Vertical)
SetGadgetState(1,power)
DrawBar(power)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Closewindow
Break
Case #PB_Event_Gadget
Select EventGadgetID()
Case 1
power=GetGadgetState(1)
DrawBar(power)
EndSelect
EndSelect
ForEver
Mit 2 Farbverläufen zwischen 3 Farben müßte es aber
auch ausreichen:
Code: Alles auswählen
Dim lifebar_colors(100)
f.f = 255/50
; For i = 0 To 25 : lifebar_colors(100-i)=RGB($00,$80+f*i/2,00) : Next
; For i = 0 To 25 : lifebar_colors( 75-i)=RGB(i*f,$FF ,00) : Next
; For i = 0 To 25 : lifebar_colors( 50-i)=RGB($FF,$FF-f*i ,00) : Next
; For i = 0 To 25 : lifebar_colors( 25-i)=RGB($FF-f*i/2,$00,00) : Next
For i = 0 To 50 : lifebar_colors(100-i)=RGB($00+f*i,$80+f*i/2 ,00) : Next
For i = 0 To 50 : lifebar_colors( 50-i)=RGB($FF-f*i/2,$FF-f*i,00) : Next
Procedure DrawBar(Index)
If Index<=100 And Index>=1 And StartDrawing(ImageOutput())
Box(0,0,50,400,lifebar_colors(Index))
StopDrawing()
SetGadgetState(0,ImageID())
EndIf
EndProcedure
Procedure DrawColors(y_start,width,height,color1,color2)
red = Red(color1)
green = Green(color1)
blue = Blue(color1)
r.f = (Red(color2) -red )/ height
g.f = (Green(color2) -green )/ height
b.f = (Blue(color2) -blue )/ height
For a = 0 To height
Line(0,a+y_start,width,0,RGB(red+a*r,green+a*g,blue+a*b))
Next a
EndProcedure
power = 100
CreateImage(0,50,400)
If StartDrawing(ImageOutput())
; DrawColors( 0,50,100,RGB($00,$80,$00),RGB($00,$FF,$00))
; DrawColors(100,50,100,RGB($00,$FF,$00),RGB($FF,$FF,$00))
; DrawColors(200,50,100,RGB($FF,$FF,$00),RGB($FF,$00,$00))
; DrawColors(300,50,100,RGB($FF,$00,$00),RGB($80,$00,$00))
DrawColors( 0,50,200,RGB($00,$80,$00),RGB($FF,$FF,$00))
DrawColors(200,50,200,RGB($FF,$FF,$00),RGB($80,$00,$00))
StopDrawing()
EndIf
OpenWindow(0,0,0,160,420,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Lifebar")
CreateGadgetList(WindowID())
ImageGadget(2,100,10,50,400,ImageID())
ImageGadget(0,10,10,50,400,CreateImage(1,50,400))
TrackBarGadget(1,70,10,20,400,1,100,#PB_TrackBar_Vertical)
SetGadgetState(1,power)
DrawBar(power)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Closewindow
Break
Case #PB_Event_Gadget
Select EventGadgetID()
Case 1
power=GetGadgetState(1)
DrawBar(power)
EndSelect
EndSelect
ForEver