This example demos the basic vector gfx commands (Dot,line,Circle,Box) and ink modes in the form of a paint program.
Commands Used: Dot, Line, Circle, Box, InkMode
[pbcode]
; PROJECT : Silly_Paint
; AUTHOR : Kevin Picone
; CREATED : 20/02/2006
; EDITED : 20/02/2006
; ---------------------------------------------------------------------
; create the display
;OpenScreen 800,600,32,2
; create an image the size of the current screen mode
global ScreenImage =NewImage(GetScreenWidth(),GetSCreenHeight())
; Pen Mode holds the current pen(brush) the demo is using
PenMode=0
; ink mode holds the current render mode that is being used
; The default mode is SOLID
PenInkMode=0
; --------------------------------------------------------
; Starting DO statement for the programs main Do/LOOP
; --------------------------------------------------------
Do
; get mouse position
mb=mousebutton()
mx=mousex()
my=mousey()
HandlePaint(mx,my,mb,PenMode,PenInkMOde)
; draw the Picture were paint to the screen
Drawimage ScreenIMage,0,0,0
;restore ink mode
inkmode 1
; Draw some controls/interface stuff
ink Rgb(0,0,255)
; DRaw Mouse pointer
tri mx,my,mx+20,my+5,mx+15,my+20
; Draw some controls/interface stuff
ink Rgb(255,255,255)
; Set the Position and size of the info console
x=10
y=30
w=200
h=60
; check if the mouse is within this area
if pointinbox(mx,my,0,0,x+w+32,y+h+32)
X=getScreenWidth()-w
Y=getScreenHeight()-h
endif
; Create some colour for the shade box edges
c1=rgb(20,30,40)
c2=rgb(200,40,220)
c3=rgb(100,240,220)
c4=rgb(200,40,220)
; draw the shaded box
shadebox x,y,x+w,y+h,c1,c2,c3,c2
; render the control & stageb info on the console
text x,y+0,"F1 + F2 to change Modes"
text x,y+20,"Pen Mode:"+GetModeName(PenMode)
text x,y+40,"Ink Mode:"+GetPenInkMode(PenInkMode)
; Check if a key press is allowed
if KeyPressed=false
; if a key is down, set the key pressed value to TRUE
if Scancode()<>0 then keypressed=true
; check if the F1 key is being pressed
if FunctionKeys(1)
inc PenMode
if PenMode>3 then PenMode=0
endif
; check if the F2 key is being pressed
if FunctionKeys(2)
inc PenInkMode
if PenInkMode>6 then PenInkMode=0
endif
endif
; Check if no keys are being pressed, if so, reset the Keypressed
; value
if Scancode()=0 then KeyPressed=false
; call sync to show the Screen to the user
SYnc
; loop back to the do statement
loop
Function HandlePaint(mx,my,mb,PenMode,PenInkMode)
Static OldX,OldY,FirstLIne
; Tell PB to redirect all drawing to this image
renderToImage ScreenImage
; randomly change the ink colour (nice and annoying :) )
Ink Rndrgb()
inkmode SetPenInkMode(PenInkMode)
inkalpha rnd#(1)
; if Left Mouse button Pressed
If MB=1
; Select what pen mode to use
select PenMode
case 0 ; mode 0 is DOT mode
dot mx,my
case 1 ; mode 1 is LIne mode
if FirstLine=false
FirstLine=true
oldx=mx
oldy=my
endif
line mx,my,oldx,oldy
oldx=mx
oldy=my
case 2; Mode 2 is random circle mode
Circle mx,my,rnd(100),true
case 3; mode 3 is random box
Box mx,my,mx+rnd(100),my+rnd(100),true
endselect
endif
; redirect rendering to the screen
rendertoscreen
EndFunction
Function GetModeName(PenMode)
Select PenMode
case 0 : Name$="Dot"
case 1 : name$="line"
case 2 : name$="Circle"
case 3 : name$="Box"
endselect
EndFunction Name$
Function GetPenInkMode(Mode)
Select Mode
case 0 : name$="Solid"
case 1 : Name$="Alpha Blend"
case 2 : Name$="Alpha Blend 50%"
case 3 : Name$="Alpha Addition"
case 3 : Name$="Alpha Subtraction"
case 4 : Name$="Logical AND"
case 5 : Name$="Logical OR"
case 6 : Name$="Logical XOR"
endselect
EndFunction Name$
Function SetPenInkMode(mode)
m=1
if Mode>0 then m=m+(2^(Mode+3))
EndFunction m
[/pbcode]