/**
* Copyright Andy.Huber ( http://wonderfl.net/user/Andy.Huber )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/iExA
*/
// forked from Andy.Huber's Snakeheads
// forked from Andy.Huber's forked from: The Simulation Universe.....Click on left side to randomize, right side to show imaginary part
// forked from Andy.Huber's The Simulation Universe.....Click on left side to randomize, right side to show imaginary part
// forked from Andy.Huber's faster :d The Simulation Universe, part II
// forked from teeandy's forked from: forked from: The Simulation Universe, part II
// 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
// final version November 2012
// AndyHubers@aol.com
// This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/.
// To understand the whole simulation script there are some books
// about: Martin Bojowald,... and other aouthors
// Running package :d
// Commends made in November 2012
// adding menu in second part of November 2012 :d
package {
// some stuff to get it run in a browser
import flash.display.Graphics;
// inserted in November 2012
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Sprite;
// end instertiong
import flash.events.Event;
import flash.display.Sprite;
import flash.events.MouseEvent;
[SWF(width="400", height="410", frameRate="30", backgroundColor="0x000000")]
public class Main extends Sprite
{
// inserted in November 2012
public var thisSprite:Sprite;
public var spr:Sprite;
// end inserting
public var runtimeS:Boolean=false; // 0 to initializy all parameters than 1 at run
public var onePart:Array; // to compare with the others
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; // used for funny colors
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=2;
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=80; // Amount of gravitons and imaginaer Unions
public var maxVelocity:int=700; // beginning speed
public var screen:int=40000;
public var visualScreen:int=400;
public var centerx:Array // to save the black materie posisions
public var centery:Array; // ... normally less
public var imagReaction:int = 4000; // screen/visualScreen/sizeImag
public var showReaction:Boolean=false;
public var version:Boolean=true; // different interpretations
public var infoMenuOn:Boolean=true; // shows the menu on the screen
// only initialisys all variables and ends afterward
// the simulation runs in an eventlistener!
// ...that was verry impressive for me...
// the whole running is in an eventlistener :d
public function Main():void {
centerx = [];
centery = [];
onePart = [];
imagReaction = screen/visualScreen*sizeImag*gUniverse/imagUniverse;
// maby got chached by a mobile screensaver
var verrynewboxx:int; // hm
var verrynewboxy:int;
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:light; // one dot
// random new possisions for all Elements
for(var ji:int=0; ji<Elements; ji++){
// centerx.push(Math.random() * screen );
centerx[ji] = (Math.random() * screen );
array++
}array=0;
for(ji=0; ji<Elements; ji++){
//centery.push(Math.random() * screen );
centery[ji] = (Math.random() * screen );
array++
}array=0;
// November 2012
thisSprite = this;
// random new possisions for the imaginaer part
for(ji=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() ;
verrynewboxx = Math.random() * screen; // hm
verrynewboxy = Math.random() * screen;
// calling the dot Class for a new allocation
newbie = new light(thisSprite, verrynewx, verrynewy, verryv, verrya, verrynewboxx, verrynewboxy, maxVelocity, screen, screen/visualScreen );
// making a indexable array :d
onePart.push(newbie);
array++;
bootSystem= true;
showReaction= true;
}
//*********************************
// main running part
// functions: plopi, plop and reMix
// part of the Eventlistener
//**********************************************************************
// definition of the eventlistener with the name plop
// nothing
addEventListener(Event.ENTER_FRAME, plop); // :D
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.DOUBLE_CLICK, onMouseDoubleClick);
runtimeS = true;
// :) plopi();
}
// normal simulation run
public function plopi( ):void
{
runtimeS = false;
var help:Boolean = false;
// one run for all Elements
for(var iss:int=0; iss<Elements; iss++){
onePart[iss].move(); // set new Realpossition
setnewVector( iss ); // setting new values interact
onePart[iss].bing(); // Borderrunners
if ( onePart[iss].v > maxVelocity /4 ) {
// onePart[iss].v = onePart[iss].v - maxVelocity/100;
}
if ( onePart[iss].v < 5 ) {
// onePart[iss].v = onePart[iss].v + 1588;
onePart[iss].a = 2* Math.PI * Math.random();
}
onePart[iss].v = onePart[iss].v - 10;
if ( onePart[iss].a < 0.001 ) {
onePart[iss].a = 2* Math.PI * Math.random();
}
// randomized is pressed
if ( bootSystem && !help ) {iss =0; help=true;}
}
bootSystem = false;
runtimeS = true;
}
// checking function, so that all elements got moved only one time
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;
}
}
// eventfunction
// printing on screen, moving and checking
public function plop(e:Event):void
{
var helperMenu:int = 0;
if ( runtimeS ) {
// inserted in November 2012...nice menu :d
/*
// if ( infoMenuOn ) {
spr = new Sprite();
var text:TextField = new TextField();
var texttwo:TextField = new TextField();
var textth:TextField = new TextField();
var textv:TextField = new TextField();
var textmenu:TextField = new TextField();
var frm:TextFormat = new TextFormat();
helperMenu = 1 ;
text.text = "more";
texttwo.text = "do not more";
textth.text = "speed up";
textv.text = "slow down";
textmenu.text = "menu";
text.x = 20;
text.y = 250;
text.width = 80;
text.height = 20;
texttwo.x = 20;
texttwo.y = 380;
texttwo.width = 80;
texttwo.height = 20;
textth.x = 120;
textth.y = 250;
textth.width = 80;
textth.height = 20;
textv.x = 120;
textv.y = 380;
textv.width = 80;
textv.height = 20;
textmenu.x = 180;
textmenu.y = 300;
textmenu.width = 80;
textmenu.height = 20;
text.setTextFormat(frm);
texttwo.setTextFormat(frm);
textth.setTextFormat(frm);
textv.setTextFormat(frm);
textmenu.setTextFormat(frm);
spr.addChild(text);
spr.addChild(texttwo);
spr.addChild(textth);
spr.addChild(textv);
spr.addChild(textmenu);
spr.buttonMode = false;
// spr.Name("Menu");
addChild(spr);
// } else {
//// if ( helperMenu == 1 ) {
// // sp.removeChild(sp.getChildAt(1) );
// removeChild(getChildAt(1));
// removeChild(sp);
// helperMenu = 0;
// }
// removeChild( spr );
// }
// end inserting :d
*/
graphics.clear();
for(var iss:int=0; iss<Elements; iss++){
onePart[iss].show(graphics, diffColor, sizeOf, sizeImag, centerx[iss], centery[iss], imagReaction, showReaction );//Painting
}
reMix();
plopi();
}
}
//********************************
// breaker function
// functions: onMouseDown, onMouseDoubleClick
//**************************
// There are three different modes to run
// left screen to rest
// upper right to show the reaction field
// lower right to show and activate the imaginaer part
public 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;
}
// changing amount of dots
if ( e.localX < 100 && e.localY > 300 ) {
if (Elements > 1 ) {
Elements--;
onePart.pop();}
}
if ( e.localX < 100 && e.localY > 200 && e.localY < 300) {
onePart.push(new light(thisSprite, Math.random() * screen, Math.random() * screen, Math.random() * maxVelocity, 2*Math.PI * Math.random(), Math.random() * screen, Math.random() * screen, maxVelocity, screen, screen/visualScreen ) );
Elements++;
}
// changing speed :d
if ( e.localX > 100 && e.localX < 200 && e.localY > 200 && e.localY < 300) {
maxVelocity = maxVelocity + 10;
}
if ( e.localX > 100 && e.localX < 200 && e.localY > 300) {
if ( maxVelocity > 11 ) {
maxVelocity = maxVelocity -10;
}
}
// changing menu visibilty
if ( e.localX < 10 ) { // > 150 && e.localX < 250 && e.localY > 150 && e.localY < 250) {
infoMenuOn = !infoMenuOn
}
// turning on off visible parts
if ( e.localX < visualScreen/2 && e.localY < visualScreen/2) {
bootSystem= !bootSystem;
}
if ( e.localX < visualScreen/2 && e.localY > visualScreen/2) {
version = !version;
}
if ( e.localX > visualScreen/2 && e.localY < visualScreen/2 ) {
realImag= !realImag;
for(i=0; i<onePart.length; i++){
onePart[i].rrealImag = realImag;
}
}
if ( e.localX > visualScreen/2 && e.localY > visualScreen/2 ) {
showReaction = !showReaction;
}
}
// same breaker like lower right
public function onMouseDoubleClick(e:MouseEvent):void
{
realImag = !realImag;
for(var i:int=0; i<onePart.length; i++){
onePart[i].rrealImag = realImag;
}
}
//***********************
// calculating functions
// functions: setImag, distance, makeGravity, makeGravityArc
// changeReal, VelocityBing, setnewVector
// all are for shure easier to make for a nice simulation
// to get a real simulation, which fits best the descriptions
// in the book of Martin Bojowald ie. its a bit tricky
// ...also there are a few cuts in the calculation cause of runtime
// and flash is not able to bring correct sollutions
// ie. sin(x) is only up to a double value. So maby thats
// why the dots move to the right side
//***************************************
// different method to get new values for the Imaginaer part
// for all Elements.
// one run through all Elements
public function setImag ( inDex:int, i:int, diff:int ):void
{
var helpx:int; helpx = onePart[inDex].bx;
var helpy:int; helpy = onePart[inDex].by;
var helpd:int=0;
var helpa:int=0;
var savex:int; savex = onePart[inDex].bx;
var savey:int; savey = onePart[inDex].by;
// first x
var j:int=1; // count of imag parts around
for(var i:int=0; i<Elements; i++){
// as they are inside of the screen
if ( ( Math.abs( onePart[inDex].bx - onePart[i].posX) < imagReaction ) && ( Math.abs( onePart[inDex].by - onePart[i].posY) < imagReaction ) ) {
helpx += onePart[i].posX;
helpy += onePart[i].posY;
++j;
}
}
//hel
helpy = helpy/j; // so there are more possible
// with /Elements only one
helpd = helpy;
centery[inDex] = helpy;
helpa = helpx;
centerx[inDex] = helpa;
helpx = helpx - onePart[inDex].bx;
helpx = Math.abs( helpx );
if ( helpx < 1 ) { helpx = 0; }else{ helpx = imagReaction/helpx; }
helpy = helpy - onePart[inDex].by;
helpy = Math.abs( helpy );
if ( helpy < 1 ) { helpy = 0; }else{ helpy = imagReaction/helpy; }
// calculating all four possibilities
//x
if (savex > helpa )
{
onePart[inDex].bx = savex - helpx;
}
else {
onePart[inDex].bx = savex + helpx; // egg
}
//y
if (savey > helpd )
{
onePart[inDex].by = savey - helpy;
}
else {
onePart[inDex].by = savey + helpy; // egg
}
// style of Interpretation
// cant be changed right now...
if ( version ) {
for(i=0; i<Elements; i++){
if (i != inDex ){
helpa = ( onePart[inDex].by - onePart[i].by )*( onePart[inDex].by - onePart[i].by );
helpd = onePart[inDex].bx - onePart[i].bx;
helpd = helpd * helpd;
helpa = Math.sqrt(helpa);
helpd = Math.sqrt(helpd);
if ( (helpa < sizeImag) && (helpd < sizeImag) ){
onePart[inDex].bx += sizeImag * (Math.random() - 0.5);
onePart[inDex].by += sizeImag * (Math.random() - 0.5);
}
} }
}
}
// returns the way between element i and element inDex
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 ) );
}
// calculating and changing the values of the
// velocity vector of all elements
// basic is: 1/r*r
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.5 ){
return 1;
}
//final
// return gUniverse*8/10*sizeOf*100/diff/diff;
// 1/diff/diff is the correct one with physical background ;d
//return 60000*diff/diff;
return screen/diff/diff*98*sizeOf*gUniverse;
// return 50/diff;
//Math.sqrt ( diff*diff*diff );// / diff;
}
// new values for the velocity vector arc
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;
}
// changing all values of the real part
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 ); // ;
}
// checking if the velocity is not to big
public function VelocityBing ( i:Number ):void {
if( onePart[i].v > maxVelocity ){
onePart[i].v = maxVelocity;
}
}
// overall function to set all real and all imaginaer parts
// for all elements
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;
// true...randomize all values
// false ... normal simulation
if ( bootSystem ){
onePart[inDex].v = Math.random() * maxVelocity;
onePart[inDex].a = 2* Math.random()*Math.PI;
onePart[inDex].posY = Math.random()*screen;
onePart[inDex].posX = Math.random()*screen;
onePart[inDex].bx = Math.random()*screen;
onePart[inDex].by = Math.random()*screen;
centerx[inDex] = Math.random()*screen;
centery[inDex] = Math.random()*screen;
}
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 );
summv=summv-0.31;
// onePart i has now the a with arcHelp as v
changeReal ( inDex, summv, arcHelp );
if ( realImag ) {
setImag ( inDex, i, diff );
}
} // end for
} // end of else
} // end function
} // end class UniverseTest
}
import flash.display.AVM1Movie; // hmhm
// inserted in November 2012
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Sprite;
// end instertiong
import flash.display.Graphics;
//*****************
// class of one element
//********************
class light extends Sprite {
public var thisSprite:Sprite;
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;
// initialyzing of the parameters
public function light(that:Sprite, newyx:int, newyy:int, newyv:int, newya:int, newybx:int, newyby:int, maxi:int , screenb:int, screenfactor:int ):void {
// November 2012
thisSprite = that;
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
}
// painting on the screen
public function show (graphic:Graphics, diffColor:int, factorDisplay:Number, factorBox:Number, centerX:int, centerY:int, imagReaction:int, showReactionn:Boolean):void
{
var Numberx:Number;
var Numbery:Number;
graphic.beginFill(myCoolor, 0.9);
if ( rrealImag )
{
Numberx = bx; Numbery = by;
graphic.drawRect(Numberx/screenF, Numbery/screenF, factorBox, factorBox ); //:D
}
Numberx = posX; Numbery = posY;
graphic.drawCircle(Numberx/screenF, Numbery/screenF, factorDisplay);
if ( showReactionn )
{
graphic.beginFill(myCoolor, 0.05);
graphic.drawCircle(centerX/screenF, centerY/screenF, factorDisplay*imagReaction/screenF);
}
graphic.endFill();
}
// saving old values
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;
}
// checking values. If they lack it sends reMix
// all values gets randomized :d
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(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(bx>screenborder){
bx = 10;
}
if(by>screenborder){ // ! upsidedown imagin :D
by = 10;
}
if(bx<=0){
bx = screenborder - 10;
}
if(by<=0){
by = screenborder - 10;
}
// the possision of the boxxes :D
} // end function bing
} // end class reDbul
// } // end package
// :d