you can use a list of floats:
float[] list = new float[8];
void setup() {
size (700, 700);
}
void draw() {
background(255);
list = new float[8];
list[0]=mouseX+1;
list[1]=mouseY-5;
list[2]=mouseX+75;
list[3]=mouseY+70;
list[4]=mouseX+10+mouseY+80;
list[5]=mouseX+1;
list[6]=mouseY+85;
list[7]=mouseX;
drawQuad(list);
}
void drawQuad(float[] list_) {
quad(list[0], list[1],
list[2], list[3],
list[4], list[5],
list[6], list[7]
);
}
Let’s put the storing in a function too
float[] list = new float[8];
void setup() {
size (700, 700);
}
void draw() {
background(255);
storeQuad();
drawQuad(list);
}
// ---------------------------------------------------------
void storeQuad() {
list[0]=mouseX+1;
list[1]=mouseY-5;
list[2]=mouseX+75;
list[3]=mouseY+70;
list[4]=mouseX+10+mouseY+80;
list[5]=mouseX+1;
list[6]=mouseY+85;
list[7]=mouseX;
}
void drawQuad(float[] list_) {
quad(list[0], list[1],
list[2], list[3],
list[4], list[5],
list[6], list[7]
);
}
Next version
You can store forms/quads in a list on mouse click
- here you can display multiple forms:
float[] list = new float[8];
// Two parallel ArrayLists
ArrayList<float[]> listOfQuads = new ArrayList();
ArrayList<Integer> listOfColors = new ArrayList(); // for Color
void setup() {
size (700, 700);
}
void draw() {
background(255);
int i=0;
for (float[] floatList : listOfQuads) {
fill(listOfColors.get(i));
drawQuad(floatList);
i++;
}//for
noFill();
storeQuad();
drawQuad(list);
}//func
// ---------------------------------------------------------
void mousePressed() {
listOfQuads.add(copyList(list));
listOfColors.add(color(random(255), 0, 0));
}
float[] copyList(float[] list_) {
float[] l1=new float [8];
int i=0;
for (float floatValue : list_) {
l1[i]=floatValue;
i++;
}
return l1;
}
void storeQuad() {
list[0]=mouseX+1;
list[1]=mouseY-5;
list[2]=mouseX+75;
list[3]=mouseY+70;
list[4]=mouseX+10+mouseY+80;
list[5]=mouseX+1;
list[6]=mouseY+85;
list[7]=mouseX;
}
void drawQuad(float[] list_) {
quad(list_[0], list_[1],
list_[2], list_[3],
list_[4], list_[5],
list_[6], list_[7]
);
}
Code a bit simplified
// draws quads according to mouse pos; click mouse to store the current quad.
float[] list = new float[8];
// Two parallel ArrayLists
ArrayList<float[]> listOfQuads = new ArrayList();
ArrayList<Integer> listOfColors = new ArrayList(); // for Color
// ---------------------------------------------------------
void setup() {
size (700, 700);
}
void draw() {
background(255);
// draw old quads
drawExistingQuads();
// the current quad
noFill();
storeQuad();
drawQuad(list);
}//func
// ---------------------------------------------------------
void mousePressed() {
// store current quad
listOfQuads.add(list.clone()); // using clone() here
listOfColors.add(color(random(255), 0, 0));
}
// ---------------------------------------------------------
void drawExistingQuads() {
// draw old quads
int i=0;
for (float[] floatList : listOfQuads) {
fill(listOfColors.get(i));
drawQuad(floatList);
i++;
}//for
}//func
void storeQuad() {
// current quad
list[0]=mouseX+1;
list[1]=mouseY-5;
list[2]=mouseX+75;
list[3]=mouseY+70;
list[4]=mouseX+10+mouseY+80;
list[5]=mouseX+1;
list[6]=mouseY+85;
list[7]=mouseX;
}
void drawQuad(float[] list_) {
// draw the quad indicated by list_
quad(
list_[0], list_[1],
list_[2], list_[3],
list_[4], list_[5],
list_[6], list_[7]
);
}
//
Minor changes
// draws quads according to mouse pos; click mouse to store the current quad.
// the current quad
float[] list = new float[8];
// Two parallel ArrayLists store the quad
ArrayList<float[]> listOfQuads = new ArrayList();
ArrayList<Integer> listOfColors = new ArrayList();
// ---------------------------------------------------------
void setup() {
size (700, 700);
}//func
void draw() {
background(255);
// draw old quads
drawExistingQuads();
// the current quad
noFill();
storeQuad(list);
drawQuad(list);
}//func
// ---------------------------------------------------------
void mousePressed() {
// store current quad
listOfQuads.add(list.clone());
listOfColors.add(color(random(255), random(255), random(255)));
}//func
// ---------------------------------------------------------
void drawExistingQuads() {
// draw old quads - using both ArrayLists
int i=0;
for (float[] floatList : listOfQuads) {
fill(listOfColors.get(i));
drawQuad(floatList);
i++;
}//for
}//func
void storeQuad(float[] list_) {
// current quad
list_[0]=mouseX+1;
list_[1]=mouseY-5;
list_[2]=mouseX+75;
list_[3]=mouseY+70;
list_[4]=mouseX+10+mouseY+80;
list_[5]=mouseX+1;
list_[6]=mouseY+85;
list_[7]=mouseX;
}//func
void drawQuad(float[] list_) {
// draw the quad indicated by list_
quad(
list_[0], list_[1],
list_[2], list_[3],
list_[4], list_[5],
list_[6], list_[7]
);
}//func
//