BBC BASIC for Windows
« Adding the 3D ELLIPSE RING TOOL »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:06pm



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: Adding the 3D ELLIPSE RING TOOL  (Read 321 times)
michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
laugh Adding the 3D ELLIPSE RING TOOL
« Thread started 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
 
« Last Edit: Mar 8th, 2016, 04:46am 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
laugh Re: Adding the 3D ELLIPSE RING TOOL
« Reply #1 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
User IP Logged

michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
laugh Re: Adding the 3D ELLIPSE RING TOOL
« Reply #2 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.



« Last Edit: Mar 8th, 2016, 1:03pm by michael » 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