xxxxxxxxxx
45
let ufoX = 0
let ufoY = 80
let ufoWidth = 90
function setup() {
createCanvas(400, 300)
noStroke()
}
function draw() {
background("skyblue")
drawSun()
drawGrass()
drawUfo()
moveUfo()
}
function drawSun() {
fill("yellow")
circle(width, 0, height / 2)
}
function drawGrass() {
fill('lightgreen')
rect(0, height * 3 / 4, width, height * 0.25)
}
function drawUfo() {
if (width * 0.4 < ufoX && ufoX < width * 0.6) {
fill('white')
triangle(ufoX, ufoY, ufoX + 20, height * 0.875,
ufoX - 20, height * 0.875)
}
fill('gray')
ellipse(ufoX, ufoY, ufoWidth, 30)
ellipse(ufoX, ufoY - 12, ufoWidth / 2, 30)
}
function moveUfo() {
ufoX += 1
if (ufoX > width) {
noLoop()
}
}