2012-11-20 6 views
0

아무도 나에게 왜이 오류가 발생하는지 공유 할 수 있습니까? 기본적으로 기본 기본 식물 성장을 시뮬레이션하려는 프로그램입니다. 저는 꽃잎이 모든 서클에 저장되는 방식으로하고 싶습니다.왜이 오류가 표시됩니까? - 처리

Stem myStem; 
Circle circles; 

float scaleFactor=0.5; 

void setup() { 
    size(floor(400*scaleFactor), floor(800*scaleFactor)); 
    myStem = new Stem(200,800); 

} 

void draw() { 

    background(150); 
    smooth(); 
    Circle circles[]; 
    circles = new Circle[5]; 
    circles[0] = new Circle(0, -40, 50, 50); 
    circles[1] = new Circle(0, -40, 50, 50); 
    circles[2] = new Circle(0, -40, 50, 50); 
    circles[3] = new Circle(0, -40, 50, 50); 
    circles[4] = new Circle(0, -40, 50, 50); 

    for (int i = 0; i < circles.length; i++) { 
    circles = ellipse(circles[i].c1, circles[i].c2, circles[i].c3, circles[i].c4); 
    rotate(radians(72)); 
    circles[i] = Circle; 
    } 

    myStem.drawStem(); 

} 

class Stem { 
    int initalloX=200; 
    int initalloY=800; 

    Stem(int tempInitalloX, int tempInitalloY) { 
    initalloX = tempInitalloX; 
    initalloY = tempInitalloY; 

    } 

    void drawStem() { 
    background(#0DBADB); 
    scale(scaleFactor, scaleFactor); 
    stroke (12, 149, 11); 
    fill (12, 149, 11); 
    strokeWeight(10); 
    line(initalloX, initalloY, initalloX, ((frameCount>250)?initalloY-500:initalloY-(2*frameCount))); 
    //stem1 
    if (frameCount>101) { 
     noStroke(); 
     translate(initalloX, initalloY-200); 
     scale(min((float)(frameCount-100)/100, 1), min((float)(frameCount-100)/100, 1)); 
     beginShape(); 
     vertex(0, 0); 
     bezierVertex(-40, -5, -30, -40, -80, -20); 
     bezierVertex(-47, -16, -52, 8, 0, 0); 
     endShape(CLOSE); 
     scale(1/min((float)(frameCount-100)/100, 1), 1/min((float)(frameCount-100)/100, 1)); 
     translate(-initalloX, -(initalloY-200)); 
    } 
    //stem2 
    if (frameCount>151) { 
     noStroke(); 
     translate(initalloX, initalloY-300); 
     scale(-min((float)(frameCount-150)/150, 1), min((float)(frameCount-150)/150, 1)); 
     beginShape(); 
     vertex(0, 0); 
     bezierVertex(-40, -5, -30, -40, -80, -20); 
     bezierVertex(-47, -16, -52, 8, 0, 0); 
     endShape(CLOSE); 
     scale(-1/min((float)(frameCount-150)/150, 1), 1/min((float)(frameCount-150)/150, 1)); 
     translate(-initalloX, -(initalloY-300)); 
    } 
    } 
} 

class Circle { 

    int c1 = 0; 
    int c2 = -40; 
    int c3 = 50; 
    int c4 = 50; 

    Circle(int tc1, int tc2, int tc3, int tc4) { 
    c1 = tc1; 
    c2 = tc2; 
    c3 = tc3; 
    c4 = tc4; 
    } 
} 

미리 감사드립니다 ... 모든 도움을 많이 받으실 수 있습니다.

+5

무엇이 오류입니까? – mtk

+1

전체 질문을 게시하시기 바랍니다 – Shashi

답변

1

이미 지적한 것 이외에 ellipse()는 void 메소드이므로, 아무것도 돌려주지 마라. 따라서 circle = ellipse(x,y,z,z) 과 같은 줄에는 의미가 없습니다. 아마도 ciclcle [i]에 저장된 값을 사용하여 타원을 그릴 수 있으므로 ellipse(circles[i].c1, circles[i].c2, circles[i].c3, circles[i].c4);를 할당 할 필요가 없습니다. 또한 내가 왜 5 동그라미를 만들지 모르겠다. 서클 개체가 단지 데이터를 저장하는 경우 왜 같은 데이터를 다섯 번 저장합니까? 전화 :

for (int i = 0; i < circles.length; i++) { 
ellipse(0, -40, 50, 50); 
rotate(radians(72)); 
} 

같은 효과가 있습니다.

그리기 끝 (물마루 myStem.drawStem())의 호출 배경()은 이전에 그려진 모든 것을 숨 깁니다. 그러나 배열을 다시 만들고 초당 60 번씩 값을 다시 지정할 필요가 없습니다.이 설정을 설정으로 옮길 수 있습니다.

귀하의 코드를 변경했습니다. 이제 컴파일 될 것입니다. 여전히 "꽃잎"은 원점에 그려진 채로 그려 지기만하면되지만, 적어도 실행되고 있습니다 :) 원 클래스에서 표시 방법을 만들고 싶을 수도 있습니다. 당신이 만든 다른 게시물에서 지적했다. 건배!

Stem myStem; 

//Circle circles; // double declaration 
    Circle circles[]; // keeping the array one only 

float scaleFactor=0.5; 

void setup() { 
    size(floor(400*scaleFactor), floor(800*scaleFactor)); 
    myStem = new Stem(200,800); 

    //mpoved this to setup, no need to recreate each frame 
    circles = new Circle[5]; 
    circles[0] = new Circle(0, -40, 50, 50); 
    circles[1] = new Circle(0, -40, 50, 50); 
    circles[2] = new Circle(0, -40, 50, 50); 
    circles[3] = new Circle(0, -40, 50, 50); 
    circles[4] = new Circle(0, -40, 50, 50); 
    // also smooth only needs to be called once 
    // unless ther is a noSmooth() somewhere 
    smooth(); 

} 

void draw() { 

    // moved this here 
    background(#0DBADB); 

    for (int i = 0; i < circles.length; i++) { 
    ellipse(circles[i].c1, circles[i].c2, circles[i].c3, circles[i].c4); 
    // note you may use this instead 
    //ellipse(0, -40, 50, 50); 
    rotate(radians(72)); 
    } 

    myStem.drawStem(); 


} 



class Stem { 
    int initalloX=200; 
    int initalloY=800; 

    Stem(int tempInitalloX, int tempInitalloY) { 
    initalloX = tempInitalloX; 
    initalloY = tempInitalloY; 

    } 

    void drawStem() { 
    //background(#0DBADB); // this was hiding all other draws 
    scale(scaleFactor, scaleFactor); 
    stroke (12, 149, 11); 
    fill (12, 149, 11); 
    strokeWeight(10); 
    line(initalloX, initalloY, initalloX, ((frameCount>250)?initalloY-500:initalloY-(2*frameCount))); 
    //stem1 
    if (frameCount>101) { 
     noStroke(); 
     translate(initalloX, initalloY-200); 
     scale(min((float)(frameCount-100)/100, 1), min((float)(frameCount-100)/100, 1)); 
     beginShape(); 
     vertex(0, 0); 
     bezierVertex(-40, -5, -30, -40, -80, -20); 
     bezierVertex(-47, -16, -52, 8, 0, 0); 
     endShape(CLOSE); 
     scale(1/min((float)(frameCount-100)/100, 1), 1/min((float)(frameCount-100)/100, 1)); 
     translate(-initalloX, -(initalloY-200)); 
    } 
    //stem2 
    if (frameCount>151) { 
     noStroke(); 
     translate(initalloX, initalloY-300); 
     scale(-min((float)(frameCount-150)/150, 1), min((float)(frameCount-150)/150, 1)); 
     beginShape(); 
     vertex(0, 0); 
     bezierVertex(-40, -5, -30, -40, -80, -20); 
     bezierVertex(-47, -16, -52, 8, 0, 0); 
     endShape(CLOSE); 
     scale(-1/min((float)(frameCount-150)/150, 1), 1/min((float)(frameCount-150)/150, 1)); 
     translate(-initalloX, -(initalloY-300)); 
    } 
    } 
} 

class Circle { 

    int c1 = 0; 
    int c2 = -40; 
    int c3 = 50; 
    int c4 = 50; 

    Circle(int tc1, int tc2, int tc3, int tc4) { 
    c1 = tc1; 
    c2 = tc2; 
    c3 = tc3; 
    c4 = tc4; 
    } 
} 
+0

입력 v.k를 보내 주셔서 감사합니다! 당신은 클래스 포인트를 구현할 수있는 방법을 아십니까? 모든 포인트가 같은 위치에서 함께 움직일 수 있도록 중심 포인트 속성을 포함하고 있습니까? – choloboy

+0

다른 게시물의 코드를 참조하십시오. 필요한 것이 있습니까? –

1

새로운 것을 배웠습니다. 배열을 선언 한 것으로 추측됩니다.

잘못된 점은 '서클'이라는 서클 변수를 사용하고있는 것처럼 보이며 서클 배열과 혼동스럽게도 모든 문제를 일으킬 수 있다고 생각합니다. 그것은 아마 당신이 고치는 것에 초점을 맞추어야 할 것입니다.

+0

그리고 그 차이점은 무엇입니까? 서클 서클이 아님 []; 서클 [] 원과 동일; ? – Burkhard

+0

오케이, 내가 틀렸어, 네가 할 수 있다는 것을 몰랐어. – Jayson

+0

아니, 틀렸어. Circle []은 C++이 아닌 Java에서만 사용할 수 있습니다. – Burkhard

1

추측 ...

내가이 circles[i] = Circle; 오류라고 생각 클래스

 Circle circles 

     Circle[] circles 
1

에 동그라미 두 가지 정의가 있습니다. Type (클래스 Circle)을 변수 (객체 또는 클래스의 인스턴스)에 대입 할 수 없습니다.

관련 문제