News:

Function Finder  Find all the functions within source code files

Main Menu

Silly Paint

Started by kevin, February 19, 2006, 04:34:40 PM

Previous topic - Next topic

kevin

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

PlayBASIC Code: [Select]
; 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
Login required to view complete source code