<?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 mousedragged() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=mousedragged%28%29</link>
      <pubDate>Sun, 08 Aug 2021 16:06:49 +0000</pubDate>
         <description>Tagged with mousedragged() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedmousedragged%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Zooming and Panning headache</title>
      <link>https://forum.processing.org/two/discussion/20813/zooming-and-panning-headache</link>
      <pubDate>Wed, 15 Feb 2017 20:49:06 +0000</pubDate>
      <dc:creator>prince_polka</dc:creator>
      <guid isPermaLink="false">20813@/two/discussions</guid>
      <description><![CDATA[<p>UPDATE: <strong>FINALLY</strong> I have a working code .... (further down is original post with glitchy code)</p>

<pre><code>// working code    
float mx,my,ratio,xpt,ypt,xzt,yzt,swt,zoom;
void setup() {
 size(600,600);
  zoom=1.0;
  mx=width/60;
  my=mx*height/width;
  ratio=mx/my;
}
void draw() {
  scale(zoom);
  translate(xpt-xzt,ypt-yzt);
  background(128);
  grid(60,60/ratio);
}
void mouseDragged(){
  xpt-=(pmouseX-mouseX)/zoom;
  ypt-=(pmouseY-mouseY)/zoom;
}
void mouseWheel(MouseEvent event) {
  swt-=event.getCount();
  if (swt==0) {
    zoom=1.0;
  } else if (swt&gt;=1 &amp;&amp; swt&lt;=10) {
    zoom=pow(2, swt);
  } else if (swt&lt;=-1 &amp;&amp; swt&gt;=-10) {
    zoom=1/pow(2, abs(swt));
  }
  xzt=((zoom-1)*width/2)/zoom;
  yzt=((zoom-1)*height/2)/zoom;
  if(event.getCount()&lt;=-1){
  xpt-=(mouseX-width/2)/zoom;
  ypt-=(mouseY-height/2)/zoom;
  } else {
  xpt+=(mouseX-width/2)/(pow(2, swt+1));
  ypt+=(mouseY-height/2)/(pow(2, swt+1));
  }
}
void grid(float x, float y) {
  stroke(0);
  for(int i = 0; i &lt; x; i++){line(i*width/x,0,i*width/x,height);}
  for(int i = 0; i &lt; y; i++){line(0,i*height/y,width,i*height/y);}
fill(#ff0000);rect(mx*10,mx*10,mx,mx);
fill(#ffff00);rect(mx*49,mx*10,mx,mx);
fill(#00ff00);rect(mx*10,mx*49,mx,mx);
fill(#0000ff);rect(mx*49,mx*49,mx,mx);
}
</code></pre>

<p><strong>Original post</strong>
I struggled with zoom for a long time and it's irritating and I'm about to give up.<br />
First I was using variables instead of translate() or scale() because I didn't know they existed.<br />
Just wanna zoom in on whatever I'm pointing the mouse at which sounds simple but yet it's zooming in somewhere else.<br />
If don't pan, or only pan when at zoom 1.0 then it works as intended.<br />
BUT if I pan at another zoom say 0.5 or 2.0 then zooming immediately becomes chaotic.<br />
I just detached the issue in a separate sketch and tried using the transform functions, and yet it acts the exact same way.<br />
Here is that sketch, problem must be somewhere between line 20 and 40</p>

<pre><code>// non working original code
float mx,my,ratio; // not relevant for problem

float xpt; // translation
float ypt;
float xzt; // zoom translation
float yzt;
float swt; //scrollwheel ticks
float zoom = 1.0;

// setup not relevant
void setup() {
 size(600,600);
  mx=width/60;
  my=mx*height/width;
  ratio=mx/my;
}

// here starts the relevant part

void draw() {
  scale(zoom);
  translate(xpt-xzt,ypt-yzt);
  background(128);
  grid(60,60/ratio);
}
void mouseDragged(){
  xpt-=(pmouseX-mouseX)/zoom;
  ypt-=(pmouseY-mouseY)/zoom;
}
void mouseWheel(MouseEvent event) {
  swt-=event.getCount(); // swt = wheel ticks
  if (swt==0) {
    zoom=1.0;
  } else if (swt&gt;=1 &amp;&amp; swt&lt;=10) {
    zoom=pow(2, swt);
  } else if (swt&lt;=-1 &amp;&amp; swt&gt;=-10) {
    zoom=1/pow(2, abs(swt));
  }
  xzt=((zoom-1)*mouseX)/zoom;
  yzt=((zoom-1)*mouseY)/zoom;
}

// here ends the relevant part

void grid(float x, float y) {
  for(int i = 0; i &lt; x; i++){line(i*width/x,0,i*width/x,height);}
  for(int i = 0; i &lt; y; i++){line(0,i*height/y,width,i*height/y);}
fill(#ff0000);rect(mx*10,mx*10,mx,mx);
fill(#ffff00);rect(mx*49,mx*10,mx,mx);
fill(#00ff00);rect(mx*10,mx*49,mx,mx);
fill(#0000ff);rect(mx*49,mx*49,mx,mx);
fill(250);rect(xzt+mouseX/zoom-xpt-mx/2,yzt+mouseY/zoom-ypt-mx/2,mx,mx);
}
</code></pre>

<p>EDITED:</p>
]]></description>
   </item>
   <item>
      <title>drag &amp; drop images in Processing</title>
      <link>https://forum.processing.org/two/discussion/28043/drag-drop-images-in-processing</link>
      <pubDate>Wed, 06 Jun 2018 15:47:35 +0000</pubDate>
      <dc:creator>komats</dc:creator>
      <guid isPermaLink="false">28043@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I am trying to make a window where it is possible to drag and drop different images and to make them overlap with a mouse click.
Found a perfect example for it in <em>openprocessing</em>: <a href="https://www.openprocessing.org/sketch/540720" target="_blank" rel="nofollow">https://www.openprocessing.org/sketch/540720</a>
but I guess it would only work in p5.js</p>

<p>In processing library there are some examples of dragging the pictures, but they do so without mouse click and it is not possible to drop them. 
So I am wondering, <strong>is there any advanced example of drag &amp; drop img that can run in Processing</strong>, or I better have to download this p5.js?</p>

<p>Cheers,
tija</p>
]]></description>
   </item>
   <item>
      <title>Converting Processing sketch to P5.js - 2D Arrays</title>
      <link>https://forum.processing.org/two/discussion/27728/converting-processing-sketch-to-p5-js-2d-arrays</link>
      <pubDate>Mon, 09 Apr 2018 19:25:37 +0000</pubDate>
      <dc:creator>borgejor</dc:creator>
      <guid isPermaLink="false">27728@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I am new to P5.js and I need some help reformating my 2D array. Can anyone tell me how it is done in P5.js? This is my sketch for simple application I am making and I want it on my demo site. The 2D Array below is for calling the different pattens.</p>

<p>`   PShape[][] shapes = new PShape[4][4];</p>

<pre><code>var boxCount = 3;
var[] positions = new var [boxCount] ;

var boxSize = 50;
var draggingBox = false;
var boxBeingDragged = 0;
var dragOffset = createVector(0, 0); 

var logo;
var index = 0;
function setup() 
{
   logo = loadImage("thesis_logo.png");
  createCanvas(1920, 1080, P2D); 
  rectMode(CENTER);

  for (var j=0; j &lt; boxCount; j++) {
    var x = random(100, 600);
    var y = random(400, 680);
    positions[j]=  createVector(x, y);
  }
  noStroke();
  fill(#5BC0EB);

  shapes[0][0] = createShape(RECT,1440,450,boxSize,boxSize);
  fill(#000000);
  shapes[0][1] = createShape(RECT,1440,510,boxSize,boxSize);
  shapes[0][2] = createShape(RECT,1440,570,boxSize,boxSize);
  shapes[0][3] = createShape(RECT,1440,630,boxSize,boxSize);

   fill(#5BC0EB);
  shapes[1][0] = createShape(RECT,1350,540,boxSize,boxSize);
  fill(#000000);
  shapes[1][1] = createShape(RECT,1410,540,boxSize,boxSize);
  shapes[1][2] = createShape(RECT,1470,540,boxSize,boxSize);
  shapes[1][3] = createShape(RECT,1530,540,boxSize,boxSize);


  fill(#5BC0EB);
  shapes[2][0] = createShape(RECT,1410,510,boxSize,boxSize);
  fill(#000000);
  shapes[2][1] = createShape(RECT,1470,510,boxSize,boxSize);
  shapes[2][2] = createShape(RECT,1410,570,boxSize,boxSize);
  shapes[2][3] = createShape(RECT,1470,570,boxSize,boxSize);

  fill(#5BC0EB);
   shapes[3][0] = createShape(RECT,1410,480,boxSize,boxSize);
   fill(#000000);
  shapes[3][1] = createShape(RECT,1470,480,boxSize,boxSize);
  shapes[3][2] = createShape(RECT,1410,540,boxSize,boxSize);
  shapes[3][3] = createShape(RECT,1410,600,boxSize,boxSize);
  patternChange();

}

function draw() 
{ 
  background(255);
  fill(#5BC0EB);
  noStroke();
  rect(480,540,50,50);
  for(var j =0; j &lt; 4;j++){
    fill(0);
   shape(shapes[index][j],50,50,boxSize,boxSize);
  }


    stroke(0);
  strokeWeight(2);
  line(width/2,0,width/2,height);
   for (var j=0; j &lt; boxCount; j++) {
    if (draggingBox &amp;&amp; j == boxBeingDragged) {
      stroke(255);  // white
    } else {
      noStroke();
    }
    rect( positions[j].x, positions[j].y, boxSize, boxSize) ;
  }

  patternChange();

image(logo, 50, 50, width/8, height/8);

}

function mousePressed() {
  grabBox();
}

function mouseReleased() {
  draggingBox = false;
}

function mouseDragged() {
  if (draggingBox) {
    positions[boxBeingDragged].x = mouseX + dragOffset.x;
    positions[boxBeingDragged].y = mouseY + dragOffset.y;
  }
}
//
function grabBox() {
  for (var i=0; i &lt; boxCount; i++) {
    // Test if the cursor is over the box
    var left = mouseX &gt; positions[i].x - boxSize/2;
    var right = mouseX &lt; positions[i].x + boxSize/2;
    var top = mouseY &gt; positions[i].y - boxSize/2;
    var bottom = mouseY &lt; positions[i].y + boxSize/2;
    if ( left  &amp;&amp; right &amp;&amp; top &amp;&amp; bottom) {
      prvarln ("mouseover box: "+i);
      boxBeingDragged=i;
      draggingBox = true;
      dragOffset.x = positions[i].x - mouseX;
      dragOffset.y = positions[i].y - mouseY;
      break;
    } else {
      draggingBox = false;
    }
  }
}


function patternChange(){

 if (keyPressed) { //switch statement for changing grid createCanvas
    switch(key){
    case '1':
index = 0;
scramble();
    break;
    case '2':
index = 1;
scramble();
    break;
       case '3':
index = 2;
scramble();
    break;

           case '4':
index = 3;
scramble();
    break;
    }
    }
}

function scramble(){
 for (var j=0; j &lt; boxCount; j++) {
    var x = random(100, 600);
    var y = random(400, 680);
    positions[j]=  createVector(x, y);
  }
}`
</code></pre>
]]></description>
   </item>
   <item>
      <title>Cant get image from webcam</title>
      <link>https://forum.processing.org/two/discussion/26817/cant-get-image-from-webcam</link>
      <pubDate>Tue, 13 Mar 2018 21:41:57 +0000</pubDate>
      <dc:creator>Pjlons83</dc:creator>
      <guid isPermaLink="false">26817@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I have my first processing sketch running with no errors but I cannot get an image from the webcam.</p>

<pre><code>import hypermedia.video.*;
import java.awt.Rectangle;

OpenCV opencv;

// contrast/brightness values
int contrast_value    = 0;
int brightness_value  = 0;



void setup() {

    size( 320, 240 );

    opencv = new OpenCV( this );
    opencv.capture( width, height );                   // open video stream
    opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );  // load detection description, here-&gt; front face detection : "haarcascade_frontalface_alt.xml"


    // print usage
    println( "Drag mouse on X-axis inside this sketch window to change contrast" );
    println( "Drag mouse on Y-axis inside this sketch window to change brightness" );

}


public void stop() {
    opencv.stop();
    super.stop();
}



void draw() {

    // grab a new frame
    // and convert to gray
    opencv.read();
    opencv.convert( GRAY );
    opencv.contrast( contrast_value );
    opencv.brightness( brightness_value );

    // proceed detection
    Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );

    // display the image
    image( opencv.image(), 0, 0 );

    // draw face area(s)
    noFill();
    stroke(255,0,0);
    for( int i=0; i&lt;faces.length; i++ ) {
        rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height ); 
    }
}



/**
 * Changes contrast/brigthness values
 */
void mouseDragged() {
    contrast_value   = (int) map( mouseX, 0, width, -128, 128 );
    brightness_value = (int) map( mouseY, 0, width, -128, 128 );
}
</code></pre>

<p>The programme is supposed to display an image, detect a face and draw a rectangle around the face. I am using windows 7 with a USB webcam. I have tried a couple of versions of processing and both are the same.</p>

<p>Any ideas of where to look first?</p>

<p>Thanks
Paul</p>
]]></description>
   </item>
   <item>
      <title>Mouse Clicked and Dragged for 2 functions</title>
      <link>https://forum.processing.org/two/discussion/26666/mouse-clicked-and-dragged-for-2-functions</link>
      <pubDate>Tue, 06 Mar 2018 08:18:41 +0000</pubDate>
      <dc:creator>newbie_ma</dc:creator>
      <guid isPermaLink="false">26666@/two/discussions</guid>
      <description><![CDATA[<p>Hi! I am a new user of processing and was wondering if there is a way to use mouse clicked and dragged for 2 functions? i am trying to create a coloring page wherein I have a .png image, a set of color palette and brush sizes. i can't seem to figure out how to make both color palette and brush size work together at once. Could you please help? thank you!</p>
]]></description>
   </item>
   <item>
      <title>How to add a mouse event in a child class</title>
      <link>https://forum.processing.org/two/discussion/26369/how-to-add-a-mouse-event-in-a-child-class</link>
      <pubDate>Thu, 15 Feb 2018 19:29:09 +0000</pubDate>
      <dc:creator>solub</dc:creator>
      <guid isPermaLink="false">26369@/two/discussions</guid>
      <description><![CDATA[<p>Following this <a rel="nofollow" href="https://forum.processing.org/two/discussion/comment/117219#Comment_117219">thread</a> I'm trying to add a mouse event to a sketch using the toxiclibs library.</p>

<p>I'd like to be able to move a specific particle with the mouse and see the distortion on the springs grid.</p>

<p>Here's what the sketch looks like</p>

<p><a href="https://imgur.com/a/vUSd1" target="_blank" rel="nofollow">https://imgur.com/a/vUSd1</a></p>

<p><img src="https://i.imgur.com/smqSOFj.png" alt="" /></p>

<p><strong>Main .Pyde file</strong></p>

<pre><code>add_library('verletphysics')
add_library('toxiclibscore')
from toxi.physics2d import VerletPhysics2D
from toxi.physics2d.behaviors import GravityBehavior 
from Particle import particle
from Locker import locker

def setup():
    size(600, 600, OPENGL)
    smooth(10)
    global physics, collection, lockers, n_rowcol

    physics = VerletPhysics2D()
    physics.addBehavior(GravityBehavior(Vec2D(0, 1)))

    collection, springs, lockers  = [], [], []
    n_rowcol, lngth, strength = 40, 10, .6

    #Display particles and add to Physics
    [[collection.append(particle(100 + (e * 10), 10 + (f * 10))) for f in range(n_rowcol)] for e in range(n_rowcol)]
    [physics.addParticle(e) for e in collection]

    #Lock specific particles
    [collection[e].lock() for e in (0, n_rowcol - 1, n_rowcol ** 2 - n_rowcol, n_rowcol ** 2 - 1)]

    #Display springs
    for e in range(0, n_rowcol ** 2 , n_rowcol):
        for f in range(n_rowcol - 1):
            a = collection[e + f]
            b = collection[e + f + 1]
            s = VerletSpring2D(a, b, lngth, strength)
            physics.addSpring(s)

    for e in range(n_rowcol):
        for f in range(0, n_rowcol ** 2 - n_rowcol, n_rowcol):
            a = collection[e + f]
            b = collection[e + f + n_rowcol]
            s = VerletSpring2D(a, b, lngth, strength)
            physics.addSpring(s)

    #Display lockers (red circles to move with mouse) 
    for e in (0, n_rowcol - 1, n_rowcol ** 2 - n_rowcol, n_rowcol**2 - 1):
        lockers.append(locker(collection[e].x(), collection[e].y()))


def draw():
    background(0)

    #Framerate
    [fill(255), text(int(frameRate), 10, 20)]

    #Run physics
    physics.update()

    #Draw lockers (red circles, not lockers really)
    for e in lockers:
        e.display()
        e.mousePressed()
        e.mouseDragged()

    #Draw particles
    [e.display() for e in collection]

    #Draw springlines
    springlines()


def springlines():
    for e in range(0, n_rowcol ** 2, n_rowcol):
        for f in range(n_rowcol - 1):
            a = collection[e + f]
            b = collection[e + f + 1]
            stroke(255)
            line(a.x(), a.y(), b.x(), b.y())

    for e in range(n_rowcol):
        for f in range(0, n_rowcol ** 2 - n_rowcol, n_rowcol):
            a = collection[e + f]
            b = collection[e + f + n_rowcol]
            stroke(255)
            line(a.x(), a.y(), b.x(), b.y())
</code></pre>

<p><strong>Locker.py file</strong></p>

<pre><code>    class locker(object):

        def __init__(self, x, y):
            self.x = x
            self.y = y
            self.over = False
            self.locked = False

        def display(self):

            if dist(self.x, self.y, mouseX, mouseY) &lt; 20:
                self.over = True
                fill(0, 0, 255)
            else:
                self.over = False
                fill(255, 20, 20)
            noStroke()
            ellipse(self.x, self.y, 20, 20)

        def mousePressed(self):
            if mousePressed and self.over:
                self.locked = True
            else:
                self.locked = False

        def mouseDragged(self):
            if self.locked:
                self.x = mouseX
                self.y = mouseY
</code></pre>

<p><strong>Particle.py file</strong></p>

<pre><code>    from toxi.physics2d import VerletParticle2D

    class particle(VerletParticle2D):

       over = False

        def display(pos):
            if dist(pos.x(), pos.y(), mouseX, mouseY) &lt; 4:
                pos.over = True
                fill(255, 20, 20)
            else:
                pos.over = False
                fill(255)

            ellipse(pos.x(), pos.y(), 4, 4)
</code></pre>

<p>The problem lies in the last snippet above (Particle.py):</p>

<p>To drag a specific particle when mousePressed, I need to access the x and y coordinates of the ellipse (the particle) and say something like:</p>

<pre><code>    def mousePressed(): 
        if pos.over:
            pos.x() = mouseX
            pos.y() = mouseY
</code></pre>

<p>But doing so gives me an error: "can't assign to function call" because x() and y() appear as functions.</p>

<p>How can I access the x and y coordinates and make that mouse event work ?</p>
]]></description>
   </item>
   <item>
      <title>Store the start and end position of a mousedrag?</title>
      <link>https://forum.processing.org/two/discussion/25253/store-the-start-and-end-position-of-a-mousedrag</link>
      <pubDate>Tue, 28 Nov 2017 16:13:38 +0000</pubDate>
      <dc:creator>godsamit</dc:creator>
      <guid isPermaLink="false">25253@/two/discussions</guid>
      <description><![CDATA[<p>As the topic suggests, is there any way to get the start and end position of a single mouse drag?</p>
]]></description>
   </item>
   <item>
      <title>Get location of touch events on touchscreen device, similar to mouse location</title>
      <link>https://forum.processing.org/two/discussion/12767/get-location-of-touch-events-on-touchscreen-device-similar-to-mouse-location</link>
      <pubDate>Thu, 01 Oct 2015 09:56:38 +0000</pubDate>
      <dc:creator>osullic</dc:creator>
      <guid isPermaLink="false">12767@/two/discussions</guid>
      <description><![CDATA[<p>I developed a number of Processing sketches many years ago, and just recently decided to embed one of these on my website using processing.js. (It's just a simple sketch where a group of lines follows the mouse location.) I have it working fine when viewed on my laptop's browser, but it doesn't work when viewed on my phone. I did read that processing.js should work with any HTML5-compatible browser.</p>

<p>I had assumed that mouseX and mouseY would receive the location of touch events on my phone's touchscreen, but then I realised that this might be where my problem is. I'd appreciate if someone could point me in the right direction for a straightforward way to get the location of touch events, in the same way that it is straightforward to get the location of the mouse.</p>

<p>Just this morning I discovered the existence of p5.js, and a quick look at the reference there shows that it has Mouse events and Touch events. Would it be more straightforward for me to abandon processing.js and just try to get my sketch working online with p5.js instead?</p>

<p>Thanks for your help, and sorry for the "newbie" question.
I did some searching, but couldn't find exactly the answer to my question.</p>
]]></description>
   </item>
   <item>
      <title>Inconsistent dragging speed when zoomed in</title>
      <link>https://forum.processing.org/two/discussion/23057/inconsistent-dragging-speed-when-zoomed-in</link>
      <pubDate>Tue, 13 Jun 2017 16:09:04 +0000</pubDate>
      <dc:creator>BadDesignException</dc:creator>
      <guid isPermaLink="false">23057@/two/discussions</guid>
      <description><![CDATA[<p>I have created a Processing sketch which supports dragging the whole display as well as zooming it in. Here are the methods I use to drag and zoom:</p>

<pre><code>public void mousePressed(){
    dragBeginX = (mouseX - offsetX);
    dragBeginY = (mouseY - offsetY);
}

public void mouseDragged(){
    if (mousePressed) {
    offsetX = (mouseX - dragBeginX);
    offsetY = (mouseY - dragBeginY);
}

public void zoomTo(float sc){
    translate(width/2, height/2);
    scale(sc);
    translate(-width/2, -height/2);
    //actual zooming handled in separate thread for smoothness
};
</code></pre>

<p>and in before doing the graphic stuff:</p>

<pre><code>translate(offsetX, offsetY);
zoomTo(currentZoom);
</code></pre>

<p>There is no actual bug in that code, but it doesn't quite work the way I want - when the application is zoomed in, the dragging speed remains the same which means that the graphics move much faster than the cursor. Opposite applies when application is zoomed out.
I have tried inserting the zoom value in the dragging math so that the drag speed would depend on the zoom, but I can't find where exactly it needs to be.</p>

<p>To sum it up, I need to make it so that when zoomed in, the object moving speed matches with the cursor dragging speed.</p>

<p>Any help is appreciated.</p>

<p>EDIT: If it was unclear, offsetX/Y is the current dragged position of the screen;</p>
]]></description>
   </item>
   <item>
      <title>How do i draw rectangles that initiate, start and end with the mouse button?</title>
      <link>https://forum.processing.org/two/discussion/22840/how-do-i-draw-rectangles-that-initiate-start-and-end-with-the-mouse-button</link>
      <pubDate>Wed, 31 May 2017 12:47:17 +0000</pubDate>
      <dc:creator>Omnarch</dc:creator>
      <guid isPermaLink="false">22840@/two/discussions</guid>
      <description><![CDATA[<p>This is what I'm after specifically;</p>

<p>There's a white 300x300 window. When you press the mouse in it, a rectangle is initiated. It has opposite corners (top left and bottom right) at that point and at the current location of the mouse respectively. The rectangle is blue and has no borders.</p>

<p>When the mouse is released, the rectangle is finished. The opposite corners are at (x1,y1), where the mouse was pressed, and (x2,y2), where it was released. The final rectangle is red with no borders.</p>

<p>Finally, the area of the rectangle drawn is displayed in integers at the centre of the screen, black, 24 font size, on top of the rectangle. The rectangle and text should both stay on until the mouse is pressed again, which repeats the procedure.</p>

<p>Preferably this would be done only in functions, no classes.</p>
]]></description>
   </item>
   <item>
      <title>How do you Change color of a rectangle after releasing the mouse click?</title>
      <link>https://forum.processing.org/two/discussion/22812/how-do-you-change-color-of-a-rectangle-after-releasing-the-mouse-click</link>
      <pubDate>Mon, 29 May 2017 10:03:06 +0000</pubDate>
      <dc:creator>Kdot_Cdot</dc:creator>
      <guid isPermaLink="false">22812@/two/discussions</guid>
      <description><![CDATA[<p>Hello,
Im trying to make a small code in which when I draw a rectangle it initially is blue but what I want it to do is once I release the mouse it automatically changes to red. 
This is my code:</p>

<pre><code>int x,y,x2,y2 = 0;

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


void draw() {
  background(255);
  fill(0,0,255);
  rect(x, y, x2, y2);
}

 void mousePressed() {
  x = mouseX;
  y = mouseY;
}


void mouseDragged() {
  x2 = mouseX - x;
  y2 = mouseY - y;
  rect(x, y, x2, y2);
}
void mouseReleased() {
  fill(255,0,0);
  rect(x,y,x2,y2);

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to make a slider stay inside the box and go either direction and display a value from 0 to 1000?</title>
      <link>https://forum.processing.org/two/discussion/22234/how-to-make-a-slider-stay-inside-the-box-and-go-either-direction-and-display-a-value-from-0-to-1000</link>
      <pubDate>Wed, 26 Apr 2017 23:51:17 +0000</pubDate>
      <dc:creator>Sandyjakes</dc:creator>
      <guid isPermaLink="false">22234@/two/discussions</guid>
      <description><![CDATA[<p>Here's what I got so far, I couldn't figure out what to do:</p>

<pre><code>void draw() {

    fill(0);
    rect(39, 124, 255, 60);
    fill(255, 0, 0);
    rect(39+255+value, 124, 20, 60);


}

void mouseDragged() {
  value = value - 1;
  if (value &gt; 255) {
    value = 0;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>[SOLVED] Draw static rect filling the screen infront of PeasyCam</title>
      <link>https://forum.processing.org/two/discussion/22047/solved-draw-static-rect-filling-the-screen-infront-of-peasycam</link>
      <pubDate>Mon, 17 Apr 2017 17:08:47 +0000</pubDate>
      <dc:creator>prince_polka</dc:creator>
      <guid isPermaLink="false">22047@/two/discussions</guid>
      <description><![CDATA[<p>The middle of the rect is static at the origin, where the camera is facing, and the rect shall also face the camera.<br />
Lik if it's stuck on a stick infront of it.<br />
<img src="http://download.java.net/media/java3d/javadoc/1.4.0/javax/media/j3d/doc-files/ViewModel11.gif" alt="" /><br />
<em>ignore the text on the picture, it's the best i found</em><br />
I want to know the coordinates of the corners so can not use camera.beginHUD() or popMatrix() to achieve this since this doesn't give me any coordinates.<br />
Also screenX/Y and the picker library isn't doing what I wan't to do.<br />
Tried to read up on how to do rotation in 3D but euler angles, rotation matrices,quaternions etc is not something I understand at the moment.<br />
Here is my code, with with just Yaw+Roll it works, but with Pitch any other angle than 0 it doesn't.<br />
Use R, Y, P keys to rotate and Enter to reset</p>

<pre><code>import peasy.*;
PeasyCam camera;
float[] rot; 
float disx;
float disy;
float yaw,pitch,roll;
void setup(){
  size(600,400,P3D);
  disx=width*0.6;
  disy=height/10;
  camera = new PeasyCam(this, 100);
  camera.setCenterDragHandler(null);
  strokeWeight(3);
}
float [] rec;

void draw(){
 background(180);
 disx=(float)camera.getDistance()*0.86;
 disy=(float)camera.getDistance()*0.57;
 rec = new float [] {-disx,-disy,0,disx,-disy,0,disx,disy,0,-disx,disy,0};
 //rot = camera.getRotations();
 //yaw=rot[0]; pitch=rot[1]; roll=rot[2];

 if(keyPressed){
 float rotspeed=0.03;
 if(key=='p') { pitch += rotspeed; }
 if(key=='y') {   yaw += rotspeed; }
 if(key=='r') {  roll += rotspeed; }
 if(key==ENTER) {  yaw=pitch=roll=0; }
 }
 camera.setRotations(yaw,pitch,roll);

 float sinyaw,cosyaw, sinpitch,cospitch, sinroll, cosroll;
 sinyaw=sin(-yaw-HALF_PI);
 cosyaw=cos(-yaw-HALF_PI);
 sinpitch=sin(pitch-HALF_PI);
 cospitch=cos(pitch-HALF_PI);
 cosroll=cos(roll);
 sinroll=sin(roll);

 for(int i=0; i&lt;12; i+=3){
 float x,y,z,x0,y0,z0;
 x0=x=rec[i]; y0=y=rec[i+1]; z=z0=rec[i+2];

 x=x0*cosroll-y0*sinroll;
 y=y0*cosroll+x0*sinroll;

 z=x0*cospitch;
 y*=sinpitch;

 z=y*cosyaw;
 y*=sinyaw;

 rec[i]=x; rec[i+1]=y; rec[i+2]=z;

 }

 stroke(#ff0000);
 line(0,0,0,100,0,0);
 stroke(#00ff00);
 line(0,0,0,0,100,0);
 stroke(#0000ff);
 line(0,0,0,0,0,100);

 stroke(0);
 line(rec[0],rec[1],rec[2], rec[3],rec[4],rec[5]);
 line(rec[3],rec[4],rec[5], rec[6],rec[7],rec[8]);
 line(rec[6],rec[7],rec[8], rec[9],rec[10],rec[11]);
 line(rec[9],rec[10],rec[11], rec[0],rec[1],rec[2]);
}
</code></pre>

<p>A bit simpler example just a rotating square and static camera, only rotating in one axis at the time.<br />
Also just found this <a rel="nofollow" href="https://www.khanacademy.org/computer-programming/3d-tutorial-4/1648921303">https://khanacademy.org/computer-programming/3d-tutorial-4/1648921303</a></p>

<pre><code>import peasy.*;
PeasyCam camera;
float S,C,R,D;
float [] rec;
void setup(){
  size(600,400,P3D);
  camera = new PeasyCam(this, 100);
  camera.setCenterDragHandler(null);
  strokeWeight(3);
  D=30;
}
void draw(){
 background(180);
 rec = new float [] {-D,-D,0,D,-D,0,D,D,0,-D,D,0};
 camera.setRotations(0,0,0);
 R+=PI/60;
 S=sin(R);
 C=cos(R);
 for(int i=0; i&lt;12; i+=3){
 float x,y,z,x0,y0,z0;
 x0=x=rec[i]; y0=y=rec[i+1]; z=z0=rec[i+2];
 if(frameCount%180&lt;60){
 x=x0*C-y0*S;
 y=y0*C+x0*S;
 }
 else if(frameCount%180&lt;120){
 z=z0*C-x0*S;
 x=x0*C+z0*S;
 }
 else{
 y=y0*C-z0*S;
 z=z0*C+y0*S;
 }
 rec[i]=x; rec[i+1]=y; rec[i+2]=z;
 }
 stroke(#ff0000);
 line(0,0,0,100,0,0);
 stroke(#00ff00);
 line(0,0,0,0,100,0);
 stroke(#0000ff);
 line(0,0,0,0,0,100);
 stroke(0);
 line(rec[0],rec[1],rec[2], rec[3],rec[4],rec[5]);
 line(rec[3],rec[4],rec[5], rec[6],rec[7],rec[8]);
 line(rec[6],rec[7],rec[8], rec[9],rec[10],rec[11]);
 line(rec[9],rec[10],rec[11], rec[0],rec[1],rec[2]);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Web Uploading Issue</title>
      <link>https://forum.processing.org/two/discussion/21069/web-uploading-issue</link>
      <pubDate>Wed, 01 Mar 2017 01:00:55 +0000</pubDate>
      <dc:creator>ltriescode</dc:creator>
      <guid isPermaLink="false">21069@/two/discussions</guid>
      <description><![CDATA[<p>This works perfectly in processing, but only the background shows up when I upload it to an html file. I've tried multiple ways of uploading and the files are properly linked Does anyone know how I can fix this? Thanks!</p>

<p>/* <a href="/two/profile/pjs">@pjs</a> preload="ToxicTots.jpg","spine.jpg","top.jpg", "bottom.jpg"; */</p>

<p>PImage tex1;
PImage tex2;
PImage tex3;
PImage tex4;</p>

<p>float rotx = PI/4;
float roty = PI/4;</p>

<p>void setup() {
  size(800, 900, P3D);
  tex1 = loadImage("ToxicTots.jpg");
  tex2 = loadImage("spine.jpg");<br />
  tex3 = loadImage("top.jpg");<br />
  tex4 = loadImage("bottom.jpg");
  textureMode(NORMAL);
  fill(255);
  stroke(color(44,48,32));
}</p>

<p>void draw() {
  background(176,224,230);
  noStroke();
  translate(width/2.0, height/3.0, -100);
  rotateX(rotx);
  rotateY(roty);
  scale(200);
  TexturedCube(tex1);<br />
  TexturedCube(tex2);<br />
  TexturedCube(tex3);
  TexturedCube(tex4);
}</p>

<p>void TexturedCube(PImage tex) {
  beginShape(QUADS);</p>

<p>// +Z "front" face
  texture(tex1);
  vertex(-.25, -1,  1, 0, 0);
  vertex( 1, -1,  1, 1, 0);
  vertex( 1,  1,  1, 1, 1);
  vertex(-.25,  1,  1, 0, 1);</p>

<p>// -Z "back" face
  texture(tex1);
  vertex( 1, -1, .75, 0, 0);
  vertex(-.25, -1, .75, 1, 0);
  vertex(-.25,  1, .75, 1, 1);
  vertex( 1,  1, .75, 0, 1);
  endShape();</p>

<p>// +Y "bottom" face<br />
  beginShape(QUADS);
  texture(tex3);
  vertex(-.25,  1,  1, 0, 0);
  vertex( 1,  1, 1, 1, 0);
  vertex( 1,  1, .75, 1, 1);
  vertex(-.25,  1, .75, 0, 1);
  endShape();</p>

<p>// -Y "top" face
  beginShape(QUADS);<br />
  texture(tex4);
  vertex(-.25, -1, 1, 0, 0);
  vertex( 1, -1, 1, 1, 0);
  vertex( 1, -1,  .75, 1, 1);
  vertex(-.25, -1,  .75, 0, 1);
  endShape();</p>

<p>// +X "right" face
  beginShape(QUADS);
  texture(tex2);
  vertex( 1, -1,  1, 0, 0);
  vertex( 1, -1, .75, 1, 0);
  vertex( 1,  1, .75, 1, 1);
  vertex( 1,  1,  1, 0, 1);</p>

<p>// -X "left" face
  vertex(-.25, -1, 1, 0, 0);
  vertex(-.25, -1,  .75, 1, 0);
  vertex(-.25,  1,  .75, 1, 1);
  vertex(-.25,  1, 1, 0, 1);
  endShape();
}</p>

<p>void mouseDragged() {
  float rate = 0.01;
  rotx += (pmouseY-mouseY) * rate;
  roty += (mouseX-pmouseX) * rate;
}</p>
]]></description>
   </item>
   <item>
      <title>Follow one function until key press</title>
      <link>https://forum.processing.org/two/discussion/21444/follow-one-function-until-key-press</link>
      <pubDate>Thu, 16 Mar 2017 23:54:43 +0000</pubDate>
      <dc:creator>codeav3</dc:creator>
      <guid isPermaLink="false">21444@/two/discussions</guid>
      <description><![CDATA[<p>My Program: User draws rectangles, one on top of another.
Aim: User should be able to interact with top previously drawn e.g. send behind, bring to front, change colour etc..</p>

<p>My initial idea was if the user clicks on a previously drawn rectangle, they will be able to interact with that particular rectangle, however I don't think it is possible because if shapes are overlapping it will select all those rectangles.</p>

<p>Instead I decided that when the user presses "i" they enter "Interact Mode" where they can interact with the top rectangle until they go back to drawing mode.</p>

<p>My problem is that the "Interact Mode" isn't working. I think it's because the user presses "i" and it enters "Interact Mode" however, as soon as they press a key after that to send the top rectangle back or forward, it changes the "key" and it leaves "Interact Mode"</p>

<pre><code>boolean startDraw;
int a, b, c, d;
Rect newRect;
Rect topRect;
ArrayList&lt;Rect&gt; rectList = new ArrayList();
boolean undo = false;

void setup() {
  size(800, 600);
  a=0;
  b=0;
  c=0;
  d=0;
}


void draw() {
  background(255);
  fill(255);
  strokeWeight(2);
   for(Rect newRect : rectList) {    
    newRect.createRect();
    topRect = rectList.get(rectList.size() - 1);
  }

  if (startDraw)
  {
    newRect = new Rect(a, b, c, d);
    newRect.createRect();
  }  



  if (undo == true) {
    rectList.remove(rectList.size() - 1);
    undo = false;
  }
}


void mousePressed() {
  startDraw = true;
  a=mouseX;
  b=mouseY;  
}


void mouseDragged() {
  if (startDraw)
  {
    c=mouseX-a;
    d=mouseY-b;
  }  

}

void mouseReleased() {
  rectList.add(newRect);
  startDraw = false;
  a=0; b=0; c=0; d=0;
}

void keyPressed() {
  if (key == 'z') {
    undo = true;
  }    
  if (key == 'i') {
    interactRect();
  }    
}

void interactRect() {    
  int currentIndex = rectList.size() - 1;
  if(key == CODED) {
    if(keyCode == UP) {
      rectList.remove(topRect);
      rectList.add(topRect);        
    } if(keyCode == DOWN) {
      currentIndex = 0;
      rectList.remove(topRect);
      rectList.add(currentIndex, topRect);
      println(currentIndex);
    } if(keyCode == LEFT) {
      currentIndex--;
      rectList.remove(topRect);
      rectList.add(currentIndex, topRect);
    } if(keyCode == RIGHT) {
      currentIndex++;
      rectList.remove(topRect);
      rectList.add(currentIndex, topRect);
  }
 }
}

class Rect {
  int a, b, c, d;

  Rect(int w, int x, int y, int z) {
    a = w;
    b = x;
    c = y;
    d = z;
  }

  void createRect() {
    rect(a, b, c, d);
  }


}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How do I create a class which would contain a PGraphics property</title>
      <link>https://forum.processing.org/two/discussion/21422/how-do-i-create-a-class-which-would-contain-a-pgraphics-property</link>
      <pubDate>Wed, 15 Mar 2017 21:30:59 +0000</pubDate>
      <dc:creator>codeav3</dc:creator>
      <guid isPermaLink="false">21422@/two/discussions</guid>
      <description><![CDATA[<p>I would like every drawn shape to be an object which I can interact with later to change the fill, stroke etc. I would also create an ArrayList so I can sort the layers by sorting the arrayList.</p>

<p>I've been told to <strong>create a class for the drawn objects which would contain a PGraphics property</strong>, and also a draw method. While dragging the mouse, I can clear the latest Shape's PGraphic and draw it again.</p>

<p>I just have no idea how!</p>

<p>PS: I will implement other shapes the user can draw but they too need to be objects so I can manipulate them</p>

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

<pre><code>ArrayList&lt;PGraphics&gt; layer = new ArrayList();
float startX, startY;

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

void draw() {
  background(255);
  for(PGraphics pg : layer) {
    image(pg, 0, 0);
  }
}
void mousePressed() {
  startX = mouseX;
  startY = mouseY;
  PGraphics pg = createGraphics(width, height);
  layer.add(pg);
}

void mouseDragged() {
  // get most recent layer
  PGraphics pg = layer.get(layer.size() - 1);
  shapeLayer.beginDraw();
  shapeLayer.clear();
  shapeLayer.rectMode(CORNERS);
  shapeLayer.rect(startX, startY, mouseX, mouseY);
  shapeLayer.endDraw();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to achieve smooth lines outside draw() function</title>
      <link>https://forum.processing.org/two/discussion/21312/how-to-achieve-smooth-lines-outside-draw-function</link>
      <pubDate>Fri, 10 Mar 2017 16:23:45 +0000</pubDate>
      <dc:creator>Novezs</dc:creator>
      <guid isPermaLink="false">21312@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to do a collaborative drawing website (very original, I know) but whenever the function for drawing a line is called when the other client sends out a data variable with the current and previous mouse positions, the lines look very pixelated as displayed in the screenshot below (right side is the one that drew, which happens in draw() and left side is the client that received it over the socket): <a href="https://gyazo.com/0c1e7b2fc823c1974c2b9fffac1c45f9" target="_blank" rel="nofollow">https://gyazo.com/0c1e7b2fc823c1974c2b9fffac1c45f9</a></p>

<p>I'm using express and node to create it.</p>

<p>This is the current client code for drawing:
<a href="http://pastebin.com/7DnTF8mn" target="_blank" rel="nofollow">http://pastebin.com/7DnTF8mn</a></p>

<p>If someone could point me in the right direction It'd be very appreciated!</p>
]]></description>
   </item>
   <item>
      <title>Background in draw()</title>
      <link>https://forum.processing.org/two/discussion/21258/background-in-draw</link>
      <pubDate>Wed, 08 Mar 2017 17:39:13 +0000</pubDate>
      <dc:creator>PRouse</dc:creator>
      <guid isPermaLink="false">21258@/two/discussions</guid>
      <description><![CDATA[<p>I'm writing a simple code where I can drag the mouse around and a color streak will appear on screen where my mouse goes.</p>

<pre><code>`void setup(){
  size(1200, 1200);
  frameRate(30);
}

void draw(){
   background(255);
  //background(random(255), random(255), random(255));
}

void mouseDragged() {
  stroke(random(255), random(255), random(255));
  strokeWeight(random(20));
  line(pmouseX, pmouseY, mouseX, mouseY);
}`
</code></pre>

<p>The issue I'm having is with the background in draw(). I do want the background color to continuously load, but I also want the background to change to a new color each time some event is triggered (preferably a mouse release), and continuously load only that color until another trigger occurs. Right now I have the background just set to white.</p>

<p>So to reiterate the program logic:</p>

<p>1)Program starts with background continuously running initial color.</p>

<p>2)Mouse pressed and dragged creating colorful streak.</p>

<p>3)Mouse released triggering background change to new random color.</p>

<p>4)Background continuously runs the new random color.</p>

<p>5)Back to (2).</p>
]]></description>
   </item>
   <item>
      <title>Scale Translate AB comparission</title>
      <link>https://forum.processing.org/two/discussion/20853/scale-translate-ab-comparission</link>
      <pubDate>Fri, 17 Feb 2017 16:24:37 +0000</pubDate>
      <dc:creator>prince_polka</dc:creator>
      <guid isPermaLink="false">20853@/two/discussions</guid>
      <description><![CDATA[<p>This is probably pointless but oh well...<br />
I had a pan and zoom problem and solved it using scale and translate functions.<br />
I got curious if there was any reason to use those functions other than convenience.<br />
So I set up this this A B comparison, one with and one without them.<br />
Turns out it makes no visual difference whether you use them or not.<br />
left-click    = pan<br />
scrollwheel = zoom<br />
right-click  = switch mode</p>

<pre><code>// scaletranslate A B comparission
float mx,my,ratio,xpt,ypt,xzt,yzt,cx,cy,swt,zoom;
boolean mode=false;
void setup() {
 size(600,600);
  zoom=1.0;
  mx=width/60;
  my=mx*height/width;
  ratio=mx/my;
}
void draw() {

  if(!mode){cxcy(60,60);}
  else if(mode){scaletranslate(60,60);}
}
void mouseClicked(){
  if(mouseButton == RIGHT){
    if(mode){mode=false;}else{mode=true;}

  }
}
void mouseDragged(){
  xpt-=(pmouseX-mouseX)/zoom;
  ypt-=(pmouseY-mouseY)/zoom;
}
void mouseWheel(MouseEvent event) {
  swt-=event.getCount();
  if (swt==0) {
    zoom=1.0;
  } else if (swt&gt;=1 &amp;&amp; swt&lt;=10) {
    zoom=pow(2, swt);
  } else if (swt&lt;=-1 &amp;&amp; swt&gt;=-10) {
    zoom=1/pow(2, abs(swt));
  }
  xzt=((zoom-1)*width/2)/zoom;
  yzt=((zoom-1)*height/2)/zoom;
  if(event.getCount()&lt;=-1){
  xpt-=(mouseX-width/2)/zoom;
  ypt-=(mouseY-height/2)/zoom;
  } else {
  xpt+=(mouseX-width/2)/(pow(2, swt+1));
  ypt+=(mouseY-height/2)/(pow(2, swt+1));
  }
}
void cxcy(float x, float y) {
  cx=(xpt-xzt); cy=(ypt-yzt);
  background(128);
  stroke(0);
  strokeWeight(zoom);
  for(int i = 0; i &lt; x; i++){line(((i*width/x)+cx)*zoom,cy*zoom,((i*width/x)+cx)*zoom,(height+cy)*zoom);}
  for(int i = 0; i &lt; y; i++){line(cx*zoom,((i*height/y)+cy)*zoom,(width+cx)*zoom,((i*height/y)+cy)*zoom);}
  fill(#ff0000);rect((cx+mx*10)*zoom,(cy+mx*10)*zoom,mx*zoom,mx*zoom);
  fill(#ffff00);rect((cx+mx*49)*zoom,(cy+mx*10)*zoom,mx*zoom,mx*zoom);
  fill(#00ff00);rect((cx+mx*10)*zoom,(cy+mx*49)*zoom,mx*zoom,mx*zoom);
  fill(#0000ff);rect((cx+mx*49)*zoom,(cy+mx*49)*zoom,mx*zoom,mx*zoom);
  fill(#abcdef);ellipse((cx+width/2)*zoom,(cy+height/2)*zoom,width/8*zoom,height/8*zoom);
  textSize(4*mx*zoom);
  fill(0);
  textAlign(CENTER);
  text("CX CY Floats",(cx+width/2)*zoom,(cy+height/2)*zoom);
}

void scaletranslate(float x, float y) {
  scale(zoom);
  translate(xpt-xzt,ypt-yzt);
  background(128);
  stroke(0);
  strokeWeight(1.0);
  for(int i = 0; i &lt; x; i++){line(i*width/x,0,i*width/x,height);}
  for(int i = 0; i &lt; y; i++){line(0,i*height/y,width,i*height/y);}
  fill(#ff0000);rect(mx*10,mx*10,mx,mx);
  fill(#ffff00);rect(mx*49,mx*10,mx,mx);
  fill(#00ff00);rect(mx*10,mx*49,mx,mx);
  fill(#0000ff);rect(mx*49,mx*49,mx,mx);
  fill(#abcdef);ellipse(width/2,height/2,width/8,height/8);
  textSize(4*mx);
  fill(0);
  textAlign(CENTER);
  text("Scale Translate",width/2,height/2);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Can you ignore mousePressed when drawing during mouseDragged?</title>
      <link>https://forum.processing.org/two/discussion/19760/can-you-ignore-mousepressed-when-drawing-during-mousedragged</link>
      <pubDate>Thu, 15 Dec 2016 01:55:26 +0000</pubDate>
      <dc:creator>jacorre</dc:creator>
      <guid isPermaLink="false">19760@/two/discussions</guid>
      <description><![CDATA[<p>When dragging with the mouse/touch, I am drawing a line on the canvas. However, if I click/touch without dragging it's drawing a dot on the canvas. Is there any way to stop that dot from appearing? Please see my <a rel="nofollow" href="http://codepen.io/jacorre/pen/woyNXG?editors=0010#0">example on CodePen</a>. Thank you!</p>
]]></description>
   </item>
   <item>
      <title>Howto pass to class code (Draggingpic)</title>
      <link>https://forum.processing.org/two/discussion/19282/howto-pass-to-class-code-draggingpic</link>
      <pubDate>Thu, 24 Nov 2016 21:00:41 +0000</pubDate>
      <dc:creator>laimperiestro</dc:creator>
      <guid isPermaLink="false">19282@/two/discussions</guid>
      <description><![CDATA[<p>Hello</p>

<p>I want to convert this code into class in order to use wherever is possible,</p>

<pre><code>PImage sample;
int x, y; 
void setup() {
  size(1000, 600); 
  noStroke(); 
  sample=loadImage("G2.png");
  x=0;
  y=400;
} 
void draw() { 
  background(255); 
  image(sample, x, y, 50, 30);
} 
void mouseDragged() { 
  x=mouseX; 
  y=mouseY;
}
</code></pre>

<p>I rewrote this code this way, but it nor show mistakes neither works, and I don't konw what am I doing wrong...</p>

<pre><code>Draggingpic Dragging = new Draggingpic(); 
void setup() {
  size(600, 600); 
  noStroke(); 
  Dragging.charge();  
}
void draw() { 
  background(255);   
  Dragging.mouseDragged();
}
class Draggingpic
{
  int x;
  int y;
  PImage sample;
  void Draggingpic(int posx,int posy,PImage sample2)
  { 
    x=posx;
    y=posy;
    sample = sample2;
  }  
  void charge()
  { 
    sample=loadImage("g2.png");  
  }
  void mouseDragged() 
  { 
    x=mouseX; 
    y=mouseY;    
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Stop blinking</title>
      <link>https://forum.processing.org/two/discussion/19318/stop-blinking</link>
      <pubDate>Sat, 26 Nov 2016 21:40:29 +0000</pubDate>
      <dc:creator>mma</dc:creator>
      <guid isPermaLink="false">19318@/two/discussions</guid>
      <description><![CDATA[<p>Hi I'm new to processing and I was trying different codes but it seems that everytime I use the mouseMoved and mouseDragged my screen starts flashing or blinking instead of just showing me what I want according to the code. It would be really helpful please, thank you.</p>

<p>boolean drawA = false;</p>

<p>boolean drawB = false;</p>

<p>boolean drawC = false;</p>

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

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

<p>noStroke();</p>

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

<p>}</p>

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

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

<p>float x = mouseX;</p>

<p>float y = mouseY;</p>

<p>float ix = width - mouseX; // Inverse X</p>

<p>float iy = height - mouseY; // Inverse Y</p>

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

<p>triangle(x, height/2, y, y,ix,iy);</p>

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

<p>ellipse(ix, height/2, iy, iy);</p>

<p>}</p>

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

<p>if ((key == 'A') || (key == 'a')) {</p>

<pre><code>drawA = true;
</code></pre>

<p>} else if ((key == 'B') || (key == 'b')){</p>

<pre><code>drawB = true;
</code></pre>

<p>}else if ((key == 'C') || (key == 'c')){</p>

<pre><code>drawC = true;
</code></pre>

<p>}</p>

<p>}</p>

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

<p>drawA = false;</p>

<p>drawB = false;</p>

<p>drawC = false;</p>

<p>}</p>

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

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

<pre><code>fill(0);

ellipse(mouseX,mouseY,70,70);
</code></pre>

<p>}</p>

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

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

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

<p>if (drawA == true) {</p>

<pre><code>ellipse(100,300,25,25);
</code></pre>

<p>} else if(drawB == true) {</p>

<pre><code>quad(290,0,290,600,310,600,310,0);
</code></pre>

<p>} else if (drawC == true){</p>

<pre><code>triangle(500,200,400,400,600,400);
</code></pre>

<p>}</p>

<p>}</p>
]]></description>
   </item>
   <item>
      <title>Click and Drag with Arrays of Objects</title>
      <link>https://forum.processing.org/two/discussion/19190/click-and-drag-with-arrays-of-objects</link>
      <pubDate>Mon, 21 Nov 2016 16:13:35 +0000</pubDate>
      <dc:creator>nlogler</dc:creator>
      <guid isPermaLink="false">19190@/two/discussions</guid>
      <description><![CDATA[<p>Hey Everyone,</p>

<p>New to the forum/community. I have been learning a ton with p5js (and processing)! I have a question about clicking and dragging objects in an array. The click and drag seems to be working, but I'm not getting all my visual feedback. My stroke isn't changing on the click and drag (highlight effect). Am I missing something obvious? Or is this not the best way to get click and drag behavior working? (*This is an adaptation of click and drag from the processing site). Code below:</p>

<pre><code>    var boxes = [];

    function setup() {
      createCanvas(500,500);
      for(var i=0; i&lt;20; i++){
        boxes.push(new Box(random(255),random(10,30)));
      }
    }

    function draw() {
      background(0,200,200);
      for(var i = 0; i&lt;boxes.length; i++){
        boxes[i].show();
      }
    }


    function mousePressed() {
      for(var i = 0; i&lt;boxes.length; i++){
        if (boxes[i].boxover ) {
            boxes[i].locked = true;
            strokeWeight(4);
            stroke(0, 150, 255);
            print("mouse is pressed")
        } else {
            noStroke();
            boxes[i].locked = false;
            print("mouse isn't pressed")
        }
        boxes[i].xoffset = mouseX - boxes[i].xpos;
        boxes[i].yoffset = mouseY - boxes[i].ypos
        print(boxes[i].locked);
      }
    }

    function mouseDragged() {
      for(var i = 0; i&lt;boxes.length; i++){
        if (boxes[i].locked) {
            boxes[i].xpos = mouseX - boxes[i].xoffset;
            boxes[i].ypos = mouseY - boxes[i].yoffset;
        }
      }
    }

    function mouseReleased() {
      for(var i = 0; i&lt;boxes.length; i++){
        boxes[i].locked = false;
      }
    }

//Box Constructor

function Box(tempColor,tempSize) {
    this.c = tempColor
    this.xpos = random(width);
    this.ypos = random(height);
    this.boxsize = tempSize;
    this.boxover = false;
    this.locked = false;
    this.xoffset = 0;
    this.yoffset = 0;
    rectMode(RADIUS);

    this.show = function() {
        if (mouseX &gt; this.xpos - this.boxsize &amp;&amp; mouseX &lt; this.xpos + this.boxsize &amp;&amp;
            mouseY &gt; this.ypos - this.boxsize &amp;&amp; mouseY &lt; this.ypos + this.boxsize) {
            this.boxover = true;
            fill(255);
        } else {
            this.boxover = false;
            noStroke();
            fill(this.c);
        }
        rect(this.xpos, this.ypos, this.boxsize, this.boxsize,7);
    };
}
</code></pre>

<p>Any insights and links to other materials is greatly appreciated. Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Coding Class with Dragging</title>
      <link>https://forum.processing.org/two/discussion/19271/coding-class-with-dragging</link>
      <pubDate>Thu, 24 Nov 2016 16:49:27 +0000</pubDate>
      <dc:creator>laimperiestro</dc:creator>
      <guid isPermaLink="false">19271@/two/discussions</guid>
      <description><![CDATA[<p>Hi:</p>

<p>Recently, somebody gave me a code which permits drag-and-drop an image wherever is possible, of course in works, I rewrote as a class, , but it nor has mistakes, but neither works.</p>

<p>Here is the code</p>

<p><code>Draggingpic Dragging = new Draggingpic(); 
void setup() {
  size(600, 600); 
  noStroke(); 
  Dragging.charge();  
} 
void draw() { 
  background(255); 
  Dragging.mouseDragged();
}
class Draggingpic
{
  int x;
  int y;
  PImage sample;  
  void Draggingpic(int posx,int posy)
  { 
    x=posx;
    y=posy;
    image(sample, x, y, 50, 30);
  }  
  void charge()
  { 
    sample=loadImage("g2.png");  
  }
  void mouseDragged() 
  { 
    x=mouseX; 
    y=mouseY;
  }
}</code></p>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>How to create a Sketchbook (Drawing app)?</title>
      <link>https://forum.processing.org/two/discussion/18989/how-to-create-a-sketchbook-drawing-app</link>
      <pubDate>Fri, 11 Nov 2016 18:16:20 +0000</pubDate>
      <dc:creator>czelisa</dc:creator>
      <guid isPermaLink="false">18989@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone,</p>

<p>I am pretty new to programming and I'm using p5 so it would be amazing if you could help me out. Basically I would like to create a drawing app, I've managed to create really simple drawing functions but I have a few questions and I'm not sure how to go about it. I know my questions aren't that specific yet - If you could just refer me to the right references to look at, that would help me a lot.</p>

<ol>
<li><p>Would it be possible to have an image of a Sketchbook laying on a desk as my background and only let the user draw on the actual book (not the rest of the background)?</p></li>
<li><p>How can I create different drawing tools (like pen, pencil etc.) that can be activated by clicking on an icon/image.</p></li>
<li><p>Is it possible to let someone draw something and then add filters to it. (editing the finished drawing)</p></li>
<li><p>Is there a way of including buttons, that let someone share what they've drawn on the canvas on Twitter, Facebook etc.</p></li>
</ol>

<p>Thanks a lot,
Elisa</p>
]]></description>
   </item>
   <item>
      <title>How can I stop the jumping over?</title>
      <link>https://forum.processing.org/two/discussion/19074/how-can-i-stop-the-jumping-over</link>
      <pubDate>Wed, 16 Nov 2016 18:29:15 +0000</pubDate>
      <dc:creator>Dracore</dc:creator>
      <guid isPermaLink="false">19074@/two/discussions</guid>
      <description><![CDATA[<p>I have this code, sorry I don't know how to format it,</p>

<pre><code>String[] images = {"life1.png", "life2.png", "life3.png"};
PImage Background; 
float[] positions =new float [images.length*2] ;
float bx;
float by;
int bs = 37;
int bz = 37;
boolean bover = false;
boolean locked = false;
float bdifx = 0.0; 
float bdify = 0.0; 
PImage[] image1 = new PImage [images.length]; 
float newx, newy;
int whichImage;

void setup() 
{
  imageMode (CENTER);
  fullScreen();
  Background = loadImage("Background.png");
  bx = width/2.0;
  by = height/2.0;
  for (int i=0; i &lt; images.length; i++) {
    image1 [i]= loadImage(images[i]); 
    image (image1[i], random(width), random(height), 75, 75) ;
  } 
  for (int j=0; j &lt; images.length*2; j+=2) {
    positions[j]= random(width);
    positions[j+1]= random(height);
  }
}

void draw() 
{ 
  background(Background);
  for (int i=0; i &lt; images.length; i++) {
    if (mouseX &gt; positions[i*2]-bs &amp;&amp; mouseX &lt; positions[i*2]+bs &amp;&amp; 
      mouseY &gt; positions[i*2+1]-bs &amp;&amp; mouseY &lt; positions[i*2+1]+bs) 
    {
      println ("mouseover image: "+i);
      whichImage=i;
      bover = true;  
      if (!locked) 
      { 
        stroke(255); 
        fill(153);
      }
      break;
    } 
    else
    {
      stroke(153);
      fill(153);
      bover = false;
    }
  }
  for (int j=0; j &lt; images.length; j++) {
    image (image1[j], positions[j*2], positions[j*2+1], 75, 75) ;
  }
}
void mousePressed() {
  if (bover) { 
    locked = true;
  } 
  else {
    locked = false;
  }
}

void mouseReleased() {
  locked = false;
}

void mouseDragged() {
  if (locked) {
    newx = mouseX; 
    newy = mouseY;
  }
  positions [whichImage*2] = newx;
  positions [(whichImage*2)+1] = newy;
}
</code></pre>

<p>It is working well, you can drag and drop the pictures around, but the problem is that If you are holding one picture and drag it over another, it drops that piece and picks up the one that you were moving over. Why does this happen, and how can I fix it?</p>
]]></description>
   </item>
   <item>
      <title>Howto Drag and Drop a pic file</title>
      <link>https://forum.processing.org/two/discussion/19025/howto-drag-and-drop-a-pic-file</link>
      <pubDate>Mon, 14 Nov 2016 04:32:19 +0000</pubDate>
      <dc:creator>laimperiestro</dc:creator>
      <guid isPermaLink="false">19025@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to drag a pic from a side to another and drop it in that new location, I have this code, but it doesn't work</p>

<p>PImage sample;</p>

<p>void setup(){<br />
  size(1000, 600);
  noStroke();
  sample=loadImage("test.png");
}</p>

<p>void draw(){
  background(255);
  image(sample,0,400,50,30);
}</p>

<p>void mouseDragged()
{
  image(sample,mouseX,mouseY,50,30);
}</p>

<p>void mouseReleased()
{
  image(sample,mouseX,mouseY,50,30);
}</p>
]]></description>
   </item>
   <item>
      <title>Click and remove a specific item from an ArrayList of Objects</title>
      <link>https://forum.processing.org/two/discussion/17680/click-and-remove-a-specific-item-from-an-arraylist-of-objects</link>
      <pubDate>Thu, 28 Jul 2016 10:06:17 +0000</pubDate>
      <dc:creator>Fed_e</dc:creator>
      <guid isPermaLink="false">17680@/two/discussions</guid>
      <description><![CDATA[<p>Hello, 
i'm new to processing and i'm still figuring it out!</p>

<p>I want to click a specific item on screen and remove it from an ArrayList. So far I can remove only the 0th item from the list.
This is obvious since i've something like this:</p>

<pre><code> if (mouseButton == RIGHT) {
        if(bubbles.size() &gt; 1) {
          if(mouseX&gt; ballX-radius*2 &amp;&amp; mouseX &lt; ballX+radius
          &amp;&amp; mouseY&gt; ballY-radius   &amp;&amp; mouseY &lt; ballY+radius){
            bubbles.remove(0);   ////HERE BE PROBLEMS
           }
</code></pre>

<p>I cannot understand how to select whatever object from the ArrayList</p>

<p>I've got other problems in the code, but if you guys help me out with the remove problem i should be able to get the other parts right.</p>

<p>here is the complete code.</p>

<p>[see below]</p>
]]></description>
   </item>
   <item>
      <title>Improving accuracy of mouseDragged() and mouseReleased() - noob question</title>
      <link>https://forum.processing.org/two/discussion/15697/improving-accuracy-of-mousedragged-and-mousereleased-noob-question</link>
      <pubDate>Sat, 26 Mar 2016 14:45:32 +0000</pubDate>
      <dc:creator>gergelysuto</dc:creator>
      <guid isPermaLink="false">15697@/two/discussions</guid>
      <description><![CDATA[<p>Hello,
I am a beginner with p5.js and am trying to create a basic patch where I can move around a circle on the canvas by clicking on it with the mouse. Releasing the mouse should "throw" the circle in the direction of the last mouse movement.
From what I can see it is not that my patch is clearly wrong, it is just not very accurate. With the mouse pressed, quicker movements make the mouse "lose" the circle. As for mouse release, it works maybe once every 10 times. 
Thank you for all suggestions about the code (fwiw this is something that seemed to work in its most basic form and without any issue in openFrameworks)
best,
gergely</p>

<pre><code>var x;
var y;
var speedX=0;
var speedY=0;
var moveable= false;
var radius=30;



function setup() {
  createCanvas(windowWidth, windowHeight);
  strokeWeight(2);
  x= width/2;
  y= height/2;
}

function draw(){
  background(127);
  x+=speedX;
  y+=speedY;

  ellipse(x,y,radius,radius);
}


function mouseDragged(){
  var d= dist(mouseX,mouseY,x,y);
  if (d&lt;radius){
    moveable= true;
    x= mouseX;
    y= mouseY;
  }
}

function mouseReleased(){
  if (moveable= true){
    speedX=mouseX-pmouseX;
    speedY=mouseY-pmouseY;
    print(speedX);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Spherical Coordinated Camera</title>
      <link>https://forum.processing.org/two/discussion/15464/spherical-coordinated-camera</link>
      <pubDate>Sat, 12 Mar 2016 20:09:52 +0000</pubDate>
      <dc:creator>noamnav</dc:creator>
      <guid isPermaLink="false">15464@/two/discussions</guid>
      <description><![CDATA[<p>hello there,</p>

<p>trying to create my own class for spherical movement of camera (based on mouse movement), i am experiencing a problem setting the up vector for the camera:
when scrolling the camera on the up and down the matrix (x and y) seem to flip.</p>

<p>don't seem to have this problem with the horizontal scroll.</p>

<p>help anyone?</p>

<p>thanks</p>

<pre><code>float camX, camY, camZ;
float camRad = width*20;
float camTheta, camPhi;
float camDragX, camDragY;
float newCamX = 50;
float newCamY = 600;
boolean moveCam = false;
PVector up;

void cam() {                                                                                            //camera
  camPhi   = map(newCamX, 0, width, PI, -PI);                              //phi is the horizontal angle 0-2PI    
  camTheta = map(newCamY, 0, height, HALF_PI, -HALF_PI);        //theta is the vertical angle 0-PI
  up    = new PVector (sin(camPhi), cos(camPhi));


  camX = camRad*sin(camTheta)*sin(camPhi);
  camY = camRad*sin(camTheta)*cos(camPhi);  
  camZ = camRad*cos(camTheta);

  camera(camX, camY, camZ, 0, 0, 0, up.x, up.y, up.z);
}

void mousePressed() {
  if (mouseButton == RIGHT) {
    camDragX = mouseX - newCamX;
    camDragY = mouseY - newCamY;
    moveCam = true;
  }
}

void mouseDragged() {
  if (mouseButton == RIGHT) {
    if (moveCam) {
      newCamX = mouseX - camDragX;
      newCamY = mouseY - camDragY;
    }
  }
}

void mouseReleased() {
  moveCam = false;
}

void mouseWheel(MouseEvent event) {
  float zoom = event.getCount();
  zoom = zoom*50;
  camRad += zoom;
}

void setup () {
  size (500, 500, P3D);
  colorMode(HSB, 360, 1, 1, 1);  
}


void draw() {
  background (0, 0, 1);  
  drawAxis();
  cam();
  fill(1,0,0);
  ellipse (width/2, height/2, 250, 250);
}

void drawAxis() {
  stroke (0, 1, 1);
  line (0, 0, 0, 1000, 0, 0);
  stroke (90, 1, 1);
  line (0, 0, 0, 0, 1000, 0);
  stroke (210, 1, 1);
  line (0, 0, 0, 0, 0, 1000);
  noStroke();
}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>