Hey all!
Think this is a gesture system anyway! Use the mouse to trace the shape and see what percentage accuracy you get. This could be used as a gesture system where, if your accuracy is high enough then an action takes place based on what gesture you traced.
It is far from perfect so if you have any suggestions then please make them!
rem Set screen resolution
set display mode 800,600,32
rem Hide loading
sync on
sync rate 0
sync
text 0,0,"LOADING"
sync
rem Enable Cloggy's dll
d3d_init
rem Enable 3D backdrop
backdrop on
color backdrop 0
rem Load tracer image
load image "test1.png",1,1
rem Make memblock to do tracer test
make memblock from image 1,1
rem Make array to hold drawing
global dim Grid(256,256) as boolean
rem Lock the frame rate
sync on
sync rate 60
rem Start the main loop
do
rem Display the tracer image
paste image 1,272,172
rem Store mouse data
mx=mousex()
my=mousey()
mmx=mousemovex()
mmy=mousemovey()
oldmclick=mclick
mclick=mouseclick()
rem Check for mouse click to draw
if mclick=1
rem Empty array
if oldmclick=0
for x=0 to 255
for y=0 to 255
Grid(x,y)=0
next y
next x
endif
rem Store drawing
if mx>271
if mx<528
if my>171
if my<428
Grid(mx-272,my-172)=1
endif
endif
endif
endif
endif
rem Wait for release to check tracer
if mclick=0
if oldmclick=1
rem Run check
percentage=CheckTrace(1,317.0)
endif
endif
rem Show drawing
d3d_color 255,0,0,255
for x=0 to 255
for y=0 to 255
if Grid(x,y)=1
d3d_dot x+272,y+172
endif
next y
next x
rem Display percentage
ink rgb(255,255,255),0
center text 400,432,"PERCENTAGE: "+str$(percentage)+"%"
rem Update the screen
sync
rem End the loop
loop
rem Function to check array against an image memblock...
rem ...and return a percentage of accuracy
function CheckTrace(memblock,perfect#)
rem Local variables
total#=0.0
correct#=0.0
rem Loop through image
for x=0 to 255
for y=0 to 255
rem Read image
image=ReadFromImageMemblock(memblock,256,256,x,y)
image=rgbr(image)
rem Check if the grid was drawn on here
if Grid(x,y)=1
rem Increas total
total#=total#+(196.0/255.0)
rem Check the tracer goes here
if image<196
rem Give points based on shade of trace image
correct#=correct#+((196-image)/255.0)
else
rem Remove points based on shade of trace image
correct#=correct#-((image-196)/255.0)
endif
endif
next y
next x
rem Calculate percentage
percentage#=(total#/perfect#)
if percentage#>1.0
percentage#=1.0
endif
percentage=((correct#/total#)*percentage#)*100.0
`percentage=(percentage#/perfect#)*100.0
rem End the function
endfunction percentage
rem Function to return the colour of an image stored in...
rem ...a memblock at a specified pixel
function ReadFromImageMemblock(MemblockID,ImageWidth,ImageHeight,X,Y)
rem Find relative position in memblock
MemblockPosition=X+(Y*ImageWidth)
rem Check the position is in the memblock range
if MemblockPosition>=0
if MemblockPosition<(ImageWidth*ImageHeight)
rem Adjust the memblock accordingly
ColorValue=memblock dword(MemblockID,12+(MemblockPosition*4))
endif
endif
rem End the function
endfunction ColorValue
I'll attach the image I used for testing as well.