processing实现canvas卡通人物死侍挥舞双手动画效果代码

代码语言:html

所属分类:动画

代码描述:processing实现canvas卡通人物死侍挥舞双手动画效果代码

代码标签: 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: #222;
          background: #f5c850;
          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>
    <canvas id="canvas"></canvas>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/processing.min.js"></script>

    <script>
        var sketchProc = function(processingInstance) {
          with (processingInstance) {
            size(600, 600); 
            frameRate(60);    
            smooth();
        
            var Deadpool = (function() {
              Deadpool = function() {
                  this.timer = 0;
                  this.speed = 3;
                  this.colors = {
                      head: color(211, 61, 64),
                      body: color(186, 54, 57),
                      dark: color(35, 35, 35),
                      light: color(245, 245, 245)
                  };
              };
              Deadpool.prototype = {
                  draw: function() {
                      pushMatrix();
                          translate(10, 0);
                          translate(300, 600);
                          rotate(radians(sin(radians(this.timer * this.speed)) * 8));
                          translate(-300, -600);
        
                          pushStyle();
                              //swords
                              //left
                              pushMatrix();
                                  translate(192, 80);
                                  translate(90, 420);
                                  rotate(radians(45 + sin(radians(this.timer - 15) * this.speed) * 25));
                                  translate(-90, -420);
        
                                  noStroke();
                                  fill(this.colors.dark);
                                  rect(80, 165, 24, 480, 5);
                                  rect(70, 290, 44, 9, 5);
                                  //diamonds on handle
                                  fill(140, 137, 140, 100);
                                  for(var i = 0; i < 7; i++) {
                                      quad(
                                          92, 168 + i * 17,
                                          99, 175 + i * 17,
                                          92, 182 + i * 17,
                                          83, 175 + i * 17);
                                  }
                              popMatrix();
        
                              //right
                              pushMatrix();
                                  translate(192, 80);
                                  translate(90, 420);
                                  rotate(radians(-45 + sin(radians(this.timer - 15) * this.speed) * 25));
                                  translate(-90, -420);
        
                              noStroke();
                                  fill(this.colors.dark);
                                  rect(80, 165, 24, 480, 5);
                                  rect(70, 290, 44, 9, 5);
                                  //diamonds on handle
                                  fill(140, 137, 140, 100);
                                  for(var i = 0; i < 7; i++) {
                                      quad(
                                          92, 168 + i * 17,
                                          99, 175 + i * 17,
                                          92, 182 + i * 17,
                                          83, 175 + i * 17);
                                  }
                              popMatrix();
        
                              pushMatrix();
                                  translate(348, 486);
                                  rotate(radians(sin(radians(this.timer - 20) * this.speed) * 10));
                                  translate(-348, -486);
        
                                  //left arm
                                  noFill();
                                  stroke(this.colors.body);
                                  strokeWeight(30);
                                  bezier(348, 486, 420, 386, 438, 273, 387, 146);
        
                                  //left hand
                                  pushMatrix();
                                      translate(387, 146);
                                      rotate(radians(sin(radians(this.timer - 20) * this.speed) * 120));
                                      translate(-387, -146);
        
                                      noStroke();
                                      fill(this.colors.dark);
                                      beginShape();
                                          vertex(343, 155);
                                          bezierVertex(338, 142, 337, 133, 339, 121);
                                          bezierVertex(330, 103, 322, 86, 331, 76);
                                          bezierVertex(346, 66, 356, 80, 360, 96);
                                          bezierVertex(360, 95, 364, 94, 367, 93);
                                          bezierVertex(367, 82, 363, 63, 375, 58);
                                          bezierVertex(393, 53, 395, 73, 395, 93);
                                          bezierVertex(396, 94, 397, 95, 400, 96);
                                          bezierVertex(403, 82, 406, 64, 420, 67);
                                          bezierVertex(434, 70, 432, 85, 430, 101);
                                          bezierVertex(424, 135, 424, 151, 408, 166);
                                          bezierVertex(396, 174, 382, 175, 368, 175);
                                          bezierVertex(356, 186, 342, 193, 333, 185);
                                          bezierVertex(325, 171, 335, 164, 343, 155);
                                      endShape(CLOSE);
                                  popMatrix();
                              popMatrix();
        
                              pushMatrix();
                                  translate(220, 486);
                                  rotate(radians(sin(radians(this.timer - 20) * this.speed) * 15));
                                  translate(-220, -486);
        
                                  //right arm
                                  noFill();
                                  stroke(this.colors.body);
                                  strokeWeight(30);
                                  bezier(220, 486, 142, 378, 147, 249, 208, 146);
        
                                  //right hand
                                  pushMatrix();
                                      translate(208, 146);
                                      rotate(radians(-50 + sin(radians(this.timer - 20) * this.speed) * 120));
                                      translate(-208, -146);
        
                                      noStroke();
                                      fill(this.colors.dark);
                                      beginShape();
                                          vertex(244, 158);
                                          bezierVertex(250, 149, 251, 136, 248, 125);
                                          bezierVertex(259, 99, 262, 84, 251, 77);
                                          bezierVertex(237, 74, 229, 85, 227, 101);
                                          bezierVertex(223, 99, 221, 97, 218, 96);
                                          bezierVertex(219, 80, 220, 69, 210, 62);
                                          bezierVertex(188, 60, 189, 77, 190, 97);
                                          bezierVertex(190, 99, 188, 100, 186, 101);
                                          bezierVertex(182, 88, 181, 74, 166, 75);
                                          bezierVertex(154, 79, 152, 87, 156, 104);
                                          bezierVertex(160, 138, 166, 162, 185, 174);
                                          bezierVertex(198, 180, 209, 181, 223, 179);
                                          bezierVertex(233, 187, 246, 197, 256, 189);
                                          bezierVertex(264, 180, 258, 167, 244, 158);
                                      endShape(CLOSE);
                                  popMatrix();
                              popMatrix();
        
                              //body
                              noStroke();
                              fill(this.colors.body);
                              beginShape();
                                  vertex(195, 640);
                                  vertex(195, 485);
                                  vertex(240, 430);
                                  vertex(325, 430);
                                  vertex(370, 485);
                                  vertex(370, 640);
                              endShape(CLOSE);
        
                              noStroke();
                              fill(this.colors.dark);
                              arc(240, 480, 96, 100, radians(180), radians(270));
                              rect(192, 479, 48, 12);
        
                              arc(325, 480, 96, 100, radians(270), radians(360));
                              rect(325, 479, 48, 12);
        
                              beginShape();
                                  vertex(195, 595);
                                  vertex(304, 430);
                                  vertex(324, 430);
                                  vertex(195, 625);
                              endShape(CLOSE);
        
                              pushMatrix();
                                  translate(285, 365);
                                  rotate(radians(sin(radians(this.timer - 15) * this.speed) * 15));
                                  translate(sin(radians(this.timer * this.speed)) * 30, sin(radians(this.timer * this.speed)) * 5);
                                  translate(-285, -365);
        
                                  //shadow under head
                                  fill(40, 40);
                                  ellipse(285, 375, 215, 255);
        
                                  //head
                                  fill(this.colors.head);
                                  ellipse(285, 365, 240, 240);
        
                                  //eyes
                                  fill(this.colors.dark);
                                  ellipse(230, 360, 97, 115);
                                  ellipse(340, 360, 97, 115);
        
                                  //eyeballs
                                  fill(this.colors.light);
                                  ellipse(240, 360, 33, 3.........完整代码请登录后点击上方下载按钮下载查看

网友评论0