//marionet // doll //joint locations float headX; float headY; float bodyX; float bodyY; float waistX; float waistY; float lShoulderX; float lShoulderY; float lElbowX; float lElbowY; float lHandX; float lHandY; float rShoulderX; float rShoulderY; float rElbowX; float rElbowY; float rHandX; float rHandY; float lHipX; float lHipY; float rHipX; float rHipY; float lKneeX; float lKneeY; float rKneeX; float rKneeY; float lFootX; float lFootY; float rFootX; float rFootY; //joint location determining variables //rotation //speed //left and right limits //waist float waistRot = 0; float waistSp = 0; float waistLimL = -0.2; float waistLimR = 0.2; //left arm //float lShoulderRot = waistRot - 0.5; float lElbowRot = 0; float lElbowSp = 0; float lElbowLimL = -0.8; float lElbowLimR = -0.3; float lHandRot = 0; float lHandSp = 0; float lHandLimL = -0.5; float lHandLimR = 0.5; //right arm //float rShoulderRot = waistRot + 0.5; float rElbowRot = 0; float rElbowSp = 0; float rElbowLimL = 0.3; float rElbowLimR = 0.8; float rHandRot = 0; float rHandSp = 0; float rHandLimL = -0.5; float rHandLimR = 0.5; //left leg float lHipRot = 0; float lKneeRot = 0; float lKneeSp = 0; float lKneeLimL = -0.63; float lKneeLimR = -0.1; float lFootRot = 0; float lFootSp = 0; float lFootLimL = -0.5; float lFootLimR = 0.3; //right lig float rHipRot = 0; float rKneeRot = 0; float rKneeSp = 0; float rKneeLimL = 0.1; float rKneeLimR = 0.63; float rFootRot = 0; float rFootSp = 0; float rFootLimL = -0.3; float rFootLimR = 0.5; void setup() { size(400, 400); } void draw() { background(101, 131, 155); drawStageBack(); doScaryMessyPhysics(); calculateXAndYLocations(); drawDoll(); drawStageFront(); println(mouseX, mouseY); } void drawDoll() { //Strings //lElbow string stroke(245); strokeWeight(1); line(lElbowX,lElbowY,mouseX*0.45+110-40,30); //lKnee string stroke(245); strokeWeight(1); line(lKneeX,lKneeY,mouseX*0.45+110-20,30); //rElbow string stroke(245); strokeWeight(1); line(rElbowX,rElbowY,mouseX*0.45+110+40,30); //rKnee string stroke(245); strokeWeight(1); line(rKneeX,rKneeY,mouseX*0.45+110+20,30); //Head string stroke(245); strokeWeight(1); line(mouseX*0.45+110,132,mouseX*0.45+110,30); //body stroke(57); strokeWeight(8); line(mouseX*0.45+110, 140+15, mouseX*0.45+110+ waistX, 140+15+ waistY); //shoulders stroke(57); strokeWeight(5); line(lShoulderX, lShoulderY, rShoulderX, rShoulderY); //lElbow stroke(57); strokeWeight(5); line(lShoulderX, lShoulderY, lElbowX, lElbowY); //rElbow stroke(57); strokeWeight(5); line(rShoulderX, rShoulderY, rElbowX, rElbowY); //lHand stroke(57); strokeWeight(5); line(lElbowX, lElbowY, lHandX, lHandY); //rHand stroke(57); strokeWeight(5); line(rElbowX, rElbowY, rHandX, rHandY); //lKnee stroke(57); strokeWeight(5); line(lHipX, lHipY, lKneeX, lKneeY); //rKnee stroke(57); strokeWeight(5); line(rHipX, rHipY, rKneeX, rKneeY); //lFoot stroke(57); strokeWeight(5); line(lKneeX, lKneeY, lFootX, lFootY); //rFoot stroke(57); strokeWeight(5); line(rKneeX, rKneeY, rFootX, rFootY); //joints ellipseMode(CENTER); noStroke(); strokeWeight(0); fill(230); //lKnee //ellipse(lKneeX,lKneeY,1,1); //rKnee //ellipse(rKneeX,rKneeY,1,1); //lElbow //ellipse(lElbowX,lElbowY,1,1); //rElbow //ellipse(rElbowX,rElbowY,1,1); //neck stroke(111); strokeWeight(4); line(mouseX*0.45+110, 140+9, mouseX*0.45+110, 140+15); //head ellipseMode(CENTER); noStroke(); strokeWeight(0); fill(170); ellipse(mouseX*0.45+110, 142, 16, 20); //nose fill(130); //triangle(mouseX*0.45+110-2, 142+2,mouseX*0.45+110+2, 142+2,mouseX*0.45+110, 142-2); } //scrapped gravity function /*void gravity(float r, float s) { if (r>-0.003 && r<0.003 && s<0.001 && s>-0.001) { rotation = 0; speed = 0; } else if ((r + s >= 0 && r <= 0) || (r + s <= 0 && r >= 0)) { speed = speed *0.75; } else if (r >0) { speed = speed - 0.003; } else if (r <0) { speed = speed + 0.003; } }*/ //scrapped limit function /* void checkLimit(float r, float s, float ll, float rl) { if (r+s > rl) { speed = 0; rotation = rl; } else if (r+s < ll) { speed = 0; rotation = ll; } } */ void drawStageBack() { //stage backdrop stroke(100, 62, 83); strokeWeight(0); fill(100, 62, 83); quad(63, 60, 400-63, 60, 400-63, 290, 63, 290); //Stage Top //outer stroke(211, 189, 100); strokeWeight(0); fill(211, 189, 100); quad(38, 308, 400-38, 308, 400-55, 289, 55, 289); //inner stroke(211, 189, 100); strokeWeight(0); fill(211, 189, 100); quad(63, 255, 63, 290, 400-63, 290, 400-63, 255); //stage front //base stroke(211, 189, 100); strokeWeight(0); fill(211, 189, 100); quad(38, 308, 400-38, 308, 400-38, 400, 38, 400); //front stroke(191, 154, 62); strokeWeight(0); fill(191, 154, 62); quad(68, 330, 68, 400, 400-68, 400, 400-68, 330); //L side stroke(243, 208, 140); strokeWeight(0); fill(243, 208, 140); quad(68, 330, 68, 400, 38, 400, 38, 308); //R side stroke(147, 113, 27); strokeWeight(0); fill(147, 113, 27); quad(400-68, 330, 400-68, 400, 400-38, 400, 400-38, 308); } void drawStageFront() { //curtains//stage backdrop // light colour 227,34,63 // dark colour 173,7,79 stroke(227, 34, 63); strokeWeight(0); fill(227, 34, 63); quad(60, 60, 100, 60, 100, 291, 60, 291); quad(400-60, 60, 400-100, 60, 400-100, 291, 400-60, 291); //pillar //pillars for (int n = 0; n < 25; n ++) { stroke(191, 154, 62); strokeWeight(8); line(60, 90+8*n, 65, 84+8*n); } for (int n = 0; n < 25; n ++) { stroke(191, 154, 62); strokeWeight(8); line(400-65, 90+8*n, 400-60, 84+8*n); } //base //left top rectMode(CENTER); stroke(191, 154, 62); strokeWeight(0); fill(191, 154, 62); rect(63+55*0, 80, 15, 27); //right top rectMode(CENTER); stroke(191, 154, 62); strokeWeight(0); fill(191, 154, 62); rect(63+55*5, 80, 15, 27); //left bottom rectMode(CENTER); stroke(191, 154, 62); strokeWeight(0); fill(191, 154, 62); rect(63+55*0, 400-110, 15, 13); //right bottom rectMode(CENTER); stroke(191, 154, 62); strokeWeight(0); fill(191, 154, 62); rect(63+55*5, 400-110, 15, 13); //left bottom ellipseMode(CENTER); stroke(191, 154, 62); strokeWeight(0); fill(191, 154, 62); ellipse(63+55*0, 297, 15, 13); //right bottom ellipseMode(CENTER); stroke(191, 154, 62); strokeWeight(0); fill(191, 154, 62); ellipse(63+55*5, 297, 15, 13); //pillar rounds Top R stroke(211, 189, 100); strokeWeight(7); line(55, 90, 70, 90); //pillar rounds Top L stroke(211, 189, 100); strokeWeight(7); line(400-55, 90, 400-70, 90); //pillar rounds Bottom R stroke(211, 189, 100); strokeWeight(7); line(55, 400-120, 70, 400-120); //pillar rounds Bottom L stroke(211, 189, 100); strokeWeight(7); line(400-55, 400-120, 400-70, 400-120); //circle decor //base for (int n= 0; n <6; n++) { ellipseMode(CENTER); stroke(211, 189, 100); strokeWeight(8); fill(100, 182, 211); ellipse(63+55*n, 60, 47, 27); } //blue for (int n= 0; n <6; n++) { ellipseMode(CENTER); stroke(211, 189, 100); strokeWeight(0); fill(211, 189, 100); ellipse(63+55*n, 60, 30, 19); } //red for (int n= 0; n <6; n++) { ellipseMode(CENTER); stroke(211, 100, 102); strokeWeight(0); fill(211, 100, 102); ellipse(63+55*n, 65, 7, 7); } //roof // lid rectMode(CORNERS); stroke(211, 189, 100); strokeWeight(0); fill(211, 189, 100); rect(35, 23, 400-35, 60); //triangle decor Red for (int n= 0; n <16; n++) { stroke(211, 100, 102); strokeWeight(0); fill(211, 100, 102); triangle(35+n*20, 38, 55+n*20, 38, 45+n*20, 47); triangle(355, 38, 365, 38, 365, 47); } //traingle decor Blue for (int n= 0; n <16; n++) { stroke(100, 182, 211); strokeWeight(0); fill(100, 182, 211); triangle(45+n*20, 38, 55+n*20, 38, 45+n*20, 47); //triangle(35,38,35,47,45,47); } } void calculateXAndYLocations(){ //calc left shouler location //lShoulderRot = waistRot - 0.5; lShoulderX =mouseX*0.45+110+ 8.0*sin(PI*(waistRot - 0.5)); lShoulderY =140+15+ 8.0*cos(PI*(waistRot - 0.5)); //calc right shouler location //rShoulderRot = waistRot + 0.5; rShoulderX =mouseX*0.45+110+ 8.0*sin(PI*(waistRot + 0.5)); rShoulderY =140+15+ 8.0*cos(PI*(waistRot + 0.5)); //calc left hip location lHipX =mouseX*0.45+110+ 42.0*sin(PI*(waistRot - 0.018)); lHipY =140+15+ 42.0*cos(PI*(waistRot - 0.018)); //calc right hip location rHipX =mouseX*0.45+110+ 42.0*sin(PI*(waistRot + 0.018)); rHipY =140+15+ 42.0*cos(PI*(waistRot + 0.018)); //calc lElbow location lElbowX =lShoulderX+ 16.0*sin(PI*lElbowRot); lElbowY =lShoulderY+ 16.0*cos(PI*lElbowRot); //calc rElbow location rElbowX =rShoulderX+ 16.0*sin(PI*rElbowRot); rElbowY =rShoulderY+ 16.0*cos(PI*rElbowRot); //calc lHand location lHandX =lElbowX+ 19.0*sin(PI*lHandRot); lHandY =lElbowY+ 19.0*cos(PI*lHandRot); //calc rHand location rHandX =rElbowX+ 19.0*sin(PI*rHandRot); rHandY =rElbowY+ 19.0*cos(PI*rHandRot); //calc lKnee location lKneeX =lHipX+ 19.0*sin(PI*lKneeRot); lKneeY =lHipY+ 19.0*cos(PI*lKneeRot); //calc rKnee location rKneeX =rHipX+ 19.0*sin(PI*rKneeRot); rKneeY =rHipY+ 19.0*cos(PI*rKneeRot); //calc lFoot location lFootX =lKneeX+ 19.0*sin(PI*lFootRot); lFootY =lKneeY+ 19.0*cos(PI*lFootRot); //calc rFoot location rFootX =rKneeX+ 19.0*sin(PI*rFootRot); rFootY =rKneeY+ 19.0*cos(PI*rFootRot); // base line calc code // l(X, Y, X+(*)*sin(PI*Rot), Y + (*)*cos(PI*Rot)); } void doScaryMessyPhysics() { //gravity code /* if (**Rot>-0.003 && **Rot<0.003 && **Sp<0.001 && **Sp>-0.001) { **Rot = 0; **Sp = 0; } else if ((**Rot + **Sp >= 0 && **Rot <= 0) || (**Rot + **Sp <= 0 && **Rot >= 0)) { **Sp = **Sp *0.75; } else if (**Rot >0) { **Sp = **Sp - 0.003; } else if (**Rot <0) { **Sp = **Sp + 0.003; } */ //limit hit code /* if (**Rot+**Sp > r**Lim) { **Sp = 0; **Rot = **Lim; } else if (**Rot+**Sp < l**Lim) { **Sp = 0; **Rot = l**Lim; } */ //calc waist //calc waist speed waistSp = waistSp + (pmouseX - mouseX)/1200.0; //add a random twitch to the doll if (waistSp == 0) { if (random (0, 600) > 598) { waistSp = 0.018; } } //calc apply speed to rotation waistRot = waistRot +waistSp; // hold movement inside limit if (waistRot+waistSp > waistLimR) { waistSp = 0; waistRot = waistLimR; } else if (waistRot+waistSp < waistLimL) { waistSp = 0; waistRot = waistLimL; } //apply gravity if (waistRot>-0.003 && waistRot<0.003 && waistSp<0.001 && waistSp>-0.001) { waistRot = 0; waistSp = 0; } else if ((waistRot + waistSp >= 0 && waistRot <= 0) || (waistRot + waistSp <= 0 && waistRot >= 0)) { waistSp = waistSp *0.75; } else if (waistRot >0) { waistSp = waistSp - 0.003; } else if (waistRot <0) { waistSp = waistSp + 0.003; } waistX = 40.0*sin(PI*waistRot); waistY = 40.0*cos(PI*waistRot); //calc lElbow //calc lElbow speed lElbowSp = lElbowSp + (pmouseX - mouseX)/1200.0; //calc apply speed to rotation lElbowRot = lElbowRot +lElbowSp; // hold movement inside limit if (lElbowRot+lElbowSp > lElbowLimR) { lElbowSp = 0; lElbowRot = lElbowLimR; } else if (lElbowRot+lElbowSp < lElbowLimL) { lElbowSp = 0; lElbowRot = lElbowLimL; } //apply gravity if (lElbowRot>-0.003 && lElbowRot<0.003 && lElbowSp<0.001 && lElbowSp>-0.001) { lElbowRot = 0; lElbowSp = 0; } else if ((lElbowRot + lElbowSp >= 0 && lElbowRot <= 0) || (lElbowRot + lElbowSp <= 0 && lElbowRot >= 0)) { lElbowSp = lElbowSp *0.75; } else if (lElbowRot >0) { lElbowSp = lElbowSp - 0.003; } else if (lElbowRot <0) { lElbowSp = lElbowSp + 0.003; } //calc lHand speed lHandSp = lHandSp + (pmouseX - mouseX)/1200.0; //add a random twitch to the doll if (lHandSp == 0) { if (random (0, 600) > 598) { lHandSp = 0.018; } } //calc apply speed to rotation lHandRot = lHandRot +lHandSp; // hold movement inside limit if (lHandRot+lHandSp > lHandLimR) { lHandSp = 0; lHandRot = lHandLimR; } else if (lHandRot+lHandSp < lHandLimL) { lHandSp = 0; lHandRot = lHandLimL; } //apply gravity if (lHandRot>-0.003 && lHandRot<0.003 && lHandSp<0.001 && lHandSp>-0.001) { lHandRot = 0; lHandSp = 0; } else if ((lHandRot + lHandSp >= 0 && lHandRot <= 0) || (lHandRot + lHandSp <= 0 && lHandRot >= 0)) { lHandSp = lHandSp *0.75; } else if (lHandRot >0) { lHandSp = lHandSp - 0.003; } else if (lHandRot <0) { lHandSp = lHandSp + 0.003; } //calc rElbow //calc rElbow speed rElbowSp = rElbowSp + (pmouseX - mouseX)/1200.0; //calc apply speed to rotation rElbowRot = rElbowRot +rElbowSp; // hold movement inside limit if (rElbowRot+rElbowSp > rElbowLimR) { rElbowSp = 0; rElbowRot = rElbowLimR; } else if (rElbowRot+rElbowSp < rElbowLimL) { rElbowSp = 0; rElbowRot = rElbowLimL; } //apply gravity if (rElbowRot>-0.003 && rElbowRot<0.003 && rElbowSp<0.001 && rElbowSp>-0.001) { rElbowRot = 0; rElbowSp = 0; } else if ((rElbowRot + rElbowSp >= 0 && rElbowRot <= 0) || (rElbowRot + rElbowSp <= 0 && rElbowRot >= 0)) { rElbowSp = rElbowSp *0.75; } else if (rElbowRot >0) { rElbowSp = rElbowSp - 0.003; } else if (rElbowRot <0) { rElbowSp = rElbowSp + 0.003; } //calc rHand speed rHandSp = rHandSp + (pmouseX - mouseX)/1200.0; //add a random twitch to the doll if (rHandSp == 0) { if (random (0, 600) > 598) { rHandSp = 0.018; } } //calc apply speed to rotation rHandRot = rHandRot +rHandSp; // hold movement inside limit if (rHandRot+rHandSp > rHandLimR) { rHandSp = 0; rHandRot = rHandLimR; } else if (rHandRot+rHandSp < rHandLimL) { rHandSp = 0; rHandRot = rHandLimL; } //apply gravity if (rHandRot>-0.003 && rHandRot<0.003 && rHandSp<0.001 && rHandSp>-0.001) { rHandRot = 0; rHandSp = 0; } else if ((rHandRot + rHandSp >= 0 && rHandRot <= 0) || (rHandRot + rHandSp <= 0 && rHandRot >= 0)) { rHandSp = rHandSp *0.75; } else if (rHandRot >0) { rHandSp = rHandSp - 0.003; } else if (rHandRot <0) { rHandSp = rHandSp + 0.003; } //calc rKnee //calc rKnee speed rKneeSp = rKneeSp + (pmouseX - mouseX)/1200.0; //calc apply speed to rotation rKneeRot = rKneeRot +rKneeSp; // hold movement inside limit if (rKneeRot+rKneeSp > rKneeLimR) { rKneeSp = 0; rKneeRot = rKneeLimR; } else if (rKneeRot+rKneeSp < rKneeLimL) { rKneeSp = 0; rKneeRot = rKneeLimL; } //apply gravity if (rKneeRot>-0.003 && rKneeRot<0.003 && rKneeSp<0.001 && rKneeSp>-0.001) { rKneeRot = 0; rKneeSp = 0; } else if ((rKneeRot + rKneeSp >= 0 && rKneeRot <= 0) || (rKneeRot + rKneeSp <= 0 && rKneeRot >= 0)) { rKneeSp = rKneeSp *0.75; } else if (rKneeRot >0) { rKneeSp = rKneeSp - 0.003; } else if (rKneeRot <0) { rKneeSp = rKneeSp + 0.003; } //calc lKnee speed lKneeSp = lKneeSp + (pmouseX - mouseX)/1200.0; //calc apply speed to rotation lKneeRot = lKneeRot +lKneeSp; // hold movement inside limit if (lKneeRot+lKneeSp > lKneeLimR) { lKneeSp = 0; lKneeRot = lKneeLimR; } else if (lKneeRot+lKneeSp < lKneeLimL) { lKneeSp = 0; lKneeRot = lKneeLimL; } //apply gravity if (lKneeRot>-0.003 && lKneeRot<0.003 && lKneeSp<0.001 && lKneeSp>-0.001) { lKneeRot = 0; lKneeSp = 0; } else if ((lKneeRot + lKneeSp >= 0 && lKneeRot <= 0) || (lKneeRot + lKneeSp <= 0 && lKneeRot >= 0)) { lKneeSp = lKneeSp *0.75; } else if (lKneeRot >0) { lKneeSp = lKneeSp - 0.003; } else if (lKneeRot <0) { lKneeSp = lKneeSp + 0.003; } //calc lFoot speed lFootSp = lFootSp + (pmouseX - mouseX)/1200.0; //calc apply speed to rotation lFootRot = lFootRot +lFootSp; // hold movement inside limit if (lFootRot+lFootSp > lFootLimR) { lFootSp = 0; lFootRot = lFootLimR; } else if (lFootRot+lFootSp < lFootLimL) { lFootSp = 0; lFootRot = lFootLimL; } //apply gravity if (lFootRot>-0.003 && lFootRot<0.003 && lFootSp<0.001 && lFootSp>-0.001) { lFootRot = 0; lFootSp = 0; } else if ((lFootRot + lFootSp >= 0 && lFootRot <= 0) || (lFootRot + lFootSp <= 0 && lFootRot >= 0)) { lFootSp = lFootSp *0.75; } else if (lFootRot >0) { lFootSp = lFootSp - 0.003; } else if (lFootRot <0) { lFootSp = lFootSp + 0.003; } //calc rFoot speed rFootSp = rFootSp + (pmouseX - mouseX)/1200.0; //calc apply speed to rotation rFootRot = rFootRot +rFootSp; // hold movement inside limit if (rFootRot+rFootSp > rFootLimR) { rFootSp = 0; rFootRot = rFootLimR; } else if (rFootRot+rFootSp < rFootLimL) { rFootSp = 0; rFootRot = rFootLimL; } //apply gravity if (rFootRot>-0.003 && rFootRot<0.003 && rFootSp<0.001 && rFootSp>-0.001) { rFootRot = 0; rFootSp = 0; } else if ((rFootRot + rFootSp >= 0 && rFootRot <= 0) || (rFootRot + rFootSp <= 0 && rFootRot >= 0)) { rFootSp = rFootSp *0.75; } else if (rFootRot >0) { rFootSp = rFootSp - 0.003; } else if (rFootRot <0) { rFootSp = rFootSp + 0.003; } }