BBC BASIC for Windows
Programming >> Graphics and Games >> Adding the 3D ELLIPSE RING TOOL
http://bb4w.conforums.com/index.cgi?board=graphics&action=display&num=1457409189

Adding the 3D ELLIPSE RING TOOL
Post by michael on Mar 8th, 2016, 02:53am

My 3rd program in BBC BASIC..I will add more complex stuff than this later.. I am just getting warmed up.

As you can see the programming habit has changed with the way I use variables. (its easier but of course I may break from this later as I progress with my level of programming)

The dimmer DI controls the depth and can affect the thickness as well
Look at the DEF PROC_ellipsering procedure to get an idea of how it works.

Oh and the mouse.. HOLD THE LEFT MOUSE BUTTON DOWN AND DRAG ACROSS THE SCREEN!!
SO MUCH FUN!!
Code:
      REM SET MODE TO 8 USING VDU
      VDU 22,8
      REM SET LINE THICKNESS TO 3
      VDU 23,23,3|
      OFF
      GCOL 1
      PROC_ellipsering(200,100,800,800,150,100,200,200,200,2)
      PROC_ellipsering(10,20,1100,400,200,100,200,50,200,2)
      PROC_ellipsering(50,200,150,400,200,100,50,145,50,2)

      PROC_sphere(200,700,50,100,200,100,3)
      PROC_sphere(800,500,250,200,150,200,1)
      PROC_sphere(600,500,300,150,150,200,1)
      PROC_sphere(500,300,300,200,200,200,1)
      (mou)
      MOUSE x,y,b
      IF b=4 THEN PROC_sphere(x,y,50,100,200,100,3)
      GOTO (mou)
      END
      DEF PROC_ellipsering(CENTERH,CENTERV,H,V,SIZE,THICKNESS,X,C,A,DI)
      IF SIZE > THICKNESS THEN SIZE = THICKNESS
      OC=THICKNESS/2
      OUTCENTERH=CENTERH+OC
      OUTCENTERV=CENTERV+OC
      R=0
      SWITCH=0
      DEPTHCOUNT=SIZE/2
      FOR Y=1 TO DEPTHCOUNT
        COLOUR 1,X,C,A
        ELLIPSE H,V,OUTCENTERH-R,OUTCENTERV-R
        ELLIPSE H,V,OUTCENTERH+R,OUTCENTERV+R
        R=R+1
        (leap)
        X=X-DI
        C=C-DI
        A=A-DI
        IF X<2 THEN X=2
        IF C<2 THEN C=2
        IF A<2 THEN A=2
      NEXT Y
      ENDPROC

      ENDPROC
      DEF PROC_sphere(H,V,SIZE,R,G,B,DI)
      r%=R
      g%=G
      b%=B
      size%=SIZE
      dimmer%=DI
      FOR x%=0 TO size%
        c%=50
        r%=r%-dimmer%
        g%=g%-dimmer%
        b%=b%-dimmer%
        IF r% <2 THEN r%=2
        IF g% <2 THEN g%=2
        IF b%<2 THEN b%=2
        IF r%<50 AND g%<50 AND b%<50 THEN GOTO (jump)
        COLOUR 1,r%,g%,b%
        CIRCLE H,V,x%
        (jump)
      NEXT x%
      ENDPROC
 

Re: Adding the 3D ELLIPSE RING TOOL
Post by DDRM on Mar 8th, 2016, 08:43am

Hi Michael,

I like the ellipses, they work really well!

Do you realise that you are clipping almost 50% of the width of some of your spheres? Now I understand what you meant in your comment that your technique can only handle a certain size of sphere.

Might a better approach be to scale your shading to the radius of the spheres? Maybe something like this:

Code:
       MODE 21
      VDU 23,23,3|
      PROCSphere(800,600,500,50,20,20)
      PROCSphere(200,200,100,50,100,20)
      PROCSphere2(900,500,200,50,20,250)
      PROCSphere2(1200,100,50,150,20,50)
      END
      :
      DEFPROCSphere(px%,py%,rdius%,r%,g%,b%)
      LOCAL x%,dw,dr
      GCOL 1
      FOR x%=0 TO rdius%-1
        dr=(x%/rdius%)^2  :REM Calculate what fraction of the shift to white has passed
        REM The squaring means you spend more time near the base colour, which I think looks better
        REM Properly, you should probably use some sort of COS function...
        COLOUR 1,r%+(255-r%)*dr,g%+(255-g%)*dr,b%+(255-b%)*dr
        CIRCLE px%,py%,rdius%-x%
      NEXT x%
      ENDPROC
      :
      DEFPROCSphere2(px%,py%,rdius%,r%,g%,b%)
      LOCAL x%,dw,dr
      GCOL 1
      FOR x%=0 TO rdius%-1
        dr=COS((PI/2)*((x%/rdius%)))  :REM Alternative version using COS
        COLOUR 1,255-(255-r%)*dr,255-(255-g%)*dr,255-(255-b%)*dr
        CIRCLE px%,py%,rdius%-x%
      NEXT x%
      ENDPROC
 


Best wishes,

D
Re: Adding the 3D ELLIPSE RING TOOL
Post by michael on Mar 8th, 2016, 12:22pm

If you like this, you will really like my latest most impressive feat. Actual adjustable Emulated 3D lighting on a custom 3D image that is resizable. And in 2D!!

Yeah, I have thought of that, but you have a dimmer (or depth) range of 255 regardless of your sphere size. So if you like your spheres, great, but with little dimmer, your sphere looks more flat.(if you know what I mean)

BUT AFTER LOOKING CAREFULLY: Your spheres could have a larger white scale spread to compensate.. This is interesting. ( so... that might mean adding some distortion or mixing other shades with the initial white scale)

BUT that is a problem because you are working with a CIRCLE.
Any change would affect the entire image on all sides.
SO that's why my latest project eliminates that. But it is a intensive process in programming. (the tool works well, but it is a process to create the image as it must be done manually at this time, much like in true 3D except not as complex)


In order to get the true depth of a sphere and really make it look deep, is to increase the dimmer.
The other effect is that your image size (clipping) must be done to prevent the image from blacking out past the visual size of the sphere.
I added the clipping as a fail safe for those who start over adjusting the dimmer vs the size of the sphere and that really was a last moment improvement.
In which case I could just make a smaller sphere with a larger dimmer.* But I just slapped this together quickly... soo

The original platform wasn't affected like BBC basic is affected (or at least I assume it because I may have overlooked something)
The graphics are upside down to me so maybe I am getting too ambitious and not paying attention to something.

If the BASICs from the west and the eastern parts of the world differ so much, imagine what a alien civilization would create for programming languages. Maybe 2D would not exist or perhaps they would have some weird way of interfacing with the program like perhaps radar visuals or direct in mind interface.