Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.serial.*;
- PImage img; // Declare variable "a" of type PImage
- int x=350;
- int y=350;//el punto centro de la pantalla
- int grados=0;//inicio de grados en el que se encuentra el rectangulo
- Serial port;//puerto por el que vamos a recibir los datos
- int valor = 0;
- int[] wormx = new int[10];
- int[] wormy = new int[10];
- void setup()
- {
- size(640, 360);
- // The image file must be in the data folder of the current sketch
- // to load successfully
- img = loadImage("nav.png"); // Load the image into the program
- port = new Serial(this, Serial.list()[0], 9600);
- size(1000,700);//tamaño de la ventana
- frameRate(60);// especifica el numero de fotogramas que muestra por segundo
- smooth();//suavizar
- fill(255,120,0);//color del cuadro
- }
- void draw ()
- {
- while (port.available() > 0)
- {
- String cadena ="00"+port.readString(); //Lectura de datos desde arduino
- valor = int(cadena.substring(2,cadena.length()));
- println(cadena + ":" + valor);
- }
- background (0,0,0);//color de fondo
- pushMatrix();//entrada a la pila de matriz
- translate(x, y);//trasladamos el rectangulo en pantalla con respecto a su estado
- rotate(radians(grados));//rotamos el rectangulo el numero de grados indicado
- // Displays the image at its actual size at point (0,0)
- image(img, 0, 0);
- // Displays the image at point (0, height/2) at half of its size
- image(img, 0, height, img.width, img.height);
- popMatrix();//restaura la pila de matriz
- //Condiciones que dependen del los valores recibidos desde arduino (movimientos de joystick)
- if (valor == 1)
- {
- valor=0;
- y-=10;
- if (y<10) y=690;
- }
- if (valor == 2)
- {
- valor=0;
- y+=10;
- if (y>670) y=10;
- }
- if (valor == 3)
- {
- valor=0;
- x+=10;
- if (x>670) x=10;
- }
- if (valor == 4)
- {
- valor=0;
- x-=10;
- if (x<10) x=690;
- }
- if (valor == 13)
- {
- valor=0;
- y-=10;
- if (y>670) y=10;
- x+=10;
- if (x<10) x=690;
- }
- if (valor == 14)
- {
- valor=0;
- y-=10;
- if (y>670) y=690;
- x-=10;
- if (x<10) x=10;
- }
- if (valor == 24)
- {
- valor=0;
- y+=10;
- if (y>670) y=690;
- x-=10;
- if (x<10) x=690;
- }
- if (valor == 23)
- {
- valor=0;
- y+=10;
- if (y>670) y=690;
- x+=10;
- if (x<10) x=690;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement