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: #0998B8;
  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 app;

var Dog = function() {
    this.colors = {
        skin: color(253, 209, 185),
        eyesOuter: color(182, 96, 86),
        eyesInner: color(255, 255, 255),
        eyeBalls: color(0, 0, 0),
        nose: color(0, 0, 0),
        tounge: color(243, 116, 122),
        toungeInner: color(240, 80, 96),
        ears: color(136, 83, 76),
        mouthOuter: color(136, 83, 76),
        mouthInner: color(0, 0, 0),
        teeth: color(255, 255, 255),
        spots: color(243, 196, 173),
        legsBehind: color(235, 190, 168)
    };
    this.timerFront = 0;
    this.timerBack = 5;
    this.sinFront = 0;
    this.sinBack = 0;
    this.speed = 12;
    
    this.update = function() {
        this.timerFront++;
        this.timerBack++;
        this.sinFront = sin(radians(this.timerFront * this.speed));
        this.sinBack = sin(radians(this.timerBack * this.speed));
    };
    this.drawHead = function() {
        noStroke();

        pushMatrix();
            translate(355, 295);
            rotate(radians(-25 + this.sinFront * 15));
            translate(-355, -295);

            //ear - behind
            fill(this.colors.ears);
            beginShape();
                vertex(366, 247);
                bezierVertex(377, 242, 390, 235, 394, 235);
                bezierVertex(400, 235, 403, 238, 404, 244);
                bezierVertex(405, 254, 404, 261, 398, 265);
            endShape(CLOSE);
            
            //head
            fill(this.colors.skin);
  .........完整代码请登录后点击上方下载按钮下载查看

网友评论0