<?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 #mousefunction - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%23mousefunction</link>
      <pubDate>Sun, 08 Aug 2021 18:04:48 +0000</pubDate>
         <description>Tagged with #mousefunction - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23mousefunction/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How can I make a character that walks to wherever the mouse clicks?</title>
      <link>https://forum.processing.org/two/discussion/15159/how-can-i-make-a-character-that-walks-to-wherever-the-mouse-clicks</link>
      <pubDate>Sat, 27 Feb 2016 19:45:18 +0000</pubDate>
      <dc:creator>Clova</dc:creator>
      <guid isPermaLink="false">15159@/two/discussions</guid>
      <description><![CDATA[<p>Our assignment is: Make a character that walks to a point you click. You can draw the character with a pen and scan it, or draw it in illustrator. 
So, I drew a character in illustrator. There are two images, because I drew the character in two positions and used an array so when animated it looks like it's walking. I got the walking character to move across the screen continuously, but I can't figure out how to make it first stand still, then when I click, start "walking" to the place I clicked then stop. As far as I can tell, it seems that the map/mouseX thing only works when you have shapes like ellipses, not Pimages. Also, I can't get the character to just appear in the first position (standing still) until clicking, when it starts "walking". I can't get it to stop switching between the images and just appear standing still in the begging, so the way I have it now, the screen is completely blank until you click, and then the moving character appears. How can I fix this? 
Here is the code i have so far, but you won't be able to actually run it because you can't access the Pimages. (however, the character is a smiling ice cream cone, like in my profile picture...)
I'm new to processing and I barely understand anything; help would be much appreciated!!! :)</p>

<p>int var1 = 200;
int numFrames = 2;
int frame = 0;
PImage[] icecream = new PImage[numFrames]; 
long timer;
float framespeed = 300;
boolean walk;
int icecreamspeed = 3;</p>

<p>void setup ()
{
  size(700,700);
 icecream[0] = loadImage("character1.jpg");
  icecream[1] = loadImage("character2.jpg");</p>

<p>timer = millis();
  imageMode(CENTER);
}</p>

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

<p>background(255);
  var1 ++;
  if(var1 == width) {
    var1 = 0;</p>

<p>}</p>

<p>if (millis() - timer &gt; framespeed) {
  timer = millis();
  frame ++;
}
if (frame == numFrames) {
  frame = 0;
}
if(walk == true) {
image(icecream[frame], var1,400);</p>

<p>}
}</p>

<p>void mouseClicked() {
walk = true;
image(icecream[frame], mouseX, 400);</p>

<p>}</p>

<p>void mouseReleased() {
  walk = false;</p>

<p>}</p>
]]></description>
   </item>
   <item>
      <title>Is there a command to set the cursor coordinate?</title>
      <link>https://forum.processing.org/two/discussion/11122/is-there-a-command-to-set-the-cursor-coordinate</link>
      <pubDate>Tue, 02 Jun 2015 23:33:41 +0000</pubDate>
      <dc:creator>Lucky_Luke</dc:creator>
      <guid isPermaLink="false">11122@/two/discussions</guid>
      <description><![CDATA[<p>I am currently making a game in processing. I want it to be where you move the ball with your mouse, and when it touches the side, it stops. However, when I start the game, the cursor is inside one of the walls, causing the game to stop. How can I fix this? Here's my code:</p>

<p>CODE REMOVED SEE NEXT COMMENT</p>
]]></description>
   </item>
   <item>
      <title>2 Player Pong Multitouch Help</title>
      <link>https://forum.processing.org/two/discussion/9965/2-player-pong-multitouch-help</link>
      <pubDate>Sat, 21 Mar 2015 16:19:42 +0000</pubDate>
      <dc:creator>knowyourenemy</dc:creator>
      <guid isPermaLink="false">9965@/two/discussions</guid>
      <description><![CDATA[<p>Hello everyone, i am currently developing a two-player pong game for android. In order to enable multitouch, i used the code i found online:</p>

<pre><code> public boolean surfaceTouchEvent(MotionEvent event) {
                pointerCount = event.getPointerCount();
                if (pointerCount&gt;2){
                  pointerCount = 2;
                }
                //println("Number of pointers: "+pointerCount);
                points.clear();
                for(int i=1; i&lt;=pointerCount; i++) {

                points.add(new PVector(event.getX(i-1), event.getY(i-1)));
                }

                //if the event is a pressed gesture finishing, 
                // it means the lifting the last touch point
                if(event.getActionMasked() == MotionEvent.ACTION_UP) points.clear();

                // if you want the variables for motionX/motionY, mouseX/mouseY etc.
                // to work properly, you'll need to call super.surfaceTouchEvent().
                return super.surfaceTouchEvent(event);

              }      
</code></pre>

<p>Within the void draw(), i did this:</p>

<pre><code>if (speedY&gt;0){
        if (tempPoint.y&gt;height/2){
         //extra code here
          rect (tempPoint.x, height-lineHeight, pongRadius*2, pongHeight*2);

          }  
        if (tempPoint.y&lt;height/2){
          //extra code here
          rect (tempPoint.y, lineHeight, pongRadius*2, pongHeight*2);

        }
      }

      if (speedY&lt;0){
        if (tempPoint.y&lt;height/2){
          //extra code here
          rect (tempPoint.x, lineHeight, pongRadius*2, pongHeight*2);


        }  
        if (tempPoint.y&gt;height/2){
          //extra code here
          rect (tempPoint.x, height-lineHeight, pongRadius*2, pongHeight*2);

        }
      }

     }
</code></pre>

<p>Basically, everything is working fine, and the 2 "pongs" or paddles move fine when they are 2 fingers holding down at both ends of the screen. However, the problem arises when one person decides to let go of the screen at the second person puts 2 fingers on their side of the screen, which results in the second person getting 2 paddles and the 1st person not able to get any. This is because i have set the limit of pointerCount to 2 in the code <code>if (pointerCount&gt;2){
      pointerCount = 2;
    }</code>.</p>

<p>Is it possible for me to have a maximum of 1 paddle (1 touch) in each side of the screen(so there will still be two touches in total), and if so, how?</p>

<p>Thanks in advance.</p>
]]></description>
   </item>
   <item>
      <title>mouseClicked / mousePressed</title>
      <link>https://forum.processing.org/two/discussion/7761/mouseclicked-mousepressed</link>
      <pubDate>Wed, 22 Oct 2014 19:20:14 +0000</pubDate>
      <dc:creator>MNGWA</dc:creator>
      <guid isPermaLink="false">7761@/two/discussions</guid>
      <description><![CDATA[<p>This seems like a simple question, but I've looked all over and I can't figure it out.</p>

<p>I understand that, functionally mousePressed is to activate something while the mouse is held down and mouseClicked activates something when the mouse is clicked and than release (with the actual action being on the release).  The problem I'm having is that I have a program with a mousePressed that I want to change to a mouseClicked, and the two commands work very differently.</p>

<p>I've tried everything and can't get it to work.</p>

<p>Here is the Bit I want to change...</p>

<pre><code>angle=atan2((ytarget-y[0]),(xtarget-x[0]))+dsteer;
if (mousePressed==true) angle=PI+angle; //reverse direction if mouse pressed
</code></pre>

<p>And the whole program for reference (there are several generations of notes in here so they probobly don't make a ton of sense)...</p>

<pre><code>color start=color(0,0,0);
color finish;
float amt = 0.0;

//Array of Lines


Streak[] Streak;
int nStreaks = 1000; //number of streaks

void setup() {
   noCursor();
  fill(start);
  finish=color(random(255),random(255),random(255));
   background(0);
  size(screen.width,screen.height);
  smooth();
  frameRate(60);
  //initialize monters with random parameters
  Streak = new Streak[nStreaks];
  for(int i=0; i&lt;nStreaks; i++){
    Streak[i] = new Streak(random(1,1),random(10000,1),random(10000,10000),random(1,100000));

 //way streaks act ^^^^^^^^^^Speed?^^^^^^^^^^^^^^^^^^^^^^Straintess?^^^^^^^^^^^^^^^^^

  }
}

void draw() {
  for(int i=0; i&lt;nStreaks; i++){
    Streak[i].update();
    Streak[i].draw();
  }
} 

class Streak {
  float xtarget; //x position of target
  float ytarget;
  float dtarget; //randomness for target
  float dmove; //randomness for movement
  float speed; //pixels per second 
  int diam=1 ; //diameter of line///////VARIABLE////////
  int nlinks=2; //number of links
  float[] x= new float[nlinks]; //x coordinates of streak
  float[] y= new float[nlinks];
  float dsteer; //steering offset in radians
  float angle;  //angle that streak is moving

  Streak(float _speed, float _dmove, float _dtarget, float _dsteer) {
    //randomize initial location 
    x[0]=random(0,width);
    y[0]=random(0,height); 
    for(int i=0; i&lt;nlinks; i++){
      x[i]=x[0];
      y[i]=y[0];
     }
    speed=_speed;
    dmove=_dmove;
    dtarget=_dtarget;
    dsteer=_dsteer;
  }

  void update() {
    //find target, add some randomness
    xtarget=width/2;
    ytarget=height/2;   
    //move each body position up one
    for(int i=nlinks-1; i&gt;0; i--){
      x[i]=x[i-1];
      y[i]=y[i-1];
    }

    //get angle to target
    angle=atan2((ytarget-y[0]),(xtarget-x[0]))+dsteer;
    if (mousePressed==true) angle=PI+angle; //reverse direction if mouse pressed

    //update position of head
    x[0]+=speed*cos(angle);
    y[0]+=speed*sin(angle);

    //keep within bounds
    if (x[0]&gt;width) x[0]=width;
    if (x[0]&lt;0) x[0]=0;
    if (y[0]&gt;height) y[0]=height;
    if (y[0]&lt;0) y[0]=0;     
  }

  //draw streak  
  void draw() {

   amt+=.00001;
  if (amt &gt;=1) {
   amt = 0.0;
  start = finish;
 finish = color(random(255),random(255),random(255));
  } stroke(lerpColor(start,finish,amt));
    fill(lerpColor(start,finish,amt));
    for(int i=0; i&lt;nlinks; i++){
      ellipse(x[i],y[i],diam,diam);
    }

  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Count and Save Elements created by mouse click</title>
      <link>https://forum.processing.org/two/discussion/5368/count-and-save-elements-created-by-mouse-click</link>
      <pubDate>Sun, 25 May 2014 07:19:48 +0000</pubDate>
      <dc:creator>sgraefiks</dc:creator>
      <guid isPermaLink="false">5368@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I wrote a code where I create flowers by mouse-click and every third flower is decreasing an augmenting pollution cloud. The code works fine. Now I would like to save how many flowers were created during the game and export the data in an excel or text-file. Could you give me a hide how to do that. Here is my code for the flower function. Thank you.</p>

<pre><code>class Plant {

  float x;
  float y;

  Plant() {
    x = mouseX;
    y = mouseY;

  }

  void display() {
  image(plantita,x,y);
  }
}
 ––––––––––––––––––––––––––––––––––––––––––––––––––

ArrayList plants; // array for plantas
int iP= 0; // iterator plantas

//quantify plants
boolean augment_plant = false;  
int counter_plants = 0;

  boolean plantation() 
  {
   for ( iP = 0; iP &lt; plants.size(); iP++ ) 
      { 
    Plant a = (Plant) plants.get(iP);
    a.display();
      }
  if (mousePressed &amp;&amp; (mouseButton == LEFT))
    {
    plants.add(new Plant());
    counter_plants = counter_plants + 1;
    if (counter_plants == 3)
      {
         augment_plant = true;
         counter_plants = 0;
      }
    else 
      {
      augment_plant = false;
      }

     }
    println(augment_plant);
    return augment_plant;
   }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Delete Image with mousePressed</title>
      <link>https://forum.processing.org/two/discussion/4400/delete-image-with-mousepressed</link>
      <pubDate>Tue, 15 Apr 2014 12:14:06 +0000</pubDate>
      <dc:creator>sgraefiks</dc:creator>
      <guid isPermaLink="false">4400@/two/discussions</guid>
      <description><![CDATA[<p>Hello everyone,</p>

<p>I need some advice about how I can delete an image with the command mousePress.
 In my code I first create an illustration by clicking with the mouse cursor on the screen. Later I would like to delete it again by clicking again on the object on the screen. Since I didn't find another solution, I programmed that by drawing a rectangle with the same color as the background, the image disappear.
Probably there are many better ways how to delete the image.</p>

<p>Thank you!</p>

<pre><code> void mousePressed(){
            if (mousePressed &amp;&amp; (mouseButton == LEFT)) { 
          //Draw the image to the screen at coordinates where clicked
          image(plant,mouseX,mouseY);
          }
          else if (mousePressed &amp;&amp; (mouseButton == RIGHT)){
          //overdraws the image to the screen at coordinates where clicked
          fill(#BCFCA1);
          noStroke();
          rect(mouseX,mouseY,120,100);
          }
            // update the screen (run draw once)
          redraw();
        }
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to create a mouse trace</title>
      <link>https://forum.processing.org/two/discussion/3437/how-to-create-a-mouse-trace</link>
      <pubDate>Tue, 04 Mar 2014 02:43:30 +0000</pubDate>
      <dc:creator>Teonaa</dc:creator>
      <guid isPermaLink="false">3437@/two/discussions</guid>
      <description><![CDATA[<p>Hello everyone! I am new to Processing and I am currently taking a course on it. I need to create a project and  I don't really know how to code my idea and I didn't really find anything about  it on the internet. 
I am trying to create something like a transparent green trace behind the mouse(maybe with the mouseDragged function..). Does anyone know how to do that? I seriously need help for my project! :)</p>
]]></description>
   </item>
   <item>
      <title>mouse position problem</title>
      <link>https://forum.processing.org/two/discussion/2875/mouse-position-problem</link>
      <pubDate>Thu, 06 Feb 2014 03:27:07 +0000</pubDate>
      <dc:creator>alexx600</dc:creator>
      <guid isPermaLink="false">2875@/two/discussions</guid>
      <description><![CDATA[<p>Hello. 
I have problem using processingjs. I think that category is the best.</p>

<p>I have problem just like in the topic. It looks like mouse position was wrong !<img src="http://forum.processing.org/two/uploads/imageupload/573/N1I0E82TH07R.jpg" alt="Clipboard05" title="Clipboard05" />
And my primitive code.</p>

<p>void setup() {
  size(500,500,JAVA2D);
  background(0);
}</p>

<p>void draw() {
    ellipse(mouseX, mouseY, 80, 80);
}</p>
]]></description>
   </item>
   <item>
      <title>How to put a shape at determinate coordinates when start running the script MouseFunction\Examples\</title>
      <link>https://forum.processing.org/two/discussion/2577/how-to-put-a-shape-at-determinate-coordinates-when-start-running-the-script-mousefunction-examples</link>
      <pubDate>Wed, 22 Jan 2014 10:24:21 +0000</pubDate>
      <dc:creator>sherkhan</dc:creator>
      <guid isPermaLink="false">2577@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
i'm importing some .svg and i used the MouseFuncion\Examples\Processing.org script,
the problem is that when running the script all the shapes appears in the same position and so i can only move all togheters.
There's any way to impose a starting position for each shape? 
or to create a kind of levels(like adobe illustrator)</p>

<p>here's the link of the example <a href="http://processing.org/examples/mousefunctions.html" target="_blank" rel="nofollow">http://processing.org/examples/mousefunctions.html</a></p>

<p>best,
Filippo</p>
]]></description>
   </item>
   <item>
      <title>Mouse Hover Over Dynamic Background</title>
      <link>https://forum.processing.org/two/discussion/2780/mouse-hover-over-dynamic-background</link>
      <pubDate>Sat, 01 Feb 2014 14:08:44 +0000</pubDate>
      <dc:creator>itsonlydallis</dc:creator>
      <guid isPermaLink="false">2780@/two/discussions</guid>
      <description><![CDATA[<p>I have a sketch which is constantly drawing ellipses. I want to be able to hover over, and have the ellipses grow and become circled, but then go back to normal when the cursor moves on, but still have the original layer continue to draw new ellipses. I was thinking that if I could do the hover over drawing on a second layer I could just wipe it clean after mouse hover, but I don't know how to do that. This is how I have it set up right now (basically each time a circle is drawn I record the coordinates to a tsv file. There's probably a better way to do this to, but this is the only way I've gotten it to work):</p>

<pre><code>void draw() {
  int x = int(random(0, 600));
  int y = int(random(0, 600));

  checkCircles();

  for (int i = 0; i &lt; 100;i++) {
    x = int(random(0, 600));
    y = int(random(0, 600));
    fill(#8c0e10);
    ellipse(x, y, circle, circle);
    circleOutput.println(x+"\t"+y);
  }
}

void checkCircles() {
  String[] circles = loadStrings("circleData.tsv");
  for (int i = 0; i&lt;circles.length;i++) {
    String[] row = split(circles[i], "\t");
    if (int(row[0]) == mouseX &amp;&amp; int(row[1]) == mouseY) {
      stroke(255);
      fill(#8c0e10);
      ellipse(int(row[0]), int(row[1]), 30, 30);
      noStroke();
    }
  }
}
]
</code></pre>

<p>But this obviously leaves the mouseHover circles behind so I'm just constantly drawing new circles. It gets covered eventually by the constantly drawn circles in the draw function, but I want them to disappear immediately. Any ideas would be greatly appreciated.</p>
]]></description>
   </item>
   </channel>
</rss>