BBC BASIC for Windows
« (spider) Array BMP sketch tool (moved to tools) »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:00pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: (spider) Array BMP sketch tool (moved to tools)  (Read 874 times)
michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx (spider) Array BMP sketch tool (moved to tools)
« Thread started on: Feb 13th, 2017, 03:47am »

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
       

« Last Edit: Jun 17th, 2017, 12:40am by michael » User IP Logged

I like making program generators and like reinventing the wheel
DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: RETROLIB 11 with BMP sketch tools
« Reply #1 on: Feb 13th, 2017, 12:25pm »

So in effect you are using the B&W sketch as a mask - the black drawing is used to direct the drawing of the (new) colour the next time round? Without seeing the code, it's difficult to see what you mean by storing the drawing actions, assuming it's constructing them from the image. I can see it would be straightforward to identify horizontal and vertical lines and store them efficiently, but curves will be more difficult, I suspect! It may be easier just to store the whole mask: if it has to be (pure) B&W it could be stored as a run-length encoded file very compactly - or just as a 1BPP bitmap - and then draw in colour wherever the mask is black.

If you have access to the drawing process *as it's occurring*, then it makes sense to store a list of the actions, so as to be able to reproduce them - essentially setting up a macro?

You also seem to be heading in the direction of vector graphics (i.e. storing the image as a series of lines/curves/fills rather than as a bitmap).

Best wishes,

D
User IP Logged

michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Re: RETROLIB 11 with BMP sketch tools
« Reply #2 on: Feb 13th, 2017, 5:26pm »

I provided a link to the code and image and output file.

The file is just the locations of the sketch pixels. Nothing else.

When it is redrawn, it allows you to place it anywhere on the screen like a bmp image and alter its color, but it only moves the sketch, and you can control the color of the sketch.

The macro idea, is already partly done. I will show a link to it when it is done.
User IP Logged

I like making program generators and like reinventing the wheel
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls