Questions about Moving line and OSC
in
Contributed Library Questions
•
1 year ago
Hi,
I was wondering if someone could help me. I am working on a project that is basically a drawing application that sends out OSC messages to MaxMSP.
I have the drawing bit coding (hopefully), unfortunately im having some trouble with certain parts of the code.
Basically after the user has drawn their sketch in the drawing window and used whatever colors they want, i want them to be able to trigger a line that moves across the screen and as it moves across the screen it sends x and y coordinates for each color out to maxmsp.
I have coded in the red line to move across the screen the same way i successfully have done it in previous projects but it doesn't work with this project. It just leaves a trail of red lines filling the screen and covering the users sketch.
I really hope this makes sense to someone, If anyone can give me any help at all it would be greatly appreciated, especially issues relating to the line and OSC (unfortunately i don't no where to begin with OSC)
- import controlP5.*;
- ControlP5 controlP5;
- int myColorBackground = color(0,0,0);
- float linex = 0.0;
- boolean start = false; //boolean to start red line
- void setup()
- {
- //Set the size of the sketch
- size(500, 500);
- //Set the background color
- smooth();
- controlP5 = new ControlP5(this);
- Radio r = controlP5.addRadio("radio",20,20);
- r.deactivateAll(); // use deactiveAll to not make the first radio button active.
- r.add("black",0);
- r.add("red",1);
- r.add("green",2);
- r.add("blue",3);
- background(255,255,255);
- smooth();
- }
- void draw()
- {
- fill(#D6CFCF);
- rect(0,0,100,100);
- stroke(myColorBackground);
- strokeWeight(5);
- if(mousePressed)
- {
- line(mouseX, mouseY, pmouseX, pmouseY);
- }
- stroke(247,15,15,200); //colors the line red.
- strokeWeight(8); //determines the thinkness.
- if(start == true){ //if start = true draw a line which moves along the y axis 2 pixels at a time.
- linex = linex + 2.0;
- line(linex,0.0,linex,500);
- if(linex>=500){ //if the line gets to 500 on the y axis it starts off again back at 0.
- linex=0;
- }
- }
- if((keyPressed == true) && (key == 's')){
- start = true; //if the user presses 's' the line begins to move.
- }
- if((keyPressed == true) && (key == 't')){
- start = false; //if the user presses 't' the line stops.
- }
- }
- void radio(int theID) {
- switch(theID) {
- case(0):
- myColorBackground = color(0);
- break;
- case(1):
- myColorBackground = color(255,0,0);
- break;
- case(2):
- myColorBackground = color(0,255,0);
- break;
- case(3):
- myColorBackground = color(0,0,255);
- break;
- }
- }
1