Advertisement
Guest User

Untitled

a guest
May 6th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. /**
  2. * oscP5sendreceive by andreas schlegel
  3. * example shows how to send and receive osc messages.
  4. * oscP5 website at http://www.sojamo.de/oscP5
  5. */
  6.  
  7. import oscP5.*;
  8. import netP5.*;
  9. int pos_x=0,pos_y=0, x2 = 0, y2 = 0;
  10.  
  11.  
  12.  
  13. //String b,d,f,h;
  14. String recMessage = "";
  15. String movement = "";
  16. OscP5 oscP5;
  17. NetAddress myRemoteLocation;
  18.  
  19.  
  20.  
  21. void setup() {
  22. size(400,400);
  23. frameRate(25);
  24. /* start oscP5, listening for incoming messages at port 12000 */
  25. oscP5 = new OscP5(this,12001);
  26.  
  27. myRemoteLocation = new NetAddress("192.168.1.169",12001);
  28.  
  29. }
  30.  
  31.  
  32.  
  33. void draw() {
  34. // background(0);
  35. if(recMessage.equals("left")){ // Ienākošā ziņa
  36. pos_x = pos_x-2;
  37. }
  38.  
  39. if(recMessage.equals("right")){ // Ienākošā ziņa
  40. pos_x = pos_x+2;
  41. }
  42.  
  43. if(recMessage.equals("up")){ // Ienākošā ziņa
  44. pos_y = pos_y-2;
  45. }
  46.  
  47. if(recMessage.equals("down")){ // Ienākošā ziņa
  48. pos_y = pos_y+2;
  49. }
  50.  
  51. fill(255,255,255);
  52. ellipse(pos_x, pos_y, 10, 10); // Mana elipse, kuru kustina otrs
  53. fill (255, 153, 204);
  54. ellipse(x2, y2, 10, 10); // Mana elipse, kuru es kustinu
  55.  
  56. if (pos_x>=width) { // Lai neiziet ārā no laukuma ienākošā elipse
  57. pos_x=width;
  58. }
  59. if (pos_x<=0) {
  60. pos_x=0;
  61. }
  62. if (pos_y>=height) {
  63. pos_y=height;
  64. }
  65. if (pos_y<=0) {
  66. pos_y=0;
  67. } // Lai neiziet ārā no laukuma ienākošā elipse beigas
  68.  
  69. if (x2>=width) { // Lai neiziet ārā no laukuma mana elipse
  70. x2=width;
  71. }
  72. if (x2<=0) {
  73. x2=0;
  74. }
  75. if (y2>=height) {
  76. y2=height;
  77. }
  78. if (y2<=0) {
  79. y2=0;
  80. } // Lai neiziet ārā no laukuma mana elipse beigas
  81.  
  82. if (movement.equals("w")){ // Manas elipses kustības
  83. y2 = y2 - 2;
  84. }
  85.  
  86. if (movement.equals("a")){
  87. x2 = x2 - 2;
  88. }
  89.  
  90. if (movement.equals("s")){
  91. y2 = y2 + 2;
  92. }
  93.  
  94. if (movement.equals("d")){ // Manas elipses kustības beigas
  95. x2 = x2 + 2;
  96. }
  97. }
  98.  
  99. void mousePressed() { // Sūta ziņu uz peles klikšķi
  100. /* in the following different ways of creating osc messages are shown by example */
  101.  
  102. OscMessage myMessage = new OscMessage("teksts");
  103.  
  104. myMessage.add(123); /* add an int to the osc message */
  105.  
  106. /* send the message */
  107. oscP5.send(myMessage, myRemoteLocation);
  108. }
  109.  
  110. void keyPressed() {
  111. if (key == 'w') {
  112. OscMessage myMessage = new OscMessage("up");
  113. myMessage.add(123);
  114. oscP5.send(myMessage, myRemoteLocation);
  115. y2 = y2 - 2; // Lai mana elipse kustētos
  116. movement = "w";
  117. }
  118. if (key == 'a') {
  119. OscMessage myMessage = new OscMessage("left");
  120. myMessage.add(123);
  121. oscP5.send(myMessage, myRemoteLocation);
  122. x2 = x2 - 2; //Lai mana elipse kustētos
  123. movement = "a";
  124. }
  125. if (key == 's') {
  126. OscMessage myMessage = new OscMessage("down");
  127. myMessage.add(123);
  128. oscP5.send(myMessage, myRemoteLocation);
  129. y2 = y2 + 2; //Lai mana elipse kustētos
  130. movement = "s";
  131. }
  132. if (key == 'd') {
  133. OscMessage myMessage = new OscMessage("right");
  134. myMessage.add(123);
  135. oscP5.send(myMessage, myRemoteLocation);
  136. x2 = x2 + 2; //Lai mana elipse kustētos
  137. movement = "d";
  138. }
  139.  
  140.  
  141.  
  142. if (key == '1') {
  143. background(random(255),random(255),random(255),random(255));
  144. }
  145.  
  146. if (key == '2') {
  147. filter(BLUR, 6);
  148. }
  149.  
  150. if (key == '3') {
  151. stroke(random(255));
  152. }
  153.  
  154. if (key == '4') {
  155. stroke(255);
  156. line(x2, y2, 10, 10);
  157. }
  158.  
  159. if (key == '5') {
  160. filter(INVERT);
  161. }
  162.  
  163. if (key == '6'); {
  164. //frameRate(random(150));
  165. loop();
  166. }
  167.  
  168. if (key == '7') {
  169. noLoop(); // Aptur
  170. }
  171.  
  172. if (key == '8') {
  173. }
  174.  
  175. if (key == '9') {
  176.  
  177. }
  178.  
  179. }
  180.  
  181. /* incoming osc message are forwarded to the oscEvent method. */
  182. void oscEvent(OscMessage theOscMessage) {
  183. /* print the address pattern and the typetag of the received OscMessage */
  184. print("### received an osc message.");
  185. print(" addrpattern: "+theOscMessage.addrPattern());
  186. println(" typetag: "+theOscMessage.typetag());
  187. recMessage = theOscMessage.addrPattern();
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement