viernes, 15 de enero de 2021

Proyecto

   Durante las últimas semanas de 2020 y las primeras de 2021, he estado trabajando en un Proyecto que consistía en que, sobre una imagen de fondo, en este caso una playa, debíamos posicionar una serie de elementos (sombrillas, gaviotas...) y que, al pulsar varias teclas del teclado cambiasen su estado de movimiento.

    Por eso mismo, a parte de sombrillas y gaviotas, también he añadido una mochila de donde salían unas gafas de buceo y unas palas de playa; un castillo y  un cubo de arena; una pelota que rebota; unos cangrejos que se mueven en sentido del eje OX u OY, entre otros. 

    Todo este proyecto ha podido ser realizado a partir de los conocimientos adquiridos una vez trabajadas las fichas y ejercicios de práctica y gracias a la indagación en Internet.


//Si pulsas la tecla 'q', aparece la pantalla de inicio con los elementos iniciales.
//Una vez pulsada la tecla 'q', mueve el ratón en el sentido del eje OX para mover a los cangrejos.
//Si pulsas la tecla 'e', aparace la pantalla final con los elementos finales.
//Una vez pulsada la tecla 'e', mueve el ratón en el sentido del eje OY para mover a los cangrejos.
//Cuando hayas pulsado la tecla 'e', pulsa el botón izquierdo del ratón para ver otro objeto.

PImage img;//imagenes
PImage img2;
PImage img3;
PImage img4;
PImage img5;
PImage img6;
PImage img7;
PImage img8;
PImage img9;
PImage img10;
PImage img11;
PImage img12;

int beginX = 137;//variables cocacola
int beginY = 200;
int endX = -100;
int endY = 60;
float x = beginX;
float y = beginY;
float step = 0.001;
float pct = 0.0;

float X = 375;//variables pelota
float Y = 400;
float speed = 0;
float gravedad = 0.1;

float x2=0.0;//variables gaviotas
float velocidad=3.0;
float radio=0.0;   



void setup()
{

  size(1000, 625);//ventana

  img = loadImage("playa1.jpg");//imagen de fondo
  img2 = loadImage("cubo.png");//cubo de arena
  img3 = loadImage("castillo.png");//castillo de arena
  img4 = loadImage("b1.png");//botella llena
  img5 = loadImage("b2.png");//botella vacia
  img6 = loadImage("mochila.png");//mochila
  img8 = loadImage("montalña.png");//alla
  img9 = loadImage("palas.png");//palas
  img10= loadImage("gafas.png");//gafas
  img11= loadImage("cartel.png");//cartel reciclar
  img12= loadImage("cangrejo.png");//cartel reciclar
}



void draw()
{
  image(img, 0, 0);//imagen de fondo

  if (key=='q' || key=='Q')//lo que ocurre al pulsar la tecla 'q'
  {
    img2.resize(0, 90);//elementos sin movimiento
    image(img2, 500, 475);//cubo
    img4.resize(0, 85);//cocacola 1
    image(img4, 300, 375);
    img6.resize(0, 90);//mochila
    image(img6, 425, 450);
    img12.resize(0, 75);
    image(img12, 150, 100+mouseY);
    image(img12, 775, mouseY);

    {
      img8.resize(0, 100);//montaña de arena
      image(img8, 550, 475);
    }
    strokeWeight(5);//sombrilla azul
    line(400, 300, 400, 500);
    strokeWeight(3);
    fill(#097169);
    triangle(400, 400, 350, 400, 400, 200);
    fill(#2CA79E);
    triangle(400, 400, 375, 400, 400, 200);
    fill(#03FFEC);
    triangle(400, 400, 450, 400, 400, 200);
    fill(#18C9BC);
    triangle(400, 400, 425, 400, 400, 200);

    strokeWeight(2);//vaso de naranjada lleno
    fill(#D8FFFC);
    rect(350, 450, 20, 35);
    fill(#FF8503);
    rect(350, 460, 20, 25);

    noFill();//gaviotas
    stroke(255, 255, 255);
    arc(435+x2, 65, 70, 100, PI+radio, PI+QUARTER_PI+radio);
    arc(365+x2, 65, 70, 100, -QUARTER_PI+radio, 0+radio);
    arc(545+x2, 85, 70, 30, PI+radio, PI+QUARTER_PI+radio);
    arc(475+x2, 85, 70, 30, -QUARTER_PI+radio, 0+radio);
    arc(370+x2, 115, 70, 50, PI+radio, PI+QUARTER_PI+radio);
    arc(300+x2, 115, 70, 50, -QUARTER_PI+radio, 0+radio);
    arc(330+x2, 75, 30, 20, PI+radio, PI+QUARTER_PI+radio);
    arc(300+x2, 75, 30, 20, -QUARTER_PI+radio, 0+radio);
    arc(460+x2, 115, 30, 20, PI+radio, PI+QUARTER_PI+radio);
    arc(430+x2, 115, 30, 20, -QUARTER_PI+radio, 0+radio);
    x2=x2+velocidad;//movimiento de las gaviotas
    if (x2>width+radio) {
      x2=-radio;
    }

    stroke(0, 0, 0);//sombrilla roja
    line(850, 285, 850, 300);
    strokeWeight(1);
    fill(255, 0, 0);
    triangle(850, 250, 840, 285, 860, 285);

    strokeWeight(3);//sombrilla caribeña
    line(900, 325, 900, 300);
    strokeWeight(1);
    fill(#957758);
    triangle(915, 300, 900, 250, 885, 300);
  }




  if (key=='e' || key=='E')//lo que ocurre cuando se pulsa la tecla 'e'
  {
    img2.resize(0, 90);//cubo de arena
    image(img2, 675, 500);
    img3.resize(0, 225);
    image(img3, 500, 375);
    img9.resize(0, 100);
    image(img9, 325, 500);
    img10.resize(0, 100);
    image(img10, 250, 475);
    img12.resize(0, 75);
    image(img12, 775+mouseX, 350);
    image(img12, mouseX, 450);
    if (mouseButton==LEFT) {
      img11.resize(0, 100);//cartel
      image(img11, 65, 130);
    }

    strokeWeight(5);//sombrilla azul 2
    line(400, 300, 400, 500);
    strokeWeight(3);
    fill(#097169);
    triangle(250, 350, 325, 350, 400, 200);
    fill(#2CA79E);
    triangle(325, 350, 400, 350, 400, 200);
    fill(#03FFEC);
    triangle(550, 350, 400, 350, 400, 200);
    fill(#18C9BC);
    triangle(475, 350, 400, 350, 400, 200);

    img5.resize(0, 50);//coca cola caida en el mar
    if (pct<1.0) {
      x=beginX + ((endX-beginX) * pct);
      y=beginY + ((endY-beginY) * pct);
      pct+=step;
    }
    image(img5, 137+x, 200+y);
    println(pct);

    strokeWeight(2);//vaso naranjada 2
    fill(#D8FFFC);
    rect(350, 450, 20, 35);
    fill(#FF8503);
    rect(350, 475, 20, 10);

    noFill();//gaviotas 2
    stroke(255, 255, 255);
    arc(425+x2, 55, 50, 25, PI+radio, PI+HALF_PI+radio);
    arc(375+x2, 55, 50, 25, PI+HALF_PI+radio, TWO_PI+radio);
    arc(525+x2, 85, 25, 10, PI+radio, PI+HALF_PI+radio);
    arc(500+x2, 85, 25, 10, PI+HALF_PI+radio, TWO_PI+radio);
    arc(325+x2, 75, 25, 10, PI+radio, PI+HALF_PI+radio);
    arc(300+x2, 75, 25, 10, PI+HALF_PI+radio, TWO_PI+radio);
    arc(350+x2, 115, 30, 20, PI+radio, PI+HALF_PI+radio);
    arc(320+x2, 115, 30, 20, PI+HALF_PI+radio, TWO_PI+radio);
    arc(460+x2, 115, 30, 20, PI+radio, PI+HALF_PI+radio);
    arc(430+x2, 115, 30, 20, PI+HALF_PI+radio, TWO_PI+radio);
    x2=x2+velocidad;
    if (x2>width+radio) {
      x2=-radio;
    }

    strokeWeight(2);//sombrilla lejana 2
    stroke(0, 0, 0);
    line(850, 270, 850, 300);
    strokeWeight(1);
    fill(255, 0, 0);
    triangle(850, 250, 825, 270, 875, 270);

    strokeWeight(3);//sombrilla caribeña 2
    line(900, 325, 900, 275);
    strokeWeight(1);
    fill(#957758);
    triangle(935, 275, 900, 250, 865, 275);

    fill(0, 250, 0);//pelota y movimiento
    ellipse (X, Y, 20, 20);
    Y = Y + speed;
    speed = speed + gravedad;
    if (Y > height) {
      speed = speed * (-0.95);
      Y=height;
    }
  }
}

 

No hay comentarios:

Publicar un comentario

Lo más visto

Semana 12 (11/01 - 15/01)