[Java][Semi-useless] Accidental 2D Orbital Physics Engine

Newbie Spellweaver
Joined
May 25, 2011
Messages
77
Reaction score
58
So a couple weeks back I was messing around with radial gradients, I wanted to make a simple variable distance starfield renderer, but something more interesting happened instead, I figured I'd stick it here:
Aerospark - [Java][Semi-useless] Accidental 2D Orbital Physics Engine - RaGEZONE Forums

The screenshot does it little justice, hers a short video.
celestial body orbital physics simulator (with frameblending) - YouTube
(that's java software rendering/processing...)

It's not a real physics simulator, but it definitely produces a similar effect.
It's always interesting when you're programming something, and something far more entertaining then you planned happens. Glitches aren't always bad.


Heres the paint/process method, I figured I'd include a code snippet:
PHP:
public void paintbuff(Graphics2D g) {
        g.setColor(awht);
        g.fillRect(0,0,1024,768);
        ttr = System.currentTimeMillis();
        for (SwirlyStar s : stars) {
            if (s.process()) {
                s.x.setTo(((mousex > s.x.value() ? (mousex - s.x.value()) : (s.x.value() - mousex)) + Math.round(Math.random() * 64) - 32) + (mousex > s.x.value() ? (s.x.value() - mousex) / 8 : (mousex - s.x.value()) / 8));
                s.y.setTo(((mousey > s.y.value() ? (mousey - s.y.value()) : (s.y.value() - mousey)) + Math.round(Math.random() * 64) - 32) + (mousey > s.y.value() ? (s.y.value() - mousey) / 8 : (mousey - s.y.value()) / 8));
            }
            g.drawImage(s.im, s.x.value(), s.y.value(), null);
        }
        g.setColor(Color.WHITE);
        g.drawString("Celestial bodies: " + stars.size(), 0, 16);
        ttr = System.currentTimeMillis() - ttr;
        g.drawString("TTR (render/process time): " + ttr + "ms", 0, 32);
    }

Oh, and here's the source for anyone interested, though it's not really... how you would normally do this: source
(left click: add 1 body, right click add 10? bodies)
If any part of this is useful to you, feel free to use it.
 
Good god I must have been bored to convert that snippet to C#

Code:
using System;

public virtual void paintbuff(Graphics2D g)
{
	g.Color = awht;
	g.fillRect( 0, 0, 1024, 768 );

	ttr = System.currentTimeMillis();
	
	foreach ( SwirlyStar s in stars )
	{
		if ( s.process() )
		{
			s.x.setTo( ( ( mousex > s.x.value() ? ( mousex - s.x.value() ) : ( s.x.value() - mousex ) ) + Math.Round( Math.random() * 64 ) - 32 ) + ( mousex > s.x.value() ? ( s.x.value() - mousex ) / 8 : ( mousex - s.x.value() ) / 8 ) );
			s.y.setTo( ( ( mousey > s.y.value() ? ( mousey - s.y.value() ) : ( s.y.value() - mousey ) ) + Math.Round( Math.random() * 64 ) - 32 ) + ( mousey > s.y.value() ? ( s.y.value() - mousey ) / 8 : ( mousey - s.y.value() ) / 8 ) );
		}
		
		g.drawImage( s.im, s.x.value(), s.y.value(), null );
	}
	
	g.Color = Color.WHITE;
	g.drawString( "Celestial bodies: " + stars.size(), 0, 16 );
	ttr = System.currentTimeMillis() - ttr;
	g.drawString( "TTR (render/process time): " + ttr + "ms", 0, 32 );
}
 
Good god I must have been bored to convert that snippet to C#

Code:
using System;

public virtual void paintbuff(Graphics2D g)
{
	g.Color = awht;
	g.fillRect( 0, 0, 1024, 768 );

	ttr = System.currentTimeMillis();
	
	foreach ( SwirlyStar s in stars )
	{
		if ( s.process() )
		{
			s.x.setTo( ( ( mousex > s.x.value() ? ( mousex - s.x.value() ) : ( s.x.value() - mousex ) ) + Math.Round( Math.random() * 64 ) - 32 ) + ( mousex > s.x.value() ? ( s.x.value() - mousex ) / 8 : ( mousex - s.x.value() ) / 8 ) );
			s.y.setTo( ( ( mousey > s.y.value() ? ( mousey - s.y.value() ) : ( s.y.value() - mousey ) ) + Math.Round( Math.random() * 64 ) - 32 ) + ( mousey > s.y.value() ? ( s.y.value() - mousey ) / 8 : ( mousey - s.y.value() ) / 8 ) );
		}
		
		g.drawImage( s.im, s.x.value(), s.y.value(), null );
	}
	
	g.Color = Color.WHITE;
	g.drawString( "Celestial bodies: " + stars.size(), 0, 16 );
	ttr = System.currentTimeMillis() - ttr;
	g.drawString( "TTR (render/process time): " + ttr + "ms", 0, 32 );
}

That doesn't even come close to compiling as C#. You didn't convert it, you ran it through a formatter and added a few keywords.
 
Back