We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I want to connect these two codes, but don't know how to do it. Basically, what I want to do is when mouse is pressed, it changes to the second code.
Here is first code
int a = 0;
void setup(){
fullScreen();
rectMode(CENTER);
frameRate(100);
noCursor();
}
void draw() {
int W = displayWidth;
int H = displayHeight;
if(a < displayWidth ) {
background(0);
translate(W/2, H/2);
for (float i = -3000; i < W; i += 200){
if(a+i <= displayWidth){
noFill();
strokeWeight(10);
rect(0, 0, a + i, (a + i) * H / W);
if(a + i > 0) {
stroke(255);
} else {
noStroke();
}
}
}
//noFill();
//strokeWeight(10);
//rect(0, 0, a, a * H / W);
//stroke(255);
//a = a - 10;
a = a + 1;
} else {
a = 0;
}
}
Here is the second code:
import processing.serial.*;
Serial myPort;
float angleX = 0.0;
float angleY = 0.0;
void setup(){
println(Serial.list());
myPort = new Serial(this, Serial.list()[1], 9600);
fullScreen();
noFill();
stroke(255);
strokeWeight(4);
//frameRate(60);
}
String val;
void draw() {
float startX = 100;
float startY = 20;
float x = 200;
float two = sqrt(2);
float a = x / two;
float b = x - a;
if (myPort.available() > 0) {
String val = myPort.readStringUntil('\n');
String[] list = split(val, 'a');
if(val != null) {
int number = int (list[0].trim());
int number2 = int (list[1].trim());
background(0);
// left
pushMatrix();
translate(startX, startY + b);
rotate(radians(angleX));
rect(0, 0, b, a);
popMatrix();
pushMatrix();
translate(startX, startY + a + b);
rotate(radians(-angleY));
rect(0, 0, b, a);
popMatrix();
pushMatrix();
translate(startX, startY + 2 * a + b);
rotate(radians(angleX*3));
rect(0, 0, b, a);
popMatrix();
pushMatrix();
translate(startX, startY + 3 * a + b);
rotate(radians(-angleY*2));
rect(0, 0, b, a);
popMatrix();
// top
pushMatrix();
translate(startX + b, startY);
rotate(radians(angleY*5));
rect(0, 0, a, b);
popMatrix();
pushMatrix();
translate(startX + a + b, startY);
rotate(radians(-angleX*2));
rect(0, 0, a, b);
popMatrix();
// right
pushMatrix();
translate(startX + b + a * 2, startY + b);
rotate(radians(angleY*7));
rect(0, 0, b, a);
popMatrix();
pushMatrix();
translate(startX + b + a * 2, startY + a + b);
rotate(radians(-angleX*3));
rect(0, 0, b, a);
popMatrix();
pushMatrix();
translate(startX + b + a * 2, startY + 2 * a + b);
rotate(radians(angleY));
rect(0, 0, b, a);
popMatrix();
pushMatrix();
translate(startX + b + a * 2, startY + 3 * a + b);
rotate(radians(-angleX*5));
rect(0, 0, b, a);
popMatrix();
// bottom
pushMatrix();
translate(startX + b, startY + a * 4 + b);
rotate(radians(angleY*3));
rect(0, 0, a, b);
popMatrix();
pushMatrix();
translate(startX + a + b, startY + a * 4 + b);
rotate(radians(-angleX));
rect(0, 0, a, b);
popMatrix();
angleX = number;
angleY = number2;
// debugging
textSize(32);
text(number, width/2, height/2 + 20);
text(number2, width/2, height/2 - 20);
if(number == 357 && number2 == 357){
text("done", width/2 + 100, height/2 + 20);
}
}
}
}
Answers
Okay! You have two codes, and they both have this format:
Right?
In the first code, rename
setup()
tosetup_first()
and remove the call tofullScreen()
. Then renamedraw()
todraw_first()
.In the second code, rename
setup()
tosetup_second()
and remove the call tofullScreen()
. Then renamedraw()
todraw_second()
.Now your merged code looks like this: