map question
in
Contributed Library Questions
•
2 months ago
hi, this code sends x/y values via osc
how do i scale those values, so the values sent for x is between 0,1 not 0, width ?
i know how to use map but cant figure out how to do this in this particular code
how do i scale those values, so the values sent for x is between 0,1 not 0, width ?
i know how to use map but cant figure out how to do this in this particular code
- import oscP5.*;
- import netP5.*;
- OscP5 oscP5;
- NetAddress panel_location;
- int x0, y0, x1, y1;
- void setup() {
- size(640, 480);
- frameRate(60);
- background(0);
- // start oscP5
- oscP5 = new OscP5(this,12009);
- panel_location = new NetAddress("127.0.0.1",12000);
- }
- void draw() {
- background(0);
- fill(255, 0, 0);
- rect(x0, y0, 50, 50);
- fill(0, 255, 0);
- rect(x1, y1, 50, 50);
- send_pos(0, x0, y0);
- send_pos(1, x1, y1);
- }
- void mouseDragged() {
- if (mouseButton == LEFT) {
- x0 = mouseX;
- y0 = mouseY;
- //fill(255, 0, 0);
- } else if (mouseButton == RIGHT) {
- //fill(0, 255, 0);
- x1 = mouseX;
- y1 = mouseY;
- }
- }
- void mousePressed() {
- if (mouseButton == LEFT) {
- x0 = mouseX;
- y0 = mouseY;
- //fill(255, 0, 0);
- } else if (mouseButton == RIGHT) {
- //fill(0, 255, 0);
- x1 = mouseX;
- y1 = mouseY;
- }
- }
- void send_pos(int id, int x, int y){
- OscMessage myMessage = new OscMessage("/location");
- myMessage.add(id);
- myMessage.add(1);
- myMessage.add(x);
- myMessage.add(y);
- oscP5.send(myMessage, panel_location);
- myMessage.clearArguments();
- }
1