Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //LAB 8
  2. //Crhistian David Lucumi
  3. //02/10/2014
  4. //Codigo Processing
  5.  
  6. import controlP5.*;
  7. import processing.serial.*;
  8.  
  9. PImage img;
  10. int iW2, iH2;
  11. int posX, posY;
  12. int velocity, angle;
  13. Serial serial;
  14. String val;
  15. void setup() {
  16. serial = new Serial(this, Serial.list()[0], 9600);
  17. // tamaƱo de la ventana
  18. size(800, 600);
  19. // carga la imagen en la variable
  20. img = loadImage("spaceship.gif");
  21. iW2 = img.width/2;
  22. iH2 = img.height/2;
  23. posX = (width/2)-iW2;
  24. posY = (height/2)-iH2;
  25. velocity = -5;
  26. angle = 0;
  27. }
  28.  
  29. void draw() {
  30. // limpia la ventana
  31. background(0);
  32. posX += velocity * sin(radians(angle));
  33. if (posX-iW2 < 0) posX = width;
  34. if (posX-iW2 > width) posX = iW2;
  35. posY += velocity * cos(radians(angle));
  36. if (posY-iH2 < 0) posY = height;
  37. if (posY-iH2 > height) posY = iH2;
  38. // dibuja la imagen
  39. pushMatrix();
  40. translate(posX-iW2, posY-iH2);
  41. rotate(radians(-angle));
  42. image(img, -iW2, -iH2);
  43. popMatrix();
  44. Cambio();
  45. }
  46.  
  47.  
  48. void Cambio(){
  49. if ( serial.available() > 0)
  50. { // If data is available,
  51. val = serial.readString()+""; // read it and store it in val
  52.  
  53. }
  54.  
  55. println(val); //print it out in the console
  56. if(val==null){val="0";}
  57. if(val.indexOf("arriba")>=0){
  58. velocity -= 5;
  59. val="";
  60. }
  61. if(val.indexOf("abajo")>=0){
  62. velocity += 5;
  63. val="";
  64. }
  65. if(val.indexOf("izq")>=0){
  66. angle += 5;
  67. val="";
  68. }
  69. if(val.indexOf("der")>=0){
  70. angle -= 5;
  71. val="";
  72. }
  73.  
  74.  
  75. }