xxxxxxxxxx
56
const ufo = {x: 0, y: -100, z: -300, spin: 0}
let grassTexture
let groundElevation = 100
function preload() {
grassTexture = loadImage('grass.png')
}
function setup() {
createCanvas(500, 500, WEBGL);
noStroke()
}
function draw() {
directionalLight(255, 255, 255, 1, 1, -1)
pointLight(255, 255, 255, ufo.x, ufo.y-30, ufo.z)
background('#330033');
drawGround();
drawUfo();
moveUfo();
}
function drawGround() {
push()
texture(grassTexture)
spotLight(255, 255, 255, ufo.x, ufo.y, ufo.z, 0, 1, 0, Math.PI/6, 3)
translate(0, groundElevation, 0)
rotateX(radians(90))
plane(900, 550)
pop()
}
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++
} else if (ufo.y < 100) {
ufo.y++
} else {
noLoop()
}
}