zdog实现一个三维图腾效果代码

代码语言:html

所属分类:三维

代码描述:zdog实现一个三维图腾效果代码

代码标签: 三维 图腾 效果

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


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

<head>

  <meta charset="UTF-8">
  


  
<style>
*, *:before, *:after {
  box-sizing: border-box;
}

body, html {
  height: 100%;
}

body {
  background: #A3C4D0;
  background: linear-gradient(to bottom, #f8f5da 0%, #FFF4E2 25%, #A3C4D0 75%, #3e4f53 100%);
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr="#f8f5da", endColorstr="#3e4f53",GradientType=0 );
  overflow: hidden;
}

main {
  display: grid;
  place-items: center;
  height: 100%;
}
@media only screen and (max-height: 470px) {
  main {
    transform: scale(0.75);
  }
}

canvas {
  transform: translateZ(40px) translateY(100vh);
  -webkit-animation: enter 2000ms cubic-bezier(0.075, 0.82, 0.165, 1) 500ms forwards;
          animation: enter 2000ms cubic-bezier(0.075, 0.82, 0.165, 1) 500ms forwards;
  will-change: transform;
  cursor: move;
}

@-webkit-keyframes enter {
  0% {
    transform: translateZ(40px) translateY(100vh);
  }
  100% {
    transform: translateZ(40px);
  }
}

@keyframes enter {
  0% {
    transform: translateZ(40px) translateY(100vh);
  }
  100% {
    transform: translateZ(40px);
  }
}
</style>


</head>

<body  >
  <main>
	<canvas class="totem" width="500" height="500"></canvas>
</main>

<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/zdog.dist.js"></script>
      <script >
let illo = new Zdog.Illustration({
  element: ".totem",
  dragRotate: true });


let anchor = new Zdog.Anchor({
  addTo: illo,
  rotate: { x: -Zdog.TAU / 24, y: Zdog.TAU * .66 } });


// groups
let one = new Zdog.Anchor({
  addTo: anchor,
  translate: { y: -216 } });


let two = new Zdog.Anchor({
  addTo: anchor,
  translate: { y: -108 } });


let three = new Zdog.Anchor({
  addTo: anchor,
  translate: { y: 0 } });


let four = new Zdog.Anchor({
  addTo: anchor,
  translate: { y: 108 } });


// shared
let sharedTopBottom = {
  width: 96,
  height: 96,
  color: "#FDAA4E",
  fill: true };


let sharedTopGroup = {
  rotate: { x: Zdog.TAU / 4 } };


let sharedBottomGroup = {
  rotate: { x: Zdog.TAU / 4 },
  translate: { y: 96 } };


let sharedFrontGroup = {
  translate: { x: -48, y: 48 },
  rotate: { y: -Zdog.TAU / 4 } };


let sharedBackGroup = {
  translate: { x: 48, y: 48 },
  rotate: { y: -Zdog.TAU / 4 } };


let sharedLeftRight = {
  width: 96,
  height: 96,
  color: "#FED240",
  fill: true };


let sharedLeftGroup = {
  translate: { y: 48, z: -48 } };


let sharedRightGroup = {
  translate: { y: 48, z: 48 } };


let sharedEye = {
  diameter: 72,
  color: "#FFFFF9",
  fill: true };


let sharedPupil = {
  diameter: 48,
  color: "#9F355A",
  fill: true };


let sharedLeftRightBorderOne = {
  width: 84,
  height: 84,
  color: "#C2C9CC",
  fill: true,
  translate: { x: -6, y: 6 } };


let sharedLeftRightBorderTwo = {
  width: 72,
  height: 72,
  color: "#FED240",
  fill: true,
  translate: { x: -12, y: 12 } };


let sharedLeftRightBorderThree = {
  width: 60,
  height: 60,
  color: "#C2C9CC",
  fill: true,
  translate: { x: -18, y: 18 } };


let sharedLeftRightBorderFour = {
  width: 48,
  height: 48,
  color: "#FED240",
  fill: true,
  translate: { x: -24, y: 24 } };


let sharedLeftRightBorderFive = {
  width: 36,
  height: 36,
  color: "#C2C9CC",
  fill: true,
  translate: { x: -30, y: 30 } };


let sharedLeftRightBorderSix = {
  width: 24,
  height: 24,
  color: "#FED240",
  fill: true,
  translate: { x: -36, y: 36 } };


let sharedFrontBack = {
  width: 96,
  height: 96,
  color: "#FEF440",
  fill: true };


let sharedButton = {
  diameter: 48,
  length: 6,
  color: "#FDAE56",
  frontFace: false,
  backface: "#FEEE57",
  fill: true,
  translate: { z: -4 } };


let sharedButtonInside = {
  diameter: 24,
  color: "#EF9355",
  fill: true,
  translate: { z: -6 } };


// cube one
let oneTopGroup = new Zdog.Group(Zdog.extend(sharedTopGroup, { addTo: one }));

let oneTop = new Zdog.Rect(Zdog.extend(sharedTopBottom, { addTo: oneTopGroup, color: "#FFFD68" }));

let oneTopBorder = new Zdog.Rect({
  addTo: oneTopGroup,
  width: 84,
  height: 72,
  color: "#E4FFFF",
  fill: true,
  translate: { x: 6 } });


let oneTopBorderCenter = new Zdog.Rect({
  addTo: oneTopGroup,
  width: 72,
  height: 48,
  color: "#FFFD68",
  fill: true,
  translate: { x: 12 } });


let oneTopBorderInside = new Zdog.Rect({
  addTo: oneTopGroup,
  width: 60,
  height: 24,
  color: "#E4FFFF",
  fill: true,
  translate: { x: 18 } });


let oneBottomGroup = new Zdog.Group(Zdog.extend(sharedBottomGroup, { addTo: one }));

let oneBottom = new Zdog.Rect(Zdog.extend(sharedTopBottom, { addTo: oneBottomGroup, color: "#FDAA4E" }));

let oneLeftGroup = new Zdog.Group(Zdog.extend(sharedLeftGroup, { addTo: one }));

let oneLeft = new Zdog.Rect(Zdog.extend(sharedLeftRight, { addTo: oneLeftGroup }));

let oneLeftEye = new Zdog.Ellipse(Zdog.extend(sharedEye, { addTo: oneLeftGroup }));

let oneLeftPupil = new Zdog.Ellipse(Zdog.extend(sharedPupil, { addTo: oneLeftGroup }));

let oneRightGroup = new Zdog.Group(Zdog.extend(sharedRightGroup, { addTo: one }));

let oneRight = new Zdog.Rect(Zdog.extend(sharedLeftRight, { addTo: oneRightGroup }));

let oneRightEye = oneLeftEye.copy({
  addTo: oneRightGroup });


let oneRightPupil = oneLeftPupil.copy({
  addTo: oneRightGroup });


let oneFrontGroup = new Zdog.Group(Zdog.extend(sharedFrontGroup, { addTo: one }));

let oneFront = new Zdog.Rect(Zdog.extend(sharedFrontBack, { addTo: oneFrontGroup }));

let oneFrontBorder = new Zdog.Rect({
  addTo: oneFrontGroup,
  width: 72,
  height: 84,
  color: "#D7ECE4",
  fill: true,
  translate: { y: 6 } });


let oneFrontBorderInside = new Zdog.Rect({
  addTo: oneFrontGroup,
  width: 48,
  height: 72,
  color: "#FEF440",
  fill: true,
  translate: { y: 12 } });


let oneBackGroup = new Zdog.Group(Zdog.extend(sharedBackGroup, { addTo: one }));

let oneBack = new Zdog.Rect(Zdog.extend(sharedFrontBack, { addTo: oneBackGroup }));

let oneBackBorderOne = new Zdog.Shape({
  addTo: oneBackGroup,
  path: [
  { x: 12, y: 0 },
  { x: 84, y: 0 },
  { x: 48, y: 84 }],

  closed: true,
  fill: true,
  color: '#D7ECE4',
  translate: { x: -48, y: -48 } });


let oneBackBorderTwo = new Zdog.Shape({
  addTo: oneBackGroup,
  path: [
  { x: 24, y: 0 },
  { x: 72, y: 0 },
  { x: 48, y: 56 }],

  closed: true,
  fill: true,
  color: '#FEF440',
  translate: { x: -48, y: -48 } });


let oneBackBorderThree = new Zdog.Shape({
  addTo: oneBackGroup,
  path: [
  { x: 36, y: 0 },
  { x: 60, y: 0 },
  { x: 48, y: 28 }],

  closed: true,
  fill: true,
  color: '#D7ECE4',
  translate: { x: -48, y: -48 } });


// cube 2
let twoTopGroup = oneTopGroup.copy({
  addTo: two });


let twoTop = oneBottom.copy({
  addTo: twoTopGroup });


let twoBottomGroup = oneBottomGroup.copy({
  addTo: two });


let twoBottom = oneBottom.copy({
  addTo: twoBottomGroup });


let twoLeftGroup = oneLeftGroup.copy({
  addTo: two });


let twoLeft = oneLeft.copy({
  addTo: twoLeftGroup });


let twoLeftBorderOne = new Zdog.Rect(Zdog.extend(sharedLeftRightBorderOne, { addTo: twoLeftGroup }));

let twoLeftBorderTwo = new Zdog.Rect(Zdog.extend(sharedLeftRightBorderTwo, { addTo: twoLeftGroup }));

let twoLeftBorderThree = new Zdog.Rect(Zdog.extend(sharedLeftRightBorderThree, { addTo: twoLeftGroup }));

let twoLeftBorderFour = new Zdog.Rect(Zdog.extend(sharedLeftRightBorderFour, { addTo: twoLeftGroup }));

let twoLeftBorderFive = new Zdog.Rect(Zdog.extend(sharedLeftRightBorderFive, { addTo: twoLeftGroup }));

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

网友评论0