Submitted by MGA on

Forums:

*' cheap bonkers.bas SmallBASIC 0.12.8 [B+=MGA] 2017-01-07*

*' from Galileo's Collection, Bonkers is a funky mystery*

*' but I think it is about colliding particles.*

*' In this version use spacebar to toggle between clearing *

*' screen. The orange balls have recently collided.*

n = 100 *'<<<<<<<<<<<< feel free to play with this number*

clrMode = 1

dim x(n), y(n), dx(n), dy(n), c(n)

for i = 0 to n

x(i) = xmax/n * i

y(i) = ymax/n * i

dx(i) = (rnd*25 +5) * iff(rnd < .5,-1, 1)

dy(i) = (rnd*25 +5) * iff(rnd < .5,-1, 1)

next

while 1

k = inkey

if asc(k) = 32 then clrMode *= -1

if clrMode < 0 then cls

for i = 0 to n

x(i) += dx(i)

if x(i) > xmax then dx(i) *= -1 : x(i) = xmax

if x(i) < 0 then dx(i) *= -1 : x(i) = 0

y(i) += dy(i)

if y(i) > ymax then dy(i) *= -1 : y(i) = ymax

if y(i) < 0 then dy(i) *= -1 : y(i) = 0

if i < n then

for j = i + 1 to n

if sqr((x(i)-x(j))^2 + (y(i)-y(j))^2) < 50 then

dx(i) *= -1 *': dy(i) *= -1 *

dy(j) *= -1 *': dx(j) *= -1 *

c(i) = 1 : c(j) = 1

fi

next

fi

for r = 25 to 1 step -1

if c(i) then

color rgb(255-5*r,64-2*r,0)

else

color rgb(255-10*r,255-10*r,255-10*r)

fi

circle x(i), y(i), r filled

next

c(i) = 0

next

showpage

delay 10

wend

- Log in to post comments

chrisws replied on Permalink

## That's really bonkers... I

That's really bonkers... I like it !

MGA replied on Permalink

## One of these days...

One of these days, I would like to work out the proper math for a deflection from a collision.

I remember running into the problem of collision deflection discussing an air hockey game sim, striking a disk with a round paddle, right here at this forum when I first started attending it.

The real bonkers example for 3 balls seems to have it worked out in vectors, hard to follow...

This cheap version just totally faked deflection paths and covered it up with too many balls to follow! ;-))

chrisws replied on Permalink

## Speaking of having fun with

Speaking of having fun with Math - here's something you might like to consider doing:

https://www.edx.org/course/artificial-intelligence-ai-columbiax-csmm-101x

MGA replied on Permalink

## Interesting

I had checked out AI books from library, in a word it seems to be all about states.

As for the course suggested, never had much luck with Python. I am like Sheldon, I need closure, everything is off just a bit without a WEND... an official end to things... fi ;-))

MGA replied on Permalink

## Aha, a collision study

(note: it had a 640 x 512 screen)

MGA replied on Permalink

## Basic Air Hockey!

Now the player has more control of where to hit the ball! This affects paddleball and Breakout games too.

Wait, I didn

't do the Breakout translation to SmallBASIC yet?MGA replied on Permalink

## Improved Bonkers

Much better collisions!