// forked from teeandy's forked from: The Simulation Universe, part II
// forked from teeandy's The Simulation Universe, part II
// forked from teeandy's The Simulation Universe
// Books about the real and imaginaer part.....
//
package {
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
[SWF(width="400", height="410", frameRate="30", backgroundColor="0x000000")]
public class Main extends Sprite
{
public var runtimeS:Boolean=false;
public var onePart:Array;
public var array:int=0;
public var bootSystem:Boolean = false; // true to randomice
// false go
public var flag:Number = 0; // 0 Beginn
// 1 Randomvalues setting
// 2 Gravity go
public var diffColor:int= 0xFF33CC;
public var realImag:Boolean=true; // true, mit Imaginaeren Teil
// false, only real part
public var gUniverse:int=4; // 4
public var percentImag:int=0.8;
public var imagUniverse:int=1;
public var sizeOf:Number=3; // to get visible on the screen
public var sizeImag:Number=9; // return value of a function
public var gSchuim:int=1; // can be :D differen
public var Elements:int=200; // Amount of gravitons and imaginaer Unions
public var maxVelocity:int=30; // beginning speed
public var screen:int=40000;
public var visualScreen:int=400;
function Main():void {
onePart = [];
var verrynewboxx:int = Math.random() * screen; // hm
var verrynewboxy:int = Math.random() * screen;
var verrynewx:int; // hm
var verrynewy:int;
// Schuim the same? no :D
//
// var newboxx:int = Math.random() % 24; // hm
// var newboxy:int = Math.random() % 24;
var verryv:int; // hm
var verrya:int; // 2*pi
var newbie:reDbul;
for(var ji:int=0; ji<Elements; ji++){
verrynewx = Math.random() * screen; // hm
verrynewy = Math.random() * screen;
// Schuim the same? no :D
//
// var newboxx:int = Math.random() % 24; // hm
// var newboxy:int = Math.random() % 24;
verryv = Math.random() * maxVelocity; // hm0 verrya = Math.random() * Math.PI; // 2*pi
verrya = 2*Math.PI * Math.random() ;
newbie = new reDbul( verrynewx, verrynewy, verryv, verrya, verrynewboxx, verrynewboxy, maxVelocity, screen, screen/visualScreen );
onePart.push(newbie);
array++;
}
// onePart[ji-1].show(graphics, sizeOf, sizeImag);//Painting
addEventListener(Event.ENTER_FRAME, plop); // :D
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.DOUBLE_CLICK, onMouseDoubleClick);
runtimeS = true;
// :) plopi();
}
public function plopi( ):void
{
runtimeS = false;
for(var iss:int=0; iss<Elements; iss++){
// graphics.clear();
// onePart[iss].show(graphics, diffColor, sizeOf, sizeImag);//Painting
onePart[iss].move(); // set new Realpossition
// setImag( iss ); // set the position of the imaginaer part
setnewVector( iss ); // setting new values interact
onePart[iss].bing(); // Borderrunners
if ( onePart[iss].v > maxVelocity /4 ) {
onePart[iss].v = onePart[iss].v - maxVelocity/10;
}
}
runtimeS = true;
}
public function reMix():void
{
var iss:int;
for( iss =0; iss<Elements && onePart[iss].remix>sizeOf*10; iss++){
onePart[iss].remix=0;
}
if( iss == Elements ) {
bootSystem= true;
plopi ();
bootSystem= false;
}
}
public function plop(e:Event):void
{
if ( runtimeS ) {
graphics.clear();
for(var iss:int=0; iss<Elements; iss++){
onePart[iss].show(graphics, diffColor, sizeOf, sizeImag);//Painting
// graphic.drawRect(Numberx, Numbery, Numberx + factorDisplay*factorBox, Numbery +factorDisplay*factorBox); //:D
}
// graphics.clear();
reMix();
plopi();
}
/*
var color:int = Math.random()*0xFF33CC;
graphics.beginFill(color, 85); //?? color,85);
graphics.drawCircle(200, 200, sizeImag);
graphics.endFill();
*/
}
private function onMouseDown(e:MouseEvent):void
{
if ( flag == 2 ) {
flag = 3;
}
if ( flag == 1 ) {
flag = 2;
}
if ( flag == 0 ) {
flag = 1;
}
for(var i:int=0; i<onePart.length; i++){
onePart[i].rflag = flag;
}
if ( e.localX < 200 ) {
bootSystem= !bootSystem;
}
// bootSystem= !bootSystem; // ;
}
private function onMouseDoubleClick(e:MouseEvent):void
{
realImag = !realImag;
for(var i:int=0; i<onePart.length; i++){
onePart[i].realImag = realImag;
}
}
public function setImag ( inDex:int, i:int, diff:int ):void {
var helpx:int;
var helpy:int;
var helpd:int;
var helpa:int;
if ( diff > 0.001 ){
helpy = onePart[i].posY - onePart[inDex].posY;
helpx = onePart[inDex].posX - onePart[inDex].posX;
helpd =Math.sqrt(helpx*helpx + helpy*helpy);
helpa = Math.asin(helpd / helpy);
//:)
if( onePart[inDex].a > helpa ){
onePart[inDex].a += 8/10/imagUniverse/20/diff*sizeImag;//percentImag*sizeImag;
}else{
onePart[inDex].a -= 8/10/imagUniverse/20/diff*sizeImag;//percentImag*sizeImag;
}
//:)
if( onePart[inDex].a- Math.PI/2 > helpa ){
helpd = sizeImag*8/10/imagUniverse/diff/100 ;
onePart[inDex].v = onePart[inDex].v + helpd;
}else{
helpd = sizeImag*8/10/imagUniverse/diff/100 ;
onePart[inDex].v = onePart[inDex].v - helpd;
}
if( onePart[inDex].a+ Math.PI/2 > helpa ){
helpd = sizeImag*8/10/imagUniverse/diff/100 ;
onePart[inDex].v = onePart[inDex].v - helpd;
}else{
helpd = sizeImag*8/10/imagUniverse/diff/100 ;
onePart[inDex].v = onePart[inDex].v + helpd;
}
} // 0.8 as percentImag and /100 and /20 for visualisation
}
public function distance ( inDex:int, i:int ):int {
// sqrt a2 + b2
// a = i.x minus inDex.x
// b = i.y minus inDex.y
var xhelp:int;
var yhelp:int;
// diff
xhelp = Math.sqrt(( onePart[inDex].posX - onePart[i].posX ) * ( onePart[inDex].posX - onePart[i].posX ) );
yhelp = Math.sqrt( ( onePart[inDex].posY - onePart[i].posY ) * ( onePart[inDex].posY - onePart[i].posY ) );
return Math.sqrt ( xhelp*xhelp + yhelp*yhelp );
// return Math.sqrt( ( onePart[i].posX - onePart[inDex].posX )*( onePart[i].posX - onePart[inDex].posX ) + ( onePart[i].posY - onePart[inDex].posY )*( onePart[i].posY - onePart[inDex].posY ) );
}
public function makeGravity ( diff:int ):int {
// Mass :D, there are only gravitons
// * 60 / diff
/* if(diff>100){
diff = 1;
diffColor = Math.random()*0xFF33CC;
return 0;
}
return 60/diff;///Math.sqrt(diff); //1 * 1 * 200 / ( diff);
perfect return 800/diff/diff;///Math.sqrt(diff); //1 * 1 * 200 / ( diff);
*/
// return gUniverse*percentImag*250/diff/diff;
//if ( diff < 0.001 ){
// return 1;
//}
//final
// return gUniverse*8/10*sizeOf*100/diff/diff;
// 1/diff/diff is the correct one with physical background ;d
return gUniverse*8/10*sizeOf*diff/diff*screen*100;
// return 800/diff/diff;
// return 50/diff;
//Math.sqrt ( diff*diff*diff );// / diff;
}
public function makeGravityArc ( inDex:int, i:int, diff:int ):int {
var nullstelle:int;
var newa:int; // arc of the gravity
var xhelp:int;
var yhelp:int;
// diff
xhelp = Math.sqrt(( onePart[inDex].posX - onePart[i].posX ) * ( onePart[inDex].posX - onePart[i].posX ) );
yhelp = Math.sqrt( ( onePart[inDex].posY - onePart[i].posY ) * ( onePart[inDex].posY - onePart[i].posY ) );
//I
if ( ( onePart[i].posX > onePart[inDex].posX ) && ( onePart[i].posY > onePart[inDex].posY ) ){
newa = -1 * Math.asin( yhelp / diff );
}
//II
if ( ( onePart[i].posX > onePart[inDex].posX ) && ( onePart[i].posY < onePart[inDex].posY ) ){
newa = Math.asin( yhelp / diff );
}
//IV
if ( ( onePart[i].posX < onePart[inDex].posX ) && ( onePart[i].posY < onePart[inDex].posY ) ){
newa = 2*Math.PI - Math.PI/2 - Math.asin( xhelp / diff );
}
//III
if ( ( onePart[i].posX < onePart[inDex].posX ) && ( onePart[i].posY > onePart[inDex].posY ) ){
newa = Math.PI/2 + Math.asin( xhelp / diff );
}
//V
// same position
if ( ( onePart[i].posX == onePart[inDex].posX ) && ( onePart[i].posY == onePart[inDex].posY ) ){
newa = onePart[inDex].a; // :d
}
return newa;
// nullstelle = Math.sqrt ( ( onePart[i].v*onePart[i].v + onePart[inDex].v*onePart[inDex].v) / 2 );
// return ( ( nullstelle * onePart[i].a )+ ( nullstelle * onePart[inDex].a) ) / nullstelle;
}
public function changeReal ( inDex:Number, v:int, arc:int ):void {
var help:int; // helper for the new v value
help = onePart[inDex].v ;
// onePart[inDex].v = Math.sqrt ( help * help + v * v );
// onePart[inDex].a = arc;
onePart[inDex].v = Math.sqrt( ( onePart[inDex].v + v*Math.cos( arc-onePart[inDex].a ) ) * ( onePart[inDex].v + v*Math.cos( arc-onePart[inDex].a ) ) + v*v*Math.sin( arc-onePart[inDex].a)*Math.sin( arc -onePart[inDex].a ) );
onePart[inDex].a = onePart[inDex].a + v*Math.sin(arc-onePart[inDex].a) / ( onePart[inDex].v + v*Math.cos(arc-onePart[inDex].a ) );
VelocityBing( inDex ); // ;
}
public function VelocityBing ( i:Number ):void {
if( onePart[i].v > maxVelocity ){
onePart[i].v = maxVelocity;
}
}
public function setnewVector( inDex:int ):void{
// one version :D
// sets new Values of the vector v with arc a of Listentry Number index
var summv:int=0;
var arcHelp:int=0;
var diff:int;
if ( bootSystem ){
onePart[inDex].v = Math.random() * maxVelocity;
onePart[inDex].a = 2* Math.random()*Math.PI;
onePart[inDex].posY = Math.random()*4000;
onePart[inDex].posX = Math.random()*4000;
}
else {
for(var i:int=0; i<Elements; i++){ // :D hehe day three
diff = distance( inDex, i );
summv = makeGravity ( diff );
arcHelp = makeGravityArc( inDex, i, summv );
// onePart i has now the a with arcHelp as v
changeReal ( inDex, summv, arcHelp );
setImag ( inDex, i, diff );
} // end for
/*
// first part for the new values
// gravitation
diff = Math.sqrt( onePart[inDex].posX * onePart[inDex].posX + onePart[inDex].posY * onePart[inDex].posY - onePart[i].posX * onePart[i].posX - onePart[i].posY * onePart[i].posY );
// distance between the summ and the next one
if( diff<=1 ){
arcHelp = 1; // two vectors are next to next
// no addition, no interaction
// they are moving like one // .. is a Merging, Fusion
// Photonbuilding
// .... H2, temperatur, pressure, magnitude..
// ... :D only gravitons :D
}
else {
arcHelp = gUniverse/diff/diff;
// how much weight have the new graviton in relation to
// distance and the constant g
// :D
}
arcHelp = arcHelp * onePart[i].v; // is now vector2
// second part
// vectoraddition
// vector2 from the last round with the for is now vector one
// vector1 summv and beta
// vector2 arcHelp and onePart[i].a
forvar = arcHelp*Math.sin(onePart[i].a-beta) / ( summv + arcHelp*Math.cos(onePart[i].a-beta ) );
// forvar as new result of the arc
// vector2 from the last round with the for is now vector one
// beta is now the new arc of summv
// beta with summv are now vector1
// arcHelp and onePart[i].a is vector2
summv = Math.sqrt( ( summv + arcHelp*Math.cos( onePart[i].a-beta ) ) * ( summv + arcHelp*Math.cos( onePart[i].a-beta ) ) + arcHelp*arcHelp*Math.sin( onePart[i].a-beta)*Math.sin( onePart[i].a-beta ) );
beta = forvar;
} // end for
// summv is now the second vector v2
// summv has now all interaction with the right difference
// Vector addition between one...inDex... and all other ....summv
// vector1 is onePart[inDex]
// vector2 is summv and beta
onePart[inDex].v = Math.sqrt( ( onePart[inDex].v + summv*Math.cos( beta-onePart[inDex].a ) ) * ( onePart[inDex].v + summv*Math.cos( beta-onePart[inDex].a ) ) + summv*summv*Math.sin( beta-onePart[inDex].a)*Math.sin( beta -onePart[inDex].a ) );
onePart[inDex].a += summv*Math.sin(beta-onePart[inDex]) / ( onePart[inDex].v + summv*Math.cos(beta-onePart[inDex].a ) );
// :D
// sorry bout the crossing usage of beta as arc in the formulas
*/
} // end of else
} // end function
} // end class UniverseTest
}
import flash.display.AVM1Movie; // hmhm
import flash.display.Graphics;
class reDbul {
public var rflag:Number;
public var rrealImag:Boolean;
public var posX:int;
public var posY:int;
public var v:int;
public var a:int;
public var bx:int;
public var by:int;
public var oldX:int;
public var oldY:int;
public var remix:int;
public var maxVelo:int;
public var myCoolor:int;
public var screenborder:int;
public var screenF:int;
public function reDbul(newyx:int, newyy:int, newyv:int, newya:int, newybx:int, newyby:int, maxi:int , screenb:int, screenfactor:int ):void {
rflag = 0;
rrealImag=true;
posX = newyx;
posY = newyy;
v = newyv;
a = newya;
bx = newybx;
by = newyby;
oldX = posX/2;
oldY = posY/2;
remix=0;
maxVelo = maxi;
myCoolor = Math.random()*0xFF33CC;
screenborder = screenb;
screenF = screenfactor; //:d
}
public function show (graphic:Graphics, diffColor:int, factorDisplay:Number, factorBox:Number):void
{
var Numberx:Number = oldX;
var Numbery:Number = oldY;
Numberx = posX; Numbery = posY;
graphic.beginFill(myCoolor, 85);
graphic.drawCircle(Numberx/screenF, Numbery/screenF, factorDisplay);
graphic.endFill();
// graphic.clear();
// Numberx = bx;
// Numbery = by;
// graphic.drawRect(Numberx, Numbery, Numberx + factorDisplay*factorBox, Numbery +factorDisplay*factorBox); //:D
}
public function move():void{
oldX =posX;
oldY = posY;
posX += v * Math.cos(a);
posY += v * Math.sin(a);
// visualisation trick
// v = v/100*80;
// a+=0.6;
}
public function bing():void{
if(v*v<0.001){
v+=0.1; // :d Quantenfluktuation PI
// interupts the full simulation
}
if(v*v>maxVelo*maxVelo){
v = v/2; // :d Quantenfluktuation PI
// interupts the full simulation
}
if(a>2*Math.PI){
a = a - 2*Math.PI;//maxvelocity;
}
if(a<-2*Math.PI){
a = a + 2*Math.PI;//maxvelocity;
}
// if( a*a < 0.0001 ) {//well (a<0.005) && (a>-0.005)){
// a += 0.6; // calculating trouble
// the galaxy starts to spinn :d
// }
// / a+=0.1; // simulation trick
// :)
if(posX==oldX || posY==oldY){
remix++;
}
else{
remix = 0;
}
if(posX>screenborder){
posX = 10;
}
if(posY>screenborder){ // ! upsidedown :D
posY = 10;
}
if(posX<=0){
posX = screenborder - 10;
}
if(posY<=0){
posY = screenborder - 10;
}
/*
if(a>6.2){
a = 6;
}
if(a<-6.2){
a += 6;
}
*/
// the possision of the boxxes :D
} // end function bing
} // end class reDbul
//} // end package