Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * oscP5sendreceive by andreas schlegel
- * example shows how to send and receive osc messages.
- * oscP5 website at http://www.sojamo.de/oscP5
- */
- import oscP5.*;
- import netP5.*;
- int pos_x=0,pos_y=0, x2 = 0, y2 = 0;
- //String b,d,f,h;
- String recMessage = "";
- String movement = "";
- OscP5 oscP5;
- NetAddress myRemoteLocation;
- void setup() {
- size(400,400);
- frameRate(25);
- /* start oscP5, listening for incoming messages at port 12000 */
- oscP5 = new OscP5(this,12001);
- myRemoteLocation = new NetAddress("192.168.1.169",12001);
- }
- void draw() {
- // background(0);
- if(recMessage.equals("left")){ // Ienākošā ziņa
- pos_x = pos_x-2;
- }
- if(recMessage.equals("right")){ // Ienākošā ziņa
- pos_x = pos_x+2;
- }
- if(recMessage.equals("up")){ // Ienākošā ziņa
- pos_y = pos_y-2;
- }
- if(recMessage.equals("down")){ // Ienākošā ziņa
- pos_y = pos_y+2;
- }
- fill(255,255,255);
- ellipse(pos_x, pos_y, 10, 10); // Mana elipse, kuru kustina otrs
- fill (255, 153, 204);
- ellipse(x2, y2, 10, 10); // Mana elipse, kuru es kustinu
- if (pos_x>=width) { // Lai neiziet ārā no laukuma ienākošā elipse
- pos_x=width;
- }
- if (pos_x<=0) {
- pos_x=0;
- }
- if (pos_y>=height) {
- pos_y=height;
- }
- if (pos_y<=0) {
- pos_y=0;
- } // Lai neiziet ārā no laukuma ienākošā elipse beigas
- if (x2>=width) { // Lai neiziet ārā no laukuma mana elipse
- x2=width;
- }
- if (x2<=0) {
- x2=0;
- }
- if (y2>=height) {
- y2=height;
- }
- if (y2<=0) {
- y2=0;
- } // Lai neiziet ārā no laukuma mana elipse beigas
- if (movement.equals("w")){ // Manas elipses kustības
- y2 = y2 - 2;
- }
- if (movement.equals("a")){
- x2 = x2 - 2;
- }
- if (movement.equals("s")){
- y2 = y2 + 2;
- }
- if (movement.equals("d")){ // Manas elipses kustības beigas
- x2 = x2 + 2;
- }
- }
- void mousePressed() { // Sūta ziņu uz peles klikšķi
- /* in the following different ways of creating osc messages are shown by example */
- OscMessage myMessage = new OscMessage("teksts");
- myMessage.add(123); /* add an int to the osc message */
- /* send the message */
- oscP5.send(myMessage, myRemoteLocation);
- }
- void keyPressed() {
- if (key == 'w') {
- OscMessage myMessage = new OscMessage("up");
- myMessage.add(123);
- oscP5.send(myMessage, myRemoteLocation);
- y2 = y2 - 2; // Lai mana elipse kustētos
- movement = "w";
- }
- if (key == 'a') {
- OscMessage myMessage = new OscMessage("left");
- myMessage.add(123);
- oscP5.send(myMessage, myRemoteLocation);
- x2 = x2 - 2; //Lai mana elipse kustētos
- movement = "a";
- }
- if (key == 's') {
- OscMessage myMessage = new OscMessage("down");
- myMessage.add(123);
- oscP5.send(myMessage, myRemoteLocation);
- y2 = y2 + 2; //Lai mana elipse kustētos
- movement = "s";
- }
- if (key == 'd') {
- OscMessage myMessage = new OscMessage("right");
- myMessage.add(123);
- oscP5.send(myMessage, myRemoteLocation);
- x2 = x2 + 2; //Lai mana elipse kustētos
- movement = "d";
- }
- if (key == '1') {
- background(random(255),random(255),random(255),random(255));
- }
- if (key == '2') {
- filter(BLUR, 6);
- }
- if (key == '3') {
- stroke(random(255));
- }
- if (key == '4') {
- stroke(255);
- line(x2, y2, 10, 10);
- }
- if (key == '5') {
- filter(INVERT);
- }
- if (key == '6'); {
- //frameRate(random(150));
- loop();
- }
- if (key == '7') {
- noLoop(); // Aptur
- }
- if (key == '8') {
- }
- if (key == '9') {
- }
- }
- /* incoming osc message are forwarded to the oscEvent method. */
- void oscEvent(OscMessage theOscMessage) {
- /* print the address pattern and the typetag of the received OscMessage */
- print("### received an osc message.");
- print(" addrpattern: "+theOscMessage.addrPattern());
- println(" typetag: "+theOscMessage.typetag());
- recMessage = theOscMessage.addrPattern();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement