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);
strokeWeight(1);
stroke(this.colors.spots);
beginShape();
vertex(306, 293);
bezierVertex(311, 269, 324, 250, 351, 245);
bezierVertex(373, 242, 399, 256, 410, 271);
bezierVertex(421, 295, 414, 321, 401, 338);
bezierVertex(380, 357, 352, 359, 326, 350);
bezierVertex(311, 340, 304, 314, 306, 293);
endShape(CLOSE);
noStroke();
//ear - front
fill(this.colors.ears);
beginShape();
vertex(284, 262);
bezierVertex(296, 257, 310, 251, 321, 251);
bezierVertex(331, 250, 333, 251, 331, 257);
bezierVertex(323, 260, 314, 269, 309, 283);
bezierVertex(308, 288, 307, 292, 304, 292);
bezierVertex(294, 285, 286, 279, 282, 274);
bezierVertex(280, 269, 280, 266, 284, 262);
endShape(CLOSE);
//eye - outer right
fill(this.colors.eyesOuter);
beginShape();
vertex(332, 265);
bezierVertex(340, 264, 352, 263, 357, 274);
bezierVertex(360, 286, 360, 295, 352, 307);
bezierVertex(341, 316, 328, 318, 318, 313);
bezierVertex(310, 304, 310, 295, 312, 286);
bezierVertex(316, 276, 322, 270, 332, 265);
endShape(CLOSE);
//eye - inner right
fill(this.colors.eyesInner);
.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0