processing实现canvas万圣节捉鬼游戏代码

代码语言:html

所属分类:游戏

代码描述:processing实现canvas万圣节捉鬼游戏代码,这个游戏是基于Google涂鸦“2018万圣节”的主题。在游戏中,幽灵们组队竞争,看谁能在月亮消失之前收集到最多的游荡鬼火。但途中会有一些意外的转折...使用方向键或WASD键来移动和收集鬼火。你可以从敌人那里偷取鬼火,但要小心,他们也可以偷走你的。将鬼火带回你的基地可以获得积分。请注意,不同的鬼火会给你不同的能力。

代码标签: processing canvas 万圣节 捉鬼 游戏 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  
  
<style>
* {
  margin: 0;
  box-sizing: border-box;
  overflow: hidden;
}

body {
  background: #242424;
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
body canvas {
  box-shadow: 0.2em 0.2em 2em #0008;
  border: none;
  outline: none;
}
</style>

  
</head>

<body translate="no">
  <canvas id="canvas"></canvas>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/processing.1.4.8.js"></script>
      <script  >
var sketchProc = function(processingInstance) {
     with (processingInstance) {
        size(600, 600);
       
        frameRate(60);
        
        smooth();
       
        var game;

      //Keys/Mouse
      {
          //Key|Button stuff
          var clicked = false;
          var hover = false;
          var keys = [];
          keyPressed = function () {
              keys[keyCode] = true;
          };
          keyReleased = function () {
              keys[keyCode] = false;
          };
          mouseClicked = function () {
              clicked = true;
          };
      }

      /** @created_by MKaelin368 (KWC) (c) 2018 */
      var setKALoopTimeout = function (ms) {
        var method_name = "KAInfiniteLoopSetTimeout";
        if (method_name in this) {
          this[method_name](ms >>> 0);
        }
      };

      var Button = function (config) {
          this.x = config.x || 0;
          this.y = config.y || 0;
          this.size = config.size || 100;
          this.content = config.content || "Home";
          this.page = config.page || "home";
          this.textSize = config.textSize || this.size / 5;
          this.borderColor = color(12, 31, 3, 20);
          this.backColor = color(70, 71, 71, 150);
          this.textColor = config.textColor || color(170, 170, 170);
          this.backColorHover = color(102, 105, 105, 150);
          this.textColorHover = color(130, 130, 130);
          this.growth = 0;
          this.func = config.func || function() {};

          this.draw = function () {
              pushStyle();
              textAlign(CENTER, CENTER);
              textSize(this.textSize + (this.growth * 0.1));
              noStroke();

              //shadow
              fill(20, 20, 20, 30);
              ellipse(this.x, this.y + this.size * 0.52, (this.size + this.growth) * 0.8, (this.size + this.growth) * 0.3);

              //circles
              if (dist(mouseX, mouseY, this.x, this.y) <= this.size / 2) { //hover
                  hover = true;
                  this.growth = constrain(this.growth + 0.5, 0, 10);
                  if (clicked) {
                      this.func();
                  }

                  fill(this.backColorHover);
                  stroke(this.borderColor);
                  noStroke();
                  ellipse(this.x, this.y, this.size + this.growth, this.size + this.growth);
                  fill(this.textColorHover);
                  switch(this.content) {
                      case "Play":
                          triangle(this.x + this.size*0.25, this.y, this.x - this.size*0.15, this.y - this.size*0.25, this.x - this.size*0.15, this.y + this.size*0.25);
                          break;
                      case "How":
                          pushStyle();
                              textSize(this.size*0.6);
                              text("?", this.x, this.y);
                          popStyle();
                          break;
                      case "Sound":
                          pushStyle();
                              noStroke();
                              fill(this.textColorHover);
                              triangle(this.x, this.y - this.size * 0.3, this.x, this.y + this.size * 0.3, this.x - this.size * 0.3, this.y);
                              rect(this.x - this.size * 0.3, this.y - this.size * 0.1, this.size * 0.3, this.size * 0.2);
                              if(game.sound) {
                                  noFill();
                                  stroke(this.textColorHover);
                                  strokeWeight(this.size/20);
                                  arc(this.x + this.size * 0.1, this.y, this.size * 0.2, this.size * 0.2, -91, 90);
                                  arc(this.x + this.size * 0.1, this.y, this.size * 0.4, this.size * 0.4, -81, 80);
                              }
                              else {
                                  noFill();
                                  stroke(this.textColorHover);
                                  strokeWeight(this.size/20);
                                  line(this.x + this.size * 0.1, this.y - this.size * 0.1, this.x + this.size * 0.25, this.y + this.size * 0.1);
                                  line(this.x + this.size * 0.1, this.y + this.size * 0.1, this.x + this.size * 0.25, this.y - this.size * 0.1);
                              }
                          popStyle();
                          break;
                      case "Story":
                          pushStyle();
                              noFill();
                              stroke(this.textColorHover);
                              strokeWeight(4);
                              line(this.x-this.size*0.23, this.y-this.size*0.2, this.x+this.size*0.23, this.y-this.size*0.2);
                              line(this.x-this.size*0.23, this.y, this.x+this.size*0.23, this.y);
                              line(this.x-this.size*0.23, this.y+this.size*0.2, this.x+this.size*0.23, this.y+this.size*0.2);
                          popStyle();
                          break;
                      case "Scoreboard":
                          pushStyle();
                              noFill();
                              stroke(this.textColorHover);
                              strokeWeight(this.size * 0.14);
                              strokeCap(SQUARE);

                              line(this.x, this.y + this.size * 0.25, this.x, this.y - this.size * 0.3);
                              line(this.x - this.size * 0.2, this.y + this.size * 0.25, this.x - this.size * 0.2, this.y - this.size * 0.1);
                              line(this.x + this.size * 0.2, this.y + this.size * 0.25, this.x + this.size * 0.2, this.y - this.size * 0.2);
                          popStyle();
                          break;
                      case "Back":
                          pushStyle();
                          beginShape();
                              vertex(this.x+this.size*0.25, this.y); //1
                              vertex(this.x+this.size*0.25, this.y+this.size*0.25); //2
                              vertex(this.x+this.size*0.07, this.y+this.size*0.25); //3
                              vertex(this.x+this.size*0.07, this.y+this.size*0.12); //4
                              vertex(this.x-this.size*0.07, this.y+this.size*0.12); //5
                              vertex(this.x-this.size*0.07, this.y+this.size*0.25); //6
                              vertex(this.x-this.size*0.25, this.y+this.size*0.25); //7
                              vertex(this.x-this.size*0.25, this.y); //8
                              vertex(this.x, this.y-this.size*0.2); //9
                              vertex(this.x+this.size*0.25, this.y); //10
                          endShape();
                          noFill();
                          stroke(this.textColorHover);
                          strokeWeight(this.size*0.05);
                          line(this.x-this.size*0.27, this.y-this.size*0.05, this.x, this.y-this.size*0.27);
                          line(this.x+this.size*0.27, this.y-this.size*0.05, this.x, this.y-this.size*0.27);
                          line(this.x+this.size*0.15, this.y-this.size*0.19, this.x+this.size*0.15, this.y-this.size*0.25);
                          popStyle();
                          break;
                      case "Replay":
                          pushStyle();
                              noFill();
                              stroke(this.textColorHover);
                              strokeWeight(5);
                              pushMatrix();
                                  translate(this.x, this.y);
                                  rotate(radians(game.rate * 5));
                                  arc(0, 0, this.size * 0.6, this.size * 0.6, 1, 275);
                                  noStroke();
                                  fill(this.textColorHover);
                                  translate(this.size * 0.30, -this.size * 0.18);
                                  rotate(radians(-70));
                                  triangle(0, -this.size * 0.1, -this.size * 0.14, -this.size * 0.3, this.size * 0.14, -this.size * 0.3);
                              popMatrix();
                          popStyle();
                          break;
                      default:
                          text(this.content, this.x, this.y);
                  }
              }
              else { //not hover
                  this.growth = constrain(this.growth - 0.5, 0, 10);
                  fill(this.backColor);
                  strokeWeight(2);
                  stroke(this.borderColor, 100);
                  noStroke();
                  ellipse(this.x, this.y, this.size + this.growth, this.size + this.growth);
                  fill(this.textColor);
                  switch(this.content) {
                      case "Play":
                          triangle(this.x + this.size*0.25, this.y, this.x - this.size*0.15, this.y - this.size*0.25, this.x - this.size*0.15, this.y + this.size*0.25);
                          break;
                      case "How":
                          pushStyle();
                              textSize(this.size*0.6);
                              text("?", this.x, this.y);
                          popStyle();
                          break;
                      case "Sound":
                          pushStyle();
                              noStroke();
                              fill(this.textColor);
                              triangle(this.x, this.y - this.size * 0.3, this.x, this.y + this.size * 0.3, this.x - this.size * 0.3, this.y);
                              rect(this.x - this.size * 0.3, this.y - this.size * 0.1, this.size * 0.3, this.size * 0.2);
                              if(game.sound) {
                                  noFill();
                                  stroke(this.textColor);
                                  strokeWeight(this.size/20);
                                  arc(this.x + this.size * 0.1, this.y, this.size * 0.2, this.size * 0.2, -91, 90);
                                  arc(this.x + this.size * 0.1, this.y, this.size * 0.4, this.size * 0.4, -81, 80);
                              }
                              else {
                                  noFill();
                                  stroke(this.textColor);
                                  strokeWeight(this.size/20);
                                  line(this.x + this.size * 0.1, this.y - this.size * 0.1, this.x + this.size * 0.25, this.y + this.size * 0.1);
                                  line(this.x + this.size * 0.1, this.y + this.size * 0.1, this.x + this.size * 0.25, this.y - this.size * 0.1);
                              }
                          popStyle();
                          break;
                      case "Story":
                          pushStyle();
                              noFill();
                              stroke(this.textColor);
                              strokeWeight(4);
                              line(this.x-this.size*0.23, this.y-this.size*0.2, this.x+this.size*0.23, this.y-this.size*0.2);
                              line(this.x-this.size*0.23, this.y, this.x+this.size*0.23, this.y);
                              line(this.x-this.size*0.23, this.y+this.size*0.2, this.x+this.size*0.23, this.y+this.size*0.2);
                          popStyle();
                          break;
                      case "Scoreboard":
                          pushStyle();
                              noFill();
                              stroke(this.textColor);
                              strokeWeight(this.size * 0.14);
                              strokeCap(SQUARE);

                              line(this.x, this.y + this.size * 0.25, this.x, this.y - this.size * 0.3);
                              line(this.x - this.size * 0.2, this.y + this.size * 0.25, this.x - this.size * 0.2, this.y - this.size * 0.1);
                              line(this.x + this.size * 0.2, this.y + this.size * 0.25, this.x + this.size * 0.2, this.y - this.size * 0.2);
                          popStyle();
                          break;
                      case "Back":
                          pushStyle();
                          beginShape();
                              vertex(this.x+this.size*0.25, this.y); //1
                              vertex(this.x+this.size*0.25, this.y+this.size*0.25); //2
                              vertex(this.x+this.size*0.07, this.y+this.size*0.25); //3
                              vertex(this.x+this.size*0.07, this.y+this.size*0.12); //4
                              vertex(this.x-this.size*0.07, this.y+this.size*0.12); //5
                              vertex(this.x-this.size*0.07, this.y+this.size*0.25); //6
                              vertex(this.x-this.size*0.25, this.y+this.size*0.25); //7
                              vertex(this.x-this.size*0.25, this.y); //8
                              vertex(this.x, this.y-this.size*0.2); //9
                              vertex(this.x+this.size*0.25, this.y); //10
                          endShape();
                          noFill();
                          stroke(this.textColor);
                          strokeWeight(this.size*0.05);
                          line(this.x-this.size*0.27, this.y-this.size*0.05, this.x, this.y-this.size*0.27);
                          line(this.x+this.size*0.27, this.y-this.size*0.05, this.x, this.y-this.size*0.27);
                          line(this.x+this.size*0.15, this.y-this.size*0.19, this.x+this.size*0.15, this.y-this.size*0.25);
                          popStyle();
                          break;
                      case "Replay":
                          pushStyle();
                              noFill();
                              stroke(this.textColor);
                              strokeWeight(5);
                              pushMatrix();
                                  translate(this.x, this.y);
                                  rotate(radians(sin(game.rate * 5) * 20));
                                  arc(0, 0, this.size * 0.6, this.size * 0.6, 1, 275);
                                  noStroke();
                                  fill(this.textColor);
                                  translate(this.size * 0.30, -this.size * 0.18);
                                  rotate(radians(-70));
                                  triangle(0, -this.size * 0.1, -this.size * 0.14, -this.size * 0.3, this.size * 0.14, -this.size * 0.3);
                              popMatrix();
                          popStyle();
                          break;
                      default:
                          text(this.content, this.x, this.y);
                  }
              }

              popStyle();
          };
      };

      var Avatar = function(config) {
          this.type = config.type || 0;
          this.draw = function() {
              switch(this.type) {
                  case 0: //Jade
                      pushMatrix();
                          pushStyle();
                              //face
                              noStroke();
                              fill(255, 255, 255);
                              beginShape();
                                  vertex(50, 5);
                                  bezierVertex(65, 4, 86, 15, 91, 34);
                                  bezierVertex(94, 58, 82, 72, 63, 79);
                                  bezierVertex(36, 82, 16, 72, 11, 52);
                                  bezierVertex(8, 32, 20, 12, 50, 5);
                              endShape(CLOSE);

                              //body
                              fill(131, 255, 174, 150);
                              stroke(20, 104, 26, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(50, 3);
                                  bezierVertex(69, 3, 88, 8, 97, 32);
                                  bezierVertex(102, 58, 101, 82, 100, 101);
                                  bezierVertex(99, 110, 100, 115, 90, 118);
                                  bezierVertex(79, 116, 80, 109, 79, 103);
                                  bezierVertex(77, 110, 70, 117, 62, 119);
                                  bezierVertex(52, 119, 48, 114, 44, 106);
                                  bezierVertex(42, 112, 32, 120, 20, 116);
                                  bezierVertex(13, 113, 9, 104, 9, 95);
                                  bezierVertex(11, 79, 6, 70, 5, 47);
                                  bezierVertex(4, 24, 23, 3, 50, 3);
                              endShape(CLOSE);

                              //eyes
                              noStroke();
                              fill(0, 97, 0);
                              ellipse(39, 29, 25, 23);
                              ellipse(70, 26, 25, 23);

                              //eyeballs
                              fill(174, 255, 174);
                              ellipse(43, 30, 11, 10);
                              ellipse(66, 27, 11, 10);

                              //mouth
                              noFill();
                              stroke(0, 97, 0, 100);
                              strokeWeight(3);
                              bezier(39, 48, 44, 53, 54, 55, 59, 52);
                          popStyle();
                      popMatrix();
                      break;
                  case 1: //Sage
                      pushMatrix();
                          pushStyle();
                              //face
                              noStroke();
                              fill(255, 255, 255);
                              beginShape();
                                  vertex(50, 5);
                                  bezierVertex(65, 4, 86, 15, 91, 34);
                                  bezierVertex(98, 60, 87, 76, 74, 77);
                                  bezierVertex(32, 88, 12, 74, 11, 52);
                                  bezierVertex(8, 32, 20, 12, 50, 5);
                              endShape(CLOSE);

                              //body
                              fill(131, 255, 174, 150);
                              stroke(20, 104, 26, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(50, 3);
                                  bezierVertex(69, 3, 88, 8, 97, 32);
                                  bezierVertex(102, 58, 101, 82, 100, 101);
                                  bezierVertex(99, 110, 100, 115, 90, 118);
                                  bezierVertex(79, 116, 80, 109, 78, 108);
                                  bezierVertex(77, 110, 70, 117, 62, 119);
                                  bezierVertex(52, 119, 48, 114, 44, 106);
                                  bezierVertex(42, 112, 32, 120, 20, 116);
                                  bezierVertex(13, 113, 9, 104, 9, 95);
                                  bezierVertex(11, 79, 6, 70, 5, 47);
                                  bezierVertex(4, 24, 23, 3, 50, 3);
                              endShape(CLOSE);

                              //glasses
                              noFill();
                              stroke(206, 114, 30);
                              strokeWeight(4);
                              beginShape();
                                  vertex(21, 15);
                                  bezierVertex(48, 12, 69, 9, 83, 6);
                                  bezierVertex(85, 18, 82, 23, 74, 26);
                                  bezierVertex(65, 27, 62, 22, 58, 15);
                                  bezierVertex(58, 22, 56, 33, 43, 34);
                                  bezierVertex(31, 34, 25, 25, 21, 16);
                              endShape(CLOSE);
                              strokeWeight(2);
                              line(24, 22, 58, 17);
                              line(28, 28, 56, 23);

                              line(61, 16, 84, 12);
                              line(63, 23, 83, 17);

                              //mouth
                              noFill();
                              stroke(0, 97, 0, 100);
                              strokeWeight(3);
                              bezier(23, 33, 32, 46, 44, 43, 49, 41);
                          popStyle();
                      popMatrix();
                      break;
                  case 2: //Kelly
                      pushMatrix();
                          pushStyle();
                              noStroke();

                              //face
                              fill(255, 255, 255);
                              beginShape();
                                  vertex(50, 5);
                                  bezierVertex(65, 4, 86, 15, 91, 34);
                                  bezierVertex(94, 58, 82, 68, 63, 73);
                                  bezierVertex(36, 77, 16, 72, 11, 52);
                                  bezierVertex(8, 32, 20, 12, 50, 5);
                              endShape(CLOSE);

                              //body
                              fill(131, 255, 174, 150);
                              stroke(20, 104, 26, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(50, 3);
                                  bezierVertex(69, 3, 88, 8, 97, 32);
                                  bezierVertex(100, 58, 93, 82, 100, 101);
                                  bezierVertex(101, 110, 100, 115, 90, 118);
                                  bezierVertex(77, 116, 77, 109, 74, 103);
                                  bezierVertex(74, 110, 67, 117, 59, 119);
                                  bezierVertex(47, 119, 43, 114, 39, 96);
                                  bezierVertex(42, 112, 32, 120, 20, 116);
                                  bezierVertex(13, 113, 9, 104, 9, 95);
                                  bezierVertex(11, 79, 6, 70, 5, 47);
                                  bezierVertex(4, 24, 23, 3, 50, 3);
                              endShape(CLOSE);

                              //eyes
                              noStroke();
                              fill(0, 97, 0);
                              ellipse(44, 21, 21, 19);
                              ellipse(65, 20, 21, 19);

                              //eyeballs
                              fill(174, 255, 174);
                              ellipse(47, 22, 8, 7);
                              ellipse(62, 21, 8, 7);

                              //mouth
                              noStroke();
                              fill(0, 97, 0, 100);
                              beginShape();
                                  vertex(35, 33);
                                  bezierVertex(42, 33, 45, 44, 55, 43);
                                  bezierVertex(61, 43, 64, 49, 62, 54);
                                  bezierVertex(55, 60, 43, 57, 33, 52);
                                  bezierVertex(27, 43, 29, 36, 35, 33);
                              endShape(CLOSE);
                          popStyle();
                      popMatrix();
                      break;
                  case 3: //Olive
                      pushMatrix();
                          pushStyle();
                              //ears
                              fill(131, 255, 174, 150);
                              stroke(20, 104, 26, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(67, 14);
                                  bezierVertex(72, 8, 79, 7, 85, 5);
                                  bezierVertex(89, 15, 91, 21, 90, 29);
                              endShape(CLOSE);

                              beginShape();
                                  vertex(37, 17);
                                  bezierVertex(30, 10, 22, 8, 15, 7);
                                  bezierVertex(11, 19, 17, 31, 20, 38);
                              endShape(CLOSE);

                              //face
                              noStroke();
                              fill(255, 255, 255);
                              beginShape();
                                  vertex(50, 12);
                                  bezierVertex(65, 10, 86, 15, 91, 34);
                                  bezierVertex(97, 58, 82, 68, 63, 71);
                                  bezierVertex(36, 74, 16, 68, 11, 52);
                                  bezierVertex(8, 32, 20, 17, 50, 12);
                              endShape(CLOSE);

                              //body
                              fill(131, 255, 174, 150);
                              stroke(20, 104, 26, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(50, 7);
                                  bezierVertex(69, 7, 88, 8, 97, 32);
                                  bezierVertex(102, 58, 101, 82, 100, 101);
                                  bezierVertex(99, 110, 100, 115, 90, 118);
                                  bezierVertex(79, 116, 80, 109, 79, 103);
                                  bezierVertex(77, 110, 70, 117, 62, 119);
                                  bezierVertex(52, 119, 48, 114, 44, 106);
                                  bezierVertex(42, 112, 32, 120, 20, 116);
                                  bezierVertex(13, 113, 9, 104, 9, 95);
                                  bezierVertex(11, 79, 6, 70, 5, 47);
                                  bezierVertex(4, 24, 23, 8, 50, 7);
                              endShape(CLOSE);

                              //eyes
                              noStroke();
                              fill(0, 97, 0);
                              ellipse(32, 28, 10, 9);
                              ellipse(74, 24, 10, 9);

                              //mouth
                              noFill();
                              stroke(0, 97, 0, 100);
                              strokeWeight(3);
                              bezier(46, 32, 48, 36, 53, 36, 55, 32);
                              bezier(55, 33, 58, 35, 62, 36, 63, 30);

                              //fish
                              //head
                              noStroke();
                              fill(127, 136, 117);
                              beginShape();
                                  vertex(55, 36);
                                  bezierVertex(67, 42, 74, 48, 71, 53);
                                  bezierVertex(60, 55, 50, 55, 46, 54);
                                  bezierVertex(45, 51, 51, 43, 55, 36);
                              endShape(CLOSE);
                              fill(177, 185, 157);
                              beginShape();
                                  vertex(55, 36);
                                  bezierVertex(67, 42, 74, 48, 71, 52);
                                  bezierVertex(56, 53, 59, 55, 55, 36);
                              endShape(CLOSE);

                              //eye
                              noStroke();
                              fill(61, 60, 61);
                              ellipse(52, 49, 5, 5);

                              //tail
                              fill(177, 185, 157);
                              beginShape();
                                  vertex(58, 71);
                                  bezierVertex(62, 71, 68, 73, 72, 77);
                                  bezierVertex(67, 78, 60, 77, 58, 71);
                              endShape(CLOSE);
                              fill(127, 136, 117);
                              beginShape();
                                  vertex(58, 71);
                                  bezierVertex(56, 77, 52, 80, 49, 80);
                                  bezierVertex(45, 79, 47, 74, 58, 71);
                              endShape(CLOSE);
                              //spine
                              noFill();
                              stroke(138, 135, 138);
                              strokeWeight(2);
                              line(58, 56, 58, 71);
                              strokeWeight(2);
                              line(49, 59, 66, 58);
                              line(49, 65, 64, 65);
                          popStyle();
                      popMatrix();
                      break;
                  case 4: //Plum
                      pushMatrix();
                          pushStyle();
                              //head
                              noStroke();
                              fill(173, 73, 255);
                              beginShape();
                                  vertex(49, 8);
                                  bezierVertex(65, 9, 82, 15, 88, 31);
                                  bezierVertex(91, 55, 80, 70, 62, 79);
                                  bezierVertex(40, 83, 17, 74, 10, 48);
                                  bezierVertex(11, 24, 27, 12, 48, 8);
                              endShape(CLOSE);

                              //body
                              fill(220, 123, 254, 150);
                              stroke(219, 81, 251, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(49, 3);
                                  bezierVertex(63, 2, 80, 9, 89, 23);
                                  bezierVertex(102, 43, 95, 83, 91, 108);
                                  vertex(80, 92);
                                  vertex(58, 119);
                                  vertex(41, 106);
                                  vertex(29, 117);
                                  vertex(21, 104);
                                  vertex(12, 115);
                                  bezierVertex(7, 84, 2, 53, 6, 33);
                                  bezierVertex(12, 16, 29, 6, 49, 3);
                              endShape(CLOSE);

                              //eyes
                              strokeWeight(2);
                              fill(255, 255, 255, 200);
                              beginShape();
                                  vertex(57, 25);
                                  vertex(80, 22);
                                  bezierVertex(82, 30, 77, 36, 72, 36);
                                  bezierVertex(63, 36, 61, 32, 57, 25);
                              endShape(CLOSE);
                              beginShape();
                                  vertex(21, 29);
                                  vertex(53, 26);
                                  bezierVertex(54, 35, 49, 42, 40, 43);
                                  bezierVertex(28, 42, 24, 36, 21, 29);
                              endShape(CLOSE);

                              //mouth
                              beginShape();
                                  vertex(58, 46);
                                  bezierVertex(62, 45, 68, 40, 73, 43);
                                  bezierVertex(76, 50, 74, 56, 68, 61);
                                  bezierVertex(61, 64, 52, 64, 46, 60);
                                  bezierVertex(42, 55, 41, 50, 42, 47);
                                  bezierVertex(46, 45, 49, 46, 57, 46);
                              endShape(CLOSE);

                              //teeth
                              line(56, 46, 53, 62);
                              line(63, 45, 70, 60);

                              //eyeballs
                              noStroke();
                              fill(173, 73, 254, 250);
                              arc(41, 27, 14, 15, -10, 181);
                              arc(68, 24, 12, 11, -14, 181);

                              //freckles
                              strokeWeight(2);
                              stroke(255, 255, 255, 150);
                              point(34, 48);
                              point(37, 55);
                              point(29, 52);
                              point(78, 42);
                              point(81, 49);
                              point(83, 40);
                          popStyle();
                      popMatrix();
                      break;
                  case 5: //Periwinkle
                      pushMatrix();
                          translate(-3, -5);
                          scale(1.05);

                          pushStyle();
                              //head
                              noStroke();
                              fill(173, 73, 255, 150);
                              beginShape();
                                  vertex(48, 5);
                                  bezierVertex(64, 6, 78, 13, 88, 24);
                                  bezierVertex(94, 36, 96, 48, 96, 58);
                                  vertex(90, 55);
                                  vertex(89, 63);
                                  vertex(75, 41);
                                  vertex(68, 53);
                                  vertex(53, 37);
                                  vertex(46, 52);
                                  vertex(36, 43);
                                  vertex(28, 56);
                                  vertex(20, 44);
                                  vertex(6, 62);
                                  bezierVertex(5, 48, 5, 33, 11, 22);
                                  bezierVertex(19, 12, 32, 6, 48, 5);
                              endShape(CLOSE);

                              //body
                              fill(220, 123, 254, 150);
                              stroke(219, 81, 251, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(45, 15);
                                  bezierVertex(59, 13, 75, 24, 83, 42);
                                  bezierVertex(87, 65, 89, 89, 91, 105);
                                  vertex(83, 101);
                                  vertex(75, 109);
                                  vertex(67, 103);
                                  vertex(58, 109);
                                  vertex(51, 104);
                                  vertex(44, 112);
                                  vertex(37, 100);
                                  vertex(25, 109);
                                  vertex(18, 98);
                                  vertex(10, 103);
                                  bezierVertex(11, 83, 10, 60, 10, 44);
                                  bezierVertex(16, 27, 29, 18, 45, 15);
                              endShape(CLOSE);

                              //mouth
                              strokeWeight(2);
                              fill(255, 255, 255, 200);
                              beginShape();
                                  vertex(48, 54);
                                  bezierVertex(55, 54, 61, 57, 61, 64);
                                  bezierVertex(59, 69, 49, 72, 39, 72);
                                  bezierVertex(33, 68, 31, 59, 31, 53);
                                  bezierVertex(37, 50, 40, 50, 48, 54);
                              endShape(CLOSE);

                              //tounge
                              noStroke();
                              fill(173, 73, 255, 100);
                              beginShape();
                                  vertex(32, 60);
                                  bezierVertex(35, 54, 39, 57, 44, 59);
                                  bezierVertex(46, 60, 50, 66, 52, 70);
                                  bezierVertex(48, 71, 42, 72, 38, 71);
                                  bezierVertex(33, 66, 33, 65, 33, 62);
                              endShape(CLOSE);

                              //freckles
                              strokeWeight(2);
                              stroke(255, 255, 255, 150);
                              point(21, 53);
                              point(17, 57);
                              point(25, 59);
                              point(70, 56);
                              point(75, 49);
                              point(78, 54);
                          popStyle();
                      popMatrix();
                      break;
                  case 6: //Iris
                      pushMatrix();
                          translate(-2, -3);
                          scale(1.05);

                          pushStyle();
                              //head
                              noStroke();
                              fill(173, 73, 255, 150);
                              beginShape();
                                  vertex(50, 9);
                                  bezierVertex(63, 9, 81, 17, 88, 32);
                                  bezierVertex(92, 55, 81, 74, 65, 81);
                                  bezierVertex(44, 85, 26, 80, 17, 68);
                                  bezierVertex(10, 52, 9, 36, 15, 24);
                                  bezierVertex(25, 14, 36, 12, 50, 9);
                              endShape(CLOSE);

                              //body
                              fill(220, 123, 254, 150);
                              stroke(219, 81, 251, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(48, 4);
                                  bezierVertex(66, 4, 85, 12, 92, 26);
                                  bezierVertex(98, 44, 98, 68, 91, 88);
                                  vertex(77, 116);
                                  vertex(69, 104);
                                  vertex(59, 118);
                                  vertex(43, 104);
                                  vertex(28, 115);
                                  bezierVertex(15, 89, 9, 71, 6, 51);
                                  bezierVertex(6, 36, 8, 24, 17, 16);
                                  bezierVertex(28, 8, 36, 5, 48, 4);
                              endShape(CLOSE);

                              //eye
                              strokeWeight(2);
                              fill(255, 255, 255, 200);
                              ellipse(57, 39, 40, 40);

                              fill(173, 73, 255, 200);
                              stroke(219, 81, 251, 70);
                              ellipse(58, 39, 20, 20);

                              noStroke();
                              fill(255, 255, 255, 200);
                              ellipse(54, 36, 6, 6);

                              //mouth
                              noFill();
                              stroke(255, 255, 255, 200);
                              arc(59, 62, 18, 16, -4, 174);

                              //headband
                              noStroke();
                              fill(173, 73, 255, 200);
                              beginShape();
                                  vertex(7, 24);
                                  bezierVertex(34, 17, 68, 12, 87, 15);
                                  vertex(94, 26);
                                  bezierVertex(56, 26, 21, 31, 4, 36);
                              endShape(CLOSE);
                          popStyle();
                      popMatrix();
                      break;
                  case 7: //Mulberry
                      pushMatrix();
                          pushStyle();
                              //head
                              noStroke();
                              fill(173, 73, 255, 150);
                              beginShape();
                                  vertex(38, 12);
                                  bezierVertex(52, 11, 66, 13, 74, 17);
                                  bezierVertex(78, 20, 80, 25, 78, 30);
                                  bezierVertex(77, 40, 71, 56, 64, 64);
                                  bezierVertex(55, 71, 40, 73, 21, 67);
                                  bezierVertex(8, 59, 6, 44, 9, 31);
                                  bezierVertex(14, 19, 27, 15, 36, 12);
                              endShape(CLOSE);

                              //body
                              fill(220, 123, 254, 150);
                              stroke(219, 81, 251, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(96, 14);
                                  vertex(79, 39);
                                  bezierVertex(91, 57, 100, 90, 98, 112);
                                  vertex(74, 89);
                                  vertex(61, 116);
                                  vertex(36, 96);
                                  vertex(13, 115);
                                  bezierVertex(4, 92, 2, 73, 1, 48);
                                  bezierVertex(3, 31, 6, 13, 26, 7);
                                  bezierVertex(45, 1, 71, 4, 96, 14);
                              endShape(CLOSE);

                              //eyes
                              strokeWeight(2);
                              fill(255, 255, 255, 200);
                              ellipse(31, 28, 26, 26);
                              ellipse(56, 21, 21, 21);

                              //eyeballs
                              noStroke();
                              fill(173, 73, 254, 250);
                              ellipse(33, 27, 14, 14);
                              ellipse(54, 21, 11, 11);

                              //nose
                              ellipse(92, 14, 14, 14);

                              //tounge
                              beginShape();
                                  vertex(32, 48);
                                  bezierVertex(36, 52, 41, 53, 48, 55);
                                  bezierVertex(46, 64, 44, 69, 36, 70);
                                  bezierVertex(28, 68, 26, 60, 30, 48);
                              endShape(CLOSE);

                              //mouth
                              noFill();
                              strokeWeight(2);
                              stroke(173, 73, 254, 250);
                              bezier(28, 46, 32, 49, 49, 57, 54, 54);
                          popStyle();
                      popMatrix();
                      break;
              }
          };
      };
      var Spirit = function(config) {
          this.headColor = config.headColor;
          this.bodyColor = config.bodyColor;
          this.bodyStroke = config.bodyStroke;

          this.draw = function() {
              pushStyle();
                  noStroke();
                  fill(173, 73, 255, 150);
                  fill(this.headColor);
                  ellipse(40, 79, 70, 55);

                  fill(220, 123, 254, 150);
                  fill(this.bodyColor);
                  stroke(219, 81, 251, 70);
                  stroke(this.bodyStroke);
                  strokeWeight(8);
                  beginShape();
                      vertex(42, 35);
                      bezierVertex(56, 48, 61, 48, 75, 65);
                      bezierVertex(78, 74, 78, 88, 71, 97);
                      bezierVertex(68, 103, 56, 104, 52, 107);
                      bezierVertex(34, 107, 16, 105, 12, 100);
                      bezierVertex(3, 89, 1, 76, 12, 58);
                      bezierVertex(17, 51, 36, 41, 42, 35);
                  endShape(CLOSE);

                  n.........完整代码请登录后点击上方下载按钮下载查看

网友评论0