用VUE 渲染一个斐波那契图形 组件
2020/12/23 8:08:17
本文主要是介绍用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)` } }), ] ); }), ] ); } }
这篇关于用VUE 渲染一个斐波那契图形 组件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-24Vue CLI多环境配置学习:从入门到实践
- 2024-11-24Vue CLI多环境配置学习:新手入门教程
- 2024-11-24Vue CLI学习:初学者指南
- 2024-11-24Vue CLI学习:从入门到上手的简单教程
- 2024-11-24Vue3+Vite学习:从零开始的前端开发之旅
- 2024-11-24Vue3阿里系UI组件学习入门教程
- 2024-11-24Vue3的阿里系UI组件学习入门指南
- 2024-11-24Vue3公共组件学习:新手入门教程
- 2024-11-24Vue3公共组件学习入门指南
- 2024-11-24vue3核心功能响应式变量学习