Main Menu

Make Shape From IMage

Started by kevin, July 27, 2010, 02:49:51 AM

Previous topic - Next topic

kevin

 Make Shape From IMage

 This function makes a shape from the hard dots (those that are not maskcolour) within an image.   The demo then draws the shape as pixels to display a message.  



PlayBASIC Code: [Select]
   LoadFont "courier",2,48,1

SetFont 2

Img=newimage(500,60,2)
rendertoimage img
print "Dotty Dotty Dot Dots"

rendertoscreen
Shape=MakeShapeFromPixelRect(Img)

Setfps 60

Zoom#=10
Do
Cls

Zoom#=cosradius(angle#,15)

rotateshape Shape,angle#,10+Zoom#
drawshape Shape,400,300,1

angle#=wrapangle(angle#+1)

Sync
loop


Function MakeShapeFromPixelRect(ThisIMage)
oldsurface=getsurface()

MaskCOlour=GetImageMaskcOlour(ThisImage)
w=getimagewidth(thisimage)
h=getimageHeight(thisimage)

x1=0
y1=0
x2=w-1
y2=h-1

rendertoimage ThisIMage

Maxverts=((x2-x1)+1)*((y2-y1)+1)
ThisShape=NewShape(MaxVerts,Maxverts)

cx=(x1+x2)/2
cy=(y1+y2)/2

ThisVertex=0
for ylp=y1 to y2
for xlp=x1 to x2
if Point(xlp,ylp)<>MaskColour
SetShapeVertex ThisShape,ThisVertex,xlp-cx,ylp-cy
SetShapeEdge ThisShape,ThisVertex,ThisVertex,ThisVertex
ThisVertex+=1
endif
next
next
rendertoimage OldSurface

EndFunction ThisShape







OldNESJunkie

This would be useful for a pinball game methinks.