erdmann
Ex Member
Re: return value for position
Reply #2 - Nov 9th , 2009, 11:01am
okay i try to explain: there are three circles placed somewhere on my sketch. each circle has a max. and a min. distance in relation to the two other circles. my aim is, when the first circle moves the other circle should follow the to the position of the first according to the distance mentioned before. an so on. actually i am so far that the distance is calculated but the movment is randomly. here is my code( i am a beginner) color weiss = color(255, 255, 255, 80); color hintergrund = color(95, 95, 95); float circleX; float circleY; float circleG; float circleH; float circleN; float circleM; float circleRadius = 3; float circleSize = circleRadius * 2; float v = random(-5, 5); float v1 = random(-5, 5); float v2 = random(-5, 5); float v3 = random(-5, 5); float v4 = random(-5, 5); float v5 = random(-5, 5); void setup() { background(hintergrund); size(1024, 768); smooth(); noFill(); circleX = random(width); circleY = random(height); circleG = random(width); circleH = random(height); circleN = random(width); circleM = random(height); } void draw() { background(hintergrund); stroke(weiss); // kreise ellipse(circleX, circleY, circleSize, circleSize); ellipse(circleG, circleH, circleSize, circleSize); ellipse(circleN, circleM, circleSize, circleSize); // verbindung zwischen den kreisen stroke(weiss); line(circleG, circleH, circleN, circleM); stroke(weiss); line(circleG, circleH, circleX, circleY); stroke(weiss); line(circleN, circleM, circleX, circleY); circleX = circleX + v; circleY = circleY + v1; if(circleX >= width) { v = -v; } if(circleX <= 0) { v = -v; } if(circleY >= height) { v1 = -v1; } if(circleY <= 0) { v1 = -v1; } if(dist(circleX, circleY, circleG, circleH) >= 300) { v = -v; } if(dist(circleX, circleY, circleG, circleH) >= 300) { v1 = -v1; } if(dist(circleX, circleY, circleN, circleM) >= 400) { v = -v; } if(dist(circleX, circleY, circleN, circleM) >= 400) { v1 = -v1; } if(dist(circleX, circleY, circleG, circleH) <= 150) { v = -v; } if(dist(circleX, circleY, circleG, circleH) <= 150) { v1 = -v1; } if(dist(circleX, circleY, circleN, circleM) <= 110) { v = -v; } if(dist(circleX, circleY, circleN, circleM) <= 110) { v1 = -v1; } circleG = circleG + v2; circleH = circleH + v3; if(circleG >= width) { v2 = -v2; } if(circleG <= 0) { v2 = -v2; } if(circleH >= height) { v3 = -v3; } if(circleH <= 0) { v3 = -v3; } if(dist(circleG, circleH, circleX, circleY) >= 300) { v2 = -v2; } if(dist(circleG, circleH, circleX, circleY) >= 300) { v3 = -v3; } if(dist(circleG, circleH, circleN, circleM) >= 250) { v2 = -v2; } if(dist(circleG, circleH, circleN, circleM) >= 250) { v3 = -v3; } if(dist(circleX, circleY, circleG, circleH) <= 150) { v2 = -v2; } if(dist(circleX, circleY, circleG, circleH) <= 150) { v3 = -v3; } if(dist(circleX, circleY, circleN, circleM) <= 200) { v2 = -v2; } if(dist(circleX, circleY, circleN, circleM) <= 200) { v3 = -v3; } circleN = circleN + v4; circleM = circleM + v5; if(circleN >= width) { v4 = -v4; } if(circleN <= 0) { v4 = -v4; } if(circleM >= height) { v5 = -v5; } if(circleM <= 0) { v5 = -v5; } if(dist(circleN, circleM, circleG, circleH) >= 250) { v4 = -v4; } if(dist(circleN, circleM, circleG, circleH) >= 250) { v5 = -v5; } if(dist(circleN, circleM, circleX, circleY) >= 400) { v4 = -v4; } if(dist(circleN, circleM, circleX, circleY) >= 400) { v5 = -v5; } if(dist(circleX, circleY, circleG, circleH) <= 150) { v4 = -v4; } if(dist(circleX, circleY, circleG, circleH) <= 150) { v5 = -v5; } if(dist(circleX, circleY, circleN, circleM) <= 110) { v4 = -v4; } if(dist(circleX, circleY, circleN, circleM) <= 110) { v5 = -v5; } }