three实现可交互三维毕达哥拉斯树(Pythagoras Tree)效果代码

代码语言:html

所属分类:三维

代码描述:three实现可交互三维毕达哥拉斯树(Pythagoras Tree)效果代码,毕达哥拉斯树(Pythagoras Tree)是一种分形图形,由荷兰数学家Albert E. Bosman于1942年创造。这个图形是基于毕达哥拉斯定理(即直角三角形中,斜边的平方等于两直角边的平方和)的几何构造。 毕达哥拉斯树的基本构造步骤如下: 从一个正方形开始,这个正方形被称为“树干”。 在正方形的上方,构造一个直角三角形,使得正方形的顶边是直角三角形的一条直角边。 在直角三角形的两条直角边上分别构造两个新的正方

代码标签: three 交互 三维 毕达哥拉斯树 Pythagoras Tree

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

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

<head>
  <meta charset="UTF-8">
  


  
  
<style>
@import url("https://fonts.googleapis.com/css2?family=Space+Mono&display=swap");

body,
html {
	margin: 0;
	overflow: hidden;
	font-family: "Space Mono", monospace;
}
canvas {
	display: block;
}
#panel {
	position: absolute;
	width: 250px;
	top: 10px;
	left: 10px;
	background-color: rgba(0, 0, 0, 0.5);
	color: white;
	padding: 10px;
	border-radius: 5px;
	font-family: Arial, sans-serif;
	font-size: 14px;
	box-sizing: border-box;
	overflow-y: auto;
}

#panel-toggle {
	cursor: pointer;
	padding: 5px;
}

.slider {
	width: 230px;
}

.color-picker {
	width: 50px;
	height: 25px;
	border: none;
	outline: none;
	cursor: pointer;
}

button {
	background-color: #4caf50;
	border: none;
	color: white;
	padding: 10px 15px;
	text-align: center;
	text-decoration: none;
	display: inline-block;
	font-size: 14px;
	margin: 10px 0;
	cursor: pointer;
	border-radius: 3px;
	font-family: "Space Mono", monospace;
	width: 100%;
}

.slider-value {
	float: right;
	width: 30px;
	text-align: right;
}
</style>


  
  
</head>

<body translate="no">
  <div id="panel">
	<span id="panel-toggle">☰</span>
	<div id="panel-content">
		<br />
		<label for="recursion">Recursion Depth: <span class="slider-value" id="recursionValue">6</span></label>
		<div><input type="range" id="recursion" min="2" max="12" value="6" class="slider" oninput="updateRecursion(this.value)"></div>
		<label for="zoom">Zoom: <span class="slider-value" id="zoomValue">30</span></label>
		<div><input type="range" id="zoom" min="10" max="100" value="30" class="slider" oninput="updateZoom(this.value)"></div>
		<label for="rotation">Rotation: <span class="slider-value" id="rotationValue">0</span></label>
		<div><input type="range" id="rotation" min="0" max="360" value="0" class="slider" oninput="updateRotation(this.value)"></div>
		<br>
		<div>Color:
			<input type="color" id="colorPicker" value="#00ff00" oninput="updateColor(this.value)">
		</div>
		<button id="randomColorBtn" onclick="updateRandomColor()">Random</button>
		<button id="rainbowBtn" onclick="toggleRainbow()">Rainbow</button>
		<br>
		<button id="fullscreenBtn" onclick="toggleFullScreen()">Toggle Full Screen</button>
	</div>
</div>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.127.js"></script>
      <script  >
let scene, camera, renderer, trees;
let recursionDepth = 6;
let zoomLevel = 30;
let rotationAngle = 0;
let treeColor = 0x00ff00;
let rainbowAnimation = false;
let rainbowAnimationTime = 0;

const rainbowButton = document.getElementById("rainbowBtn");

function init() {
  scene = new THREE.Scene();
  camera = new THREE.PerspectiveCamera(
  75,
  window.innerWidth / window.innerHeight,
  0.1,
  1000);

  camera.position.z = zoomLevel;

  renderer = new THREE.WebGLRenderer({ antialias: true });
  renderer.setSize(window.innerWidth, window.innerHeight);
  document.body.appendChild(renderer.domElement);

  const light = new THREE.PointLight(0xffffff, 1, 100);
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0