News:

Welcome to RetroCoders Community

Main Menu

The ULTIMATE gradient ball

Started by ZXDunny, Jul 12, 2023, 09:27 AM

Previous topic - Next topic

ZXDunny

This is ported from something I've been messing around in on SpecBAS on and off for the past few years - it's part of a "solar system image generator" thing. Hope you like it, I guess it could be fun to animate somehow!

Move your mouse around while it's running.

' Ball shader
' by ZXDunny 2023

sw=800
sh=480
screen _newimage(sw,sh,24) ' SpecBAS uses this as its default window size

xc=sw/2
yc=sh/2
r=100
amb=0.0125
k=3
mxp=(1-amb)*255
r2=r*r

do
	lx=xc-_mousex
  ly=yc-_mousey
  lz=-75
  
  cls
  l=sqr(lx*lx+ly*ly+lz*lz)
  nlx=lx/l
  nly=ly/l
  nlz=lz/l
  
  for x=-r to r
  	x2=x*x
    for y=-r to r
    	y2=y*y
      if x2+y2<=r2 then
      	v2=sqr(r2-x2-y2)
        l=sqr(x2+y2+v2*v2)
        v0=x/l
        v1=y/l
        v2=v2/l
        d=nlx*v0+nly*v1+nlz*v2
        i=mxp*(iff(d<0,-d^k,0)+amb)
        ink=_RGB32(int(i),int(i),int(i))
        plot(x+xc,y+yc),ink
			end if
		next y
	next x
  _display
loop

CharlieJV

Oh My Lanta, that is some nice !

CharlieJV

That reminds me of this Lightmapping program I found and got working in BAM.

ZXDunny

Thanks! Now I'm just wondering what to actually do with it :)

CharlieJV

Quote from: ZXDunny on Jul 12, 2023, 01:57 PMThanks! Now I'm just wondering what to actually do with it :)

I'm thinking: go to pet store, get pet monkey, get monkey to move mouse for bananas, sit back, enjoy hot cup o' something or cold mug o' something, enjoy the show, resupply monkey's banana bowl.

That aside: I've got my "development" version of BAM setup to implicitly do INT on _RGB32 (and the alternative keyword for that function: _RGB) parameters.  Holding on release of that because I'm not quite done testing the new PCOPY statement.

CharlieJV

Quote from: ZXDunny on Jul 12, 2023, 09:27 AMThis is ported from something I've been messing around in on SpecBAS on and off for the past few years - it's part of a "solar system image generator" thing. Hope you like it, I guess it could be fun to animate somehow!

Move your mouse around while it's running.

' Ball shader
' by ZXDunny 2023

sw=800
sh=480
screen _newimage(sw,sh,24) ' SpecBAS uses this as its default window size

xc=sw/2
yc=sh/2
r=100
amb=0.0125
k=3
mxp=(1-amb)*255
r2=r*r

do
	lx=xc-_mousex
  ly=yc-_mousey
  lz=-75
  
  cls
  l=sqr(lx*lx+ly*ly+lz*lz)
  nlx=lx/l
  nly=ly/l
  nlz=lz/l
  
  for x=-r to r
  	x2=x*x
    for y=-r to r
    	y2=y*y
      if x2+y2<=r2 then
      	v2=sqr(r2-x2-y2)
        l=sqr(x2+y2+v2*v2)
        v0=x/l
        v1=y/l
        v2=v2/l
        d=nlx*v0+nly*v1+nlz*v2
        i=mxp*(iff(d<0,-d^k,0)+amb)
        ink=_RGB32(int(i),int(i),int(i))
        plot(x+xc,y+yc),ink
			end if
		next y
	next x
  _display
loop

That is just to good to not have the "executable" published:

ULTIMATE Gradient Ball

(Source code)

ZXDunny

Thanks Charlie :)

If anyone wants to play, lx,ly,lz are the light source coordinates in 3D space (the ball is centred on 0,0,0).

"amb" is the amount of ambient light applied
"k" is the light intensity/spread. The larger the value of k, the more of a reflection "spot" the highlight becomes. I'm wondering if I should remove the k parameter and make it a function of the distance of the light source from the ball. Maybe later.