how to make a ball/round running with a ellipse track (still not solve!!!)

Here is my code is here if can't solve my problem please give tips for me to walk in another way,thanks in advance.

int leth=1,sze_X=900,sze_Y=600;
float center_X=sze_X/3,center_Y=sze_Y/3,ellipse_center_X=center_X+50,ellipse_center_Y=center_Y,equation_c;
float x[]=new float[leth],y[]=new float[leth],size_1[]=new float[leth],step[]=new float[leth],angle[]=new float[leth],equation_a[]=new float[leth],equation_b[]=new float[leth],equation_A[]=new float[leth],equation_B[]=new float[leth],equation_C;
double ellipse_a[]=new double[leth],ellipse_b[]=new double[leth];
boolean negation_X[]=new boolean[leth],negation_Y[]=new boolean[leth];
void setup(){
  size(sze_X,sze_Y,OPENGL);
  background(0);
  smooth(8);
  noStroke();
  rdm();
  equation_c=dist(center_X,center_Y,ellipse_center_X,ellipse_center_Y);
  eqt();
  println(equation_A+","+equation_B+","+equation_c+",");
  step[0]=0.01;
}

void rdm(){
  int half_size=45;
  for(int i=0;i<leth;i++){
    x[i]=random(-sze_X,sze_X);
    y[i]=random(-sze_Y,sze_Y);
    if(center_X-half_size-13<=x[i]&&x[i]<=center_X+half_size+13){
      if(center_Y-half_size-13<=y[i]&&y[i]<=center_Y+half_size+13){
        while(center_Y-half_size-13<=y[i]&&y[i]<=center_Y+half_size+13){y[i]=random(0,sze_Y);}
      }
    }
    size_1[i]=random(5,13);
  }
  x[0]=100;
  y[0]=100;
  size_1[0]=30;
}

void eqt(){
  for(int i=0;i<leth;i++){
    equation_A[i]=sq(equation_c)*sq(x[i]); 
    equation_B[i]=sq(x[i])+sq(y[i])+sq(equation_c);
    equation_C=1;
    if((equation_B[i]-sqrt(sq(equation_B[i])-4*equation_A[i]*equation_C))>=0){equation_a[i]=1/((equation_B[i]-sqrt(sq(equation_B[i])-4*equation_A[i]*equation_C))/2*equation_A[i]);}
    else if((equation_B[i]-sqrt(sq(equation_B[i])-4*equation_A[i]*equation_C))<0){equation_a[i]=1/((equation_B[i]+sqrt(sq(equation_B[i])-4*equation_A[i]*equation_C))/2*equation_A[i]);}
    else{println("@@@@@@@@@@@@@@@@@@");}
    equation_b[i]=equation_a[i]-sq(equation_c);
    ellipse_a[i]=sqrt(equation_a[i]);
    ellipse_b[i]=sqrt(equation_b[i]);
  }
}

void draw(){
  color blk=color(0,0,0);
  color blu=color(100,255,252);
  int size=100;
  float number=0.01;
  color change=lerpColor(blk,blu,0);
  clear();
  for(int i=0;i<100;i++){
    if(number<=1){
      change=lerpColor(blk,blu,number);
      number=number+0.01;
      fill(change);
     }
  else{
    fill(blu);
  }
  if(size>0){
  ellipse(center_X,center_Y,size,size);
  }
  size=size-1;
  }
  star();
  rotte();
}

void star(){
  color blc=color(0,0,0);
  color org=color(255,252,45);
  float size_2=5.0;
  float number;
  color change;
  for(int i=0;i<leth;i++){
    size_2=size_1[i];
    number=0;
    for(int j=0;j<size_1[i];j++){
      if(number<=1){
        change=lerpColor(blc,org,number);
        number=number+1/size_1[i];
        fill(change);
      }
      else{
        fill(org);
      }
      if(size_2>0){
        if(negation_X[i]==true){
          if(negation_Y[i]==true){ellipse(-x[i],-y[i],size_2,size_2);}
          else{ellipse(-x[i],y[i],size_2,size_2);}
        }
        else{
          if(negation_Y[i]==true){ellipse(x[i],-y[i],size_2,size_2);} 
          else{ellipse(x[i],y[i],size_2,size_2);}
        }
        ellipse(x[i],y[i],size_2,size_2);
        negation_X[i]=false;negation_Y[i]=false;
      }
     size_2=size_2-1;
    }
  }
}

void rotte(){
  int i;
  for(i=0;i<leth;i++){  
    x[i]=(float)(y[i]+ellipse_a[i]*cos(angle[i]));
    y[i]=(float)(x[i]+ellipse_b[i]*sin(angle[i]));
    angle[i]+=step[i];
    if(angle[i]>TWO_PI){angle[i]-=TWO_PI;}
    if(x[i]<0){negation_X[i]=true;x[i]=-x[i];}
    else if(y[i]<0){negation_Y[i]=true;y[i]=-y[i];}
    else{negation_X[i]=false;negation_Y[i]=false;}
  }
}

Answers

  • edited October 2013

    here...........................

    Did you mean this?

    int leth=1, sze_X=900, sze_Y=600;
    float center_X=sze_X/3, center_Y=sze_Y/3, ellipse_center_X=center_X+50, ellipse_center_Y=center_Y, equation_c;
    float x[]=new float[leth], y[]=new float[leth], size_1[]=new float[leth], step[]=new float[leth], angle[]=new float[leth], equation_a[]=new float[leth], equation_b[]=new float[leth], equation_A[]=new float[leth], equation_B[]=new float[leth], equation_C;
    double ellipse_a[]=new double[leth], ellipse_b[]=new double[leth];
    boolean negation_X[]=new boolean[leth], negation_Y[]=new boolean[leth];
    float x1=10, y1=10;
    float angleForPosition = 0; 
    
    void setup() {
      size(sze_X, sze_Y );
      background(0);
      smooth(8);
      noStroke();
      rdm();
      equation_c=dist(center_X, center_Y, ellipse_center_X, ellipse_center_Y);
      eqt();
      println(equation_A+","+equation_B+","+equation_c+",");
      step[0]=0.01;
    }
    
    void rdm() {
      int half_size=45;
      for (int i=0;i<leth;i++) {
        x[i]=random(-sze_X, sze_X);
        y[i]=random(-sze_Y, sze_Y);
        if (center_X-half_size-13<=x[i]&&x[i]<=center_X+half_size+13) {
          if (center_Y-half_size-13<=y[i]&&y[i]<=center_Y+half_size+13) {
            while (center_Y-half_size-13<=y[i]&&y[i]<=center_Y+half_size+13) {
              y[i]=random(0, sze_Y);
            }
          }
        }
        size_1[i]=random(5, 13);
      }
      x[0]=100;
      y[0]=100;
      size_1[0]=30;
    }
    
    void eqt() {
      for (int i=0;i<leth;i++) {
        equation_A[i]=sq(equation_c)*sq(x[i]); 
        equation_B[i]=sq(x[i])+sq(y[i])+sq(equation_c);
        equation_C=1;
        if ((equation_B[i]-sqrt(sq(equation_B[i])-4*equation_A[i]*equation_C))>=0) {
          equation_a[i]=1/((equation_B[i]-sqrt(sq(equation_B[i])-4*equation_A[i]*equation_C))/2*equation_A[i]);
        }
        else if ((equation_B[i]-sqrt(sq(equation_B[i])-4*equation_A[i]*equation_C))<0) {
          equation_a[i]=1/((equation_B[i]+sqrt(sq(equation_B[i])-4*equation_A[i]*equation_C))/2*equation_A[i]);
        }
        else {
          println("@@@@@@@@@@@@@@@@@@");
        }
        equation_b[i]=equation_a[i]-sq(equation_c);
        ellipse_a[i]=sqrt(equation_a[i]);
        ellipse_b[i]=sqrt(equation_b[i]);
      }
    }
    
    void draw() {
      color blk=color(0, 0, 0);
      color blu=color(100, 255, 252);
      int size=100;
      float number=0.01;
      color change=lerpColor(blk, blu, 0);
      translate(x1, y1); 
      clear();
      for (int i=0;i<100;i++) {
        if (number<=1) {
          change=lerpColor(blk, blu, number);
          number=number+0.01;
          fill(change);
        }
        else {
          fill(blu);
        }
        if (size>0) {
          ellipse(center_X, center_Y, size, size);
        }
        size=size-1;
      }
      star();
      rotte();
      angleForPosition++;
      x1 = 150+cos (radians(angleForPosition)) * 389;
      y1 = 40+ sin (radians(angleForPosition)) * 139;
    }
    
    void star() {
      color blc=color(0, 0, 0);
      color org=color(255, 252, 45);
      float size_2=5.0;
      float number;
      color change;
      for (int i=0;i<leth;i++) {
        size_2=size_1[i];
        number=0;
        for (int j=0;j<size_1[i];j++) {
          if (number<=1) {
            change=lerpColor(blc, org, number);
            number=number+1/size_1[i];
            fill(change);
          }
          else {
            fill(org);
          }
          if (size_2>0) {
            if (negation_X[i]==true) {
              if (negation_Y[i]==true) {
                ellipse(-x[i], -y[i], size_2, size_2);
              }
              else {
                ellipse(-x[i], y[i], size_2, size_2);
              }
            }
            else {
              if (negation_Y[i]==true) {
                ellipse(x[i], -y[i], size_2, size_2);
              } 
              else {
                ellipse(x[i], y[i], size_2, size_2);
              }
            }
            ellipse(x[i], y[i], size_2, size_2);
            negation_X[i]=false;
            negation_Y[i]=false;
          }
          size_2=size_2-1;
        }
      }
    }
    
    void rotte() {
      int i;
      for (i=0;i<leth;i++) {  
        x[i]=(float)(y[i]+ellipse_a[i]*cos(angle[i]));
        y[i]=(float)(x[i]+ellipse_b[i]*sin(angle[i]));
        angle[i]+=step[i];
        if (angle[i]>TWO_PI) {
          angle[i]-=TWO_PI;
        }
        if (x[i]<0) {
          negation_X[i]=true;
          x[i]=-x[i];
        }
        else if (y[i]<0) {
          negation_Y[i]=true;
          y[i]=-y[i];
        }
        else {
          negation_X[i]=false;
          negation_Y[i]=false;
        }
      }
    }
    
  • you could also save the ball as an image and then display this - faster

  • edited October 2013

    I want to change its size and the number of it if I want so I wrote this code,but the point is how to make it run with an ellipse track

  • you need to be more precise with your questions I am afraid...

    Do you mean the form of the ball itself should be like an ellipse?

  • the ball‘s center is in ellipse track and the properties of ellipse can be change,so that to create new shape of ellipse for the center goes in

  • here....

    int leth=1, sze_X=900, sze_Y=600;
    float center_X=sze_X/3, center_Y=sze_Y/3, ellipse_center_X=center_X+50, ellipse_center_Y=center_Y, equation_c;
    float x[]=new float[leth], y[]=new float[leth], size_1[]=new float[leth], step[]=new float[leth], 
    angle[]=new float[leth], equation_a[]=new float[leth], equation_b[]=new float[leth], 
    equation_A[]=new float[leth], equation_B[]=new float[leth], equation_C;
    double ellipse_a[]=new double[leth], ellipse_b[]=new double[leth];
    boolean negation_X[]=new boolean[leth], negation_Y[]=new boolean[leth];
    int sizeyMaxGlobal=100;
    int sizeyMaxAdd=-1;
    
    
    void setup() {
      size(sze_X, sze_Y );
      background(0);
      smooth(8);
      noStroke();
      rdm();
      equation_c=dist(center_X, center_Y, ellipse_center_X, ellipse_center_Y);
      eqt();
      println(equation_A+","+equation_B+","+equation_c+",");
      step[0]=0.01;
    }
    
    
    void rdm() {
      int half_size=45;
      for (int i=0;i<leth;i++) {
        x[i]=random(-sze_X, sze_X);
        y[i]=random(-sze_Y, sze_Y);
        if (center_X-half_size-13<=x[i]&&x[i]<=center_X+half_size+13) {
          if (center_Y-half_size-13<=y[i]&&y[i]<=center_Y+half_size+13) {
            while (center_Y-half_size-13<=y[i]&&y[i]<=center_Y+half_size+13) {
              y[i]=random(0, sze_Y);
            }
          }
        }
        size_1[i]=random(5, 13);
      }
      x[0]=100;
      y[0]=100;
      size_1[0]=30;
    }
    
    void eqt() {
      for (int i=0;i<leth;i++) {
        equation_A[i]=sq(equation_c)*sq(x[i]);
        equation_B[i]=sq(x[i])+sq(y[i])+sq(equation_c);
        equation_C=1;
        if ((equation_B[i]-sqrt(sq(equation_B[i])-4*equation_A[i]*equation_C))>=0) {
          equation_a[i]=1/((equation_B[i]-sqrt(sq(equation_B[i])-4*equation_A[i]*equation_C))/2*equation_A[i]);
        }
        else if ((equation_B[i]-sqrt(sq(equation_B[i])-4*equation_A[i]*equation_C))<0) {
          equation_a[i]=1/((equation_B[i]+sqrt(sq(equation_B[i])-4*equation_A[i]*equation_C))/2*equation_A[i]);
        }
        else {
          println("@@@@@@@@@@@@@@@@@@");
        }
        equation_b[i]=equation_a[i]-sq(equation_c);
        ellipse_a[i]=sqrt(equation_a[i]);
        ellipse_b[i]=sqrt(equation_b[i]);
      }
    }
    
    void draw() {
      //
      pushMatrix();
      translate (140, 120);
      ball1(100, sizeyMaxGlobal) ;
      popMatrix();
      //---------------------
      pushMatrix();
      translate (200, 110);
      star();
      popMatrix();
      // ------------------
      pushMatrix();
      translate (290, 110);
      ball1(100, 100) ;
      popMatrix();
    
      rotte();
      if (sizeyMaxGlobal<20)
        sizeyMaxAdd=1;
      else if (sizeyMaxGlobal>199) 
        sizeyMaxAdd=-1;
    
      sizeyMaxGlobal+=sizeyMaxAdd;
    }
    
    void ball1(  int sizeXMax, int sizeYMax  ) {
    
      color blk=color(0, 0, 0);
      color blu=color(100, 255, 252);
      int sizeX=sizeXMax;
      int sizeY=sizeYMax;
      float number=0.01;
      color change=lerpColor(blk, blu, 0);
      // clear();
      for (int i=0;i<100;i++) {
        if (number<=1) {
          change=lerpColor(blk, blu, number);
          number=number+0.01;
          fill(change);
        }
        else {
          fill(blu);
        }
        if (sizeX>0 && sizeY>0) {
          ellipse(center_X, center_Y, sizeX, sizeY);
        }
        sizeX--;
        sizeY--;
      } // for
    } // func
    
    void star() {
      color blc=color(0, 0, 0);
      color org=color(255, 252, 45);
      float size_2=5.0;
      float number;
      color change;
      for (int i=0;i<leth;i++) {
        size_2=size_1[i];
        number=0;
        for (int j=0;j<size_1[i];j++) {
    
          if (number<=1) {
            change=lerpColor(blc, org, number);
            number=number+1/size_1[i];
            fill(change);
          }
          else {
            fill(org);
          }
          //    ellipse(-x[i], -y[i], size_2, size_2); // ????
    
          if (size_2>0) {
            if (negation_X[i]==true) {
              if (negation_Y[i]==true) {
                ellipse(-x[i], -y[i], size_2, size_2);
              }
              else {
                ellipse(-x[i], y[i], size_2, size_2);
              }
            }
            else {
              if (negation_Y[i]==true) {
                ellipse(x[i], -y[i], size_2, size_2);
              }
              else {
                ellipse(x[i], y[i], size_2, size_2);
              }
            }
            ellipse(x[i], y[i], size_2, size_2);
            negation_X[i]=false;
            negation_Y[i]=false;
          }
          size_2=size_2-1;
        }
      }
    }
    
    void rotte() {
      int i;
      for (i=0;i<leth;i++) { 
        x[i]=(float)(y[i]+ellipse_a[i]*cos(angle[i]));
        y[i]=(float)(x[i]+ellipse_b[i]*sin(angle[i]));
        angle[i]+=step[i];
        if (angle[i]>TWO_PI) {
          angle[i]-=TWO_PI;
        }
        if (x[i]<0) {
          negation_X[i]=true;
          x[i]=-x[i];
        }
        else if (y[i]<0) {
          negation_Y[i]=true;
          y[i]=-y[i];
        }
        else {
          negation_X[i]=false;
          negation_Y[i]=false;
        }
      }
    }
    
  • Sorry my meaning is the yellow ball move in the ellipse track , with one focus had set and one i can set arbitrarily (from setting the ellipse's center(ellipse_center_X,ellipse_center_Y)) , i want the computer to calculate it so i give the equation (equation_a[]=new float[leth], equation_b[]=new float[leth], equation_A[]=new float[leth], equation_B[]=new float[leth], equation_C;)

    maybe i didnt describe what i want clearly , so please help me again, thanks!

  • edited October 2013

    I don't get your english...

    Let me quote you and ask what you mean...

    the yellow ball move in the ellipse track

    Do you want that the yellow ball moves towards the blue ball?

    with one focus had set and one i can set arbitrarily

    Do you mean the x- or y-value of the yellow ball is fixed? Because it has no focus.

    the equation (equation_a[]=new float[leth], equation_b[]=new float[leth], equation_A[]=new float[leth], equation_B[]=new float[leth], equation_C;)

    What do you want to achieve by this?

  • Draw an ellipse with nothing fill in, regard it as the track of yellow ball ,but I want the track(ellipse)can be user-defineded , so I created an ellipse_center ,but how can I make the computer creat by itself?so I used my math knowledge to calculate it and give the final equation,so that the computer can calculate the point(the axis a and b of the ellipse)from
    origin of coordinates I give (change a way to say I give the center and the The elliptical focal length from the length to calculate other two key axis a and b) ,and after done that I can use the yellow ball's x,y and the center to move it in the ellipse.

  • I asked you 3 questions, could you answer all 3 questions, please?

  • edited October 2013

    here

    when you click left mouse, ellipse is at this position

    whenn you click right mouse, you set radius in x and y of the ellipse

    int leth=1, sze_X=900, sze_Y=600;
    float center_X=sze_X/3, center_Y=sze_Y/3, ellipse_center_X=center_X+50, ellipse_center_Y=center_Y, equation_c;
    float x[]=new float[leth], y[]=new float[leth], size_1[]=new float[leth], step[]=new float[leth], 
    angle[]=new float[leth], equation_a[]=new float[leth], equation_b[]=new float[leth], 
    equation_A[]=new float[leth], equation_B[]=new float[leth], equation_C;
    double ellipse_a[]=new double[leth], ellipse_b[]=new double[leth];
    boolean negation_X[]=new boolean[leth], negation_Y[]=new boolean[leth];
    int sizeyMaxGlobal=100;
    int sizeyMaxAdd=-1;
    float starX = random (100), starY = random (100); 
    float starXAdd=12.2;
    float starYAdd=11.2;
    float angleStar=0.0;
    float centerX, centerY;
    float radiusX=111, radiusY=60; 
    
    void setup() {
      size(sze_X, sze_Y );
      background(0);
      smooth(8);
      noStroke();
      rdm();
      equation_c=dist(center_X, center_Y, ellipse_center_X, ellipse_center_Y);
      eqt();
      println(equation_A+","+equation_B+","+equation_c+",");
      step[0]=0.01;
    }
    
    
    void rdm() {
      int half_size=45;
      for (int i=0;i<leth;i++) {
        x[i]=random(-sze_X, sze_X);
        y[i]=random(-sze_Y, sze_Y);
        if (center_X-half_size-13<=x[i]&&x[i]<=center_X+half_size+13) {
          if (center_Y-half_size-13<=y[i]&&y[i]<=center_Y+half_size+13) {
            while (center_Y-half_size-13<=y[i]&&y[i]<=center_Y+half_size+13) {
              y[i]=random(0, sze_Y);
            }
          }
        }
        size_1[i]=random(5, 13);
      }
      x[0]=100;
      y[0]=100;
      size_1[0]=30;
    }
    
    void eqt() {
      for (int i=0;i<leth;i++) {
        equation_A[i]=sq(equation_c)*sq(x[i]);
        equation_B[i]=sq(x[i])+sq(y[i])+sq(equation_c);
        equation_C=1;
        if ((equation_B[i]-sqrt(sq(equation_B[i])-4*equation_A[i]*equation_C))>=0) {
          equation_a[i]=1/((equation_B[i]-sqrt(sq(equation_B[i])-4*equation_A[i]*equation_C))/2*equation_A[i]);
        }
        else if ((equation_B[i]-sqrt(sq(equation_B[i])-4*equation_A[i]*equation_C))<0) {
          equation_a[i]=1/((equation_B[i]+sqrt(sq(equation_B[i])-4*equation_A[i]*equation_C))/2*equation_A[i]);
        }
        else {
          println("@@@@@@@@@@@@@@@@@@");
        }
        equation_b[i]=equation_a[i]-sq(equation_c);
        ellipse_a[i]=sqrt(equation_a[i]);
        ellipse_b[i]=sqrt(equation_b[i]);
      }
    }
    
    void draw() {
      //
      //  pushMatrix();
      //  translate (140, 120);
      //  ball1(100, sizeyMaxGlobal) ;
      //  popMatrix();
      //---------------------
      pushMatrix();
      // starX=starX+starYAdd;
      translate (starX, starY);
      star();
      starX=centerX+ cos (radians(angleStar)) * radiusX;
      starY=centerY+ sin (radians(angleStar)) * radiusY;
      popMatrix();
      // ------------------
      pushMatrix();
      translate (290, 210);
      ball1(100, 100) ;
      popMatrix();
      // ------------------
      //  rotte();
    
    
      //  if (sizeyMaxGlobal<20)
      //    sizeyMaxAdd=1;
      //  else if (sizeyMaxGlobal>199) 
      //    sizeyMaxAdd=-1;
      //
      //  sizeyMaxGlobal+=sizeyMaxAdd;
      println (starX+"       "+millis());
      angleStar+=4;
    }
    
    void mousePressed() {
      // 
      if (mouseButton == LEFT) {
        centerX=mouseX;
        centerY=mouseY;
      } // if 
      else {
        //
        radiusX=mouseX;
        radiusY=mouseY;
      } // else  
      //
    } // func
    
    void ball1(  int sizeXMax, int sizeYMax  ) {
    
      color blk=color(0, 0, 0);
      color blu=color(100, 255, 252);
      int sizeX=sizeXMax;
      int sizeY=sizeYMax;
      float number=0.01;
      color change=lerpColor(blk, blu, 0);
      // clear();
      for (int i=0;i<100;i++) {
        if (number<=1) {
          change=lerpColor(blk, blu, number);
          number=number+0.01;
          fill(change);
        }
        else {
          fill(blu);
        }
        if (sizeX>0 && sizeY>0) {
          ellipse(center_X, center_Y, sizeX, sizeY);
        }
        sizeX--;
        sizeY--;
      } // for
    } // func
    
    void star() {
      color blc=color(0, 0, 0);
      color org=color(255, 252, 45);
      float size_2=5.0;
      float number;
      color change;
      for (int i=0;i<leth;i++) {
        size_2=size_1[i];
        number=0;
        for (int j=0;j<size_1[i];j++) {
    
          if (number<=1) {
            change=lerpColor(blc, org, number);
            number=number+1/size_1[i];
            fill(change);
          }
          else {
            fill(org);
          }
          //    ellipse(-x[i], -y[i], size_2, size_2); // ????
    
          if (size_2>0) {
            if (negation_X[i]==true) {
              if (negation_Y[i]==true) {
                ellipse(-x[i], -y[i], size_2, size_2);
              }
              else {
                ellipse(-x[i], y[i], size_2, size_2);
              }
            }
            else {
              if (negation_Y[i]==true) {
                ellipse(x[i], -y[i], size_2, size_2);
              }
              else {
                ellipse(x[i], y[i], size_2, size_2);
              }
            }
            ellipse(x[i], y[i], size_2, size_2);
            negation_X[i]=false;
            negation_Y[i]=false;
          }
          size_2=size_2-1;
        }
      }
    }
    
    void rotte() {
      int i;
      for (i=0;i<leth;i++) { 
        x[i]=(float)(y[i]+ellipse_a[i]*cos(angle[i]));
        y[i]=(float)(x[i]+ellipse_b[i]*sin(angle[i]));
        angle[i]+=step[i];
        if (angle[i]>TWO_PI) {
          angle[i]-=TWO_PI;
        }
        if (x[i]<0) {
          negation_X[i]=true;
          x[i]=-x[i];
        }
        else if (y[i]<0) {
          negation_Y[i]=true;
          y[i]=-y[i];
        }
        else {
          negation_X[i]=false;
          negation_Y[i]=false;
        }
      }
    }
    
    //
    
  • the picture of my meaning

  • who can help me????

  • I hope there's someone can help me out

  • I have no idea.... sry....

  • you can use a drag and drop with the mouse on the blue ball. Do you want that? The 2nd focus of the ellipse should then be fixed? ok, I don't have the math for your idea. The math I have at my command you see above. it works with sin, cos and different radius for both.

    see you

  • From your drawing it is absolutely unclear what you're trying to accomplish.

    Maybe you can draw several http://sketchtoy.com/49496868 sketches, to show us the dynamics of what you're trying to accomplish. You don't have to draw doraimon but just few drafts of movements of your ellipses.

  • you didn't answer my question. you can use a drag and drop with the mouse on the blue ball. Do you want that?

  • edited October 2013

    first question is No, i want to change leth and remove x[0]=100;y[0]=100;size_1[0]=30; to get hundreds of yellow ball , the blue ball is static and its center is the focus of the ellipse, all can be changed is the center, once set the center ,the another focus will be set and be fixed at the same time and the computer will know what the ellipse like automaticly,so the second question is Yes.maybe my equation is wrong please check it , sorry for ignored.

  • edited October 2013

    Stop rejecting replies that aren't even answers! It becomes on the verge of being offensive...

  • I don't have the math for this. But I think what the guy wants it that he can let the user change an existing ellipse on which a yellow ball spins around. One focus of the ellipse is fixed, the other focus is the blue ball and when the user drags the blue ball, the ellipse changes. Or the user can set first the left focus, then the right one?

  • edited October 2013

    Maybe something like this:

    void setup() {
      size(1280, 720);
      noStroke();
    }
    
    void draw() {
      background(0);
      translate(width*.5, height*.5);
      ellipse(
        sin(frameCount*.05)*300, 
        cos(frameCount*.05)*200, 50, 50);
      ellipse(-200,0,100,100);
    }
    

    Shame on me, I didn't read the whole thing before posting. Maybe this could be a start for what OP wants though.

  • edited October 2013

    here

    you can place one ball

    place the other ball (same Y)

    and then ellipse starts

    also you can drag both balls (only X)

    //
    // the states of the program 
    final int statePlaceBlueBall_1 = 0; // place 1st ball
    final int statePlaceBlueBall_2 = 1; // place 2nd ball
    final int statePlayEllipse     = 2; // play 
    int state = statePlaceBlueBall_1;   // current state (one of the above)
    //
    // the 2 focus of the ellipse 
    float rightX, rightY;
    float leftX, leftY;
    float centerX, centerY; // the middle between the 2 
    //
    // the yellow ball is called star
    float starX, starY; 
    float angleStar;
    float radiusX, radiusY;
    //
    // to drag
    boolean dragLeft=false;
    boolean dragRight=false;
    //
    //
    // ---------------------------------------------------------------
    //
    void setup()
    {
      // init
      size(800, 600);
      background(0);
      noStroke();
    } // func 
    //
    //
    void draw() 
    { 
      background(0);
    
      switch (state) {
      case statePlaceBlueBall_1:
        fill(255);
        text ("place left ball", 40, 40);
        break;
      case statePlaceBlueBall_2:
        // show text
        fill(255);
        text ("place right ball", 40, 40);
        // show ball
        pushMatrix();
        translate (leftX, leftY);
        ball1(100, 100) ;
        popMatrix();
        // make a small line 
        stroke(255);
        line(0, leftY, width, leftY);
        noStroke();
        break;
      case statePlayEllipse:
        // show text
        fill(255);
        text ("ellipse", 40, 40);
        //
        pushMatrix();
        translate (leftX, leftY);
        ball1(100, 100) ;
        popMatrix();
        //
        pushMatrix();
        translate (rightX, rightY);
        ball1(100, 100) ;
        popMatrix();
    
        //---------------------
        pushMatrix();
        // starX=starX+starYAdd;
        // http://de.wikipedia.org/wiki/Ellipse#Ellipsengleichung_.28Parameterform.29
        starX = centerX + (cos (radians(angleStar)) * radiusX);
        starY = centerY + (sin (radians(angleStar)) * radiusY);
        translate (starX, starY);
        star();
        popMatrix();
        angleStar++;
        //
        break;    
      default:
        break;
      } // switch
      // 
      //
    } // func 
    //
    
    
    // =====================================================================
    
    void mousePressed() {
      // 
      switch (state) {
      case statePlaceBlueBall_1:
        // init left 
        leftX=mouseX;
        leftY=mouseY;
        state=statePlaceBlueBall_2;
        break;
      case statePlaceBlueBall_2:
        // init right 
        rightX=mouseX;
        // rightY=mouseY;
        rightY=leftY; // same y value ! 
        //
        // next state 
        state=statePlayEllipse;
        // some calculations 
        makeCalculations();
        break;
      case statePlayEllipse:
        //---------------------
        // no mouse 
        if (nearLeft()) {
          dragLeft=true;
        }
        else if (nearRight()) {
          dragRight=true;
        } 
    
        break;
      default:
        break;
      } // switch
      //
    } // func 
    
    void makeCalculations() {
      centerX = (leftX+rightX)/2; 
      centerY = (leftY+rightY)/2;
      radiusX=abs(rightX-leftX)+40;
      radiusY=radiusX-(55*(radiusX/100));
    }//func
    
    void mouseReleased() {
      //
    }
    
    void mouseDragged() {
      if (dragLeft) 
        leftX=mouseX;
      else if (dragRight) 
        rightX=mouseX;
      if (dragLeft||dragRight)   
        makeCalculations() ;
    }
    
    void ball1(  int sizeXMax, int sizeYMax  ) {
    
      color blk=color(0, 0, 0);
      color blu=color(100, 255, 252);
      int sizeX=sizeXMax;
      int sizeY=sizeYMax;
      float number=0.01;
      color change=lerpColor(blk, blu, 0);
      // clear();
      for (int i=0;i<100;i++) {
        if (number<=1) {
          change=lerpColor(blk, blu, number);
          number=number+0.01;
          fill(change);
        }
        else {
          fill(blu);
        }
        if (sizeX>0 && sizeY>0) {
          ellipse(0, 0, sizeX, sizeY);
        }
        sizeX--;
        sizeY--;
      } // for
    } // func
    
    //
    
    void star() {
      color org=color(255, 252, 45);
      fill(org);
      ellipse (0, 0, 10, 10);
    }
    
    boolean nearLeft() {
      return dist(mouseX, mouseY, leftX, leftY)<30;
    }
    
    boolean nearRight() {
      return dist(mouseX, mouseY, rightX, rightY)<30;
    }
    
    void keyPressed() {
      switch (key) {
      case 'c':
        background(0);
        break;
      default:
        state = statePlaceBlueBall_1;
        background(0);
        break;
      } // switch
    } // func
    
    // =====================================================================
    
  • Answer ✓

    Hello! I haven't understood your formula, partly because of your language and your use of abbrevations... what means leth? Angle? rdm? rotte? eqt? Also equation_A[i]= ... this is not a helpful name. What is the purpose of the equation? That would be a better name... Thank you! Chrisir

  • closed i am having a nother topic to replace this one

  • Closed, ok.

    But what's missing in my program?

Sign In or Register to comment.