BBC BASIC for Windows
Programming >> Graphics and Games >> Spider demo for new sketch overlay tool (fixed)
http://bb4w.conforums.com/index.cgi?board=graphics&action=display&num=1497330647

Spider demo for new sketch overlay tool (fixed)
Post by michael on Jun 13th, 2017, 05:10am

**** The Following content has been moved to TOOLS section


This program requires BBC4W. (fixed a flaw where the scanned image info would not match the size of the araysize% variable. Causes a overdrawn edge)

The image is 256 color BMP format. Draws in black will be sketched into a data file and then reloaded into an array and plotted with many colors in random locations.

Try it out .

IMPORTANT : if you modify the image you must adjust the array size or it may not display proper. (araysize% too large and you will get extra plots.. araysize% too small and you will lose image data)

You will need to download both files and extract them before you load the program into BBC4W and run.

https://1drv.ms/f/s!AmYwmTjbmULXlVGudMKOlNuEiJk6

The image display tool will be modified to handle the data files and will be for all platforms including BBCSDL

Here is a more simplified sample. I removed unnecessary components. You will need the BMP image from the above link for this to work. (or you can try to make an image yourself)

Code:
        
     MODE 8
     LET araysize%=120 :REM You need to keep the data size for only what is needed to get the sketch
      DIM hori%(araysize%)  :REM if the entire image is not captured you will need to increase hori% and vert% value
      DIM vert%(araysize%)
      ti%=0
       PROCloadbmp("mypic.bmp",0,0,300,300)
      PROCsketchscan("face",araysize%)
      PROCcolor("f","blue")
      PROCsketchdra("face")
      REPEAT
        PROCarraydra(RND(500),RND(500),RND(15))
        ti%+=1
      UNTIL  ti%=100
      WAIT 0
      END
    REM PROCEDURES ******************************
      DEF PROCgraphics(x,y)
      VDU 23,22,x;y;8,15,16,1
      OFF: VDU 5
      ENDPROC
      DEFPROCsavebmp(name$,x%,y%,h%,v%)
      OSCLI "SCREENSAVE """+name$+""" "+STR$(x%)+","+STR$(y%)+","+STR$(h%)+","+STR$(v%)
      ENDPROC
      DEFPROCloadbmp(name$,x%,y%,h%,v%)
      OSCLI "DISPLAY """+name$+""" "+STR$(x%)+","+STR$(y%)+","+STR$(h%)+","+STR$(v%)
      ENDPROC
      REM draw the array
      DEFPROCarraydra(x%,y%,gc%)
      LOCAL n%
      GCOL gc%
      REPEAT
        LINE x%+hori%(n%),y%+vert%(n%),x%+hori%(n%),y%+vert%(n%)
        n%+=1
      UNTIL n%=araysize%
      ENDPROC
      DEFPROCsketchdra(name$)
      LOCAL cx%,cy%,oun%,sof%
      A=OPENIN(@dir$+name$+".txt")
      oun%=0
      REPEAT
        INPUT#A,hori%(oun%),vert%(oun%)
        IF hori%(oun%)=1 THEN sof%=1
        oun%+=1
      UNTIL sof%=1 OR oun%>araysize%
      MOVE 0,0
      CLOSE#A
      ENDPROC

      REM widthheight is the size of the bmp.. it must be perfectly square (this tool makes a file with the sketch pixel locations
      DEFPROCsketchscan(name$,wh%)
      LOCAL cycle%,trip%,sr%,sg%,sb%,ar%,fin%
      A=OPENOUT(@dir$+name$+".txt")
      REPEAT
        REPEAT
          PROCrgbret(cycle%,trip%,sr%,sg%,sb%)
          IF sr%+sg%+sb%=0 THEN PRINT#A,cycle%,trip%
    
          cycle%+=2
        UNTIL cycle%>wh%
        cycle%=0
        trip%+=2
      UNTIL trip%=araysize%
      PRINT#A,1,1
      CLOSE#A
      ENDPROC
      REM *****SPECIAL RGB tools (color extraction) has use with PROCdotrgb
      DEF PROCrgbret(x%,y%,RETURN r%,RETURN g%,RETURN b%)
      LOCAL rgb%
      rgb%=TINT(x%,y%)
      r%=rgb% AND &FF
      g%=rgb%>>8 AND &FF
      b%=rgb%>>16 AND &FF
      ENDPROC
      DEF PROCcolor(fb$,rgb$)
      PRIVATE assemble$,br%,bg%,bb%
      IF rgb$="0" OR rgb$="black" THEN rgb$="000,000,000"
      IF rgb$="1" OR rgb$="red" THEN rgb$="200,000,000"
      IF rgb$="2" OR rgb$="green" THEN rgb$="000,200,000"
      IF rgb$="3" OR rgb$="yellow" THEN rgb$="200,200,000"
      IF rgb$="4" OR rgb$="blue" THEN rgb$="000,000,200"
      IF rgb$="5" OR rgb$="magenta" THEN rgb$="200,000,200"
      IF rgb$="6" OR rgb$="cyan" THEN rgb$="000,200,200"
      IF rgb$="7" OR rgb$="white" THEN rgb$="200,200,200"
      IF rgb$="8" OR rgb$="grey" THEN rgb$="056,056,056"
      IF rgb$="9" OR rgb$="light red" THEN rgb$="248,056,056"
      IF rgb$="10" OR rgb$="light green" THEN rgb$="056,248,056"
      IF rgb$="11" OR rgb$="light yellow" THEN rgb$="248,248,056"
      IF rgb$="12" OR rgb$="light blue" THEN rgb$="056,056,248"
      IF rgb$="13" OR rgb$="light magenta" THEN rgb$="248,056,248"
      IF rgb$="14" OR rgb$="light cyan" THEN rgb$="056,248,248"
      IF rgb$="15" OR rgb$="light white" THEN rgb$="248,248,248"
      assemble$=rgb$
      br%=VAL(MID$(assemble$,1,3)):bg%=VAL(MID$(assemble$,5,3)):bb%=VAL(MID$(assemble$,9,3))
      IF fb$="f" OR fb$="F" THEN COLOUR 0,br%,bg%,bb% : GCOL 0
      IF fb$="b" OR fb$="B" THEN COLOUR 1,br%,bg%,bb% : GCOL 128+1
      ENDPROC
 

Re: Spider demo for new sketch overlay tool
Post by hellomike on Jun 14th, 2017, 7:44pm

If you removed unnecessary components, why is the same variable assigned twice in the first two lines?

I probably wouldn't have bothered by it if you didn't make that remark.
Re: Spider demo for new sketch overlay tool
Post by michael on Jun 14th, 2017, 11:39pm

hellomike

Quote:
If you removed unnecessary components, why is the same variable assigned twice in the first two lines?

I probably wouldn't have bothered by it if you didn't make that remark.


I would say that at times I have had to define or initialize a variable before use.. Has that changed in this case?

If I typed :

Code:
LET araysize%=150   


Then I wouldn't need to do this :

Code:
araysize%=0
          araysize%=150 


Perhaps I am mistaken?

I have removed the first line and modified araysize% to

Code:
LET araysize% =150