xxxxxxxxxx
41
const ufo = {x: 0, y: -100, z: -1000, theta: 0}
function setup() {
createCanvas(400, 400, WEBGL)
}
function draw() {
background(220)
drawGround()
drawUfo()
moveUfo()
}
function drawUfo() {
push()
translate(ufo.x, ufo.y, ufo.z)
rotateY(ufo.theta)
ellipsoid(100, 20, 100)
translate(0, -20, 0)
ellipsoid(40, 20, 40)
pop()
}
function drawGround() {
push()
translate(0, 200, 0)
rotateX(1.5)
plane(500, 500)
pop()
}
function moveUfo() {
ufo.theta += 0.01
if (ufo.z < 0) {
ufo.z += 1
} else if (ufo.y < 200) {
ufo.y += 1
} else {
noLoop()
}
}