benutzt.
2.) Box, Circle & Ellipse auch gefüllt darzustellen - die sind immer nur 'outlined'
die Du Fred gerne als Anregung mal zeigen kannst.
Code: Alles auswählen
#SCREEN_W = 800 ; screen width
#SCREEN_H = 600 ; screen height
Procedure _Locate(x,y)
Shared Drawing2D_LocationX
Shared Drawing2D_LocationY
Drawing2D_LocationX = x
Drawing2D_LocationY = y
Locate(x,y)
EndProcedure
Procedure _DrawingMode(mode)
Shared Drawing2D_Mode
Drawing2D_Mode = mode
EndProcedure
Procedure _BackColor(Red,Green,Blue)
Shared Drawing2D_BackColor
Drawing2D_BackColor = RGB(Red,Green,Blue)
BackColor(Red,Green,Blue)
EndProcedure
Procedure _DrawText(text$)
Shared Drawing2D_Mode
Shared Drawing2D_LocationX
Shared Drawing2D_LocationY
Shared Drawing2D_BackColor
#Current_TextHeight = 8
If Drawing2D_Mode = 0
Box(Drawing2D_LocationX-1,Drawing2D_LocationY-1,TextLength(text$)+2,#Current_TextHeight+2,Drawing2D_BackColor)
DrawText(text$)
ElseIf Drawing2D_Mode = 1
DrawText(text$)
ElseIf Drawing2D_Mode = 2
; direct screen access to XOR text?
ElseIf Drawing2D_Mode = 4
; draw outlined text?
EndIf
EndProcedure
Procedure _Box(x,y,w,h,color)
Shared Drawing2D_Mode
If Drawing2D_Mode = 0
Box(x,y,w,h,color)
;ElseIf Drawing2D_Mode = 1
; only used for text
ElseIf Drawing2D_Mode = 2
; direct screen access to XOR box?
ElseIf Drawing2D_Mode = 4
Line( x , y , w , 0 ,color) ; -
Line(x+w, y , 0 , h ,color) ; |
Line( x , y , 0 , h ,color) ; |
Line( x ,y+h, w , 0 ,color) ; -
EndIf
EndProcedure
Procedure _Circle(x,y,radius,color)
; Bresenham circle algorithm
Shared Drawing2D_Mode
temp_x = 0
d = 3 - 2 * radius
While temp_x <= radius
If Drawing2D_Mode = 0 ; filled
LineXY(x-temp_x, y+radius, x+temp_x, y+radius, color) ; part 1
LineXY(x-radius, y+temp_x, x+radius, y+temp_x, color) ; part 2
LineXY(x-radius, y-temp_x, x+radius, y-temp_x, color) ; part 3
LineXY(x-temp_x, y-radius, x+temp_x, y-radius, color) ; part 4
;ElseIf Drawing2D_Mode = 1
; only used for text
ElseIf Drawing2D_Mode = 2
; direct screen access to XOR circle?
ElseIf Drawing2D_Mode = 4 ; outlined
Plot(x+temp_x, y+radius, color) ; part 1
Plot(x-temp_x, y+radius, color)
Plot(x+radius, y+temp_x, color) ; part 2
Plot(x-radius, y+temp_x, color)
Plot(x+radius, y-temp_x, color) ; part 3
Plot(x-radius, y-temp_x, color)
Plot(x-temp_x, y-radius, color) ; part 4
Plot(x+temp_x, y-radius, color)
EndIf
If d < 0
d + 4*temp_x + 6
Else
d + 4*(temp_x - radius) + 10
radius - 1
EndIf
temp_x + 1
Wend
EndProcedure
Procedure _Ellipse(x,y,radius_x,radius_y,color)
; middle-point ellipse algorithm
Shared Drawing2D_Mode
temp_x = 0
temp_y = radius_y
temp_radius_x1 = radius_x*radius_x
temp_radius_y1 = radius_y*radius_y
temp_radius_x2 = temp_radius_x1*2
temp_radius_y2 = temp_radius_y1*2
temp_fx = 0
temp_fy = temp_radius_x2*radius_y
p = temp_radius_y1 - temp_radius_x1*radius_y + Int(0.25*temp_radius_x1)
If radius_x = radius_y
_Circle(x,y,radius_x,color)
ProcedureReturn
EndIf
While temp_fx <= temp_fy
If Drawing2D_Mode = 0 ; filled
LineXY(x-temp_x, y+temp_y, x+temp_x, y+temp_y, color) ; part 1
LineXY(x-temp_x, y-temp_y, x+temp_x, y-temp_y, color) ; part 4
;ElseIf Drawing2D_Mode = 1
; only used for text
ElseIf Drawing2D_Mode = 2
; direct screen access to XOR ellipse?
ElseIf Drawing2D_Mode = 4 ; outlined
Plot(x+temp_x, y+temp_y, color) ; part 1
Plot(x-temp_x, y+temp_y, color)
Plot(x-temp_x, y-temp_y, color) ; part 4
Plot(x+temp_x, y-temp_y, color)
EndIf
temp_x + 1
temp_fx + temp_radius_y2
If p < 0
p + temp_fx + temp_radius_y1
Else
temp_y - 1
temp_fy - temp_radius_x2
p + temp_fx + temp_radius_y1 - temp_fy
EndIf
Wend
If Drawing2D_Mode = 0 ; filled
LineXY(x-temp_x, y+temp_y, x+temp_x, y+temp_y, color) ; part 1
LineXY(x-temp_x, y-temp_y, x+temp_x, y-temp_y, color) ; part 4
ElseIf Drawing2D_Mode = 2
; direct screen access to XOR ellipse?
ElseIf Drawing2D_Mode = 4 ; outlined
Plot(x+temp_x, y+temp_y, color) ; part 1
Plot(x-temp_x, y+temp_y, color)
Plot(x-temp_x, y-temp_y, color) ; part 4
Plot(x+temp_x, y-temp_y, color)
EndIf
p = temp_radius_y1 * (temp_x - 0.5)*(temp_x+0.5)+temp_radius_x1*(temp_y-1)*(temp_y-1)-temp_radius_x1*temp_radius_y1
While temp_y > 0
temp_y - 1
temp_fy - temp_radius_x2
If p >= 0
p - temp_fy + temp_radius_x1
Else
temp_x + 1
temp_fx + temp_radius_y2
p + temp_fx - temp_fy + temp_radius_x1
EndIf
If Drawing2D_Mode = 0 ; filled
LineXY(x-temp_x, y+temp_y, x+temp_x, y+temp_y, color) ; part 1
LineXY(x-temp_x, y-temp_y, x+temp_x, y-temp_y, color) ; part 4
ElseIf Drawing2D_Mode = 2
; direct screen access to XOR ellipse?
ElseIf Drawing2D_Mode = 4 ; outlined
Plot(x+temp_x, y+temp_y, color) ; part 1
Plot(x-temp_x, y+temp_y, color)
Plot(x-temp_x, y-temp_y, color) ; part 4
Plot(x+temp_x, y-temp_y, color)
EndIf
Wend
EndProcedure
If InitSprite()=0 Or InitKeyboard()=0
MessageRequester("ERROR","Cant init game engine !"):End
EndIf
If OpenScreen(#SCREEN_W,#SCREEN_H,32,"DrawingMode")=0
If OpenScreen(#SCREEN_W,#SCREEN_H,24,"DrawingMode")=0
If OpenScreen(#SCREEN_W,#SCREEN_H,16,"DrawingMode")=0
MessageRequester("ERROR","Cant open screen !"):End
EndIf:EndIf:EndIf
Repeat
FlipBuffers()
If isScreenActive()
ClearScreen($80,$80,$80)
If StartDrawing(ScreenOutput())
; Text with Background
_DrawingMode(0)
_Locate(100,10)
FrontColor($00,$00,$00)
_BackColor($FF,$FF,$00)
_DrawText("Hello! xyz")
; Transparent Text
_DrawingMode(1)
_Locate(300,10)
FrontColor($FF,$FF,$FF)
_DrawText("Hello! xyz")
; filled box
_DrawingMode(0)
_Box(100,50,100,100,$FFFF00)
; outlined Boxes
_DrawingMode(4)
_Box(300,50,100,100,$FFFFFF)
; filled circle
_DrawingMode(0)
_Circle(150,250,50,$FFFF00)
; outlined circle
_DrawingMode(4)
_Circle(350,250,50,$FFFFFF)
; filled ellipse
_DrawingMode(0)
_Ellipse(150,400,90,50,$FFFF00)
; outlined ellipse
_DrawingMode(4)
_Ellipse(350,400,90,50,$FFFFFF)
; animated things
Line(0,525,800,0,$FFFFFF)
; filled
_DrawingMode(0)
_Box (offX+100-anim,525-anim,anim*2,anim*2,$FF00FF)
_Circle (offX+250, 525 ,anim ,$FF00FF)
_Ellipse(offX+450, 525 ,anim*2,anim ,$FF00FF)
_Ellipse(offX+650, 525 ,anim ,anim*2,$FF00FF)
; outlined
_DrawingMode(4)
_Box (offX+050+anim,475+anim,100-anim*2,100-anim*2,$00FF00)
_Circle (offX+250,525,50-anim, $00FF00)
_Ellipse(offX+450,525,100-anim*2,50-anim, $00FF00)
_Ellipse(offX+650,525,50-anim,100-anim*2, $00FF00)
_DrawingMode(0)
_Circle(offX+100,525,1,$000000)
_Circle(offX+250,525,1,$000000)
_Circle(offX+450,525,1,$000000)
_Circle(offX+650,525,1,$000000)
If animflag=0
anim + 2
if anim > 50 : anim = 50 : animflag+1 : EndIf
Else
anim - 2
If anim < 0 : anim = 0 : animflag!1 : EndIf
EndIf
offX + 1
If offX = #SCREEN_W : offX = -#SCREEN_W : EndIf
counter + 1
DrawingMode(0)
_Locate(10,10)
_BackColor($00,$00,$FF)
FrontColor($80,$80,$FF)
_DrawText(StrU(counter,#LONG))
StopDrawing()
EndIf
EndIf
ExamineKeyboard()
Delay(1)
Until KeyboardPushed(#PB_KEY_ESCAPE)
DrawText(): Bei DrawingMode(0) wird vorher eine Box() gezeichnet mit der Farbe von BackColor()
Könnte Fred also mal einbauen.