xxxxxxxxxx
54
let ufo = {x: 0, y: -100, z: -450, spin: 0}
const groundElevation = 100
function setup() {
createCanvas(500, 500, WEBGL);
noStroke()
}
function draw() {
directionalLight(255, 255, 255, 1, 1, -1)
spotLight(255, 255, 0, ufo.x, ufo.y, ufo.z, 0, 1, 0, radians(30), 3)
drawBackground()
drawGround()
drawUfo()
moveUfo()
}
function drawGround() {
push()
fill('lightgreen')
translate(0, 100, 0)
rotateX(radians(90))
plane(900, 550)
pop()
}
function drawBackground() {
background('midnightblue');
}
function drawUfo() {
push()
translate(ufo.x, ufo.y, ufo.z)
rotateY(ufo.spin)
ellipsoid(100, 20, 100)
translate(0, -15, 0)
sphere(30)
translate(0, 35, 0)
emissiveMaterial('white')
sphere(10)
pop()
}
function moveUfo() {
ufo.spin += 0.01
if (ufo.z < 0) {
ufo.z += 1
} else if (ufo.y < groundElevation-20) {
ufo.y += 1
} else {
noLoop()
}
}