p5.easycam实现三维多个地球绕月球转动画效果代码
代码语言:html
所属分类:三维
代码描述:p5.easycam实现三维多个地球绕月球转动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
body {
margin: 0;
padding: 0;
}
canvas {
display: block;
height:100%;
width:100%;
}
</style>
×
</head>
<body >
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/p5.1.4.0.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/p5.easycam.min.js"></script>
<script >
class Planet {
constructor(r, d, o, texxture=planetImg) {
this.v = p5.Vector.random3D();
this.radius = r;
this.distance = d;
this.v.mult(this.distance);
this.angle = random(TWO_PI);
this.orbitspeed = o;
this.texture = texxture;
this.texturePl = planetImg2;
this.textureMoon = moon;
this.planets = null;
}
orbit() {
this.angle = this.angle + this.orbitspeed;
if (this.planets != null) {
for (let i = 0; i < this.planets.length; i++) {
this.planets[i].orbit();
}
}
}
spawnMoons(total, level, txtr=this.texturePl) {
this.planets = [];
for (let i = 0; i < total; i++) {
let r = this.radius / (level * 4);
let d = random(this.radius + r, (this.radius + r) * 2);
let o = random(-0.1, 0.1);
this.planets[i] = new Planet(r, d, o, txtr);
if (level < 2) {
//initialMoons
let num = int(random(0, 3));
this.planets[i].spawnMoons(num, level + 1, this.textureMoon);
}
}
}
show() {
push();
noStroke();
let v2 = createVector(1, 0, 1);
let p = this.v.cross(v2);
// Rotation around a 0-length axis doesn't work in p5.js, so don't do that.
if (p.x != 0 || p.y != 0 || p.z != 0) {
rotate(this.angle, p);
}
stroke(255);
// line(0, 0, 0, this.v.x, this.v.y, this.v.z);
// line(0, 0, 0, p.x, p.y, p.z);
translate(this.v.x, this.v.y, this.v.z);
noStroke();
texture(.........完整代码请登录后点击上方下载按钮下载查看
网友评论0