color many e with mouse:)
/**
* 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/3HSx
*/
// forked from Andy.Huber's many e with mouse:)
// forked from Andy.Huber's many with mouse:)
// forked from Andy.Huber's with mouse:)
package {
import flash.display.AVM1Movie;
// import flash.display.AVM1Movie;
// import flash.sampler.DeleteObjectSample;
// 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;
// end instertiong
import flash.events.Event;
import flash.display.Sprite;
import flash.events.MouseEvent;
[SWF(width="600", height="410", frameRate="43", backgroundColor="0x000000")]
public class Main extends Sprite
{
// addings NOvember 2014
private var pmouseX:Number;
private var pmouseY:Number;
private var mX:Number;
private var mY:Number;
public var isss:int;
private var mousePressed:Boolean;
private var mousePad:Boolean = false;
private var penSize:int = 2400;
public var changeme:Boolean = false;
// 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=49; // return value of a function
public var gSchuim:int=1; // can be :D differen
public var Elements:int=50; // Amount of gravitons and imaginaer Unions
public var maxVelocity:int=40; // beginning speed
public var screen:int=40000;
public var visualScreenX:int=600;
public var visualScreenY:int=410;
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=false; // different interpretations
public var infoMenuOn:Boolean=false; // shows the menu on the screen
//adding June 2014 stabiliezing moveing of all dots
// on screen
public var stabily:Boolean=false;
public var stx:int=0.0;
public var sty:int=0.0;
public var stmx:int=200.0;
public var stmy:int=200.0;
public var dotrandomi:int=2;
public var massenjoy:Boolean=true;
public var gravitall:Boolean=true;
public var realElements:int;
public var fast:Boolean=true; public var hfast:Boolean=false;
// 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
//nov14
imagReaction = screen/ ( visualScreenX+visualScreenY)/2 * sizeImag*gUniverse/imagUniverse;
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
//nov14
var nmulti:int;
// 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;
//nov14
nmulti = 10 * Math.random();
// calling the dot Class for a new allocation
newbie = new light(dotrandomi, thisSprite, verrynewx, verrynewy, verryv, verrya, verrynewboxx, verrynewboxy, maxVelocity, screen, screen/visualScreenX ,screen/visualScreenY , nmulti );
// making a indexable array :d
onePart.push(newbie);
array++;
realElements = Elements;
bootSystem= true;
}
//*********************************
// main running part
// functions: plopi, plop and reMix
// part of the Eventlistener
//**********************************************************************
// definition of the eventlistener with the name plop
// nothing
stage.addEventListener(Event.ENTER_FRAME, plop); // :D
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
// stage.addEventListener(MouseEvent.DOUBLE_CLICK, onMouseDoubleClick);
// adding November 2014
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
runtimeS = true;
// :) plopi();
}
// normal simulation run
public function plopi( ):void
{
runtimeS = false;
var help:Boolean = false;
// st2014
var sx:int=0.0;
var sy:int=0.0;
var iss:int;
// adding November 2014
var mouseXvel:Number = mouseX - pmouseX;
var mouseYvel:Number = mouseY - pmouseY;
// one run for all Elements
for(var isk:int=0; isk<Elements; isk++){
iss = Math.random() * Elements;
// ;)
// adding November 2014
if ( mousePressed && mousePad ) {
isss = iss;
updateGridDataVelocity( iss, mX, mY, penSize );
// should become very slow
}
// st2014
sx = onePart[iss].posX;
sy = onePart[iss].posY;
onePart[iss].move(); // set new Realpossition
setnewVector( iss ); // setting new values interact
onePart[iss].bing(); // Borderrunners
if ( onePart[iss].a == 0 ){// flsh, screen, error, ??
// onePart[iss].a = 6*Math.random();
// onePart[iss].v = maxVelocity/4;
}
// st2014
if ( stabily ) { stabilize ( iss, sx, sy );}
// randomized is pressed
if ( bootSystem && !help ) {iss =0; help=true;}
// adding November 2014
pmouseX = mX;
pmouseY = mY;
}//for
bootSystem = false;
runtimeS = true;
}
// adding November 2014
/**
* マウスドラッグの処理
* @param gridData
* @param mvelX
* @param mvelY
* @param penSize
*/
public function updateGridDataVelocity(iss:int, mxX:int, myY:int, penSize:Number):void {
// if (( ( onePart[iss].posX - mxX )* ( onePart[iss].posX - mxX ) < penSize*penSize ) && ( ( onePart[iss].posY - myY )* ( onePart[iss].posY - myY ) < penSize*penSize ) ){
// onePart[iss].posX = mxX;
// onePart[iss].posY = myY;
//00
// }
}
//st2014
//reduces same movements on screen
// better with a list [element]
public function stabilize ( iss:int, sx:int, sy:int ) : void {
var dx:int=0.0;
var dy:int=0.0;
//stailizer one: overall movement
// dots on border ignoring: all who are speedy
dx = onePart[iss].posX - sx ;
dy = onePart[iss].posY - sy ;
if ( ( dx * dx < visualScreenX * visualScreenX - visualScreenX / 10 ) &&
( dy * dy < visualScreenY * visualScreenY - visualScreenY / 10 ) ) {
// stabilizing
stx += ( dx ) / Elements - stx/Elements;
sty += ( dy ) / Elements - sty/Elements;
onePart[iss].posX -= stx;
onePart[iss].posY -= sty;
}
stmx = stmx + onePart[iss].posX/Elements - stmx/Elements;
stmy = stmy + onePart[iss].posY/Elements - stmy/Elements;
dx = ( stmx - visualScreenX/2 ) / Elements;
dy = ( stmy- visualScreenY/2 ) / Elements;
onePart[iss].posX -= dx;
onePart[iss].posY -= dy;
}
// 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 ) {
graphics.clear();
if ( infoMenuOn ) graphics.beginFill ( 0.5*0xFF33CC, 0.9);
else graphics.beginFill ( 0.5*0xF033CC, 0.9);
graphics.drawRect( 0 ,0 ,20, 12 ); //:D
// stabilizer
//graphics.drawRect( stmx / Elements ,stmy/Elements ,12, 12 ); //:D
if ( stabily ) graphics.beginFill ( 0.5*0xFF33CC, 0.9);
else graphics.beginFill ( 0.5*0xF033CC, 0.9);
graphics.drawRect( 100 ,0 ,20, 12 ); //:D
if ( dotrandomi ) graphics.beginFill ( dotrandomi* 0.5*0xFF33CC, 0.9);
else graphics.beginFill ( dotrandomi*0.5*0xF033CC, 0.9);
graphics.drawRect( 200 ,0 ,20, 12 ); //:D
if ( massenjoy ) graphics.beginFill ( 0.5*0xFF33CC, 0.9);
else graphics.beginFill ( 0.5*0xF033CC, 0.9);
graphics.drawRect( 300 ,0 ,20, 12 ); //:D
if ( gravitall ) graphics.beginFill ( 0.5*0xFF33CC, 0.9);
else graphics.beginFill ( 0.5*0xF033CC, 0.9);
graphics.drawRect( 400 ,0 ,20, 12 ); //:D
if ( fast ) graphics.beginFill ( 0.5*0xFF33CC, 0.9);
else graphics.beginFill ( 0.5*0xF033CC, 0.9);
graphics.drawRect( 500 ,0 ,20, 12 ); //:D
//adding November 2014
if ( mousePad ) graphics.beginFill ( 0.5*0xFF33CC, 0.9);
else graphics.beginFill ( 0.5*0xF033CC, 0.9);
graphics.drawRect( 0 ,100 ,12, 20 ); //:D
graphics.endFill();
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
//**************************
//adding November 2014
public function onMouseUp(e:MouseEvent):void {
mX = screen/visualScreenX*e.localX;
mY = screen/visualScreenY*e.localY;
// stage.mouseLock = true;
changeme = true;
for(var iss:int=0; iss<Elements; iss++){
var hx:int = onePart[iss].posX - mX ;
hx = hx*hx;
var hy:int = onePart[iss].posX - mX ;
hy = hy*hy;
if ( mousePad && ( hx < penSize*penSize ) &&
( hy < penSize*penSize ) ){
onePart[iss].posX = mX;
onePart[iss].posY = mY;
//00
}}
// stage.mouseLock = false;
// trace(e.localX + " /n ");
mousePressed = false;
}
// 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
{
// adding November 2014
mousePressed = true;
mX = e.localX;
mY = e.localY;
// adding November 2014
// mousePad
if (e.localX < 25 && e.localX > 0 && e.localY < 125 && e.localY > 100 )
mousePad = true;
if (e.localX < 530 && e.localX > 0 && e.localY < 25 && e.localY > 0 )
mousePad = false;
// stabilizer
if ( !mousePad && e.localX > 75 && e.localX < 125 && e.localY < 20 ) {
mousePad = false;// adding November 2014
stabily = !stabily;
}
// sgmeh randomizer
if ( !mousePad && e.localX > 175 && e.localX < 225 && e.localY < 20 ) {
mousePad = false;// adding November 2014
dotrandomi ++;
if ( dotrandomi > 2 ) dotrandomi = 0;
}
if ( !mousePad && e.localX > 275 && e.localX < 325 && e.localY < 20 ) {
mousePad = false;// adding November 2014
massenjoy = !massenjoy;
}
if ( !mousePad && e.localX > 375 && e.localX < 425 && e.localY < 20 ) {
mousePad = false;// adding November 2014
gravitall = !gravitall;
}
if ( !mousePad && e.localX > 475 && e.localX < 525 && e.localY < 20 ) {
mousePad = false;// adding November 2014
fast = !fast;
}
// painting new dots
if ( !mousePad && infoMenuOn && e.localX<visualScreenX && e.localY<visualScreenY && e.localY>30) {
onePart.push(new light(dotrandomi, thisSprite, screen/visualScreenX*e.localX, screen/visualScreenY*e.localY, maxVelocity, 2*Math.PI * Math.random(), x,y ,maxVelocity, screen, screen/visualScreenX ,screen/visualScreenY , 10*Math.random() ) );
Elements++; realElements++;
}
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 ( !mousePad && !infoMenuOn && e.localX < 100 && e.localY > 300 ) {
if (Elements > 1 ) {
realElements--;
Elements--;
onePart.pop();}
}
if ( !mousePad && !infoMenuOn && e.localX < 100 && e.localY > 200 && e.localY < 300) {
onePart.push(new light(dotrandomi, thisSprite, Math.random() * screen, Math.random() * screen, Math.random() * maxVelocity, 2*Math.PI * Math.random(), Math.random() * screen, Math.random() * screen, maxVelocity, screen, screen/visualScreenX ,screen/visualScreenY , 10*Math.random() ) );
Elements++; realElements++;
}
// changing speed :d
if ( !mousePad && !infoMenuOn && e.localX > 100 && e.localX < 200 && e.localY > 200 && e.localY < 300) {
maxVelocity = maxVelocity + 4;
}
if ( !mousePad && !infoMenuOn && e.localX > 100 && e.localX < 200 && e.localY > 300) {
if ( maxVelocity > 11 ) {
maxVelocity = maxVelocity -5;
}
}
// changing menu visibilty
if ( !mousePad && e.localX < 20 && e.localY < 20 ) { // > 150 && e.localX < 250 && e.localY > 150 && e.localY < 250) {
infoMenuOn = !infoMenuOn;
}
// turning on off visible parts
if ( !mousePad && !infoMenuOn &&
e.localX > 10 && e.localX < visualScreenX/2 && e.localY < visualScreenY/2&& e.localY >30) {
bootSystem= !bootSystem;
}
if ( !mousePad && !infoMenuOn &&
e.localX < visualScreenX/2
&& e.localY > visualScreenY/2) {
version = !version;
}
if ( !mousePad && !infoMenuOn &&
e.localX > visualScreenX/2 &&
e.localY < visualScreenY/2 &&
e.localY > 30 ) {
realImag= !realImag;
for(i=0; i<onePart.length; i++){
onePart[i].rrealImag = realImag;
}
}
if ( !mousePad && !infoMenuOn && e.localX > visualScreenX/2 && e.localY > visualScreenY/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 {
if ( diff < 10){ //screen
return 240000000/diff/diff/diff*98*sizeOf*sizeOf*gUniverse;
}
//else
// {
return diff/diff*98*sizeOf*sizeOf*gUniverse;
// }
}
// 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[i].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;
}
// onePart[i].v = onePart[i].v - 0.0000000001;
}
// 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;
//nov14
onePart[inDex].multipl = 10*Math.random();
onePart[inDex].type = 1;
onePart[inDex].l = 1;
onePart[inDex].vv = 3;
if ( dotrandomi == 1 ) { // only s
onePart[inDex].type = 0;
onePart[inDex].l = 2 * Math.random();
onePart[inDex].vv = 2 * Math.random();
}
if ( dotrandomi == 2 ) { // all
onePart[inDex].type = Math.round(5 * Math.random() );
if ( onePart[inDex].type == 0 ) {//s
onePart[inDex].l = 1 * Math.random();
onePart[inDex].vv = 1 * Math.random();
}
if ( onePart[inDex].type == 1 ) {//g
onePart[inDex].l = 1 * Math.random();
onePart[inDex].vv = 3 * Math.random();
}
if ( onePart[inDex].type == 2 ) {//m
onePart[inDex].l = 1 * Math.random();
onePart[inDex].vv = 4 * Math.random();
}
if ( onePart[inDex].type == 3 ) {//e
onePart[inDex].l = 1 * Math.random();
onePart[inDex].vv = 5 * Math.random();
}
if ( onePart[inDex].type == 4 ) {//h
onePart[inDex].l = 5 * Math.random();
onePart[inDex].vv = 5 * Math.random();
}
}
}//randomize
else {
var i:int=0;
for(var ij:int=0; ij<Elements; ij++){ // :D hehe day three
i=Math.random()*Elements;
// while ( i == inDex){
//nov14
var h:int = onePart[inDex].multipl - onePart[i].multipl ;
h= h*h;
while ( i == inDex || h > 160 ){ // 16 is real
// not the same plus the same quantsystem
i=Math.random()*Elements;
h = onePart[inDex].multipl - onePart[i].multipl ;
h= h*h;
}
//nov14
// reacting with 1/ ( e` multidiff ) ;)
h = Math.sqrt( h );
h = 1 / Math.pow( Math.E , h );
if ( gravitall || onePart[i].type == 1 && onePart[inDex].type == 1 ) {
diff = distance( inDex, i );
// summv = makeGravity ( diff );
//nov14
summv = makeGravity ( diff * h );
arcHelp = makeGravityArc( inDex, i, summv );
//summv=summv-0.37;
// onePart i has now the a with arcHelp as v
changeReal ( inDex, summv, arcHelp );
if ( realImag ) {
setImag ( inDex, i, diff );
}
}//11
//sgmeh
if ( onePart[i].type == 0 && onePart[inDex].type == 0 ) {
values00( i, inDex );
} else {if( !hfast ) { if ( onePart[i].type == 0 && onePart[inDex].type == 3) {
values10( i, inDex );}
} else {
if ( !hfast ) { if ( onePart[i].type == 0 && onePart[inDex].type == 2 ) {
values02( i, inDex );}
} else {
if ( !hfast ) { if ( onePart[i].type != 0 && onePart[inDex].type != 0) {
valuesxx( i, inDex );}
} else {
if ( !hfast ) { if ( onePart[i].type == 0 && onePart[inDex].type == 3) {
values02( i, inDex );}
} else {
if ( !hfast ) { if ( onePart[i].type == 0 && onePart[inDex].type == 4 ) {
valuesx4( i, inDex );}
} else {
if ( !hfast) { if ( onePart[inDex].type == 4 ) {
valuesx4( i, inDex );}
} }
}} }}} // else
//...
if ( onePart[inDex].type == 4 ) {
valuesx4( i, inDex );}
hfast = false;
if ( !massenjoy && onePart[inDex].type ==4 && (onePart[inDex].l > 8 || onePart[inDex].vv > 8 )) {
//?
collapse ( inDex );
}
if ( onePart[inDex].type != 4 ){
reducemax( inDex );
}
} // end for
if( realElements > Elements ) {
onePart.push(new light(dotrandomi, thisSprite, Math.random() * screen, Math.random() * screen, Math.random() * maxVelocity, 2*Math.PI * Math.random(), Math.random() * screen, Math.random() * screen, maxVelocity, screen, screen/visualScreenX ,screen/visualScreenY , 10*Math.random() ) );
Elements++;
}
if( realElements < Elements && Elements > 1) {
onePart.pop();
Elements--;
}
}
} // end function
public function reducemax( inDex:int ):void{
if ( onePart[inDex].l > 9 ) onePart[inDex].l = 9;
if ( onePart[inDex].vv > 9 ) onePart[inDex].vv = 9;
}
public function collapse( inDex:int ):void{
onePart[inDex].type = 0;
while (onePart[inDex].l + onePart[inDex].vv > 0 ){
onePart.push(new light(1, thisSprite, Math.random() * screen, Math.random() * screen, Math.random() * maxVelocity, 2*Math.PI * Math.random(), Math.random() * screen, Math.random() * screen, maxVelocity, screen, screen/visualScreenX ,screen/visualScreenY , 10*Math.random()) );
Elements++;
onePart[inDex].vv -= 2;
onePart[inDex].l -= 2;
if ( onePart[inDex].vv + onePart[inDex].l > 20 ){
onePart[inDex].vv =10;
onePart[inDex].l =10;
}
}
onePart[inDex].type = 0;
onePart[inDex].l = 2*Math.random();
onePart[inDex].vv = 2*Math.random();
}
public function valuesxx( i:int, inDex:int ):void{
var help:int=0; var helpy:int=0;
help = onePart[i].posX - onePart[inDex].posX;
help = Math.sqrt(help*help);
helpy = onePart[i].posY - onePart[inDex].posY;
helpy = Math.sqrt(helpy*helpy);
if ( ( help/5 < onePart[i].l + onePart[inDex].l) && ( helpy/5 < onePart[i].l + onePart[inDex].l) ) {
help = onePart[i].vv + onePart[inDex].vv ;
helpy = onePart[i].l ;
if (fast ){
// onePart.pop();
}else{
onePart.splice( i-1, 1 ); // for one missing
Elements = Elements -1; // uff buggy
hfast = true;
}
onePart[inDex].vv = (help);
onePart[inDex].l = (helpy + onePart[inDex].l );
// onePart[inDex].l = Math.sqrt(helpy + onePart[inDex].l );
if ( help > 0.6 && onePart[inDex].type != 4) {
// >h
onePart[inDex].l = 4; onePart[inDex].vv = 4;
onePart[inDex].type = 4;
}
}// if in range
}
public function valuesx4( i:int, inDex:int ):void{
var help:int=0; var helpy:int=0;
help = onePart[i].posX - onePart[inDex].posX;
help = Math.sqrt(help*help);
helpy = onePart[i].posY - onePart[inDex].posY;
helpy = Math.sqrt(helpy*helpy);
if ( ( help/5 < onePart[i].l + onePart[inDex].l) && ( helpy/5 < onePart[i].l + onePart[inDex].l) ) {
help = onePart[i].vv + onePart[inDex].vv ;
helpy = onePart[i].l ;
if (fast ){
// onePart.pop();
}else{
onePart.splice( i-1, 1 ); // for one missing
Elements = Elements -1; // uff buggy
hfast = true;
}
onePart[inDex].vv = (help);
onePart[inDex].l = (helpy + onePart[inDex].l );
// onePart[inDex].l = Math.sqrt(helpy + onePart[inDex].l );
}// if in range
}
public function values02( i:int, inDex:int ):void{
var help:int=0; var helpy:int=0;
help = onePart[i].posX - onePart[inDex].posX;
help = Math.sqrt(help*help);
helpy = onePart[i].posY - onePart[inDex].posY;
helpy = Math.sqrt(helpy*helpy);
if ( ( help/5 < onePart[i].l + onePart[inDex].l) && ( helpy /5< onePart[i].l + onePart[inDex].l) ) {
help = onePart[i].vv + onePart[inDex].vv ;
helpy = onePart[i].l ;
if (fast ){
// onePart.pop();
}else{
onePart.splice( i-1, 1 ); // for one missing
Elements = Elements -1; // uff buggy
hfast = true;
}
onePart[inDex].vv = help;
onePart[inDex].l = helpy + onePart[inDex].l ;
// >m
// >e
if ( help > 0.6 && onePart[inDex].type != 4) {
// >h
onePart[inDex].l = 4;onePart[inDex].vv = 4;
onePart[inDex].type = 4;
}
}// if in range
}
public function values10( i:int, inDex:int ):void{
var help:int=0; var helpy:int=0;
help = onePart[i].posX - onePart[inDex].posX;
help = Math.sqrt(help*help);
helpy = onePart[i].posY - onePart[inDex].posY;
helpy = Math.sqrt(helpy*helpy);
if ( ( help /5< onePart[i].l + onePart[inDex].l) && ( helpy /5< onePart[i].l + onePart[inDex].l) ) {
help = onePart[i].vv + onePart[inDex].vv ;
helpy = onePart[i].l ;
if (fast ){
// onePart.pop();
}else{
onePart.splice( i-1, 1 ); // for one missing
Elements = Elements -1; // uff buggy
hfast = true;
}
onePart[inDex].vv = help;
onePart[inDex].l = helpy + onePart[inDex].l ;
// >m
// >e
if ( help > 3.4 ) {
// >e
onePart[inDex].l = 4;
onePart[inDex].type = 3;
}
if ( help > 0.6) {
// >h
onePart[inDex].l = 4;onePart[inDex].vv = 4;
onePart[inDex].type = 4;
}
}// if in range
}
public function values00( i:int, inDex:int ):void{
var help:int=0; var helpy:int=0;
help = onePart[i].posX - onePart[inDex].posX;
help = Math.sqrt(help*help)/3;
helpy = onePart[i].posY - onePart[inDex].posY;
helpy = Math.sqrt(helpy*helpy)/3;
if ( ( help / 5 < onePart[i].l + onePart[inDex].l) && ( helpy / 5 < onePart[i].l + onePart[inDex].l) ) {
help = onePart[i].vv + onePart[inDex].vv ;
helpy = onePart[i].l ;
if (fast ){
//onePart.pop();
}else{
onePart.splice( i-1, 1 ); // for one missing
Elements = Elements -1; // uff buggy
hfast = true;
}
onePart[inDex].vv = help;
if ( help > 1.7 ) {
// >g
onePart[inDex].l = 4;
onePart[inDex].type = 1;
} else { //>s
onePart[inDex].l = helpy + onePart[inDex].l ;
if ( help > 0.9 ) {
// >m
onePart[inDex].l = 4;
onePart[inDex].type = 4;
}else{
if ( help > 0.7 ) {
// >e
onePart[inDex].l = 4;
onePart[inDex].type = 2;
}else{
if ( help > 0.55) {
// >h
onePart[inDex].l = 4;onePart[inDex].vv = 4;
onePart[inDex].type = 3;
}
} } }//else
}// if in range
} //function value00
} // end class UniverseTest
} //pack?
//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;
// nov 14
public var multipl:int;
public var screenborder:int;
public var screenFX:int;
public var screenFY:int;
public var type:Number;//0s 1g 2m 3e 4h
public var l:int;
public var vv:int;
// initialyzing of the parameters
public function light(dotrandomi:int, that:Sprite, newyx:int, newyy:int, newyv:int, newya:int, newybx:int, newyby:int, maxi:int , screenb:int, screenfactorX:int , screenfactorY:int , newmultipl:int ):void {
// November 2012
thisSprite = that;
//nov14
multipl = newmultipl;
rflag = 0;
rrealImag=false;
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;
//;)
screenFX = screenfactorX; //:d
screenFY = screenfactorY; //:d
if ( dotrandomi == 0 ) { // only g
type = 1;
l = 1 * Math.random();
vv = 3 * Math.random();
}
if ( dotrandomi == 1 ) { // only s
type = 0;
l = 2* Math.random();
vv = 2* Math.random();
}
if ( dotrandomi == 2 ) { // all
type = Math.round(5 * Math.random() );
if ( type == 0 ) {//s
l = 1 * Math.random();
vv = 1 * Math.random();
}
if ( type == 1 ) {//g
l = 1 * Math.random();
vv = 3 * Math.random();
}
if ( type == 2 ) {//m
l = 1 * Math.random();
vv = 4 * Math.random();
}
if ( type == 3 ) {//e
l = 1 * Math.random();
vv = 5 * Math.random();
}
if ( type == 4 ) {//h
l = 5 * Math.random();
vv = 5 * Math.random();
}
}
}
// 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;
//nov14
if ( multipl > 1 && multipl < 9 ) // one this visible quantsystem,... our :)
//should be in example >3 , <4 , ....
{
graphic.lineStyle(0, myCoolor, 100);
if ( rrealImag )
{
Numberx = bx; Numbery = by;
graphic.beginFill(myCoolor, 0.9);
graphic.drawRect(Numberx/screenFX, Numbery/screenFY, factorBox, factorBox ); //:D
graphic.endFill();
}
Numberx = posX; Numbery = posY;
if ( type == 1 ) {//g
graphic.beginFill(myCoolor, 0.9);
graphic.drawCircle(Numberx/screenFX, Numbery/screenFY, factorDisplay);
graphic.endFill();
}
if ( type == 0 ) {//s
// graphic.drawCircle(Numberx/screenF, Numbery/screenF, factorDisplay/3+3*l*vv);
graphic.moveTo(Numberx/screenFX, Numbery/screenFY );
graphic.curveTo(Numberx/screenFX+vv, Numbery/screenFY+vv, Numberx/screenFX+l, Numbery/screenFY+l );
}
if ( type == 2 ) {//m
graphic.drawRect(Numberx/screenFX, Numbery/screenFY, factorDisplay+l, factorDisplay+vv);
}
if ( type == 3 ) {//e
graphic.moveTo(Numberx/screenFX, Numbery/screenFY );
graphic.lineTo(Numberx/screenFX+vv, Numbery/screenFY+l );
}
if ( type == 4 ) {//h
graphic.beginFill(myCoolor, 0.25);
graphic.lineStyle(0, myCoolor, 0);
graphic.drawCircle(Numberx/screenFX, Numbery/screenFY, factorDisplay+l+vv+9);
graphic.endFill();
}
if ( showReactionn )
{
graphic.beginFill(myCoolor, 0.05);
graphic.drawCircle(centerX/screenFX, centerY/screenFY, factorDisplay*imagReaction/(screenFX+screenFY)/2);
graphic.endFill();
}
}//quantsystem
}
// 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<0){//-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