Atom Smash simulation

User projects written in or related to FreeBASIC.
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Atom Smash simulation

Post by coderJeff »

EDIT: All of the source mentioned in this post is available for download here: http://frontpage.execulink.com/coder/fr ... /atoms.asp

I was looking around for a module in my old qb code and I found this instead:

Image

Blocks (made of simulated bonded atoms) are dropped from some height and smash against the ground and each other.

I made it about 6 years ago in QB. It's one of several that I did trying to simulate things like jello and dominos. Anyway, I only had to change a few lines to get it to compile and run in freebasic. (it could not have been easier).

There are some constants at the top of the program that can be tweaked to give different effects. Since the simulation is not based on any real physics, numbers don't have any real world meaning: so you will just have to play with the values. And I'm sorry if it's too fast for newer computers, there's no timing code. Maybe you can add a sleep or something in the main loop.

Download Source :atom_smash.bas 10k

I now go back to my search for what I was really looking for.
Last edited by coderJeff on Mar 27, 2006 22:17, edited 1 time in total.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Post by anonymous1337 »

Can you add a feature so I can hit space or click and bounce them against each other? I really like this program.
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Post by coderJeff »

Hmmm, looking at the code, looks like I put something like that in there. (Must have been thinking the same thing as you) Press uppercase "A" and it will give one of the atoms a jerk upward. Look in the code around line 129 where it has CASE "A" Maybe you could add some of your own CASE statements in there and play around with it.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Post by anonymous1337 »

Thanks ^_~
redcrab
Posts: 623
Joined: Feb 07, 2006 15:29
Location: France / Luxemburg
Contact:

Post by redcrab »

That's cool , and look so realistic .... great physic stuff

I added SCREENSYNC before "FLIP" and the motion looks even better (less nervous move)

I really like it !
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Post by coderJeff »

screensync ... great idea, I wish I thought of that. I noticed that I was also missing a constant for the maximum speed an atom could go. (It is set to 5). So I also added that and updated the posted source. Thanks!
mambazo
Posts: 652
Joined: Jul 17, 2005 13:02
Location: Ireland
Contact:

Post by mambazo »

Brilliant!

I see the makings of a 2D Stickman Ragdoll System!!!

http://mambazo.langfordtavern.com/zips/ ... _lines.bas

Who's up for the challenge! :P
arenth
Posts: 511
Joined: Aug 30, 2005 6:22

Post by arenth »

The fact that nodes snap off is incredible, imagine using this as a ragdoll system in some side scrolling game, your guy leaps off an edge, impacts the ground, and he is dismembered...
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Post by anonymous1337 »

arenth wrote:The fact that nodes snap off is incredible, imagine using this as a ragdoll system in some side scrolling game, your guy leaps off an edge, impacts the ground, and he is dismembered...
Thanks. I'll add that to my project list.

EDIT: *Added Mr. Ragdoll to project list*
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Post by coderJeff »

2D stickmen ... Cool idea! Maybe a good way to get out aggressiveness by tossing them and squashing them with heavy virtual bricks. (Oh, nooo! who will help Mr. Bill? SPLAT!)

Some of the global constants could be coded in to the "Bonds" type so that things like body joints could have different properties from things like legs and arms. So that when dismemberment occurs, it's more likely to occur at a joint.

Here's an idea. Create a program that takes a color bitmap and converts it to an atom lattice structure, different colors could indicate different properties.

I added some of mambazo's code bits to add color to the atoms. Also, press "ESC" to exit, "R" to restart, SPACE to add random velocities.

I added a function to create a triangular shaped block, and I also re-read though my code and made a comment about how the program is supposed to work.

Link is as before: atom_smash.bas 12 k

Code: Select all

'' This particle system is not based on any real world model but
'' it does have some theory.  The math is simplified by having
'' all "atoms" of the same size and mass.  (There is no mass in
'' any of the calculations)  Also, certain physical effects are
'' simulated using factors and conditions to change the state of
'' the system.
''
'' The solid bodies are made up of "atoms". 
''
'' * Atoms have a spacing and a size (ATOMSPACE, ATOMSIZE)
'' * Atoms are affected by gravity (XGRAVITY, YGRAVITY)
'' * Atoms can bounce off the sides and bottom of the screen
''  and when they do, lose some momentum due to the
''  collision (BOUNDDECAY)
'' * Atoms have a max speed (MAXSPEED) to limit values and
''  make the simulation work better.
''
'' "Bonds" represent the relationship between two atoms.
'' When a bond is first created a distance between two atoms
'' is set to indicate how far the two atoms should be from
'' each other.  Too far or too close and the system will move
'' the atoms closer or further apart.  Let's call this the
'' balanced distance.
''
'' * The rate at which two atoms return to the balanced
''   distance is affected by stiffness (STIFFNESS).
'' * If two atoms are moving away from each other and the
''   instantaneous velocity is high enough the bond is
''   broken. (BREAKTHRESHOLD)
'' * If the magnitude of the relative velocity between two
''   atoms is high enough (DEFORMTHRESHOLD) the bond can be
''   deformed.  The amount of deformation is controlled
''   by a factor. (FDEFORM)
mambazo
Posts: 652
Joined: Jul 17, 2005 13:02
Location: Ireland
Contact:

Post by mambazo »

Did anyone see that "game", where you had a 3D Stickman, and a scene (like a flight of stairs, or a truck) and you had to cause as much damage as possible to the stick man by 'pushing' his limbs?
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Post by coderJeff »

Oh, I know what you're talking about now: http://jet.ro/dismount/
Not sure how it would work in 2D though ...
mambazo
Posts: 652
Joined: Jul 17, 2005 13:02
Location: Ireland
Contact:

Post by mambazo »

Thats the one! :P
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Post by coderJeff »

OK, here's another version that can load a from a bitmap.

ragdoll_smash.bas 14 k
ragdoll.bmp 4 k

WARNING: Some may find this program offensive and may not be suitable for younger audiences.
mambazo
Posts: 652
Joined: Jul 17, 2005 13:02
Location: Ireland
Contact:

Post by mambazo »

EDIT: Brilliant! :P
Post Reply