栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > Vue.js

用VUE 渲染一个斐波那契图形 组件

Vue.js 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

用VUE 渲染一个斐波那契图形 组件

export default {
  functional: true,
  render: function (h,ctx) {
    function fibonacci(n) {
      var res1 = 1;
      var res2 = 1;
      var sum = res2;
      for (var i = 1; i < n; i++) {
 sum = res1 + res2;
 res1 = res2;
 res2 = sum;
      }
      return sum;
    }
    // eslint-disable-next-line no-unused-vars
    let diration = 0;
    let nums = [];
    let s = 0;
    let x = 0;
    let z = 0;
    let y = 0;
    return h(
      "div",
      {
 style: {
   width: "0px",
   height: "0px",
   top: 0,
   right: 0,
   bottom: 0,
   left: 0,
   margin: 'auto',
   position: "absolute",
   // border: "0.5px solid #000",
 },
      },
      [
 new Array(ctx.props.count||11).fill(null).map((i, k) => {
   let num = fibonacci(k);
   let pre = fibonacci(k - 1);
   let size = num * 10;
   let style;
   nums.push(num);
   if (k !== 0) {
     switch (diration) {
case 1:
  x = x + fibonacci(k - 4) * 10;
  style = {
    top: x + "px",
    left: -z + "px",
    transform: 'rotate(-90deg)'
  };
  break;
case 2:
  y = y + fibonacci(k - 4) * 10;
  style = {
    left: y + "px",
    top: -s + "px",
    transform: 'rotate(-180deg)'
  };
  break;
case 3:
  s = s + num * 10;
  style = {
    top: -s + "px",
    left: -z + "px",
    transform: 'rotate(90deg)'
  };
  break;
case 4:
  z = z + num * 10;
  style = {
    left: -z + "px",
    top: -s + "px",
    transform: 'rotate(0deg)'
  };
  break;
default:
  break;
     }
   }

   k > 0 && diration < 4 ? diration++ : (diration = 1);
   return h(
     "div",
     {
style: {
  width: size + "px",
  height: size + "px",
  border: "0.5px solid #c1c1c1",
  position: "absolute",
  fontSize: "12px",
  textAlign: "center",
  lineHeight: size + "px",
  boxSizing: "border-box",
  ...style,
  // overflow:'hidden'
},
     },
     [
// k > 0 &&
h("div", {
  style: {
    width: size * 2 + "px",
    height: size * 2 + "px",
    borderRadius: "50%",
    border: "0.5px solid #000",
    // backgroundColor: `rgba(${num},${pre},${num},0.2)`
  }
}),
     ]
   );
 }),
      ]
    );
  }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/240106.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号