xxxxxxxxxx
53
// A p5.js animation of a UFO landing on a grassy field
let elevation = -300
let finalElevation = 190
let grassImage
function preload() {
grassImage = loadImage('grass.png')
}
function setup() {
createCanvas(700, 700, WEBGL)
noStroke()
}
function draw() {
background('midnightblue');
directionalLight(255, 255, 255, 1, 1, -1)
pointLight(255, 255, 255, 0, elevation-30, 0)
drawGround()
drawUfo()
elevation += 1
if (elevation === finalElevation) {
noLoop()
}
}
function drawGround() {
push()
texture(grassImage)
spotLight(255, 255, 255, 0, elevation, 0, 0, 1, 0, Math.PI/6, 3)
translate(0, 200, 0)
rotateX(radians(90))
plane(550, 550)
pop()
}
function drawUfo() {
push()
translate(0, elevation, 0)
scale(1, 0.25, 1)
ambientMaterial('lightblue')
sphere(80)
translate(0, -80, 0)
scale(1, 2, 1)
sphere(40)
translate(0, 80, 0)
scale(1, 2, 1)
emissiveMaterial('white')
sphere(10)
pop()
}