# Make two sketches comunicate

**URL:** <https://discourse.processing.org/t/make-two-sketches-comunicate/30755>\
**Category:** Coding Questions\
**Created:** [June 17, 2021, 9:08am UTC](https://discourse.processing.org/t/make-two-sketches-comunicate/30755 "2021-06-17T09:08:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fatou](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@fatou](https://discourse.processing.org/u/fatou)\
**Post date:** [June 17, 2021, 9:08am UTC](https://discourse.processing.org/t/make-two-sketches-comunicate/30755/1 "2021-06-17T09:08:53Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

Hello everyone!  
I´m working on a project that consists of two sketches that communicate. In the first one, you can draw with the mouse, and when you finish you have to click a button on the second sketch display to make your drawing appear (on the second display). The problem is that the drawing must appear slowly simulating the mouse path on the first window movement, but I can’t figure out how to make this happen.  
Here’s the code.  
PWindow win;

public void settings() {  
size(600, 600);  
}  
void setup() {  
win = new PWindow();  
}  
void draw() {  
if (mousePressed == true) {  
frameRate(999999999);  
fill(0);  
ellipse(mouseX, mouseY, 20, 20);  
}}  
void mouseDragged() {  
println(pmouseX, pmouseY);  
float relPosX = map(mouseX, 0, this.width, 0, 100);  
float relPosY = map(mouseY, 0, this.height, 0, 100);  
win.evokedFromPrimary(relPosX, relPosY);  
}  
class PWindow extends PApplet {  
ArrayList vectors = new ArrayList();  
PWindow() {  
super();  
PApplet.runSketch(new String {this.getClass().getSimpleName()}, this);  
}  
void evokedFromPrimary(float relPosX, float relPosY) {  
println(“evoked from primary”);  
float xPos = map(relPosX, 0, 100, 0, this.width);  
float yPos = map(relPosY, 0, 100, 0, this.height);  
vectors.add(new PVector(xPos, yPos));  
}  
void settings() {  
size(600, 600);  
}  
void setup() {  
background(150);  
}  
float x = 100;  
float y = 50;  
float w = 150;  
float h = 80;

void draw() {  
rect(x,y,w,h);  
fill(255);  
frameRate(999999999);  
if (mousePressed == true){  
background(150);  
//store the vector size before using to avoid ConcurrentModificationException  
float listLength = vectors.size();  
for(int i = 0; i \< listLength; i++) {  
fill(0);  
PVector v = vectors.get(i);  
ellipse(v.x, v.y,20, 20);  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 17, 2021, 11:00am UTC](https://discourse.processing.org/t/make-two-sketches-comunicate/30755/2 "2021-06-17T11:00:22Z")

</div>

Hello,

The guidelines in the Processing FAQ asks:

> **Please help us help you** by formatting your code on this forum. Formatted code is not only easier to read, it sometimes cannot be cut-pasted and run correctly if not formatted, making it difficult for others to help you.

Link to Processing FAQ:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

``:)`

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [June 17, 2021, 4:53pm UTC](https://discourse.processing.org/t/make-two-sketches-comunicate/30755/3 "2021-06-17T16:53:33Z")

</div>

It looks like youll want to temporarily store the mouse locations either using an array or other structure.
