2012-11-20 19 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

除了所有已經指出的事情,請注意,橢圓()是一個無效的方法,所以它贏得了' t返回任何東西。因此,像 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次,您可以將其移動到設置。

我做了這些改變你的代碼。它現在會編譯。仍然是「花瓣」beeing起源,填補/中風需要處理,但至少它正在運行:) 你可能想在你的圈子類中做一個顯示方法...更像我指出你所做的另一篇文章。乾杯!

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.!你知道我該如何實現一個班級Point,它包含一箇中心點屬性,這樣所有的部件都可以在這個位置一起移動? – choloboy

+0

請參閱您其他帖子中的代碼,這是您需要的嗎? –

1

教訓我猜聲明數組新的東西。

至於什麼錯誤,它看起來像你正在使用一種名爲「圓」一個圈變量,並通過還呼籲IT界這可能是導致各種問題與圓的陣列混淆了。這可能是你應該關注的問題。

+0

有什麼區別?不是圓圈[];與Circle []圈相同; ? – Burkhard

+0

哎呦,猜我錯了,不知道你能做到這一點。 – Jayson

+0

不,我錯了。 Circle []只能在Java中使用,而不能在C++中使用。 – Burkhard

1

猜測...

有界的兩種定義在類

 Circle circles 

     Circle[] circles 
1

我覺得這circles[i] = Circle;是錯誤。你不能將類型(類Circle)賦給一個變量(即一個對象或類的一個實例)

相關問題