zdog绘制一个三维奔跑中男女卡通效果代码

代码语言:html

所属分类:三维

代码描述:zdog绘制一个三维奔跑中男女卡通效果代码

代码标签: 三维 奔跑 男女 卡通 效果

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


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

<head>

 
<meta charset="UTF-8">
 

 
 
 
<style>
html
{ height: 100%; }

body
{
 
min-height: 100%;
 
margin: 0;
 
display: flex;
 
align-items: center;
 
justify-content: center;
 
background: #09D;
 
font-family: sans-serif;
 
text-align: center;
}

canvas
{
 
display: block;
 
margin: 0px auto 20px;
 
cursor: move;
}

a
{ color: white; }
a:hover { color: #606; }

button
{
 
background: #848;
 
color: white;
 
font-size: 14px;
 
font-family: inherit;
 
border: none;
 
border-radius: 3px;
 
padding: 8px 10px;
}

button:hover {
 
background: #606;
 
cursor: pointer;
}
</style>



</head>

<body >
 
<div class="container">
 
<canvas class="illo"></canvas>
 
<p><a >Original illustration by Robin Davey</a></p>
 
<p><button class="reset-button">Reset</button></p>
</div>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/zdog.dist.js"></script>
     
<script  >
// Made with Zdog

var illoElem = document.querySelector('.illo');
var illoSize = 128;
var minWindowSize = Math.min(window.innerWidth - 20, window.innerHeight - 60);
var zoom = Math.floor(minWindowSize / illoSize);
illoElem.setAttribute('width', illoSize * zoom);
illoElem.setAttribute('height', illoSize * zoom);

var isSpinning = true;
var TAU = Zdog.TAU;
var sceneStartRotation = { y: -TAU / 8 };

var illo = new Zdog.Illustration({
  element: illoElem,
  zoom: zoom,
  rotate: sceneStartRotation,
  dragRotate: true,
  onDragStart: function () {
    isSpinning = false;
  } });


var quarterTurn = Math.sin(TAU / 8);

// ----- colors ----- //

var beigeDark = '#F96';
var beigeLight = '#FC9';
var skinDark = '#F66';
var skinMedium = '#F88';
var skinLight = '#FAA';
var navy = '#036';
var midnight = '#003';
var auburn = '#903';
var red = '#C33';
var sky = '#09D';
var offWhite = '#FFD';
var white = 'white';
var blueDark = '#66C';
var bluePale = '#CCF';

// -- models --- //

var ground = new Zdog.Anchor({
  addTo: illo,
  translate: { y: 56 } });


// ----- dude ----- //

(function () {

  var dude = new Zdog.Anchor({
    addTo: ground,
    translate: { x: -24, z: -12 } });


  var hipX = 8 / quarterTurn / 2;
  var hips = new Zdog.Shape({
    path: [
    { x: -hipX },
    { x: hipX }],

    addTo: dude,
    translate: { y: -49 },
    rotate: { x: TAU / 16 },
    stroke: 8,
    color: beigeLight });


  // right thigh
  var rightThigh = new Zdog.Shape({
    path: [
    { y: 0 },
    { y: 18 }],

    addTo: hips,
    translate: { x: -hipX },
    stroke: 8,
    color: beigeLight });

  // right tight line
  var rightThighLine = rightThigh.copy({
    addTo: rightThigh,
    translate: { x: -4 },
    color: white,
    stroke: 0.5 });


  var shinEnd = { y: 22 };

  var rightShin = rightThigh.copy({
    path: [
    { y: 0 },
    shinEnd],

    addTo: rightThigh,
    translate: { y: 18 } });

  // right shin line
  rightThighLine.copy({
    path: [
    { y: -2 },
    shinEnd],

    addTo: rightShin });


  var rightAnkle = new Zdog.Shape({
    path: [
    { y: 3 },
    { y: 4 }],

    addTo: rightShin,
    translate: shinEnd,
    color: skinMedium,
    stroke: 6 });


  var leftThigh = rightThigh.copy({
    translate: { x: hipX },
    color: beigeDark });

  // left thigh line
  rightThighLine.copy({
    addTo: leftThigh,
    translate: { x: 4 },
    color: beigeLight });


  var leftShin = rightShin.copy({
    addTo: leftThigh,
    rotate: { x: -TAU / 4 - hips.rotate.x },
    color: beigeDark });

  // left shin line
  leftShin.copy({
    addTo: leftShin,
    translate: { x: 4 },
    rotate: {},
    color: beigeLight,
    stroke: rightThighLine.stroke });


  var leftAnkle = rightAnkle.copy({
    addTo: leftShin,
    color: skinDark });


  // shoes
  [true, false].forEach(function (isRight) {
    var shoeAngleX = isRight ? -TAU / 16 : -hips.rotate.x;
    var shoe = new Zdog.RoundedRect({
      width: 2,
      height: 10,
      cornerRadius: 2,
      addTo: isRight ? rightAnkle : leftAnkle,
      translate: { y: 6, z: 4 },
      rotate: { x: -TAU / 4 - shoeAngleX },
      color: isRight ? white : offWhite,
      fill: true,
      stroke: 6 });


    // laces
    var lacesGroup = new Zdog.Group({
      addTo: shoe,
      translate: { z: -3 } });

    var shoeLace = new Zdog.Shape({
      path: [{ x: -1 }, { x: 1 }],
      scale: { x: 2 },
      addTo: lacesGroup,
      translate: { y: -2 },
      color: blueDark,
      stroke: 1 });

    shoeLace.copy({
      translate: { y: -4 } });

    // HACK, add invisible shape so laces better render on top
    new Zdog.Shape({
      visible: false,
      addTo: lacesGroup,
      translate: { y: 4 } });


    // soles
    new Zdog.RoundedRect({
      width: 6,
      height: 13,
      cornerRadius: 3,
      addTo: shoe,
      translate: { z: 3.5 },
      // rotate: { x: -TAU/4 },
      stroke: 1,
      fill: true,
      color: blueDark });

  });

  var torsoX = 6 / quarterTurn;
  var torso = new Zdog.Shape({
    path: [
    { x: -torsoX },
    { x: torsoX }],

    addTo: dude,
    translate: { y: -59, z: -6 },
    color: navy,
    stroke: 16 });


  var shoulderX = torsoX + 1.5;
  var rightShoulder = new Zdog.Shape({
    path: [
    { y: 0 },
    { y: 14 }],

    addTo: torso,
    translate: { x: -shoulderX, y: -3 },
    rotate: { x: -TAU / 16, z: TAU / 8 },
    stroke: 10,
    color: navy });


  var leftShoulder = rightShoulder.copy({
    translate: {.........完整代码请登录后点击上方下载按钮下载查看

网友评论0