2014-01-30 76 views
0

基本上我試圖做的是當我將鼠標懸停在臉部上時改變臉部。一切都在編譯,但由於某種原因,當光標位於其座標上時,面部保持不變。我不知道這是否有事情做與不使用安裝程序或繪製方法,但我仍然得到同樣的問題,當我在添加這些。處理:試圖讓臉部通過鼠標位置改變

size(600, 400); 
background(49, 185, 232); 
noStroke(); 
smooth(8); 

//Loop that determines if face is scared or unsuspecting based off of mouse position. 
if(mouseX>200 && mouseY<400) 
{ 
//Scared Face 
//Intializing head position data 
    int headX=300; 
    int headY=200; 
    int headSize=200; 
//Actual head rendering 
    fill(255, 196, 77); 
    ellipse(headX, headY, headSize, headSize); 

//Intializing nose position data 
    int noseTopX=300; 
    int noseTopY=200; 
    int noseLX=280; 
    int noseLY=220; 
    int noseRX=320; 
    int noseRY=220; 
//Rendering of nose 
    fill(245, 74, 86); 
    triangle(noseTopX, noseTopY, noseLX, noseLY, noseRX, noseRY); 

//Intializing mouth position data 
    int mouthLX=260; 
    int mouthLY=250; 
    int mouthRX=340; 
    int mouthRY=250; 
//Mouth Rendering 
    stroke(1); 
    strokeWeight(40); 
    line(mouthLX, mouthLY, mouthRX, mouthRY); 

//Getting rid of stroke 
    noStroke(); 

//Initializing Left Eye position 
    int eyeLX=250; 
    int eyeLY=170; 
    int eyeLSize1=75; 
    int eyeLSize2=50; 
    int pupilL=50; 
//Initializing Left Eye 
    fill(250); 
    ellipse(eyeLX, eyeLY, eyeLSize1, eyeLSize2); 
    fill(1); 
    ellipse(eyeLX, eyeLY, pupilL, pupilL); 

//Initializing Right 
    int eyeRX=350; 
    int eyeRY=170; 
    int eyeRSize1=75; 
    int eyeRSize2=50; 
    int pupilR=30; 
//Initializing Right Eye 
    fill(250); 
    ellipse(eyeRX, eyeRY, eyeRSize1, eyeRSize2); 
    fill(1); 
    ellipse(eyeRX, eyeRY, pupilR, pupilR); 
} 
else 
{ 
//Unsuspected Face 
//Intializing Head Data 
    int headX=300; 
    int headY=200; 
    int headSize=200; 
//Actual head rendering 
    fill(255, 196, 77); 
    ellipse(headX, headY, headSize, headSize); 

//Intializing nose position data 
    int noseTopX=300; 
    int noseTopY=200; 
    int noseLX=280; 
    int noseLY=220; 
    int noseRX=320; 
    int noseRY=220; 
//Rendering of nose 
    fill(245, 74, 86); 
    triangle(noseTopX, noseTopY, noseLX, noseLY, noseRX, noseRY); 

//Intializing mouth position data 
    int mouthLX=260; 
    int mouthLY=250; 
    int mouthRX=340; 
    int mouthRY=250; 
//Mouth Rendering 
    stroke(1); 
    strokeWeight(4); 
    line(mouthLX, mouthLY, mouthRX, mouthRY); 

//Getting rid of stroke 
    noStroke(); 

//Initializing Left Eye position 
    int eyeLX=250; 
    int eyeLY=170; 
    int eyeLSize1=45; 
    int eyeLSize2=30; 
    int pupilL=10; 
//Initializing Left Eye 
    fill(250); 
    ellipse(eyeLX, eyeLY, eyeLSize1, eyeLSize2); 
    fill(1); 
    ellipse(eyeLX, eyeLY, pupilL, pupilL); 

//Initializing Right 
    int eyeRX=350; 
    int eyeRY=170; 
    int eyeRSize1=45; 
    int eyeRSize2=30; 
    int pupilR=10; 
//Initializing Right Eye 
    fill(250); 
    ellipse(eyeRX, eyeRY, eyeRSize1, eyeRSize2); 
    fill(1); 
    ellipse(eyeRX, eyeRY, pupilR, pupilR); 
} 

回答

1

擁有加工,如果你想後做的東西在第一幀中,您必須包含明確的draw()方法。只需將setup()draw()添加到您的代碼中即可實現交互性。請注意,改變臉部的區域似乎是不正確的編碼,但也許它是你想要的。

void setup() { 
    size(600, 400); 
    background(49, 185, 232); 
    noStroke(); 
    smooth(8); 
} 
void draw() { 
    //Loop that determines if face is scared or unsuspecting based off of mouse position. 
    if (mouseX>200 && mouseY<400) 
    { 
    //Scared Face 
    //Intializing head position data 
    int headX=300; 
    int headY=200; 
    int headSize=200; 
    //Actual head rendering 
    fill(255, 196, 77); 
    ellipse(headX, headY, headSize, headSize); 

    //Intializing nose position data 
    int noseTopX=300; 
    int noseTopY=200; 
    int noseLX=280; 
    int noseLY=220; 
    int noseRX=320; 
    int noseRY=220; 
    //Rendering of nose 
    fill(245, 74, 86); 
    triangle(noseTopX, noseTopY, noseLX, noseLY, noseRX, noseRY); 

    //Intializing mouth position data 
    int mouthLX=260; 
    int mouthLY=250; 
    int mouthRX=340; 
    int mouthRY=250; 
    //Mouth Rendering 
    stroke(1); 
    strokeWeight(40); 
    line(mouthLX, mouthLY, mouthRX, mouthRY); 

    //Getting rid of stroke 
    noStroke(); 

    //Initializing Left Eye position 
    int eyeLX=250; 
    int eyeLY=170; 
    int eyeLSize1=75; 
    int eyeLSize2=50; 
    int pupilL=50; 
    //Initializing Left Eye 
    fill(250); 
    ellipse(eyeLX, eyeLY, eyeLSize1, eyeLSize2); 
    fill(1); 
    ellipse(eyeLX, eyeLY, pupilL, pupilL); 

    //Initializing Right 
    int eyeRX=350; 
    int eyeRY=170; 
    int eyeRSize1=75; 
    int eyeRSize2=50; 
    int pupilR=30; 
    //Initializing Right Eye 
    fill(250); 
    ellipse(eyeRX, eyeRY, eyeRSize1, eyeRSize2); 
    fill(1); 
    ellipse(eyeRX, eyeRY, pupilR, pupilR); 
    } 
    else 
    { 
    //Unsuspected Face 
    //Intializing Head Data 
    int headX=300; 
    int headY=200; 
    int headSize=200; 
    //Actual head rendering 
    fill(255, 196, 77); 
    ellipse(headX, headY, headSize, headSize); 

    //Intializing nose position data 
    int noseTopX=300; 
    int noseTopY=200; 
    int noseLX=280; 
    int noseLY=220; 
    int noseRX=320; 
    int noseRY=220; 
    //Rendering of nose 
    fill(245, 74, 86); 
    triangle(noseTopX, noseTopY, noseLX, noseLY, noseRX, noseRY); 

    //Intializing mouth position data 
    int mouthLX=260; 
    int mouthLY=250; 
    int mouthRX=340; 
    int mouthRY=250; 
    //Mouth Rendering 
    stroke(1); 
    strokeWeight(4); 
    line(mouthLX, mouthLY, mouthRX, mouthRY); 

    //Getting rid of stroke 
    noStroke(); 

    //Initializing Left Eye position 
    int eyeLX=250; 
    int eyeLY=170; 
    int eyeLSize1=45; 
    int eyeLSize2=30; 
    int pupilL=10; 
    //Initializing Left Eye 
    fill(250); 
    ellipse(eyeLX, eyeLY, eyeLSize1, eyeLSize2); 
    fill(1); 
    ellipse(eyeLX, eyeLY, pupilL, pupilL); 

    //Initializing Right 
    int eyeRX=350; 
    int eyeRY=170; 
    int eyeRSize1=45; 
    int eyeRSize2=30; 
    int pupilR=10; 
    //Initializing Right Eye 
    fill(250); 
    ellipse(eyeRX, eyeRY, eyeRSize1, eyeRSize2); 
    fill(1); 
    ellipse(eyeRX, eyeRY, pupilR, pupilR); 
    } 
} 
+0

謝謝,我早些時候嘗試過,但我不斷收到編譯器錯誤。 –