Press left and right arrows to move the character. Press 's' to make the sunrise
xxxxxxxxxx
let imgR;
let x = -45
let y = 185
function preload() {
imgRR = loadImage('ninjaRedRight.png');
imgGR = loadImage('ninjaGreenRight.png');
}
function setup() {
background(50);
createCanvas(600, 400);
rectMode(CENTER)
c1 = color(61,139,255)
c2 = color(205,201,0)
}
function draw() {
// background(50);
noStroke()
//grass
fill(139, 191, 78)
quad(0,325,600,325,600,400,0,400)
//mountain right
fill(59, 9, 71)
triangle(370,145,70,325,320,325)
fill(80, 12, 97)
triangle(370,145,320,325,575,325)
//mountain left
fill(59, 9, 71)
triangle(170,125,-50,325,105,325)
fill(80, 12, 97)
triangle(170,125,105,325,330,325)
//tree left
fill(120, 58, 22)
rect(260,302,12,45)
fill(3,138,48)
triangle(240,302,260,302,260,240)
fill(4,181, 63)
triangle(280,302,260,302,260,240)
//tree right
fill(120, 58, 22)
rect(310,302,12,45)
fill(3,138,48)
triangle(275,302,310,302,310,220)
fill(4,181, 63)
triangle(345,302,310,302,310,220)
//cloud left
fill(225)
ellipse(100,60,100,45)
circle(80,45,35)
circle(100,38,35)
circle(123,50,35)
//cloud middle
fill(225)
ellipse(250,80,100,45)
circle(230,65,35)
circle(250,58,35)
circle(273,70,35)
//cloud right
fill(225)
ellipse(470,80,100,45)
circle(450,65,35)
circle(470,58,35)
circle(493,70,35)
mousePressed()
}
function mousePressed(){
if (mouseIsPressed && x < 390)
{
image(imgGR,x,y,240,340)
}
else
{
image(imgRR,x,y,240,340)
}
}
//move image
function keyPressed(){
if(keyCode == RIGHT_ARROW)
{
x += 15
}
if(keyCode == LEFT_ARROW)
{
x -= 15
}
if (x < -45)
{
x = 390
}
if(x > 390)
{
x = -45
}
if (key == 's')
{
setGradient(c1,c2)
}
}
function setGradient(c1,c2)
{
noFill()
for(var y = 0; y < 325; y++)
{
var inter = map(y, 0, height, 0, 1)
var c = lerpColor(c1,c2,inter)
stroke(c)
line(0, y, width, y);
}
}