void setupDotList()
{
dotList = new PVector [ dotAmount ];
checkCircleSizeList = new float [ circleAmount ];
prevCircleSizeList = new float [ circleAmount ];
prevDotList = new PVector [ dotAmount ];
}
void creatDotList()
{
randomSeed(actRandomSeed);
int dotCount = 0;
int circleCount = circleAmount;
int circle = 0;
PVector checkDot;
while (circle < circleCount)
{
float circleSize = random (10, height/4);
int centerX = width/2;
int centerY = height/2;
int objectCount = dotAmount/circleAmount;
float radius = random (50, (width+height)/4);
// save Radius in List--------------------------------------------
if (morphing == false)
{
prevCircleSizeList [circle] = radius;
//println (prevCircleSizeList [circle]);
}
// morph old Radius to new Radius--------------------------------------------
if (morphing == true)
{
float prevRadius = prevCircleSizeList [circle];
float newRadius = radius;
float ma = map(morphCount, 0,maxPositionFactor, 0,1);
ma = constrain(ma, 0, 1);
radius = lerp(prevRadius,newRadius, ma);
}
float sortZ = random (-200,200);
float steps = TWO_PI / objectCount;
float angle = 0;
int count = 0;
while (count < objectCount)
{
float x = 0, y = 0, z = 0;
float currentAngleX = random (cos(angle-steps/2), cos(angle));
float currentAngleY = random (sin(angle-steps/2), sin(angle));
x = centerX + currentAngleX * radius;
y = centerY + currentAngleY * radius;
float randomZ = random (-200,200);
float m = map(positionFactor, 0,maxPositionFactor, 0,1);
m = constrain(m, 0, 1);
z = lerp(randomZ, sortZ, m);
// save old Position in List--------------------------------------------
if (morphing == false)
{
prevDotList [dotCount] = new PVector ( x, y, z );
if (altMode == true) prevDotList [count+(circle*count)] = new PVector ( x, y, z );
}
// morph old x,y,z to new x,y,z
if (morphing == true)
{
// alte Werte für x,y,z ---------------------------------------------
checkDot = prevDotList [ dotCount ];
float startX = checkDot.x, startY = checkDot.y, startZ = checkDot.z;
float targetX = x, targetY = y, targetZ = z;
float mb = map(morphCount, 0,maxPositionFactor, 0,1);
mb = constrain(mb, 0, 1);
x = lerp(startX, targetX,mb);
y = lerp(startY, targetY, mb);
z = lerp(startZ, targetZ, mb);
}
dotList [dotCount] = new PVector ( x, y, z );
if (altMode == true) dotList [count+(circle*count)] = new PVector ( x, y, z );
dotCount ++;
angle = angle + steps;
count++;
}
circle++;
}
}
void drawLinesBetweenDots ()
{
int dotCount = 0;
int circleCount = circleAmount;
int circle = 0;
while (circle < circleCount)
{
int count = 0;
int countMax = dotAmount/circleAmount;
PVector currentDot;
while (count < countMax)
{
currentDot = dotList [dotCount];
if (altMode == true) currentDot = dotList [count+(circle*count)];
checkDistanceRight (currentDot);
dotCount++;
count++;
}
circle++;
}
}
void checkDistanceRight (PVector currentDot)
{
int dotCount = 0;
int circleCount = circleAmount;
int circle = 0;
while (circle < circleCount)
{
int count = 0;
int countMax = dotAmount/circleAmount;
PVector checkDot;
while (count < countMax)
{
checkDot = dotList [ dotCount ];
if (altMode == true) checkDot = dotList [ count+(circle*count) ];
float startZ = zFactor*currentDot.z;
float targetZ = zFactor*checkDot.z;
float distance = dist( currentDot.x, currentDot.y, currentDot.z, checkDot.x, checkDot.y, checkDot.z);
if (distance < (200*connectionFactor) && distance > (130*connectionFactor))
{
stroke (5, 10);
strokeWeight (0.5);
if (altMode == true) {
stroke (5, 3);
strokeWeight (0.5);
}
line (currentDot.x, currentDot.y,startZ, checkDot.x, checkDot.y,targetZ);
}
if (distance < (130*connectionFactor) && distance> (80*connectionFactor))
{
stroke (5, 10);
strokeWeight (0.75);
if (altMode == true) {
stroke (5, 3);
strokeWeight (0.5);
}
line (currentDot.x, currentDot.y,startZ, checkDot.x, checkDot.y, targetZ);
}
if (distance < (80*connectionFactor) && distance > (40*connectionFactor))
{
stroke (5, 5);
strokeWeight (1);
if (altMode == true) {
stroke (5, 3);
strokeWeight (0.5);
}
line (currentDot.x, currentDot.y,startZ, checkDot.x, checkDot.y, targetZ);
}
/*
stroke (3);
strokeWeight (3);
point (currentDot.x, currentDot.y,startZ);
*/
dotCount++;
count++;
}
circle++;
}
}
void keyReleased ()
{
if (keyCode == KeyEvent.VK_PLUS )
{
actRandomSeed +=1;
morphing = true;
frameCounter = 0;
}
if (keyCode == KeyEvent.VK_MINUS )
{
actRandomSeed -=1;
morphing = true;
frameCounter = 0;
}
}
void keyPressed()
{
// Play & Pause------------------------------------------------------------------------
if (keyCode == KeyEvent.VK_M)
{
if (isPlaying == false) isPlaying = true;
else if (isPlaying == true) isPlaying = false;
}
// show or hide Pause img------------------------------------------------------------------------
if (keyCode == KeyEvent.VK_N)
{
if (hideimage == true) hideimage = false;
else if (hideimage == false) hideimage = true;
}
// Position------------------------------------------------------------------------
if (keyCode == KeyEvent.VK_A)
{
positionFactor -= 0.10;
positionFactor = constrain (positionFactor, 0,maxPositionFactor);
creatDotList ();
}
if (keyCode == KeyEvent.VK_S && positionFactor < maxPositionFactor)
{
positionFactor += 0.10;
positionFactor = constrain (positionFactor, 0,maxPositionFactor);
creatDotList ();
}
// Tiefe------------------------------------------------------------------------
if (keyCode == KeyEvent.VK_E) {
zFactor -= 0.1;
zFactor = constrain (zFactor,0,4);
}
if (keyCode == KeyEvent.VK_R) {
zFactor += 0.1;
zFactor = constrain (zFactor,0,4);
}
// LinesNumber------------------------------------------------------------------------
if (keyCode == KeyEvent.VK_Y) {
connectionFactor -=0.05;
connectionFactor = constrain (connectionFactor, 0,2);
}
if (keyCode == KeyEvent.VK_X) {
connectionFactor +=0.05;
connectionFactor = constrain (connectionFactor, 0,2);
}
// Alternative Mode------------------------------------------------------------------------
if (keyCode == KeyEvent.VK_1)
{
if (altMode == false)
{
altMode = true;
dotAmount = 600;
setupDotList ();
creatDotList ();
}
else if (altMode == true)
{
altMode = false;
dotAmount = 500;
setupDotList ();
creatDotList ();
}
}
}
//import processing.opengl.*;
import peasy.*;
// Classes --------------------------------------------------------------------
PeasyCam cam;
// Data --------------------------------------------------------------------
PImage bg, play_img;
// Globales --------------------------------------------------------------------
int dotAmount = 500, actRandomSeed, circleAmount = 16, maxPositionFactor = 10, frameCounter;
float positionFactor, zFactor, connectionFactor, oldCircleSize, morphCount;
PVector dotList[];
float [] checkCircleSizeList;
float [] prevCircleSizeList;
PVector prevDotList[];
// Boolean --------------------------------------------------------------------
boolean isPlaying = false, hideimage = false, morphing = false, createNewDotList = false, altMode = false;
void setup()
{
//size (720,576, OPENGL);
size (720,576, P3D);
background (247);
//smooth();
noLoop();
frameRate(25);
loop();
setSetup();
setupDotList ();
creatDotList ();
}
void draw()
{
background (bg);
if (morphing == true) creatDotList();
drawLinesBetweenDots();
playPause ();
//if (morphing == true && morphCount == 0) morphCount += 0.2;
//if (morphing == true && morphCount > 0) morphCount = morphCount*1.05;
if (morphing == true ) morphCount += 0.2;
if (morphCount >=maxPositionFactor)
{
morphCount = 0;
morphing = false;
createNewDotList = true;
}
if (createNewDotList == true) creatDotList ();
createNewDotList = false;
if (morphing == false && isPlaying == true) frameCounter++;
if (frameCounter == 25)
{
actRandomSeed +=1;
morphing = true;
frameCounter = 0;
}
}
void setSetup()
{
// Hint for OPENGL------------------------------------------------------------------
/*
hint(ENABLE_NATIVE_FONTS);
hint(DISABLE_DEPTH_TEST);
hint(DISABLE_OPENGL_ERROR_REPORT);
hint(ENABLE_OPENGL_4X_SMOOTH);
int(DISABLE_OPENGL_2X_SMOOTH);
*/
// LoadData --------------------------------------------------------------------
bg = loadImage ("bg.png");
play_img = loadImage("play.png");
// SetSize --------------------------------------------------------------------
actRandomSeed = 6;
isPlaying = true;
maxPositionFactor = 10;
positionFactor = 9.3;
zFactor = 1;
connectionFactor = 0.6;
oldCircleSize = 10;
morphCount = 0;
frameCounter = 0;
// Camera --------------------------------------------------------------------
cam = new PeasyCam(this, width/2, height/2, 0,800);
cam.setMinimumDistance(50);
cam.setMaximumDistance(8000);
}
void playPause ()
{
if (isPlaying == false)
{
if (hideimage == false) image(play_img, -280, -72);
}
if (isPlaying == true)
{
}
}
This one looks & works much better using OPENGL.
Controls:
mouse = Camera
'm' = play / pause
'n' = show / hide pause image
'+' / '-' = morph manual
'y' / 'x' = remove / add connections
'a' / 's' = increase / decrease random
'e' / 'r' = decrease / increase depth adjustment