We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › full 360 in 1 secon
Page Index Toggle Pages: 1
full 360 in 1 secon? (Read 970 times)
full 360 in 1 secon?
Mar 28th, 2010, 6:17am
 
Hi,

with risk to be banned from this forum, because of spamming with questions,  I dare to ask one more (and unfortunately most surely not last one)


I want to make a full 360 degrees spin in lets say 3 seconds.

I cant figure out how to define the time in relation to rotation.

Code:

float time = 3000;

if(time>0)
{
for(int i = 0; i<time; i++)
 {
 angle = (angle*i/time+1)%360;

fill(255,255,0);
rotate(radians(angle));
rect(100,0,10,10);
  }
time --;
}




?
Re: full 360 in 1 secon?
Reply #1 - Mar 28th, 2010, 6:37am
 
doing it like this its not time but frames, but that might be enough if you have a steady frameRate of lets say 60 fps.

i still dont get what you want, could you explain it ?
Re: full 360 in 1 secon?
Reply #2 - Mar 28th, 2010, 6:56am
 
Well.... huh  Shocked  where should I start...

I`m working on a project for my studies. I want to make an app that does the following:

By clicking and dragging the user creates a new sphere with centerpoint at where the mouse has been clicked and  a radius equals to the dragged distance.

The sphere has a certain speed at birth. If this speed is more then a certain threshold, it gets linearly accelerated to a maximum speed, where the rings of the sphere start to dissolve (because of the speed). And vice verca - if the speed at birth is lower then the threshold point, it gets decreased until it hits the minimum speed, where the rings also dissolve. The thing with the colors you already know Smiley

OH! oh ! there`s the light! While explaining this to you now, I`ve just spotted a logical/thinking problem myself....

Let me look if I can change my implementation, and if not I`ll continue my storytelling Smiley
Eventually it should start looking hopefully a bit like this :
http://www.flickr.com/photos/alexposada/sets/72157623578136140/
with the difference, that the spheres are not concentric.  


MORAL: always ask the right and SIMPLE questions

Re: full 360 in 1 secon?
Reply #3 - Mar 28th, 2010, 7:12am
 
no need to explain the project, i have read and as you know aswered all your other posts Smiley
it was just not clear to me, how your "360 degree turn in 3 sec" would fit in your program

let me know if you solv it yourself Smiley thats always the best way to do it
Re: full 360 in 1 secon?
Reply #4 - Mar 28th, 2010, 8:34am
 
Undecided

I guess I have to re-write everything using vectors Sad

10 days I`ve been tweeking on this, and now I have to start over.

Lets see if I get it working until Wednesday


Or before I invest the last 2 days until the deadline, I`d better ask:

Using Vectors, could I influence the position and the speed of the point within the formula for Sphere that I`m using

Code:
  
void drawSphere()
{
for(int i=1; i<wRings; i++)
{
float phase = i*1./wRings;
ringCenterY = (sin(phase*PI+HALF_PI)*.5+.5)*radius;
ringSizeX = sin(phase*PI)*radius/2;
ringSizeY = ringSizeX/4;
drawRing();
}
}

void drawRing()
{
noStroke();

for(int i=0; i<hRings; i++)
{
float phase = i*slice/hRings-angle;
x = ringCenterX + ringSizeX*cos(phase*TWO_PI);
y = ringCenterY + ringSizeY*sin(phase*TWO_PI);

pointSize = abs(sin(phase+angle)*TWO_PI);

float colorShifter = speed*100;

float cRed = 255*colorShifter;
float cBlue = 255*(1-colorShifter);
// println("RED: " + cRed + "BLUE: " + cBlue);
fill(cRed,255,cBlue);
ellipse(x,y, pointSize,pointSize);
}
}


May be also color ?

Re: full 360 in 1 secon?
Reply #5 - Mar 28th, 2010, 8:54am
 
thinking in realtime just now:

Since the rings of the sphere a just points, that follow an elliptical path, I could indeed use vector containing x,y.

Secondly, the speed of the motion along this path should be given by another vector, added to the location vector?

Thirdly the acceleration would be held in a third vector that will be added to the speed-vector.

Are my thoughts going the right direction ? Theoretically it sounds promising.
Re: full 360 in 1 secon?
Reply #6 - Mar 28th, 2010, 9:35am
 
sorry, but i just cant follow your thoughts here.
i cant see what the problem is and how this should be solved by using vectors now...
Re: full 360 in 1 secon?
Reply #7 - Mar 28th, 2010, 12:09pm
 
I thought it would be easier to control rotations and speed and so on, since you have math functions with vectors, that allow you to calculate distances, angles, add coordinates and so on.

I`ve been trying now for an hour but cant really get it moving.

Code:

PVector ring, radius;
PVector angle, acceleration;

void setup()
{
 size(500,500);
 smooth();
 noStroke();
 ring = new PVector(0,0);
 radius = new PVector(100,50);
 angle = new PVector(1,1);
 acceleration = new PVector(10,10);
}


void draw()
{
 fill(0,2);
 rect(0,0,width,height);
 translate(width/2,height/2);
 drawRing();
 rotateRing();
 println(ring.x + " " + ring.y)
}

void drawRing()
{
 for(int i=0; i<60; i++)
 {
   
   float phase = i*1./60;
   float pointSize = abs(sin(phase)*TWO_PI);
   fill(255,255*phase,155);
   ring.x = ring.x + radius.x*cos(phase*TWO_PI);
   ring.y = ring.y + radius.y*sin(phase*TWO_PI);
   ellipse(ring.x,ring.y,pointSize,pointSize);

 }

}

void rotateRing()
{  
 
   angle.add(acceleration);
   ring.add(angle);
}



Now I`ll to try the angleBetween-function to add angles togeter....
Re: full 360 in 1 secon?
Reply #8 - Mar 28th, 2010, 12:14pm
 
as far as i understood your programm i dont see a reason to use vectors now...
Re: full 360 in 1 secon?
Reply #9 - Mar 28th, 2010, 12:29pm
 
huh, you think so?

hmh... you musst be right, bull I^ll give myself one more hour with the vectors.... I dont have a great choice really, because with the other implimentation komme ich nicht wirklich weiter. es hackt noch an wichtigen stellen.

gruss
Re: full 360 in 1 secon?
Reply #10 - Mar 28th, 2010, 1:52pm
 


Code:


PVector ring, radius;
PVector angle, acceleration, speed;
PVector timeVector;

float time;
float  speedMax, speedMin;

void setup()
{
 size(500,500);
 smooth();
 noStroke();
 ring = new PVector(0,0);
 radius = new PVector(200,50);
 angle = new PVector(PI,PI);


 speedMax = 1;
 speedMin = 0.1;
 
}


void draw()
{
 fill(0,10);
 rect(0,0,width,height);
 translate(width/2,height/2);
 drawRing();
 rotateRing();
 //println(ring.x + " " + ring.y);
}


void drawRing()
{
 pushMatrix();
 for(int i=0; i<200; i++)
 {
   
   float phase = i*1./200;
   float pointSize = abs(sin(phase)*TWO_PI);
   
   fill(255,0,155);
   ring.x = mouseX + radius.x*cos(radians(angle.x));
   ring.y = mouseY + radius.y*sin(radians(angle.y));
   ellipse(ring.x,ring.y,pointSize,pointSize);  
 }
  popMatrix();
}

void rotateRing()
{  
  for(int i=0;i<360;i++){
   
   time = millis();
   acceleration = new PVector(time,time);
   acceleration.normalize();
   acceleration.mult(0.01);
   
   
   angle.add(acceleration);
   ring.add(angle);
  }
   
}




Now I just have to figure out, how to make an acceleration/deceleration to max or min speed. I guess I need a parameter for the acceleration.mult(p) that gives me a relation to .... speed over time, may be?
Any ideas?


never give up hope!
Page Index Toggle Pages: 1