BBC BASIC for Windows
« Textured Sprite tool: The depth filler project »

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



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: Textured Sprite tool: The depth filler project  (Read 615 times)
michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Textured Sprite tool: The depth filler project
« Thread started on: Aug 16th, 2016, 02:38am »

Phase 1: The idea in a working example

Well, here it is.. It is the beginning of the texture/depth project. The idea is that eventually, a person could say, draw a cartoon and this tool would fill in a curve texture in different directions. Its hard to make toons look good.. and now its possible to define shading on curves or edges.

There is the stagger option that I want to add along with accelerated dimming at different parts of the filled area.

Think of this as a PAINT texture filling tool.

This is supposed to start in the center and shade to the sides.. BUT the location of the filler matters, and it has a limit.. Its for small images.. If you make the fill area too big, it just wont work properly.

With the stagger option, the fill tool would measure the distance and add duplicate color to lengthen the distance you can spread the shade and then accelerate it near the edges.

Code:
      INSTALL @lib$+"SPRITELIB"
      cy%=0:di%=0
      REM       width;height;charwidth,charheight,number of colors,character set
      VDU 23,22,1024;600;8,15,16,1 :REM max width is 1920 and 1440 height
      IF FN_initsprites(10) = 0 STOP
      PROCsbox(0,0,100,100,"black","white")
      REM texture x,y,r,g,b
      cy%=5
      di%=3:REM the feared dimmer "EEEEEEKKK!!!"
      REPEAT
        cy%=cy%+2
        PROCtexture(30,cy%,255,200,250,di%)
      UNTIL cy%>90


      REM ***create a mask for the selected area and save new sprite as mybox.bmp  **
      PROCmask(0,0,101,100,"mybox")
      PROCpixel(500,500,"green")
      REM mask must be before _getbmp.. otherwise it wont update
      PROC_getbmp(9,"mybox")
      REM sprite #, x,y, 0=off 1= on
      FOR X=100 TO 1000 STEP 5
        PROC_movesprite(9,X,100,1)
        WAIT 1
      NEXT X
      PROC_exitsprites
      REM Turn off the text cursor _
      OFF
      VDU 5 : REM Treat text as graphics (transparent background)
      PROCset(200,200,"5")
      c%=TINT(0,0)
      PROCpr(110,100,"TEST: THE MASK IS CREATED","green")
      WAIT 0
      END
      REM local color assignment is faster than using PROCcolor in this case
      REM speed helps with intense texture work and the variables are easier to work with
      DEFPROCtexture(x%,y%,br%,bg%,bb%,cd%)
      LOCAL stage1%,stage2%,edger%,edgel%,cr%,cl%,di%
      edger%=x%
      edgel%=x%
      REPEAT
        IF cr%=0 THEN cr%=TINT(edger%,y%):edger%+=1
      UNTIL cr%>0
      edger%-=1
      REPEAT
        IF cl%=0 THEN cl%=TINT(edgel%,y%):edgel%-=1
      UNTIL cl%>0
      edgel%+=1
      coun%=0:di%=0
      temp%=0
      REPEAT
        COLOUR 0,br%-di%,bg%-di%,bb%-di%
        GCOL 0
        MOVE x%+coun%,y%:DRAW x%+coun%,y%
        coun%=coun%+1
        temp%=x%+coun%
        di%+=cd%
  
      UNTIL temp%=edger%
      coun%=0:di%=0
      temp%=0
      REPEAT
        COLOUR 0,br%-di%,bg%-di%,bb%-di%
        GCOL 0
        MOVE x%-coun%,y%:DRAW x%-coun%,y%
        coun%=coun%+1
        temp%=x%-coun%
        di%+=cd%
  
      UNTIL temp%=edgel%
      ENDPROC

      REPEAT
        COLOUR 0,br%,bg%,bb% : GCOL 0
      UNTIL x%=stage1%
      REM h and v must always be a higher value as they are the top right corner of the image.( I make make this smart like sbox)
      DEFPROCmask(x%,y%,h%,v%,name$)
      LOCAL dx%,dy%,c%,counx%,couny%
      counx%=0:couny%=0
      dx%= h%-x%
      dy%= v%-y%
      IF dx%>dy% OR dx%=dy% THEN
        REPEAT
          c%=TINT(x%+counx%,y%+couny%)
          IF c%=0 THEN PROCpixel(x%+counx%,y%+couny%+dy%+1,"light white") ELSE PROCpixel(x%+counx%,y%+couny%+dy%+1,"0")
          couny%+=1:IF couny%=y%+dy% THEN couny%=0:counx%=counx%+1
        UNTIL counx%=dx%
      ENDIF
      IF dy%>dx% THEN
        REPEAT
          c%=TINT(x%+counx%,y%+couny%)
          IF c%=0 THEN PROCpixel(x%+counx%,y%+couny%+dy%+1,"255,255,255") ELSE PROCpixel(x%+counx%,y%+couny%+dy%+1,"0")
          counx%+=1:IF counx%=x%+dx% THEN counx%=0:couny%=couny%+1
        UNTIL couny%=dy%
      ENDIF
      OSCLI "SCREENSAVE """+name$+""" "+STR$(x%)+","+STR$(y%)+","+STR$(dx%)+","+STR$(dy%*2)
      ENDPROC
      DEFPROCpixel(x%,y%,c$)
      PROCcolor("f",c$)
      MOVE x%,y%:DRAW x%,y%
      ENDPROC
      REM this may slow things a bit, but I want to change it
      DEFPROC_getbmp(num%,bmpname$)
      LOCAL a%
      bmpname$+=".bmp"
      IF FN_createspritefrombmp(num%,bmpname$) = 0 THEN
        ERROR 100, "Couldn't create "+bmpname$+" sprite"
      ENDIF
      ENDPROC
      REM c$ can be colors like blue or 1 or a R,G,B color
      DEF PROCset(x%,y%,c$)
      LOCAL h%
      PROCcolor("f",c$)
      FOR h%=0 TO 20
        LINE x%+h%,y%,x%+h%,y%+20
      NEXT
      MOVE 0,0
      ENDPROC
      REM c$ is fill color. b$ is border color
      DEF PROCsbox(x%,y%,w%,h%,c$,b$)
      LOCAL ry%,sx%,sy%
      sx%=x%:sy%=y%
      IF x%>w% THEN x%=w%:w%=sx%
      IF y%>h% THEN y%=h%:h%=sy%
      ry%=y%
      PROCcolor("f",c$)
      REPEAT
        LINE x%,y%,w%,y%
        y%=y%+1
      UNTIL y%=h%
      y%=ry%
      PROCcolor("f",b$)
      LINE x%+2,y%+2,w%-2,y%+2
      LINE w%-2,y%+2,w%-2,h%-4
      LINE w%-2,h%-4,x%+2,h%-4
      LINE x%+2,h%-4,x%+2,y%+2
      ENDPROC
      REM color "F"or"B", "color name number or R G B"
      REM this was created to manage special colors and to hold onto the original first 2 pallets (as I use them all the time)
      DEF PROCcolor(fb$,rgb$)
      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$="magneta" 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 magnetta" OR rgb$="light purple" 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"
      PRIVATE assemble$,br%,bg%,bb%
      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
      REM X,Y,text color,message,r,g,b
      REM ************************************************************************
      DEF PROCpr(X,Y,msg$,c$)
      LOCAL initialx%,fi%,reduction%,tx,ty
      initialx%=LEN(msg$)
      PROCcolor("f",c$)
      GCOL 0
      LET tx= X+initialx%+25
      LET ty= Y:reduction%=0
      reduction%=initialx%/2
      reduction%=reduction%*6
      IF initialx%<20 THEN reduction%=reduction%/2
      initialx%=initialx%*22-reduction%
      FOR fi%=12 TO 48
        LINE X-3,Y+20-fi%,X+initialx%+8,Y+20-fi%
      NEXT
      COLOUR 0,0,0,0
      GCOL 0
      MOVE tx,ty
      PRINT msg$
      MOVE 0,0 REM hide that thing
      ENDPROC

 
« Last Edit: Aug 18th, 2016, 2:30pm 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: Textured Sprite tool: The depth filler project
« Reply #1 on: Aug 17th, 2016, 10:57am »

Hi Michael,

Can't quite work out what the texture section is doing, but I liked the way you create a sprite on the fly. Your routine doesn't cater for the case where dx%=dy%, though!

Here's a variant focussing on the sprite aspect, for anyone who might find that useful. It's a bit simpler, and also quicker.

Code:
      INSTALL @lib$+"SPRITELIB"
      IF FN_initsprites(1) = 0 STOP  :REM Only allows for one sprite (sprite 0) - increase if you want more!
      MODE 21
      GCOL 1
      FOR x%=45 TO 0 STEP -1
        COLOUR 1,255-x%*2,255-x%*5,255-x%*5
        CIRCLE FILL 50,50,x%
      NEXT x%
      REM ***create a mask for the selected area and save new sprite as mybox.bmp  **
      PROCmask(0,0,100,100,"mybox.bmp")
      IF FN_createspritefrombmp(0,"mybox.bmp") = 0 THEN ERROR 100, "Couldn't create "+bmpname$+" sprite"
      GCOL 4
      RECTANGLE FILL 0,0, 1600,1200
      FOR X=100 TO 1000 STEP 5
        REM sprite #, x,y, 0=off 1= on
        PROC_movesprite(0,X,100,1)
        WAIT 5
      NEXT X
      PROC_exitsprites
      END

      REM In my version I've assumed x%,y%,h%,v% are all in BB4W graphics coordinates (i.e. 2 per pixel)
      DEFPROCmask(x%,y%,h%,v%,name$)
      LOCAL dx%,dy%
      GCOL 0
      RECTANGLE FILL x%,y%+v%+2,h%,v%
      GCOL 1
      FOR dx%=x% TO x%+h% STEP 2
        FOR dy%=y% TO y%+v% STEP 2
          IF TINT(dx%,dy%)>0 THEN COLOUR 1,0,0,0 ELSE COLOUR 1,255,255,255
          PLOT 69,dx%,dy%+v%+2
        NEXT dy%
      NEXT dx%
      OSCLI "SCREENSAVE """+name$+""" "+STR$(x%)+","+STR$(y%)+","+STR$(h%)+","+STR$(v%*2)
      ENDPROC
 


I know you tend to redefine your colours a lot, so I've not assumed that the colours will be as expected, and I know that means I end up with Colour 1 being corrupted. You could put it back to normal at the end of the routine, but that still won't be right if you've already changed it somewhere else!

Best wishes,

D
User IP Logged

michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Re: Textured Sprite tool: The depth filler project
« Reply #2 on: Aug 18th, 2016, 02:39am »

I fixed the dx%=dy% issue. I had fixed it before, but somehow I ended up putting an older version of my program here.. UGH

Basically, the texture has a center starting point.
It will attempt to shade from that point to the sides.
The highest color would be in the center, but you can place the starting point on either left or right side, giving the effect of shading and lighting and depth, but I am working on improvement. .
Say, for instance I wanted to make a ball for a pin ball game, I would want to animate lighting to show the direction of movement.
( the rolling ball animation.)
« Last Edit: Aug 18th, 2016, 2:24pm by michael » User IP Logged

I like making program generators and like reinventing the wheel
David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: Textured Sprite tool: The depth filler project
« Reply #3 on: Aug 18th, 2016, 11:44pm »

It's perhaps interesting to compare the speed of the program listed below when run under BB4W versus BBC-SDL (Windows):

Code:
      MODE 8
      OFF

      W% = 64
      H% = 64

      DIM T%(W%-1, H%-1)

      TIME=0

      FOR Y%=0 TO H%-1
        FOR X%=0 TO H%-1
          T%(X%,Y%)=TINT(2*X%,2*Y%)
        NEXT
      NEXT

      t% = TIME

      PRINT '" It took "; t%; " cs. to scan ";
      PRINT STR$(W%*H%) + " pixels."
 


BB4W completes the task some 80 times faster, on my laptop.

So, Michael, if it's your intention that cross-platform BBC BASIC users get to enjoy your programs and tools as well as BB4W users, then some faster means of generating masked sprites from screen images may be called for!

Drawing bitmap images via *MDISPLAY is also much, much slower under BBC-SDL.

Directly exploiting SDL's rendering backend (OpenGL) is probably the way to go for fast rendering of bitmaps and sprites. Anyone into writing libraries? ;)


David.
--
User IP Logged

michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Re: Textured Sprite tool: The depth filler project
« Reply #4 on: Aug 19th, 2016, 01:46am »

Well actually, I am making Libraries from all my work. And yes, the tools will be here to help everyone.

As for the mask tool, it is actually just as fast as the API driven version for LB and LBB, and it is actually A LOT easier. BBC basic has more built in capabilities.

Once I get these tools perfected I will work on trying to perhaps see if there is even more efficient ways to do the work.
* right now I am trying to figure out why my texture filler is not always doing what I designed it to do..
I am thinking it is because I am using 0 as my palette..
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