import java.awt.*; public class Doraemon extends BufferedApplet { int width = 0; int height = 0; double f = 1500; double scale = 6; double startTime = getTime(); double speed = 3.1; double moveSpeed = 0.5; int torsoI = 110; int headI = 210; // int torsoI = 50; // int headI = 100; int bambooCopterI = 15; int limbI = 50; double bambooSize = 0.9; double headSize = 10; double torsoSize = headSize * 0.7; double limbSize = headSize * 0.2; Color background = new Color(135, 206, 235); Color bamboo = new Color(255, 215, 0); double temp[] = new double[4]; Matrix m = new Matrix(); Matrix tempM = new Matrix(); Color chooseC = Color.blue; boolean copter = false; // movement!!!!!!! double moveShoulderX[][] = { {0*moveSpeed,0}, {1*moveSpeed,Math.PI/5}, {3*moveSpeed,-Math.PI/5}, {5*moveSpeed,Math.PI/5}, {7*moveSpeed,-Math.PI/5}, {8*moveSpeed,0}, {29*moveSpeed,0}, {30*moveSpeed,Math.PI/5}, {32*moveSpeed,-Math.PI/5}, {34*moveSpeed,Math.PI/5}, {36*moveSpeed,-Math.PI/5}, {37*moveSpeed,0}, }; Movement MoveShoulder1 = new Movement(moveShoulderX); double rotShoulder1; double moveShoulderZ[][] = { {8.5*moveSpeed,Math.PI/5}, {9.5*moveSpeed, Math.PI/5.5}, {10.5*moveSpeed, Math.PI/5}, {11.5*moveSpeed,Math.PI}, {12.5*moveSpeed,0}, {14.5*moveSpeed,Math.PI-Math.PI/6}, {16.5*moveSpeed,Math.PI+Math.PI/6}, {18.5*moveSpeed,Math.PI-Math.PI/6}, {20.5*moveSpeed,Math.PI+Math.PI/6}, {22.5*moveSpeed,Math.PI-Math.PI/6}, {24.5*moveSpeed,Math.PI+Math.PI/6}, {26.5*moveSpeed,Math.PI}, {27.5*moveSpeed,Math.PI/5}, {28.5*moveSpeed,0} }; Movement MoveShoulder2 = new Movement(moveShoulderZ); double rotShoulder2; double moveAll[][] = { {11.5*moveSpeed,0}, {15.5*moveSpeed,10}, {20.5*moveSpeed,10}, {25.5*moveSpeed,0} }; Movement MoveAll = new Movement(moveAll); double moveAllY; double moveBody[][] = { {11.5*moveSpeed,0}, {15.5*moveSpeed,Math.PI/10}, {20.5*moveSpeed,Math.PI/10}, {25.5*moveSpeed,0} }; Movement MoveBody = new Movement(moveBody); double rotBodyX; Geometry bambooCopterLeft, bambooCopterRight, bambooCopterCenter, bambooCopterStick, head, nose, torso, bell, armLeft, armRight, handLeft, handRight, legRight, legLeft, footRight, footLeft; Geometry world, all, body, neck, shoulderLeft, shoulderRight, hipLeft, hipRight, bambooCopter; public Doraemon() { initialize(); } public void render(Graphics g) { double time = getTime() - startTime; width = getWidth(); height = getHeight(); g.setColor(background); g.fillRect(0,0,width,height); // grass g.setColor(Color.green); g.fillRect(0,height/3,width,height*2/3); animate(time); // traverse and draw world.globalMatrix.identity(); drawIt(all, world.globalMatrix, g); } public void drawIt(Geometry object, Matrix matrix, Graphics g) { int childNumber = object.getNumChildren(); Matrix relativeMatrix = object.getMatrix(); matrix.multiply(relativeMatrix); object.globalMatrix.copy(matrix); if (childNumber == 0) { int what = object.what; switch (what) { case 0: transformAndRender(object, matrix, g, Color.blue); break; case 1: transformAndRender(object, matrix, g, bamboo); break; case 2: drawHead(object, matrix, g); break; case 3: transformAndRender(object, matrix, g, Color.red); break; case 4: transformAndRender(object, matrix, g, Color.yellow); break; case 5: drawBody(object, matrix, g); break; case 6: transformAndRender(object, matrix, g, Color.white); break; } } else { for (int i=0; i= 11.5*moveSpeed && !copter) { //bambooCopter = all.add(); bambooCopter = body.add(); bambooCopterLeft = bambooCopter.add(); bambooCopterRight = bambooCopter.add(); bambooCopterStick = bambooCopter.add(); bambooCopterCenter = bambooCopter.add(); bambooCopterLeft.cylinder(bambooCopterI); // what = 1 bambooCopterLeft.what = 1; bambooCopterRight.cylinder(bambooCopterI); // what = 1 bambooCopterRight.what = 1; bambooCopterCenter.globe(bambooCopterI); // what = 1 bambooCopterCenter.what = 1; bambooCopterStick.cylinder(bambooCopterI); // what = 1 bamboo bambooCopterStick.what = 1; m = bambooCopterCenter.getMatrix();// bambooCopterCenter!!! m.translate(0,(4.0+0.35)*bambooSize,0); m.scale(0.35*bambooSize, 0.35*bambooSize, 0.35*bambooSize); m = bambooCopterStick.getMatrix(); m.rotateX(Math.PI / 2); // bambooCopterStick!!! m.translate(0, 0, -2.0*bambooSize); m.scale(0.2*bambooSize, 0.2*bambooSize, 2.0*bambooSize); m = bambooCopterLeft.getMatrix(); m.translate((2.0+0.35)*bambooSize,(4.0+0.35)*bambooSize,0); m.rotateY(Math.PI / 2); // bambooCopterLeft!!! m.scale(0.25*bambooSize, 0.25*bambooSize, 2.0*bambooSize); m = bambooCopterRight.getMatrix(); m.translate(-(2.0+0.35)*bambooSize,(4.0+0.35)*bambooSize,0); m.rotateY(-Math.PI / 2); // bambooCopterRight!!! m.scale(0.25*bambooSize, 0.25*bambooSize, 2.0*bambooSize); copter = true; } if (time >= 26.5*moveSpeed && copter) { copter = false; //all.remove(bambooCopter); body.remove(bambooCopter); } if (copter) { m = bambooCopter.getMatrix(); // bambooCopter!!! m.identity(); m.rotateY(speed*time*3.1); m.translate(0, headSize*2+4*bambooSize, 0); m = all.getMatrix(); // all!!! m.identity(); //m.perspect(f); m.rotateY(Math.PI/6); moveAllY = MoveAll.getMove(time); m.translate(0,moveAllY,0); m = body.getMatrix(); // body!!! m.identity(); rotBodyX = MoveBody.getMove(time); m.rotateX(rotBodyX); } else { m = body.getMatrix(); // body!!! m.identity(); } m = neck.getMatrix(); // neck!!! m.identity(); m.translate(0, torsoSize*0.55*0.9, 0); m = shoulderLeft.getMatrix(); // shoulderLeft!!! m.identity(); m.translate(0,torsoSize*0.6,0); m.translate( -torsoSize-limbSize/2, 0, 0); rotShoulder1 = MoveShoulder1.getMove(time); rotShoulder2 = MoveShoulder2.getMove(time); m.rotateX(rotShoulder1); m.rotateZ(rotShoulder2); m = shoulderRight.getMatrix(); // shoulderRight!!! m.identity(); m.translate(0,torsoSize*0.6,0); m.translate( torsoSize+limbSize/2, 0, 0); m.rotateX(-rotShoulder1); m = hipLeft.getMatrix(); // hipLeft!!! m.identity(); m.translate(0,-torsoSize*0.8,0); m.translate( -torsoSize*0.5, 0, 0); m.rotateX(-rotShoulder1); m = hipRight.getMatrix(); // hipRight!!! m.identity(); m.translate(0,-torsoSize*0.8,0); m.translate( torsoSize*0.5, 0, 0); m.rotateX(rotShoulder1); if (time >= 28.5*moveSpeed) { startTime = getTime(); } } public Geometry getWorld() { Geometry World = new Geometry(); World.globalMatrix.identity(); World.relativeMatrix.identity(); return World; } public void transformAndRender(Geometry geo, Matrix m, Graphics g, Color color) { g.setColor(color); for (int i=0; i 0.85) { // draw collar g.setColor(Color.red); } else if ( -Math.sqrt(0.54) < indexX && indexX <= Math.sqrt(0.54) && indexY < 0 && indexZ >= 0.12 && indexZ < 0.12 + 0.03) { // draw pocket g.setColor(Color.black); } else if ( 0.51 < mouthCo && mouthCo <= 0.54 && indexY < 0 && indexZ < 0.12) { // draw pocket g.setColor(Color.black); } else if ( 0.88 < faceCo && faceCo <= 0.9 && indexY < 0) { // draw bally g.setColor(Color.black); } else if ( faceCo <= 0.9 && indexY < 0 ) { g.setColor(Color.white); } else { g.setColor(Color.blue); } for (int j=0; j= (-0.48-0.015) && indexZ > 0) { // draw beard left down g.setColor(Color.black); } else if ( (0.47-0.25) <= indexX && indexX <= (0.47+0.25) && indexX+2.4*indexY <= (0.48+0.015) && indexX+2.4*indexY >= (0.48-0.015) && indexZ > 0) { // draw beard right down g.setColor(Color.black); } else if ( (-0.575-0.275) <= indexX && indexX <= (-0.575+0.275) && indexY <= (0.18+0.005) && indexY >= (0.18-0.005) && indexZ > 0) { // draw beard left middle g.setColor(Color.black); } else if ( (0.575-0.275) <= indexX && indexX <= (0.575+0.275) && indexY <= (0.18+0.005) && indexY >= (0.18-0.005) && indexZ > 0) { // draw beard right middle g.setColor(Color.black); } else if ( (-0.47-0.25) <= indexX && indexX <= (-0.47+0.25) && indexX+2.0*indexY <= (0.25+0.015) && indexX+2.0*indexY >= (0.25-0.015) && indexZ > 0) { // draw beard left up g.setColor(Color.black); } else if ( (0.47-0.25) <= indexX && indexX <= (0.47+0.25) && indexX-2.0*indexY <= (-0.25+0.015) && indexX-2.0*indexY >= (-0.25-0.015) && indexZ > 0) { // draw beard right up g.setColor(Color.black); } else if ( (0.23-Math.sqrt(0.006/1.5)) <= indexX && indexX <= (0.23) && indexX-indexY <= -0.375 && indexX-indexY >= -0.405 && indexZ > 0) { // draw eyeball g.setColor(Color.black); } else if ( (0.23) <= indexX && indexX <= (0.23+Math.sqrt(0.006/1.5)) && indexX+indexY >= 0.835 && indexX+indexY <= 0.865 && indexZ > 0) { // draw eyeball g.setColor(Color.black); } else if ( leftEyeBallCo <= 0.006 && indexZ > 0) { // draw eyeball g.setColor(Color.black); } else if ( 0.06 < leftEyeCo && leftEyeCo <= 0.07 && indexZ > 0) { // draw eyes g.setColor(Color.black); } else if ( leftEyeCo < 0.07 && indexZ > 0) { g.setColor(Color.white); } else if ( 0.06 < rightEyeCo && rightEyeCo <= 0.07 && indexZ > 0) { g.setColor(Color.black); } else if ( rightEyeCo < 0.07 && indexZ > 0) { g.setColor(Color.white); } else if ( -0.01 <= indexX && indexX <= 0.01 && -0 <= indexY && indexY <= 0.4 && indexZ > 0) { // draw nose line g.setColor(Color.black); } else if ( mouthCo <= 0.4 && indexY < -0 && indexZ > 0) { // draw mouth g.setColor(Color.red); } else if ( 0.68 < faceCo && faceCo <= 0.7 && indexZ > 0) { // draw face g.setColor(Color.black); } else if ( faceCo <= 0.7 && indexZ > 0) { g.setColor(Color.white); } else { g.setColor(Color.blue); } for (int j=0; j