<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with mousepressed() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=mousepressed%28%29</link>
      <pubDate>Sun, 08 Aug 2021 19:13:00 +0000</pubDate>
         <description>Tagged with mousepressed() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedmousepressed%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>change colour on mouse press</title>
      <link>https://forum.processing.org/two/discussion/27362/change-colour-on-mouse-press</link>
      <pubDate>Mon, 26 Mar 2018 10:10:11 +0000</pubDate>
      <dc:creator>aarony</dc:creator>
      <guid isPermaLink="false">27362@/two/discussions</guid>
      <description><![CDATA[<p>I have got to this point, using help from this post <a href="https://forum.processing.org/two/discussion/20148/beginner-question-how-to-change-color-of-the-ellipse-everytime-the-mouse-is-pressed" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/20148/beginner-question-how-to-change-color-of-the-ellipse-everytime-the-mouse-is-pressed</a></p>

<p>and have changed it a bit to get the following:</p>

<p>color[] colours = new color[3];
int c = 0;</p>

<p>void setup() {
  size(500, 500);
  colours[0] = color(255, 0, 0);
  colours[1] = color(0, 255, 0);
  colours[2] = color(0, 0, 255);
}</p>

<p>void draw() {
  if (mousePressed == true &amp;&amp; (mouseButton == LEFT)) {</p>

<pre><code>fill(colours[c]);


ellipse(mouseX, mouseY, 50, 50);

c = (c + 1) % 3;
</code></pre>

<p>}
}</p>

<p>However, when I click the left mouse button, it continuously displays circles until the mouse click is released. Instead I wish it to display one circle of one colour per click.
I.E.
1st click = red circle at mouse coordinates, release mouse click
2nd click = green circle at mouse coordinates, release mouse click
3rd click  = blue circle at mouse coordinates, release mouse click
4th click = returns to red circle, release mouse click
And so on...</p>

<p>How would I go about doing this?</p>

<p>Thanks for any help.</p>
]]></description>
   </item>
   <item>
      <title>Trying to add CP5 buttons using Mouse events with UDP network communication</title>
      <link>https://forum.processing.org/two/discussion/26147/trying-to-add-cp5-buttons-using-mouse-events-with-udp-network-communication</link>
      <pubDate>Sun, 28 Jan 2018 01:51:02 +0000</pubDate>
      <dc:creator>Ragooman</dc:creator>
      <guid isPermaLink="false">26147@/two/discussions</guid>
      <description><![CDATA[<p>I'm still learning how to make GUI screens and this is my first attempt to add buttons together with mouse events. I've mostly used a command line style interfaces in the past over the serial port or network. This time I wanted to have a button send the command line in text over the network. So I started using the CP5 library and the mouse events function. But when I try this, something appears to be out of sync. This is a project using the RPI as an instrument to collect data.</p>

<p>But when I add the additional CP5 library and the mouse event function, in 'udp_server5', the packet messages are received out of sync. I don't get the correct packet when I click on any of the buttons. They seem to be out of sync by one or two messages. I would get the correct packet after a couple of mouse clicks. I use the console to print debug messages so I can follow the state of the program. I added some screenshots below to show what happens. The 'udp_server5' code is also show below.</p>

<p>I use the same python code on the RPI for either udp server code on the PC. I already worked out the udp network communications with my RPI with the previous code show below in 'udp_server4'. There, I just use a command line to send a text command over the network. My RPI is running python to decode the command, then acknowledge the command back to the server, along with a packet sequence# so I can know if I'm getting the correct packet. At the moment, I only decode 3 commands.</p>

<p>In the udp_server5 code, I use a button flag to keep track of which button I click on. From looking at the debug messages in the console, I see the button events occur last. I was expecting them to occur first when I click on any button. So the button flag doesn't get updated with the current value. And so the wrong command is sent over the network. When I click on the same button again, the button flag is finally updated with the correct value, so then the right command is sent over the network.</p>

<p>Another item I don't understand from looking at the debug messages. When I start the program I see Control Events already in my console from the 3 buttons I created without clicking on anything. so this also causes my Button Flag to begin with the wrong value.</p>

<p>I'm currently using Processing ver3.3.6. And I used the CP5 library examples from Processing to add the buttons to my code in 'udp server 5'. And I found the mouse event function on the reference page and in the examples. But I'm not sure if these steps are combined in the correct order.</p>

<p>Could I be using the wrong coding technique ?</p>

<p><strong>Here's the code for 'udp_server4'</strong></p>

<pre><code>//=====================================================
//UDP Server 4
//press any key to send a command message from the Server to RPI client
//The RPI client will reply back to the Server
//Send:    Server PC  (10.0.0.3)  to RPI Client(10.0.0.10)
//Receive: RPI Client (10.0.0.10) to Server PC (10.0.0.3)
//ControlP5 Library Buttons
//-----------------------------------------------------------------------------------
// import UDP library
import hypermedia.net.*;
// import Button library
//import controlP5.*;
//
UDP udp;  //define the UDP object
//ControlP5 cp5;
//
//-----------------------------------------------------------------------------------
//
int myColor = color(255);
int c1,c2;
int c = 0;
int indent = 25;
int ButtonFlag;
float n,n1;
//
String message1 = "";
String message2 = "00000";
String status = "";
char command;
//
//--------------------------------------------------------------------------------
void setup() 
{
  //create a new datagram connection
  //From Client to Server=5555
  //From Server to Client=5556
  //
  int UDP_port_rcv = 5555;
  int UDP_port_snd = 5556;
  //
  smooth();
  size(800, 600);
  background(128);
  //
  fill(255);  // Set fill to white
  noStroke();
  rect(350, 550, 55, 25, 5);
  //
  text("UDP SERVER 4\nEnter Command for client. ", indent, 40);
  //
  println("============================");
  println("UDP SERVER 4: ");
  //noStroke();
  //
  //--------------------------------------------------------------------------------
  // load a new font. ControlFont is a wrapper for processing's PFont
  PFont pfont = createFont("Courier",20,true); // use true/false for smooth/no-smooth
  //ControlFont font = new ControlFont(pfont,20); //font size for Text Field
  //
  //-----------------------------------
  udp = new UDP( this, UDP_port_rcv );  
  //
  //printout the connection activity
  //udp.log( true );
  //
  // wait for incoming message
  udp.listen( true );           
}

//--------------------------------------------------------------------------------
//process events
//keep draw() here to continue looping
void draw()
{
  //background(128);
  //clear text area for packet message
  fill(125);  // Set fill to gray
  stroke(1);
  rect(25,475,300,90);
  //
  //clear area for packet sequence#
  fill(255);  // Set fill to white
  noStroke();
  rect(350, 550, 55, 25, 5);
  //
  //display packet message
  fill(0);  // Set fill to black
  text("CMD: " + command,indent,500);
  text("RCVD: " + message1,indent,525);
  text("STATUS: " + status,indent,550);
  //
  //display packet sequence#
  fill(0);  // Set fill to black
  text(message2, 360, 550, 55, 55);
  //
}

//--------------------------------------------------------------------------------
//On key pressed event:
//send the command to the client
void keyPressed() 
{
  String ip       = "10.0.0.10"; // the Client IP address
  int port_snd    = 5556;        // Sent Port
  String commandS;
  switch (key) 
  {
    case 'c':
      command = key;
      status = "GOOD";
      //
      commandS = str(command);
      udp.send(commandS, ip, port_snd );   // the message to send
      println("&gt;&gt;&gt;Key Command Sent");
      break;
    case 'x':
      command = key;
      status = "GOOD";
      //
      commandS = str(command);
      udp.send(commandS, ip, port_snd );   // the message to send
      println("&gt;&gt;&gt;Key Command Sent");
      break;
    case 'z':
      command = key;
      status = "GOOD";
      //
      commandS = str(command);
      udp.send(commandS, ip, port_snd );   // the message to send
      println("&gt;&gt;&gt;Key Command Sent");
      break;
    default:
      command = key;
      message1 = "";
      status = "KEY COMMAND INCORRECT";
      println("***Incorrect Key Command***");
  }
}

//--------------------------------------------------------------------------------
//Extended handler
//In the Extended Handker,
//The two arguments representing in order, 
//the sender IP address and the sender port
public void receive( byte[] data, String ip, int port ) 
{
  // get the "real" message =
  // forget the ";\n" at the end &lt;-- !!! only for a communication with Pd !!!
  //data = subset(data, 0, data.length-2);

  //String message = new String( data );
  message1 = new String(data);
  //Extract Packet Sequence#
  message2 = new String(message1.substring(35,message1.length()));

  //print the result
  println( "RCVD: "+ip+":"+port+" = "+""+message1);
  //print packet sequence#
  println( "RCVD: "+message2);
  //
}

//=============================================================
</code></pre>

<p><strong>Here's the code for 'udp_server5'</strong></p>

<pre><code>//=====================================================
//UDP Server 5
//click mouse to send a command message from the Server to RPI client
//Send:    Server PC  (10.0.0.3)  to RPI Client(10.0.0.10)
//Receive: RPI Client (10.0.0.10) to Server PC (10.0.0.3)
//ControlP5 Library Buttons
//-----------------------------------------------------------------------------------
// import UDP library
import hypermedia.net.*;
// import Button library
import controlP5.*;
//
UDP udp;  //define the UDP object
ControlP5 cp5;
//
//-----------------------------------------------------------------------------------
//
int myColor = color(255);
int c1,c2;
int c = 0;
int indent = 25;
int ButtonFlag;
float n,n1;
//
String message1 = "";
String message2 = "00000";
String status = "";
char command = ' ';
//
String ip       = "10.0.0.10"; // the Client IP address
int port_snd    = 5556;        // Sent Port
byte[] data;
//
//--------------------------------------------------------------------------------
void setup() 
{
  //create a new datagram connection
  //From Client to Server=5555
  //From Server to Client=5556
  //
  int UDP_port_rcv = 5555;
  int UDP_port_snd = 5556;
  //
  smooth();
  size(800, 600);
  background(128);
  //
  fill(255);  // Set fill to white
  rect(350, 550, 55, 25, 5);
  //
  text("UDP SERVER 5\nEnter Command for client. ", indent, 40);
  //
  println("============================");
  println("UDP SERVER 5: ");
  //noStroke();
  //
  //--------------------------------------------------------------------------------
  // load a new font. ControlFont is a wrapper for processing's PFont
  PFont pfont = createFont("Courier",20,true); // use true/false for smooth/no-smooth
  ControlFont font = new ControlFont(pfont,20); //font size for Text Field
  //
  cp5 = new ControlP5(this);
  cp5.enableShortcuts();
  frameRate(50);
  //
  // create a new button 
  cp5.addButton("RESET")
     .setValue(0)
     .setPosition(100,100)
     .setSize(100,39)
     .setId(2);
     ;
  // create a new button 
  cp5.addButton("OHM")
     .setValue(100)
     .setPosition(100,140)
     .setSize(100,39)
     .setId(2);
     ;
  // create a new button 
  cp5.addButton("VOLTS")
     .setPosition(100,180)
     .setSize(100,39)
     .setValue(0)
     .setId(2);
     ;
  //--------------------------------------------------------------------------------
  // change the font and content of the captionlabels 
  // for both buttons create earlier.
  cp5.getController("RESET")
     .getCaptionLabel()
     .setFont(font)
     .toUpperCase(false)
     .setSize(16)
     ;
  //   
  cp5.getController("OHM")
     .getCaptionLabel()
     .setFont(font)
     .toUpperCase(false)
     .setSize(16)
     ;
  //   
  cp5.getController("VOLTS")
     .getCaptionLabel()
     .setFont(font)
     .toUpperCase(false)
     .setSize(16)
     ;
  //-----------------------------------
  udp = new UDP( this, UDP_port_rcv );  
  //
  //printout the connection activity
  //udp.log( true );
  //
  // and wait for incoming message
  udp.listen( true );           
}

//--------------------------------------------------------------------------------
//process events
// keep draw() here to continue looping
void draw()
{
  //background(128);
  //clear text area for packet message
  fill(125);  // Set fill to gray
  stroke(1);
  rect(25,475,300,90);
  //
  //clear number area for packet sequence#
  fill(255);  // Set fill to white
  noStroke();
  rect(350, 550, 55, 25, 5);
  //
  //display packet message
  fill(0);  // Set fill to black
  text("CMD: " + command,indent,500);
  text("RCVD: " + message1,indent,525);
  text("STATUS: " + status,indent,550);
  //
  //display packet sequence#
  fill(0);  // Set fill to black
  text(message2, 360, 550, 55, 55);
  //
}

//--------------------------------------------------------------------------------
//On key pressed event:
//send the command to the client

void keyPressed() 
{
  String ip       = "10.0.0.10"; // the Client IP address
  int port_snd    = 5556;        // Sent Port
  String commandS;
  println("------------------------------------------");
  switch (key) 
  {
    case 'c':
      command = key;
      status = "GOOD";
      //
      commandS = str(command);
      udp.send(commandS, ip, port_snd );   // the message to send
      println("&gt;&gt;&gt;Key Command Sent");
      break;
    case 'x':
      command = key;
      status = "GOOD";
      //
      commandS = str(command);
      udp.send(commandS, ip, port_snd );   // the message to send
      println("&gt;&gt;&gt;Key Command Sent");
      break;
    case 'z':
      command = key;
      status = "GOOD";
      //
      commandS = str(command);
      udp.send(commandS, ip, port_snd );   // the message to send
      println("&gt;&gt;&gt;Key Command Sent");
      break;
    default:
      command = key;
      message1 = "";
      status = "KEY COMMAND INCORRECT";
      println("***Incorrect Key Command***");
  }
}

//-----------------------------------------------------------------------

void mousePressed()
{
  println("------------------------------------------");
  switch (ButtonFlag)
  {
    case 1:
      command = 'c';
      status = "GOOD RESET COMMAND";
      println("Switch: Button Flag  from RESET: "+ButtonFlag);
      break;
    case 2:
      command = 'z';
      message1 = "";
      status = "GOOD OHM COMMAND";
      println("Switch: Button Flag  from OHM: "+ButtonFlag);
      break;
    case 3:
      command = 'x';
      message1 = "";
      status = "GOOD VOLTS COMMAND";
      println("Switch: Button Flag  from VOLTS: "+ButtonFlag);
      break;
  }  
  sendcmd();
}

//--------------------------------------------------------------------------------
//Transmit Command
public void sendcmd() 
{
  //String ip       = "10.0.0.10"; // the Client IP address
  //int port_snd    = 5556;        // Sent Port
  //
  println("------------------------------------------");
  String commandS = str(command);
      udp.send(commandS, ip, port_snd );   // the message to send
      println("&gt;&gt;&gt;Command Sent");
}

//--------------------------------------------------------------------------------
// Extended handler
//In the Extended Handker,
//The two arguments representing in order, 
//the sender IP address and the sender port
public void receive( byte[] data, String ip, int port ) 
{
  //String message = new String( data );
  println("------------------------------------------");
  message1 = new String(data);
  message2 = new String(message1.substring(35,message1.length()));

  //print the result
  //println( "receive: \""+message+"\" from "+ip+" on port "+port );
  println( "RCVD: "+ip+":"+port+" = "+""+message1);
  println( "RCVD: "+message2);
  //
}
//-----------------------------------------------------------------------
public void controlEvent(ControlEvent theEvent) {
  println("------------------------------------------");
  println("ControlEvent: ",theEvent.getController().getName());
  n = 0;
}

//-----------------------------------------------------------------------
// function RESET will receive changes from 
// controller with name COLORA
public void RESET(int theValue) {
  println("------------------------------------------");
  println("Button Event from RESET: "+theValue);
  ButtonFlag = 1;
  println("Button Flag  from RESET: "+ButtonFlag);
}

//-----------------------------------------------------------------------
// function OHM will receive changes from 
// controller with name COLORB
public void OHM(int theValue) {
  println("------------------------------------------");
  println("Button Event from OHM: "+theValue);
  ButtonFlag = 2;
  println("Button Flag  from OHM: "+ButtonFlag);
}

//-----------------------------------------------------------------------
// function VOLTS will receive changes from 
// controller with name COLORC
public void VOLTS(int theValue) {
  println("------------------------------------------");
  println("Button Event from VOLTS: "+theValue);
  ButtonFlag = 3;
  println("Button Flag  from VOLTS: "+ButtonFlag);
}

//====================================================
</code></pre>

<p><strong>Here's a screenshot from the console in when starting 'udp_server5'</strong>
<img src="https://forum.processing.org/two/uploads/imageupload/771/DXHPV3YV8NQG.jpg" alt="console_udpserver5-1" title="console_udpserver5-1" /></p>

<p><strong>Here's a screenshot from the console when I click on the RESET button in 'udp_server5'</strong>
<img src="https://forum.processing.org/two/uploads/imageupload/530/5OTCPU1WWRNP.jpg" alt="console_udpserver5-2" title="console_udpserver5-2" /></p>

<p><strong>Here's a screenshot from the gui screen when I click on the RESET button in 'udp_server5'</strong>
<img src="https://forum.processing.org/two/uploads/imageupload/721/TFXBEDZ5OQR7.jpg" alt="gui_udpserver5-1" title="gui_udpserver5-1" /></p>
]]></description>
   </item>
   <item>
      <title>Processing with mouse click</title>
      <link>https://forum.processing.org/two/discussion/24988/processing-with-mouse-click</link>
      <pubDate>Mon, 13 Nov 2017 16:52:05 +0000</pubDate>
      <dc:creator>DeDaymar</dc:creator>
      <guid isPermaLink="false">24988@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I have to write a processing program which responds to a left mouseclick only. It's quite simple actually, the background hast to be red, if I click with my mouse the background has to turn green and when I click again it has to turn blue. And then again red etc. 
I am stuck at the point where I have to make a difference between the mouse clicks, like first mouse click second mouse click. I saw some examples on the internet but those weren't just with the left mousebutton only.</p>

<p>And should I use an void mousePressed() or not at all ?</p>

<p>I hope someone can give me some good directions.</p>
]]></description>
   </item>
   <item>
      <title>p5js- create new object when clicking on canvas</title>
      <link>https://forum.processing.org/two/discussion/24872/p5js-create-new-object-when-clicking-on-canvas</link>
      <pubDate>Sat, 04 Nov 2017 23:58:55 +0000</pubDate>
      <dc:creator>kveloso</dc:creator>
      <guid isPermaLink="false">24872@/two/discussions</guid>
      <description><![CDATA[<p>I'm really new to programming, and I've made a bunch of 'cells' bounce around the canvas. When they touch each other they combine and when you click on each cell they split. I'm struggling to figure out how to allow the user to click on the canvas and create a new 'cell'. I want this to work when the user clicks only on the canvas and not on the object. Any suggestions on how to fix my code would be lifesaving!</p>

<p>I think i'm stuffing up in the "clicked cell" function and when I call it in the mousePressed function</p>

<p>Thanks</p>

<p>Here is my code:</p>

<pre><code>function Cell(x, y, r) {

    this.x = x;
    this.y = y;
    this.r = r;
    this.speedx = random(-1, 1);
    this.speedy = random(-1, 1);

    this.show = function() {
        stroke(255);
        fill(26, 229, 209, 50)
        ellipse(this.x, this.y, this.r * 2);
    }

    this.clickedcell = function(x, y) {
        var d = dist(this.x, this.y, x, y);
        if (d &lt; this.r) {
            return true;
        } else {
            return false;
        }
    }

    this.clickedcanvas = function(x, y) {
        var d = dist(this.x, this.y, x, y);
        if (d &gt; this.r) {
            return true;
        } else {
            return false;
        }
    }

    this.split = function() {
        var cell = new Cell(random(width), random(height), this.r * 0.5);
        return cell;
    }

    this.move = function() {
        this.x = this.x + this.speedx;
        this.y = this.y + this.speedy;
    }

    this.bounce = function() {
        if (this.x &gt; width || this.x &lt; 0) {
            this.speedx = -this.speedx;
        }
        if (this.y &gt; height || this.y &lt; 0) {
            this.speedy = -this.speedy;
        }
    }


    this.eats = function(other) {
        var d = dist(this.x, this.y, other.x, other.y);
        if (d &lt; this.r + other.r) {
            this.r += other.r * 0.6;
            return true;
        } else {
            return false;
        }
    }

}

var cells = [];

function setup() {
    createCanvas(600, 600);
    for (var i = 0; i &lt; 50; i++) {
        cells[i] = new Cell(random(width), random(height), 10);
    }
}


function mousePressed() {
    for (var i = 0; i &lt; cells.length; i++) {
        if (cells[i].clickedcell(mouseX, mouseY)) {
            cells.push(cells[i].split());
            cells.push(cells[i].split());
            cells.splice(i, 1);
        }
    }
}

function mousePressed() {
    for (var i = 0; i &lt; cells.length; i++) {
        if (cells[i].clickedcanvas(mouseX, mouseY)) {
            cells.push(new Cell(mouseX, mouseY, 10));
        }
    }
}


function draw() {
    background(255);
    for (var i = cells.length - 1; i &gt;= 0; i--) {
        cells[i].show();
        cells[i].move();
        cells[i].bounce();

        for (var j = cells.length - 1; j &gt;= 0; j--) {
            if (j != i &amp;&amp; cells[i] &amp;&amp; cells[i].eats(cells[j])) {
                cells.splice(j, 1);
            }
        }
    }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>millis() function</title>
      <link>https://forum.processing.org/two/discussion/23934/millis-function</link>
      <pubDate>Sat, 26 Aug 2017 12:55:29 +0000</pubDate>
      <dc:creator>coyote</dc:creator>
      <guid isPermaLink="false">23934@/two/discussions</guid>
      <description><![CDATA[<p>wgar</p>
]]></description>
   </item>
   <item>
      <title>Moving object when mousePressed</title>
      <link>https://forum.processing.org/two/discussion/23709/moving-object-when-mousepressed</link>
      <pubDate>Sat, 05 Aug 2017 02:55:07 +0000</pubDate>
      <dc:creator>tonmoy0010</dc:creator>
      <guid isPermaLink="false">23709@/two/discussions</guid>
      <description><![CDATA[<p>Can anyone help me out with this problem?</p>

<p>When mouse is pressed in the top half of the window then, a circle appears.
Pressing the mouse in the bottom half of the window has no effect.
Any previous shape disappears when the new shape appears
The shape moves down the window, two pixels at a time, until it completely disappears off the bottom
of the window</p>

<p>I tried this code but, it doesnt work when the circle crosses the other half. :/</p>

<pre><code>int x = -1000, y;
int diam = 50;

void setup() {
  size(400, 400);
}

void mousePressed(){
  if (y &lt;= height/2) {
    x = mouseX;
    y = mouseY;
  }
  //else {
  //}
}
void draw() {
  background(0);
  ellipse(x, y, diam, diam);
  y++;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>splice</title>
      <link>https://forum.processing.org/two/discussion/23249/splice</link>
      <pubDate>Thu, 29 Jun 2017 02:12:23 +0000</pubDate>
      <dc:creator>1rulesupersedes</dc:creator>
      <guid isPermaLink="false">23249@/two/discussions</guid>
      <description><![CDATA[<p>I want to make the first image disappear when it reaches 10 images. I am thinking splice the array. However not sure where or how.</p>

<p>index.html</p>

<pre><code>    &lt;html&gt;
    &lt;head&gt;

      &lt;meta charset="UTF-8"&gt;
      &lt;script language="javascript" type="text/javascript" src="libraries/p5.js"&gt;&lt;/script&gt; 
      &lt;script language="javascript" src="libraries/p5.dom.js"&gt;&lt;/script&gt;
      &lt;script language="javascript" src="libraries/p5.sound.js"&gt;&lt;/script&gt;
      &lt;script language="javascript" src="images.js"&gt;&lt;/script&gt;
      &lt;script language="javascript" src="images_2.js"&gt;&lt;/script&gt;
    &lt;/head&gt; 
      &lt;!-- this line removes any default padding and style. you might only need one of these values set. --&gt;
      &lt;style&gt; 
      &lt;/style&gt;

    &lt;/head&gt;

    &lt;body&gt;

    &lt;/body&gt;
    &lt;/html&gt;
</code></pre>

<p>============================================================================
images.js</p>

<pre><code>    var bubbles = [];
    var flowers = [];

    function preload(){

        for(var i = 0; i&lt; 6; i++){
            flowers[i] = loadImage("fet_pictures/" + i + ".jpg");
        }

    }

    function windowResized(){
        resizeCanvas(windowWidth, windowHeight);
    }

    function setup(){
        createCanvas(windowWidth, windowHeight);
    }

    function mousePressed(){
        var r = floor(random(0, flowers.length));
        var b = new Bubble(mouseX, mouseY, flowers[r]);
        bubbles.push(b);
    }

    function draw(){
        background(0);
        for(var i = bubbles.length -1; i &gt;= 0; i--){
            bubbles[i].update();
            bubbles[i].display();
        }
    }
</code></pre>

<p>============================================================================
images_2.js</p>

<pre><code>        function Bubble(x, y, img){
        this.x = x;
        this.y = y;
        this.img = img;
        this.lifespan = 255;

        this.display = function(){
            imageMode(CENTER);
            image(this.img, this.x, this.y);
            this.img.resize(100, 0);
            //ellipse(this.x, this.y, 48, 48);
        }

        this.update = function() {
            this.x = this.x + random(-1, 1);
            this.y = this.y + random(-1, 1);
           }
        }
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to duplicate a shape when mouse is clicked</title>
      <link>https://forum.processing.org/two/discussion/22970/how-to-duplicate-a-shape-when-mouse-is-clicked</link>
      <pubDate>Wed, 07 Jun 2017 03:47:02 +0000</pubDate>
      <dc:creator>Megsyy</dc:creator>
      <guid isPermaLink="false">22970@/two/discussions</guid>
      <description><![CDATA[<p>Hi I'm new to processing. I'm just having another issue with my mini fishing game. I'm trying to get it so that when the fish is clicked on and restarts, it duplicates that fish each time. I've tried adding the shape again under the if statement in mousepressed(). But it's just doing the same thing. I've been trying to research online about it, but I can't find much on duplicating pshapes. So I don't know how to go about it.
Thank you.</p>

<pre><code>PShape fish1, body1, tail1, eye1, fish2, body2, tail2, eye2, fish3, body3, tail3, eye3, fish4, body4, tail4, eye4;
int xPos1 = 800;
int xPos2 = 800;
int xPos3 = 800;
int xPos4 = 800;

float per1 = sin(radians(10 * frameCount)); 
float per2 = sin(radians(20 * frameCount)); 
float per3 = sin(radians(30 * frameCount)); 
float per4 = sin(radians(frameCount));
float r = random(0, 600);
float yPos1 = random(0, 400);
float yPos2 = random(0, 400);
float yPos3 = random(0, 400);
float yPos4 = random(0, 400);

boolean qPressed = false;
boolean wPressed = false;
boolean ePressed = false;
boolean rPressed = false;

void setup() {
  size(800, 700);
  background(80, 208, 232);
  smooth();
  noStroke();

  //Creating the fish as a group of shapes parented together
  //fish 1
  fish1 = createShape(GROUP);
  tail1 = createShape (TRIANGLE, 22, 0, 60, -15 + per2, 60, 15 + per2); 
  tail1.setFill(color(252, 193, 97));
  body1 = createShape (ELLIPSE, 0, 0, 70, 50);
  body1.setFill(color(252, 193, 97));
  eye1 = createShape (ELLIPSE, -15, -5, 10, 10);
  eye1.setFill(color(0));

  fish1.addChild(tail1);
  fish1.addChild(body1);
  fish1.addChild(eye1);

  //fish 2    
  fish2 = createShape(GROUP);
  tail2 = createShape (TRIANGLE, 50, 0, 65, -30 + per2, 65, 30 + per2);
  tail2.setFill(color(160, 159, 158));
  body2 = createShape (ELLIPSE, 0, 0, 100, 35);
  body2.setFill(color(160, 159, 158));
  eye2 = createShape(ELLIPSE, -30, -5, 10, 10);
  eye2.setFill(color(0));

  fish2.addChild(tail2);
  fish2.addChild(body2);
  fish2.addChild(eye2);

  //fish 3
  fish3 = createShape(GROUP);
  tail3 = createShape (TRIANGLE, 20, 0, 50, -20 + per3, 50, 20 + per3);
  tail3.setFill(color(227, 156, 214));
  body3 = createShape (ELLIPSE, 0, 0, 60, 80);
  body3.setFill(color(227, 156, 214));
  eye3 = createShape (ELLIPSE, -20, -5, 10, 10);
  eye3.setFill(color(0));

  fish3.addChild(tail3);
  fish3.addChild(body3);
  fish3.addChild(eye3);

  //fish 4
  fish4 = createShape(GROUP);
  tail4 = createShape (TRIANGLE, 15, 0, 25, -10 + per3, 25,10 + per3);
  tail4.setFill(color(195, 247, 234));
  body4 = createShape (ELLIPSE, 0, 0, 40, 20);
  body4.setFill(color(195, 247, 234));
  eye4 = createShape (ELLIPSE, -10, 0, 5, 5);
  eye4.setFill(color(0));

  fish4.addChild(tail4);
  fish4.addChild(body4);
  fish4.addChild(eye4);

}

void draw() {

  //draw a looping fish swimming horizontally across the screen in random y coordinate each time it reaches the end.
  background(80, 208, 232);

  //fish 1 loop
  shape(fish1, xPos1, yPos1);
  xPos1 = xPos1-3;

  if (xPos1&lt;-200) {
    xPos1 = 800;
    yPos1 = random(0, 400); 
  } 

  //fish 2 loop
  shape(fish2, xPos2, yPos2);
  xPos2 = xPos2-4;

  if (xPos2&lt;-200) {
    xPos2 = 800;
    yPos2 = random(0, 400);
  }

  //fish 3 loop
  shape(fish3, xPos3, yPos3);
  xPos3 = xPos3-2;

  if (xPos3&lt;-200) {
    xPos3 = 800;
    yPos2 = random(0, 400);
  }

  //fish 4 loop
  shape(fish4, xPos4, yPos4);
  xPos4 = xPos4 - 5;

  if (xPos4&lt;-200) {
    xPos4 = 800;
    yPos4 = random(0, 400);
  }

  //Boxes that have the bait in them
  noFill();
  // Q
  if(qPressed == true) {
    stroke(203, 0, 0);
    strokeWeight(3);
  } else {
    stroke(1);
    strokeWeight(1);
  }
  rect(250, 620, 75, 75);

  // W
  if(wPressed == true) {
    stroke(203, 0, 0);
    strokeWeight(3);
  } else {
    stroke(1);
    strokeWeight(1);
  }
  rect(330, 620, 75, 75);

  // E
  if(ePressed == true) {
    stroke(203, 0, 0);
    strokeWeight(3);
  } else {
    stroke(1);
    strokeWeight(1);
  }
  rect(410, 620, 75, 75);

  // R
  if(rPressed == true) {
    stroke(203, 0, 0);
    strokeWeight(3);
  } else {
    stroke(1);
   strokeWeight(1);
  }
  rect(490, 620, 75, 75);

  }

void keyPressed() {

  //When 'q' or 'Q' key is pressed, the first box will turn red. When another key is pressed it will go back to black.
  if (key == 'q' || key == 'Q') {
    qPressed = true;
    wPressed = false;
    ePressed = false;
    rPressed = false;
  } 

  //When 'w' or 'W' key is pressed, the second box will turn red. When another key is pressed it will go back to black.
  else if (key == 'w' || key == 'W') {
    qPressed = false;
    wPressed = true;
    ePressed = false;
    rPressed = false;
  }

  //When 'e' or 'E' key is pressed, the third box will turn red. When another key is pressed it will go back to black.
  else if (key == 'e' || key == 'E') {
    qPressed = false;
    wPressed = false;
    ePressed = true;
    rPressed = false;
  } 

  //When 'r' or 'R' key is pressed, the fourth box will turn red. When another key is pressed it will go back to black.
  else if (key == 'r' || key == 'R') {
    qPressed = false;
    wPressed = false;
    ePressed = false;
    rPressed = true;
  }  
}

void mousePressed(){
  //When q is pressed (first box selected) and mouse is pressed on fish 1, that fish goes back to the beginning
 if (qPressed == true &amp;&amp; dist(xPos1, yPos1, mouseX, mouseY) &lt; 40){
  shape(fish1, xPos1, yPos1);
  xPos1 = 1000;
 }
 else if (qPressed == false &amp;&amp; dist(xPos1, yPos1, mouseX, mouseY) &lt; 40){
 shape(fish1, xPos1, yPos1);

 }

if (wPressed == true &amp;&amp; dist(xPos2, yPos2, mouseX, mouseY) &lt; 30){
  shape(fish2, xPos2, yPos2);
  xPos2 = 1200;
 }
 else if (wPressed == false &amp;&amp; dist(xPos2, yPos2, mouseX, mouseY) &lt; 30){
 shape(fish2, xPos2, yPos2);
 }

 if (ePressed == true &amp;&amp; dist(xPos3, yPos3, mouseX, mouseY) &lt; 40){
  shape(fish3, xPos3, yPos3);
  xPos3 = 1000;
 }
 else if (ePressed == false &amp;&amp; dist(xPos3, yPos3, mouseX, mouseY) &lt; 40){
 shape(fish3, xPos3, yPos3);
 }

if (rPressed == true &amp;&amp; dist(xPos4, yPos4, mouseX, mouseY) &lt; 20){
  shape(fish4, xPos4, yPos4);
  xPos4 = 1300;
 }
 else if (qPressed == false &amp;&amp; dist(xPos4, yPos4, mouseX, mouseY) &lt; 20){
 shape(fish4, xPos4, yPos4);
 }

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to make it so mousepressed() only works on a moving shape</title>
      <link>https://forum.processing.org/two/discussion/22953/how-to-make-it-so-mousepressed-only-works-on-a-moving-shape</link>
      <pubDate>Tue, 06 Jun 2017 08:57:13 +0000</pubDate>
      <dc:creator>Megsyy</dc:creator>
      <guid isPermaLink="false">22953@/two/discussions</guid>
      <description><![CDATA[<p>Hi I'm fairly new to Processing and at the moment I'm trying to make a mini fishing game. So just to quickly explain the game, each of those boxes will each have a different bit of bait in it. Only certain bait works on certain fish. Eventually I'll have it so over time the amount of fish increases. To select the boxes is Q, W, E and R, respectively.</p>

<p>What I'm stuck on is how to make mousePressed() only work on a particular moving fish (as well as when a certain key is pressed).  At the moment I've only gotten it to work when I press anywhere on the screen. I've tried adding mouseX == xPos1 etc to the if statement In the void mousePressed() section. But it doesn't seem to work, and I'm really not sure where to go from there. Any help would be greatly appreciated.</p>

<pre><code>PShape fish1, body1, tail1, eye1, fish2, body2, tail2, eye2, fish3, body3, tail3, eye3, fish4, body4, tail4, eye4;
int xPos1 = 800;
int xPos2 = 800;
int xPos3 = 800;
int xPos4 = 800;
float per1 = sin(radians(10 * frameCount)); 
float per2 = sin(radians(20 * frameCount)); 
float per3 = sin(radians(30 * frameCount)); 
float per4 = sin(radians(frameCount));
float r = random(0, 600);
float yPos1 = random(0, 400);
float yPos2 = random(0, 400);
float yPos3 = random(0, 400);
float yPos4 = random(0, 400);

boolean qPressed = false;
boolean wPressed = false;
boolean ePressed = false;
boolean rPressed = false;

void setup() {
  size(800, 700);
  background(80, 208, 232);
  smooth();
  noStroke();

  //Creating the fish as a group of shapes parented together
  //fish 1
  fish1 = createShape(GROUP);
  tail1 = createShape (TRIANGLE, 120, 70, 165, 50 + per2, 165, 100 + per2); 
  tail1.setFill(color(252, 193, 97));
  body1 = createShape (ELLIPSE, 100, 70, 70, 50);
  body1.setFill(color(252, 193, 97));
  eye1 = createShape (ELLIPSE, 80, 60, 10, 10);
  eye1.setFill(color(0));

  fish1.addChild(body1);
  fish1.addChild(tail1);
  fish1.addChild(eye1);

  //fish 2    
  fish2 = createShape(GROUP);
  tail2 = createShape (TRIANGLE, 150, 70, 165, 40 + per2, 165, 100 + per2);
  tail2.setFill(color(160, 159, 158));
  body2 = createShape (ELLIPSE, 100, 70, 100, 35);
  body2.setFill(color(160, 159, 158));
  eye2 = createShape(ELLIPSE, 70, 65, 10, 10);
  eye2.setFill(color(0));

  fish2.addChild(body2);
  fish2.addChild(tail2);
  fish2.addChild(eye2);

  //fish 3
  fish3 = createShape(GROUP);
  tail3 = createShape (TRIANGLE, 120, 70, 150, 55 + per3, 150, 85 + per3);
  tail3.setFill(color(227, 156, 214));
  body3 = createShape (ELLIPSE, 100, 70, 60, 80);
  body3.setFill(color(227, 156, 214));
  eye3 = createShape (ELLIPSE, 80, 65, 10, 10);
  eye3.setFill(color(0));

  fish3.addChild(body3);
  fish3.addChild(tail3);
  fish3.addChild(eye3);

  //fish 4
  fish4 = createShape(GROUP);
  tail4 = createShape (TRIANGLE, 115, 70, 130, 75+ per3, 130, 65 + per3);
  tail4.setFill(color(195, 247, 234));
  body4 = createShape (ELLIPSE, 100, 70, 40, 20);
  body4.setFill(color(195, 247, 234));
  eye4 = createShape (ELLIPSE, 87, 70, 5, 5);
  eye4.setFill(color(0));

  fish4.addChild(body4);
  fish4.addChild(tail4);
  fish4.addChild(eye4);
}

void draw() {

  //draw a looping fish swimming horizontally across the screen in random y coordinate each time it reaches the end.
  background(80, 208, 232);

  //fish 1 loop
  shape(fish1, xPos1, yPos1);
  xPos1 = xPos1-3;

  if (xPos1&lt;-200) {
    xPos1 = 800;
    yPos1 = random(0, 400);
  } 

  //fish 2 loop
  shape(fish2, xPos2, yPos2);
  xPos2 = xPos2-4;

  if (xPos2&lt;-200) {
    xPos2 = 800;
    yPos2 = random(0, 400);
  }

  //fish 3 loop
  shape(fish3, xPos3, yPos3);
  xPos3 = xPos3-2;

  if (xPos3&lt;-200) {
    xPos3 = 800;
    yPos2 = random(0, 400);
  }

  //fish 4 loop
  shape(fish4, xPos4, yPos4);
  xPos4 = xPos4 - 5;

  if (xPos4&lt;-200) {
    xPos4 = 800;
    yPos4 = random(0, 400);
  }

  //Boxes that have the bait in them
  noFill();
  // Q
  if(qPressed == true) {
    stroke(203, 0, 0);
    strokeWeight(3);
  } else {
    stroke(1);
    strokeWeight(1);
  }
  rect(250, 620, 75, 75);

  // W
  if(wPressed == true) {
    stroke(203, 0, 0);
    strokeWeight(3);
  } else {
    stroke(1);
    strokeWeight(1);
  }
  rect(330, 620, 75, 75);

  // E
  if(ePressed == true) {
    stroke(203, 0, 0);
    strokeWeight(3);
  } else {
    stroke(1);
    strokeWeight(1);
  }
  rect(410, 620, 75, 75);

  // R
  if(rPressed == true) {
    stroke(203, 0, 0);
    strokeWeight(3);
  } else {
    stroke(1);
   strokeWeight(1);
  }
  rect(490, 620, 75, 75);

}

void keyPressed() {

  //When 'q' or 'Q' key is pressed, the first box will turn red. When another key is pressed it will go back to black.
  if (key == 'q' || key == 'Q') {
    qPressed = true;
    wPressed = false;
    ePressed = false;
    rPressed = false;
  } 

  //When 'w' or 'W' key is pressed, the second box will turn red. When another key is pressed it will go back to black.
  else if (key == 'w' || key == 'W') {
    qPressed = false;
    wPressed = true;
    ePressed = false;
    rPressed = false;
  }

  //When 'e' or 'E' key is pressed, the third box will turn red. When another key is pressed it will go back to black.
  else if (key == 'e' || key == 'E') {
    qPressed = false;
    wPressed = false;
    ePressed = true;
    rPressed = false;
  } 

  //When 'r' or 'R' key is pressed, the fourth box will turn red. When another key is pressed it will go back to black.
  else if (key == 'r' || key == 'R') {
    qPressed = false;
    wPressed = false;
    ePressed = false;
    rPressed = true;
  }  
}

void mousePressed(){
  //When q is pressed (first box selected) and mouse is pressed on fish 1, that fish goes back to the beginning
  //This is the part I'm stuck on  
 if (qPressed == true){
  shape(fish1, xPos1, yPos1);
  xPos1 = 1000;
 }
 else if (qPressed == false){
 shape(fish1, xPos1, yPos1);
 }

}
</code></pre>

<p>So at the moment I've got it so for the first fish, it only moves when you pressed 'q' or 'Q' , then click anywhere.</p>
]]></description>
   </item>
   <item>
      <title>How to check if you clicked an image</title>
      <link>https://forum.processing.org/two/discussion/22861/how-to-check-if-you-clicked-an-image</link>
      <pubDate>Thu, 01 Jun 2017 16:04:21 +0000</pubDate>
      <dc:creator>Epicness35</dc:creator>
      <guid isPermaLink="false">22861@/two/discussions</guid>
      <description><![CDATA[<p>Hello . I have an image and want to check if the user clicked it, and print a value. How would I do this? Thanks for any help!</p>
]]></description>
   </item>
   <item>
      <title>recognize Object in p5js</title>
      <link>https://forum.processing.org/two/discussion/22618/recognize-object-in-p5js</link>
      <pubDate>Tue, 16 May 2017 14:42:03 +0000</pubDate>
      <dc:creator>Adeeba</dc:creator>
      <guid isPermaLink="false">22618@/two/discussions</guid>
      <description><![CDATA[<p>how i can recognize which object is selected by mousePressed on the object.
I have make two objects textarea and div created by createElement() on p5js canvas.but when I mousePressed on textarea,it doesn'tt recognize it.</p>
]]></description>
   </item>
   <item>
      <title>How do I use textfield with button in p5?</title>
      <link>https://forum.processing.org/two/discussion/22472/how-do-i-use-textfield-with-button-in-p5</link>
      <pubDate>Tue, 09 May 2017 00:26:23 +0000</pubDate>
      <dc:creator>banana</dc:creator>
      <guid isPermaLink="false">22472@/two/discussions</guid>
      <description><![CDATA[<p>There is an example in DOM category call Input Bottom. I am trying to make something similar using html. For some reason my code does not work.For html I have:</p>

<p></p>

<pre><code>&lt;h1&gt;What is your name?&lt;/h1&gt;

&lt;input type="text" class="tf"&gt;

&lt;button type="button" class="btn"&gt;Click Me!&lt;/button&gt; 
</code></pre>

<p></p>

<p>in js file I have:</p>

<pre><code>

var input, button, greeting;

function setup() {
  noCanvas();

  input = select('tf');
  
  button = select('btn');
  button.mousePressed(greet);
}

function greet() {
  greeting.html('hello ' + input.value() + '!');
}

</code></pre>
]]></description>
   </item>
   <item>
      <title>How do I make my button an image?</title>
      <link>https://forum.processing.org/two/discussion/22244/how-do-i-make-my-button-an-image</link>
      <pubDate>Thu, 27 Apr 2017 14:06:03 +0000</pubDate>
      <dc:creator>BowDown097</dc:creator>
      <guid isPermaLink="false">22244@/two/discussions</guid>
      <description><![CDATA[<p>So I'm trying to make a main menu for a game I'm making, but I'll need images for the buttons. Unfortunately, when using the button() function and using all the appropriate stuff, the button works, but I can't make the button an image. If I try making the button an image, the button just displays "[Object] Object". Am I doing something wrong?</p>

<p>button = createButton(img5);
  button.position(100, 100);
 //test position, not final
  button.mousePressed(gotoGame);</p>
]]></description>
   </item>
   <item>
      <title>Drawing from mousePressed?</title>
      <link>https://forum.processing.org/two/discussion/21482/drawing-from-mousepressed</link>
      <pubDate>Sun, 19 Mar 2017 20:29:06 +0000</pubDate>
      <dc:creator>pyan83</dc:creator>
      <guid isPermaLink="false">21482@/two/discussions</guid>
      <description><![CDATA[<p>Ok, so I'm sure there is a stupidly easy answer and I'm totally embarrassed to ask this...</p>

<p>I want to draw a circle when the mouse is clicked at mouseX, mouseY but it doesn't seem to work. Can you explain why?</p>

<pre><code>function setup() {
    createCanvas(600, 600);
}

function draw() {
    background(200);
}

function mousePressed() {
    ellipse(mouseX, mouseY, 180);
}
</code></pre>

<p>I have been trying to google and search the forums for an answer. I did find a KahnAcademy <a rel="nofollow" href="https://www.khanacademy.org/computer-programming/mouseclicked-processingjs/1897113673">answer</a> which is pretty much the same code but they're using processing.js.</p>
]]></description>
   </item>
   <item>
      <title>Save the time when mouse is pressed to use it in a variable - Python Mode</title>
      <link>https://forum.processing.org/two/discussion/21027/save-the-time-when-mouse-is-pressed-to-use-it-in-a-variable-python-mode</link>
      <pubDate>Mon, 27 Feb 2017 11:40:38 +0000</pubDate>
      <dc:creator>avocado</dc:creator>
      <guid isPermaLink="false">21027@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I'm trying to save the time in a variable to use it for a figure to disappear 10 seconds after it appears or disappear randomly.
and for every figure that appears on screen.</p>

<p>At the moment It saves the time many times.</p>

<pre><code>"""
Mouse Press.

Move the mouse to position the shape.
Press the mouse button to invert the color.
"""
#tick=millis()


def update_tick():
    #text(12)
    #textAlign(CENTER)
    pd= millis()/1000
    return pd

def setup():
    global times
    size(640, 360)
    noSmooth()
    fill(126)
    background(102)
    times=[]


def draw():
    #times=[]
    the_time=update_tick()
    if mousePressed:

        stroke(255)
        line(mouseX - 66, mouseY, mouseX + 66, mouseY)
        line(mouseX, mouseY - 66, mouseX, mouseY + 66)
        times.append(the_time) 
        print times
    else:
        stroke(0)
</code></pre>

<h2>Thank you!!</h2>
]]></description>
   </item>
   <item>
      <title>using mousePressed to both PUSH and SPLICE objects in array</title>
      <link>https://forum.processing.org/two/discussion/19628/using-mousepressed-to-both-push-and-splice-objects-in-array</link>
      <pubDate>Fri, 09 Dec 2016 21:05:16 +0000</pubDate>
      <dc:creator>Gene_Webber</dc:creator>
      <guid isPermaLink="false">19628@/two/discussions</guid>
      <description><![CDATA[<p>Hi all, I've been trying to figure this out all day. 
I've got an array of bubbles floating on the screen. I'm using the mousePressed function to push bubbles into the array. 
Now I want to make it so if the cursor is within the bounds of a bubble (its diameter) then instead of pushing new bubbles into the array, it will delete that specific bubble from the array. My current code no longer pushes new bubbles and certainly isn't deleting anything. 
The problem seems to be with cycling through the array when there are no objects yet inside it, but I don't know how to get past this as I need the loop in order for the program to check the cursor's location in relation to the object in the first place...</p>

<pre><code>function mousePressed(){


   for  (var j = bang.length-1; j &gt;= 0; j--) {


       var distance = dist(mouseX, mouseY, bang[j].x, bang[j].y); 

       if  (distance &gt; bang[j].diameter){
          bang.push(new Bigbang(mouseX, mouseY,sounds[Math.round(random(sounds.length-1))]));
         } 
       else if (distance &lt; bang[j].diameter) {
          bang.splice(bang[j], 1);
         }

         console.log("new bubble"+bang);   
    }
}
</code></pre>

<p>big cheers to anyone willing to help me solve this...I guess there is a slightly long-winded logical way around the problem but all of my attempts have failed so far.</p>
]]></description>
   </item>
   <item>
      <title>Could anyone help me rearrange my code so that mousepressed presses all four ellipses?</title>
      <link>https://forum.processing.org/two/discussion/19333/could-anyone-help-me-rearrange-my-code-so-that-mousepressed-presses-all-four-ellipses</link>
      <pubDate>Sun, 27 Nov 2016 18:04:21 +0000</pubDate>
      <dc:creator>nathan7485</dc:creator>
      <guid isPermaLink="false">19333@/two/discussions</guid>
      <description><![CDATA[<p>The assignment is to create four ellipses that each have a different sound, and to make the code run so that each ellipse plays its sound when clicked (mousepressed). I have managed to get the top two ellipses to work; however, I cannot get the other two to work so I would really appreciate some help. (Down at the very end with my if/else if/else statements).</p>

<pre><code>    // import Minim
     import ddf.minim.*;

     Minim minim;
     AudioSample d1;
     AudioSample d2;
     AudioSample d3;
     AudioSample d4;

     AudioOutput out;

     // track when a drum has been struck
     boolean drum1struck;
     boolean drum2struck;
     boolean drum3struck;
     boolean drum4struck;


     void setup() {
       // initialize the screen
       size(400, 400);
       smooth();

       // initialize sound
       minim = new Minim(this);
     out = minim.getLineOut();

       d1 = minim.loadSample("bongo1.wav");
       d2 = minim.loadSample("bongo7.wav");
       d3 = minim.loadSample("tom1.wav");
       d4 = minim.loadSample("tom2.wav");

       // set boolean variables to initialize the graphics
       drum1struck = false;
       drum2struck = false;
       drum3struck = false;
       drum4struck = false;

     }

     void draw() {
        background(255);

       // draw the drums: if a drum has just been struck
       // then fill its ellipse with color as visual feedback for the user

       // drum 1
       if (drum1struck == true) {
         fill(255,0,0);
         drum1struck = false;
       } 
       else 
       {
         fill(255);
       }
       ellipse(50, 55, 100, 100);

       // drum 2
       if (drum2struck == true) {
         fill(255,0,0);
         drum2struck = false;
       } else {
         fill(255);
       }
       ellipse(160, 55, 100, 100);

       //drum 3
       if (drum3struck == true) {
         fill(255,0,0);
         drum3struck = false;
       } 
       else {
         fill(255);
       }
       ellipse(50, 165, 100, 100);

       //drum 4
       if (drum4struck == true) {
         fill(255,0,0);
         drum4struck = false;
       } else {
         fill(255);
       }
       ellipse(160, 165, 100, 100);


     }
     void keyPressed() {
       if (key == 'a' || key == 'A') {   //note you may have to retype the
         drum1struck = true;             //single quote marks after copying
         d1.trigger();
       }
       else if (key == 'b' || key == 'B') {
         drum2struck = true;
         d2.trigger();
       }
       else if (key == 'c' || key == 'C') {
         drum3struck = true;
         d3.trigger();
       }
       else if (key == 'd' || key == 'D') {
         drum4struck = true;
         d4.trigger();
       }
     }

     void mousePressed() {
       if (mouseX&lt;105)
       {
            d1.trigger();
            //set Boolean for drum1 to true
            drum1struck = true;
       }
       else if (mouseX&gt;105)
            {d2.trigger();
            //set Boolean for drum1 to true
           drum2struck = true;
       }
      else if (mouseY&lt;-200)
       {
            d3.trigger();
            //set Boolean for drum1 to true
            drum3struck = true;
       }
       else  {
            d4.trigger();
            //set Boolean for drum1 to true
            drum4struck = true;
     }
     }
</code></pre>
]]></description>
   </item>
   <item>
      <title>mousePressed not working - simple code</title>
      <link>https://forum.processing.org/two/discussion/19056/mousepressed-not-working-simple-code</link>
      <pubDate>Tue, 15 Nov 2016 16:11:51 +0000</pubDate>
      <dc:creator>tder133</dc:creator>
      <guid isPermaLink="false">19056@/two/discussions</guid>
      <description><![CDATA[<p>Hi! I'm new to both coding and the boards so please bear with me. I'm trying to make a simple code where circles, which are supposed to represent tear drops, fall and the person controlling the mouse cursor, which takes on the image of a bucket, clicks on the tears to make them disappear, to make the illusion of tears falling into the bucket.</p>

<p>I'm having trouble with the mousePressed command. I cannot seem to be able to make the falling circles disappear when clicked on. Does anyone have any suggestions to help get me on the right track?</p>

<p>Here is what I have:</p>

<p><code>Tear t1;
PImage mouseCursor;
int numDrops = 80;
Tear[] drops = new Tear[numDrops]; // This creates the array of tears - how many will be able to fall.
void setup() {
  size(1000,800);
  background(0);
  smooth();
  noStroke(); // This loops the array of tears.
  for (int i = 0; i &lt; drops.length; i++) {
drops[i] = new Tear(); // This creates the tears as objects.
    t1 = new Tear();
  }
  mouseCursor = loadImage("bucket.png"); // This loads the image of the bucket as the cursor.
}
void draw(){
  fill(0,80);
  rect(0,0,1000,800); // This loops the array of tears.
  for (int i = 0; i &lt; drops.length; i++) {
    drops[i].fall();
  }
  if(mouseX &lt; 1000) { // This command makes the cursor the bucket image at all times.
    cursor(mouseCursor, 0, 0);
  } else {
    cursor(HAND);
  }
}
class Tear { // This allows the tears to be able to fall randomly at random positions on the screen.
  float t = random(1000);
  float y = random(-height);
void fall() {
    y = y + 10;
    fill(0,139,211,255); // The tears themselves. :'(
    ellipse(t, y, 10, 10);
    if(y&gt;height){
   t = random(1000);
   y = random(-200);
   }
  }
  void mousePressed(){
   ;if (mouseX &gt;= t &amp;&amp; mouseX &lt;= t + width &amp;&amp; 
   mouseY &gt;= y &amp;&amp; mouseY &lt;= y+ height){
    fill(0);
  } else {
    fill(0,139,211,255);}}
  }</code></p>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Adding the number of boxes</title>
      <link>https://forum.processing.org/two/discussion/19078/adding-the-number-of-boxes</link>
      <pubDate>Wed, 16 Nov 2016 20:01:16 +0000</pubDate>
      <dc:creator>123nqk456</dc:creator>
      <guid isPermaLink="false">19078@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone, I have a problem with my project. I want to add more boxes into my project by mousePressed function.</p>

<pre><code>Box[] boxes=new Box[5];
 void setup(){
   size(200,200);
   rectMode(CENTER);
   for(int i=0;i&lt;boxes.length;i++){
     boxes[i]= new Box( random(100),random(100), random(5,15)
     );
   }
 }
  void draw(){
    background(192);
    for(int i=0;i&lt;boxes.length;i++){
      boxes[i].draw();
    }
    for(int j=0;j&lt;boxes.length;j++){
      for(int k=0; k&lt; boxes.length; k++){
        if(j !=k){
          boxes[j].attract(boxes[k]);
        }
      }
    }
  }

  void mousePressed(){
    for(int i=0;i&lt;boxes.length;i++){
      boxes[i].mousePressed();
    }
  }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Strokes as a class instances</title>
      <link>https://forum.processing.org/two/discussion/18479/strokes-as-a-class-instances</link>
      <pubDate>Mon, 10 Oct 2016 00:25:12 +0000</pubDate>
      <dc:creator>djevazi</dc:creator>
      <guid isPermaLink="false">18479@/two/discussions</guid>
      <description><![CDATA[<p>Hello. Here is my little drawing sketch again. Please, draw something on the screen. Every time you hold a mouse, there is a stroke of certain color and shade, and when you release a mouse, the stroke ends, and the next stroke will be another color and shade. So, the stroke is something that lasts from holding a mouse till release. My question is - how to make every 
single stroke become a class instance, so it may have its own coordinates (for example to move all the strokes up and down, left and right), and how to store all the strokes inside ArrayList (for example to have a possibility to delete the last stroke)?</p>

<pre><code>int size;
color [] ccc;
float rotAngle = 0;
color colour;
color rand;
int x = 0;
int y = 0;


void setup()   
{
  size(1200, 900);
  background(0);
  frameRate (50);
  smooth();
  noStroke();

  size = 20;
  ccc = new color[size*size];
  colour = color(random(255), random(255), random(255));
  rand = color(random(-50, 50), random(-50, 50), random(-50, 50));

  for (int i = 0; i &lt; size*size; i++)
  {
    rand = rand+int(random(-50,50));
    ccc[i] = colour+rand;
  }
} 


void draw()
{

  if (mousePressed)
  {
    brush01();
  }
}


void brush01()
{
  int i;
  float brush_X = 0;
  float brush_Y = 0;

  for (i =1; i&lt;size*size; i++)
  {
    if (mouseX != pmouseX || mouseY != pmouseY)
    {
      rotAngle = atan2(mouseY - pmouseY, mouseX - pmouseX);
    }

    pushMatrix();
    rectMode(CENTER);
    translate(mouseX, mouseY);
    rotate(rotAngle);
    translate(0-size/2, 0-size/2);
    fill(ccc[i]);
    rect(brush_X, brush_Y, 1, 1);
    popMatrix();

    brush_X ++;
    if (brush_X &gt; size)
    {
      brush_X = 0;
      brush_Y ++;
    }
  }
}


void mouseReleased()
{
  colour = color(random(255), random(255), random(255));
  rand = color(random(-50, 50), random(-50, 50), random(-50, 50));

  for (int i = 0; i &lt; size*size; i++)
  {
    rand = rand+int(random(-50,50));
    ccc[i] = colour+rand;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Why does this not work? (8 Squares)</title>
      <link>https://forum.processing.org/two/discussion/18472/why-does-this-not-work-8-squares</link>
      <pubDate>Sun, 09 Oct 2016 15:02:21 +0000</pubDate>
      <dc:creator>daniel00101</dc:creator>
      <guid isPermaLink="false">18472@/two/discussions</guid>
      <description><![CDATA[<p>Hi! I'm an absolute beginner programmer, and my exercise is to make 8 squares, that scales with the window and with numbers from 1 to 8 inside them (which is pretty much already done).</p>

<p>What I cannot get to work is to make the rectangles change color to red when you click on one of them, and when you clock on another of the 8 rectangle the rectangle you clock on changes color to red and the the rectangle you previously clicked on goes white again</p>

<p>Here is my code so far:</p>

<pre><code>int pressedButton;
float spaceWidth;
float boxSize;

void setup() {
  size(900, 300);
  boxSize = width/10;
  spaceWidth = width/(5*9);
  background(0);
  pressedButton = 0;
}

void draw() {
  noStroke();
  for (int i = 0; i &lt; 8; i++) {
    fill(255);
    rect(spaceWidth+i*(boxSize+spaceWidth), 70, boxSize, boxSize);
    fill(0);
    text(i+1, spaceWidth+i*(boxSize+spaceWidth), 81);
    fill(255);
  }
}

void mousePressed() {
  for (int i=0; i&lt;8; i++) {
    if (mouseX &gt; spaceWidth+i*(boxSize+spaceWidth) &amp;&amp; mouseX &lt; spaceWidth+i*(boxSize+spaceWidth)+width) {
      fill (255, 0, 0);
    }
    if (mouseY &gt; height &amp;&amp; mouseY &lt; height) {
      fill (255, 0, 0);
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>mousePressed create objects from an array</title>
      <link>https://forum.processing.org/two/discussion/18231/mousepressed-create-objects-from-an-array</link>
      <pubDate>Wed, 21 Sep 2016 16:18:09 +0000</pubDate>
      <dc:creator>wjsandbe</dc:creator>
      <guid isPermaLink="false">18231@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to create mousePressed ellipses from and array in P5, but I'm having trouble defining my objects. I've just transitioned from processing to P5 and I'm a little lost. Here is my code:</p>

<pre><code>var Shape;
var value = 0;
var value2 = 0;
var x;
var y;


function setup() {
    colorMode(HSB, width, height, 100);
createCanvas(500, 500);
Shape = new ball();


}

function mousePressed(){
 //If mouse is pressed outside sliding bar, add a shape. 
  if (mouseY &gt; (height/2 + 40)  || ( mouseY &lt; ( height/2 - 20))){
  for(var i = 0; i &lt; 1; i++){
    balls.add(new Shape(mouseX, mouseY));  

    if (balls &gt; 8) {
    balls.remove(0);
println(balls());
  }
}}
}

function draw() {
  background(51);

for (var i = Shape -1; i &gt;= 0; i--) {
   // ball[i].move();
    ball[i].display();


    if(balls[i].isOffScreen()){
      balls.remove[i];

    }
}
}

function ball() {
  //An array for all the shapes
  this.balls = []; //initialize the array
this.x = x;
this.y = y;
this.display = function() {
 // stroke (255);
    fill(200, 252, 70);
    ellipse(this.x, this.y, 50, 50);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Passing clicks through a p5js canvas to DOM elements underneath</title>
      <link>https://forum.processing.org/two/discussion/17559/passing-clicks-through-a-p5js-canvas-to-dom-elements-underneath</link>
      <pubDate>Sun, 17 Jul 2016 14:18:22 +0000</pubDate>
      <dc:creator>marcusround</dc:creator>
      <guid isPermaLink="false">17559@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I have a p5js canvas which is mostly transparent but overlays to the entire screen, so you can still see some of the HTML webpage underneath. The Problem is that the canvas kind of 'intercepts' any clicks because it lays over the top, so you can no-longer click on any links etc on the underlying webpage.</p>

<p>How can I pass through the clicks to the underlying page? I have googled and found that solutions do exist for people working in javascript ( such as <a rel="nofollow" href="http://www.vinylfox.com/forwarding-mouse-events-through-layers/">this one</a> ) but I don't really know anything about web coding outside of my p5js 'safety net' and the explanations go over my head a bit.
Is there a native p5js method for this or can anyone explain how I step outside the p5 DOM environment to hook this up?</p>

<p>Edit: Forgot to mention it would be ideal to be able control if/when the click is passed through, ie. depending on mouse position or if a variable returns true/false etc.</p>

<p>Thank you</p>

<p>Marcus</p>
]]></description>
   </item>
   <item>
      <title>How to send data from arduino after mousepressed()?</title>
      <link>https://forum.processing.org/two/discussion/17515/how-to-send-data-from-arduino-after-mousepressed</link>
      <pubDate>Wed, 13 Jul 2016 14:44:31 +0000</pubDate>
      <dc:creator>rojascan</dc:creator>
      <guid isPermaLink="false">17515@/two/discussions</guid>
      <description><![CDATA[<p>Basically what I want to do is to send values of a potentiometer to the processing and show them in the console after I press a button in the processing program. However, I'm not getting what I want.</p>

<p>My program does a few things that already worked. It has three different modes to move a servo and those are in the main screen of my program. And I've got another screen when I press the button and some of the values of the potentiometer are shown. However, those values don't keep showing unless I press the button again.</p>

<p>This is the relevant arduino code:</p>

<pre><code>void loop ()
{

  if (Serial.available()) {
    val = Serial.read();
  }
 //val is send from processing to the arduino to change modes 
  switch (val) {
    //-------------------------- Close Modes----------------------//
    case 0:
        digitalWrite(ledPot, LOW);
        digitalWrite(ledCPM, LOW);
        digitalWrite(ledFSR, LOW);
      break;
    //--------------------------CPM Mode----------------------//
    case 1:
        cpmMovement();
        digitalWrite(ledCPM, HIGH);
        digitalWrite(ledPot, LOW);
        digitalWrite(ledFSR, LOW);
      break;
    //--------------------------POT Mode----------------------//
    case 2:
        digitalWrite(ledPot, HIGH);
        digitalWrite(ledCPM, LOW);
        digitalWrite(ledFSR, LOW);
        potMovement();
      break;
    //--------------------------FSR Mode----------------------//
    case 3:
        digitalWrite(ledPot, LOW);
        digitalWrite(ledCPM, LOW);
        digitalWrite(ledFSR, HIGH);
        fsrMovement();
      break;
    //---------------------Calibration Mode-----------------------//
    case 4:
        digitalWrite(ledPot, HIGH);
        digitalWrite(ledCPM, HIGH);
        digitalWrite(ledFSR, HIGH);
      break;
    //----------------Sending Values--------------------//  This is the relevant block
    case 5:
        digitalWrite(ledPot, LOW);
        digitalWrite(ledCPM, LOW);
        digitalWrite(ledFSR, HIGH);
        stateCAL == true;
        while(stateCAL == true){
        sendMaxValue();
        }
     break; 

  }
}

void sendMaxValue(){ //Function which sends the values to the console
  unsigned long startTime = millis();
  long calibrationTime = 3000;

  while(millis() - startTime &lt;= calibrationTime) {
    maxforce = analogRead(Pot)/4;
    if (maxforce &gt; maxReading) maxReading = maxforce;
    Serial.print(maxReading);         
    Serial.print('\t');         
    Serial.print(maxforce);
    Serial.print('\t');         
    Serial.print(startTime);
    Serial.print('\t');         
    Serial.println(millis() - startTime);

  }

  if (millis() - startTime &gt; calibrationTime){
    stateCAL = false;
    Serial.println("Falso");
    Serial.print("After 5 seconds, the maximum reading was: ");
    Serial.println(maxReading);
    maxReading = 0;
  } 

}
</code></pre>

<p>And this is the relevant processing code:</p>

<pre><code>void mousePressed() {
  println("Coordinates: "  + mouseX + "," + mouseY);
  if (pressedCPMButton &amp;&amp; currentColorCPM==butColor) { //Changing color CPM to pressed button color
    currentColorCPM = butpreColor;
    currentColorPOT = butColor;
    currentColorFSR = butColor;
    currentColorCAL = butColor;
    myPort.write(1);   //Send 1 to port
    println(1);
  } else if (pressedCPMButton &amp;&amp; currentColorCPM==butpreColor) {
    currentColorCPM = butColor;
    currentColorPOT = butColor;
    currentColorFSR = butColor;
    currentColorCAL = butColor;
    myPort.write(0);   //Send 1 to port
    println(0);
  }
  if (pressedPOTButton &amp;&amp; currentColorPOT==butColor) {
    currentColorCPM = butColor;
    currentColorPOT = butpreColor;
    currentColorFSR = butColor;
    currentColorCAL = butColor;
    myPort.write(2);   //Send 1 to port
    println(2);                                    //Send 2 to port
  } else if (pressedPOTButton &amp;&amp; currentColorPOT==butpreColor) {
    currentColorCPM = butColor;
    currentColorPOT = butColor;
    currentColorFSR = butColor;
    currentColorCAL = butColor;
    myPort.write(0);   //Send 1 to port
    println(0);
  }
  if (pressedFSRButton &amp;&amp; currentColorFSR==butColor) {
    currentColorCPM = butColor;
    currentColorPOT = butColor;
    currentColorFSR = butpreColor;
    currentColorCAL = butColor;
    myPort.write(3);   //Send 1 to port
    println(3);                                  //Send 3 to port
  } else if (pressedFSRButton &amp;&amp; currentColorFSR==butpreColor) {
    currentColorCPM = butColor;
    currentColorPOT = butColor;
    currentColorFSR = butColor;
    currentColorCAL = butColor;
    myPort.write(0);   //Send 1 to port
    println(0);
  }
  if (pressedCALButton &amp;&amp; currentColorCAL==butColor) {
    currentScreen = 1;
    currentColorCPM = butColor;
    currentColorPOT = butColor;
    currentColorFSR = butColor;
    currentColorCAL = butpreColor;
    myPort.write(4);   //Send 1 to port
    println(4);                                  //Send 4 to port
  } else if (pressedBACKButton) {
    currentScreen = 0;
    currentColorCPM = butColor;
    currentColorPOT = butColor;
    currentColorFSR = butColor;
    currentColorCAL = butColor;
    myPort.write(0);   //Send 1 to port
    println(0);
  }

  if (pressedSTARTCALButton) {     //This is the bit that isn't working well.
    if(myPort.available() &gt; 0){
    }
    myPort.write(5);     //Send 5 to port
    println(5);
    valforce = myPort.readString();
    println(valforce);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Interactivity- changing image upon click in P5js</title>
      <link>https://forum.processing.org/two/discussion/16944/interactivity-changing-image-upon-click-in-p5js</link>
      <pubDate>Thu, 02 Jun 2016 05:25:42 +0000</pubDate>
      <dc:creator>hailruff</dc:creator>
      <guid isPermaLink="false">16944@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I'm trying to create an interactive page using p5js where you click on various images to change between them.  The page starts out with 5 different images I have put in various places, and for each of those 5 images I have 3-4 alternative images to change between upon click.  I have all of the different images loaded as different variables, and have tested all of the alternative images to make sure their varying sizes fit nicely in the same (x,y) placement of the original images.  I am now stuck trying to make the interactivity happen- I tried starting out changing one of the images using the mousePressed() function, which worked for switching between just 2 images, but I want to randomize between the 3+ images upon click.  I then tried making arrays for each of the 5 original images, and in those arrays were the options for the other images.  I think this might work with the mousePressed() function as well, but I am having trouble with the syntax of randomizing images in an array upon click... also having trouble with the placement of the mouse for the click because these are not square images. Is there a way I can just have the conditional statement apply to clicking on the image itself rather than the x &amp; y ranges?  Also, I might be completely off with everything, should I even use arrays? If anyone has suggestions I would very much appreciate it because this seems like a big undertaking and I only just learned p5js about a month ago!</p>
]]></description>
   </item>
   <item>
      <title>Mouse Pressed</title>
      <link>https://forum.processing.org/two/discussion/16252/mouse-pressed</link>
      <pubDate>Mon, 25 Apr 2016 20:51:03 +0000</pubDate>
      <dc:creator>myusername005001</dc:creator>
      <guid isPermaLink="false">16252@/two/discussions</guid>
      <description><![CDATA[<p>What I want to do is have have multiple images within my code. When image A clicked image 1 will appear. And when image B is clicked image 2 to will appear.</p>

<p>how will i set this up?</p>
]]></description>
   </item>
   <item>
      <title>Making a clickable button</title>
      <link>https://forum.processing.org/two/discussion/14881/making-a-clickable-button</link>
      <pubDate>Fri, 12 Feb 2016 20:44:37 +0000</pubDate>
      <dc:creator>dkoenigslieb</dc:creator>
      <guid isPermaLink="false">14881@/two/discussions</guid>
      <description><![CDATA[<p>Hi!
I am very new to processing and have an assignment for a class that is making a button that when clicked twice it turns from inactive (black color) to active (green color) and when clicked 4 times after this it turns back to inactive. Right now I can't seem to figure out how to get the button or the sketch in general to track how many times the button has been clicked. I have tried making a variable that would represent how many times the mouse has been pressed but I am missing something. Our professor told us to assign mousePressed to a variable and then perform a test each time it is clicked with a conditional statement. Here is the code I have so far</p>

<p>int rectX = 300;</p>

<p>int rectY = 200;  //Position of square button</p>

<p>int rectSize = 200; //Size of button</p>

<p>int mouseClicked; //Number count</p>

<p>color inactiveColor;</p>

<p>color activeColor;</p>

<p>void setup() {</p>

<p>size( 600, 400 );</p>

<p>inactiveColor = color( 0 );</p>

<p>activeColor= color( 62, 211, 95 );</p>

<p>println( mouseClicked );</p>

<p>}</p>

<p>void draw() {</p>

<p>background( 150 );</p>

<p>rectMode( CENTER );</p>

<p>fill( inactiveColor );</p>

<p>rect( rectX, rectY, rectSize, rectSize );</p>

<p>}</p>

<p>Do I seem like I am on the right path? If not can someone steer me in the right path and give me a couple pointers on how to make this variable work and implement it into a conditional statement? I am also puzzled when it comes to how I will determine whether the mouse is clicking inside the button. I know I will have to use a conditional statement but I am just confused. Thanks to anyone who can help!</p>
]]></description>
   </item>
   <item>
      <title>Using mousePressed to load and blend random images from an array</title>
      <link>https://forum.processing.org/two/discussion/14275/using-mousepressed-to-load-and-blend-random-images-from-an-array</link>
      <pubDate>Tue, 05 Jan 2016 19:14:08 +0000</pubDate>
      <dc:creator>R_B</dc:creator>
      <guid isPermaLink="false">14275@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to write a code where pressing the mouse shows and blends two random images from an array of 10. 
If this is possible, I can't really get my head around how to create the array's and call them in draw.</p>

<p>Any pointers would be appreciated!</p>

<p>`//VARIABLES
PImage[] photo = new PImage[9];
PImage[] photo2 = new PImage[9];</p>

<p>//SETUP
void setup () 
{
size(600,600);</p>

<p>photo[0] = loadImage("Photo1.png");
photo[1] = loadImage("Photo2.png"); 
photo[2] = loadImage("Photo3.png"); 
photo[3] = loadImage("Photo4.png"); 
photo[4] = loadImage("Photo5.png"); 
photo[5] = loadImage("Photo6.png"); 
photo[6] = loadImage("Photo7.png"); 
photo[7] = loadImage("Photo8.png");
photo[8] = loadImage("Photo9.png");
photo[9] = loadImage("Photo10.png");
}</p>

<p>//DRAW
void draw() 
{ 
if(mousePressed)
{
photo.blend(photo2,0,0,600,600,0,0,600,600,ADD);
image(photo,0,0);
}
}`</p>
]]></description>
   </item>
   <item>
      <title>keyPressed and for loop issues</title>
      <link>https://forum.processing.org/two/discussion/13589/keypressed-and-for-loop-issues</link>
      <pubDate>Sat, 21 Nov 2015 15:47:07 +0000</pubDate>
      <dc:creator>parabyte</dc:creator>
      <guid isPermaLink="false">13589@/two/discussions</guid>
      <description><![CDATA[<p>Hey there,</p>

<p>I've been trying to figure out how to connect a specific keyPressed function with an Array loop: when you press the d key, connect previous mouse pressed pulses with current mouse pressed, and* increase the stroke each time. I figured a key Presssed boolean might get me there, but I don't seem to understand the order or placement of the two functions. Do I keep everything in draw or should the line increase only be in keyPressed, which would eliminate the need for a boolean?</p>

<p>Any help would make my day!</p>

<pre><code>//start the pulse pulseTotal at 0
int pulseTotal =0;

Pulse[] pulseArray = new Pulse[1000];

//connected lines is initialized to false
boolean lineConnect = false;


void setup() {
  size(500, 500);
  background(255);
}

void draw() {
  //refresh
  background(255);
  //if i is equal to 0, make i less than the pulseTotal number of pulses and increase it by 1 each time
  for (int i =0; i &lt; pulseTotal; i++) {
    if (i&gt;0 &amp;&amp; lineConnect == true) {
      //if i is greater than 0 and connected lines is true, connect line from current (i) pulse to previous pulse x and y
      //..and increase strokeWeight with each i increase
      strokeWeight(i);
      stroke(0);
      line(pulseArray[i-1].xPosition, pulseArray[i-1].yPosition, pulseArray[i].xPosition, pulseArray [i].yPosition);
    }
    pulseArray[i].display();
  }
}


// --------------------------
//Mouse Pressed interaction 
// --------------------------
void mousePressed() {

  pulseArray[pulseTotal] = new Pulse(mouseX, mouseY, 25, 200);
  //we increment the pulseTotal pulseArray by 1
  pulseTotal = pulseTotal +1;
}



// --------------------------
//Keyboard interaction 
// --------------------------
void keyPressed() {

  //if key is equal to 32 (32 as a symbol that represents the space bar// 
  //...set background to white (reset the background)
  if (key == 32) { // 32 is the ASCII decimal value representing the space bar
    pulseTotal=0;
  }

  //if D is pressed, make line connect (displays lines and increases stroke each time) true
  if (key == 68) {
    lineConnect = true;
  }
}
//--------------------------
// Pulse Class
//--------------------------
// draws a pulsing dot on the screen
class Pulse {
  /* properties */
  // scale of the pulse
  int pulseScale = 25;         
  // x-coordinate of the pulse  
  float xPosition;              
  // y-coordinate of the pulse  
  float yPosition;            
  // width of the pulse  
  float pulseWidth;         
  // height of the pulse  
  float pulseHeight;            
  // size of the pulse  
  float pulseSize;      
  // fill color of pulse  
  color fillColor;                

  /* methods */
  // constructor 
  Pulse(float newPulseX, float newPulseY, int newPulseScale, color newColor) {
    xPosition = newPulseX;
    yPosition = newPulseY;
    pulseScale = newPulseScale;
    fillColor = newColor;
    pulseSize = 20;
  }

  // draws the pulse and updates its size
  void display() {

    // set the width of the pulse using the sine function 
    pulseWidth = sin(pulseSize)*pulseScale;
    // set the height of the pulse using the sine function 
    pulseHeight = sin(pulseSize)*pulseScale;

    // draw the ellipse at the center
    ellipseMode(CENTER);
    //no stroke on the ellipse
    noStroke();
    //fill the pulse by the fill color variable
    fill(fillColor);
    //draw the ellipse
    ellipse(xPosition, yPosition, pulseWidth, pulseHeight);

    //increment size
    pulseSize = pulseSize + 0.1;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>mapping event (modifying x and y)</title>
      <link>https://forum.processing.org/two/discussion/13573/mapping-event-modifying-x-and-y</link>
      <pubDate>Fri, 20 Nov 2015 03:03:29 +0000</pubDate>
      <dc:creator>gperez</dc:creator>
      <guid isPermaLink="false">13573@/two/discussions</guid>
      <description><![CDATA[<p>Hi. 
I'm working on a "control window", meaning a secondary window that can control the primary one. 
In that control window I have a little representation of the main window. And i wish i could click on that little section and map mouseEvents to primary window. Issue is that mouseEvent class has no public method to modify x and y values. 
Is there any java trick I could implement?
Thanks in advance.</p>
]]></description>
   </item>
   </channel>
</rss>