<?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 mousewheel() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=mousewheel%28%29</link>
      <pubDate>Sun, 08 Aug 2021 16:06:56 +0000</pubDate>
         <description>Tagged with mousewheel() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedmousewheel%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>Fade background with animation at the same time</title>
      <link>https://forum.processing.org/two/discussion/27697/fade-background-with-animation-at-the-same-time</link>
      <pubDate>Thu, 05 Apr 2018 15:14:28 +0000</pubDate>
      <dc:creator>LoCamillo</dc:creator>
      <guid isPermaLink="false">27697@/two/discussions</guid>
      <description><![CDATA[<p>I've been trying to do a project that fade in/out a series of backgrounds. These backgrounds are made of images and they fade/in and out in a sequence showing a text in between. But at the same time, there's an animation of stars playing in the background. The problem is that when the fade of the backgrounds are happening, the stars get slower. I want to fade the backgrounds and keep the stars with the same speed. This is what I have:</p>

<pre><code>     var particles = [];
        var fundos = [];
        var glifos = [];
        var img;
        var logotri;
        var teste;
        var m = 0;
        var loop;
        var alphafade = 255;
        var idlogo= 255;
        var idglifo = 0;


        function setup() {
          cvn = createCanvas(windowWidth, windowHeight);
          logotri = loadImage("logofinal.png");
          teste = loadImage("primeira-tela-1.png");
          loop = 0;

          for (var i = 0; i &lt; 8; i++){
            fundos[i] = loadImage("primeira-tela-" + (i+1) + ".png");
          }

          for (var i = 0; i &lt; 7; i++){
            glifos[i] = loadImage("Glifo" + (i+1) + ".png");
          }

          for (var i = 0; i &lt; 256; i++) {
            p = new Estrelas();
            particles.push(p); // Criação do vetor das estrelas do fundo
          }
        }

        function draw() {
          background(fundos[0]);

          if (m == 0) { //Página inicial estática
            estrelas();
            image(logotri, windowWidth / 3, windowHeight / 3);
          }

          else if (m == 1){ //Fadeout do logo
            tint(255, alphafade);
            image(logotri, windowWidth / 3, windowHeight / 3);
            estrelas();
            fadeout(2, 2);
            noTint();
            }

          else if (m == 2){ //Fadein do glifo 1 + mudança de fundo
            tint(255, alphafade);
            image(fundos[1], 0,0);
            image(glifos[0], windowWidth / 2, windowHeight / 2, 100, 100);
            fadein(3, 3);
            estrelas();
            noTint();

          }

          else if (m == 3){
            image(fundos[1], 0,0);
            tint(255, alphafade);
            image(glifos[0], windowWidth / 2, windowHeight / 2, 100, 100);
            fadeout(4, 2);
            estrelas();
            noTint();


          }
            else if (m == 4){
            image(fundos[1], 0,0);
            texto('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent posuere sapien vitae vulputate aliquam.');
            estrelas();
            fadein(5, 1);

          }
          else if (m == 5){
            image(fundos[1], 0,0);
            texto('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent posuere sapien vitae vulputate aliquam.');
            estrelas();
            fadeout(6, 2);
          }

          else if (m == 6){
            image(fundos[1], 0,0);
            tint(255, alphafade);
            image(fundos[2], 0,0);
            image(glifos[1], windowWidth / 2, windowHeight / 2, 100, 100);
            estrelas();
            fadein(7, 1);
            noTint();
          }

          else if (m == 7){
            image(fundos[2], 0,0);
            tint(255, alphafade);
            image(glifos[1], windowWidth / 2, windowHeight / 2, 100, 100);
            estrelas();
            fadeout(8, 1);
            noTint();
          }


          else if (m == 8){
            image(fundos[2], 0,0);
            estrelas();
            }
          }

        //Função que controla o movimento das estrelas do fundo
        function estrelas() {
          for (var i = 0; i &lt; particles.length - 1; i++) {
            if (particles[i].getalfa() &lt; 5) {
              particles[i].reset(); //Quando o alfa das particulas está quase apagando, ele reseta a particula
              break;
            }
          }

          for (i = 0; i &lt;= particles.length - 1; i++) {
            particles[i].update();
            particles[i].show(); //Mostra as particulas se movendo
          }
        }

        //Função que controla o fadeout das imagens e passa pro proximo nivel de animação
        function fadeout(proximonivel, speed){
          alphafade = alphafade - speed;
          if (alphafade &lt; 0)
            {
                alphafade = 0;
                m = proximonivel;
              }
        }

        //Função que controla o fadein das imagens e passa pro proximo nivel de animação
        function fadein(proximonivel, speed){
          alphafade = alphafade + speed;
          if (alphafade &gt; 255)
            {
                alphafade = 255;
                m = proximonivel;
              }
        }

        //Função que controla no início se houve movimento na roda do mouse
        function mouseWheel(event) {
          if (event.delta != 0 &amp;&amp; loop == 0) {
            m = 1;
            loop = 1;
          }
        }

        //Função que controla no inicio se houve clique do mouse
        function mouseClicked(){
          if ( loop == 0){
            m = 1;
            loop = 1;
          }
        }

        //Função que mostra texto e controla as propriedades
        function texto(string){
          tint(255, alphafade);
          fill(255, alphafade);
          textSize(20);
          textAlign(CENTER, CENTER);
          text(string, windowWidth / 2, windowHeight / 2);
          noTint();
        }

        class Estrelas {

          constructor() {
            this.x = random(0, 1200);
            this.y = random(0, 800);
            this.vx = random(-1, 1);
            this.vy = random(-2, -1);
            this.alfa = random(0, 100);
          }

          getalfa() {
            return this.alfa;
          }

          reset() {
            this.x = random(0, 1200);
            this.y = random(0, 800);
            this.vx = random(-1, 1);
            this.vy = random(-2, -1);
            this.alfa = 100;


          }

          update() {
            this.x += this.vx;
            this.y += this.vy;
            this.alfa--;

          }

          show() {
            fill(255, 255, 255, this.alfa);
            noStroke();
            ellipse(this.x, this.y, 5, 5);
          }

        }
</code></pre>

<p>I have tried a lot of things but i can't make it work.</p>
]]></description>
   </item>
   <item>
      <title>This is being wierd, that's the best way I can explain it</title>
      <link>https://forum.processing.org/two/discussion/27925/this-is-being-wierd-that-s-the-best-way-i-can-explain-it</link>
      <pubDate>Sun, 06 May 2018 21:16:57 +0000</pubDate>
      <dc:creator>metype</dc:creator>
      <guid isPermaLink="false">27925@/two/discussions</guid>
      <description><![CDATA[<p>I referenced p5.js and p5.dom.js and, of course, Evolution.js</p>

<p>Evolution.js:</p>

<pre><code>var img;
var X;
var Y;
var noclipspeed = 20
var Z
var shp
var shpi
var speed
var freecam = false
var XR = 0
var YR = 0
var debug = true
function preload() {
town = loadImage('./assets/town.png');
BG = loadImage('./assets/BG.png');
X = random(-250,250)
Y = random(-250,250)
Z = 1
shop = loadImage('./assets/shop.png')
hax = loadImage('./assets/hax.png')
cursor(CROSS)
}


function setup() {
 createCanvas(1905,1065,WEBGL);
}


function draw() {
  rotateY(XR)
  rotateX(YR)
  cursor(CROSS)
  keyPressed()
  translate(0,0,10000)
  texture(hax)
  plane(10000,10000)
  translate(0,0,-10000)
  translate(0,0,-10000)
  texture(BG)
  plane(10000000,1000000)
  texture(town)
  translate(0,0,10000)
  translate(X-1000,Y-1000,Z)
  plane(950,567)
  translate(800,750)
  texture(shop)
  plane(100,100)
  if(freecam === false) {
  if (Z&gt;577) {
  Z = 577
} else if (Z &lt; -2600) {
  Z = -2600
} else if (Z === 0 ) {
 Z = 1
}
}
if (shpi === 1) {
Z = 577
X = -814.219833927416
Y = -751.7183831208923
}
if (noclipspeed &lt; 10) {
noclipspeed = 10
}
}

function keyPressed() {
 if (keyIsDown(70)) {
   fullscreen(1)
} else if (keyIsDown(78)) {
   fullscreen(0)
} else if (keyIsDown(79)) {
    freecam = true
  } else if (keyIsDown(76)) {
    freecam = false
    XR = 0
    YR = 0
  } else if (keyIsDown(113)) {
saveCanvas("EvolutionTST","png")
}
 if (freecam === false) {
 XR = 0
 YR = 0
 if (keyIsDown(65)) {
    X+=10;
  } else if (keyIsDown(68)) {
    X-=10;
  } else if (keyIsDown(87)) {
    Y+=10;
  } else if (keyIsDown(83)) {
    Y-=10;
  } else if (keyIsDown(70)) {
   fullscreen(1)
  } else if (keyIsDown(78)) {
   fullscreen(0)
  }
} else {
 if (keyIsDown(65)) {
    X += noclipspeed
} else if (keyIsDown(68)) {
    X -= noclipspeed
} else if (keyIsDown(87)) {
    Z += noclipspeed
} else if (keyIsDown(83)) {
    Z -= noclipspeed
} else if (keyIsDown(32)) {
    Y += noclipspeed
} else if (keyIsDown(16)) {
    Y -= noclipspeed
} else if (keyIsDown(39)) {
    XR += 0.05
} else if (keyIsDown(37)) {
    XR -= 0.05
} else if (keyIsDown(38)) {
    YR -= 0.05
} else if (keyIsDown(40)) {
    YR += 0.05
} else if (keyIsDown(107)) {
    noclipspeed += 10
} else if (keyIsDown(109)) {
    noclipspeed -= 10
} 
}
}

function mouseWheel(event) {
   Z -= event.delta
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How do zoom relative to mouse?</title>
      <link>https://forum.processing.org/two/discussion/27927/how-do-zoom-relative-to-mouse</link>
      <pubDate>Sun, 06 May 2018 22:25:47 +0000</pubDate>
      <dc:creator>Vanthex</dc:creator>
      <guid isPermaLink="false">27927@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>My sketch basically draws objects from left to right. I implemented a zoom function with the mouse wheel with translation but it doesn't zoom relative to my mouse.</p>

<p>Any ideas how to fix this?</p>

<pre><code>float x = 100;
int y = 200;
int gap = 50;
float scale = 1.0;

ArrayList&lt;Body&gt; bodies = new ArrayList&lt;Body&gt;();

class Body {

  String name;
  int size;

  Body(String name, int size) {
    this.name = name;
    this.size = size;
  }

  float getSize() {
    return this.size * scale;
  }

  void draw(float x) {
    fill(255);
    noStroke();
    ellipse(x, y - this.getSize() / 2, this.getSize(), this.getSize());
    noFill();
    stroke(255,0,255);
    rect(x, y - this.getSize() / 2, this.getSize(), this.getSize());
  }
}

float getOffset() {
  int offset = 0;
  for (Body body : bodies) {
    offset += body.getSize();
    offset += gap;
  } 
  return offset;
}

void setup() {
  size(1600, 900);
  ellipseMode(CORNER);

  bodies.add(new Body("test", 100));
  bodies.add(new Body("2", 400));
  bodies.add(new Body("big", 1000));
}

void draw() {
  fill(0);
  noStroke();
  rect(0, 0, 1600, 900);

  pushMatrix();
  translate(x, y);

  float drawX = x;
  for (Body body : bodies) {
    body.draw(drawX);
    drawX += (body.getSize() + gap);
    fill(255,255,0);
    noStroke();
    rect(drawX - gap, y - gap / 2, gap, gap);
  }

  popMatrix();
}

void keyPressed() {
  float prevOffset = getOffset();
  if (keyCode == UP) {
    scale *= 1.1;
    float newOffset = getOffset();
    //x -= (newOffset - prevOffset) / 2;
    x -= mouseX * 0.1;
  } else if (keyCode == DOWN) {
    scale *= 0.9;
    float newOffset = getOffset();
    //x += (prevOffset - newOffset) / 2;
    x += mouseX * 0.1;
  } else if (keyCode == LEFT) {
    x += 10;
  } else if (keyCode == RIGHT) {
    x -= 10;
  }
  if (scale &lt; 0) {
    scale = 0;
  }
}

void mouseWheel(MouseEvent event) {
  float e = event.getCount();
  if (e &lt; 0) {
    scale *= 1.1;
  } else if (e &gt; 0) {
    scale *= 0.9;
  }
  x -= event.getCount() * mouseX / 1000;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Get the RGB value of a pixel on a textured sphere ?</title>
      <link>https://forum.processing.org/two/discussion/27796/get-the-rgb-value-of-a-pixel-on-a-textured-sphere</link>
      <pubDate>Wed, 18 Apr 2018 18:07:51 +0000</pubDate>
      <dc:creator>mala</dc:creator>
      <guid isPermaLink="false">27796@/two/discussions</guid>
      <description><![CDATA[<p>I have a P3D sketch with a Sphere primitive at 0,0,0. 
Surrounding the sphere (though not touching) are a number of cubes that are orientated so their z-axis points to the center of the sphere.</p>

<p>The sphere is textured with an image file.
How would I go about finding the colour on the surface of the sphere at the point a line from each cube to 0,0,0 intersects the surface ?</p>

<p>looking for general ideas at this stage... was thinking collision detection,raytracing... but also wondered (hoping!) if there may be a simpler method ?</p>

<p>cheers,
mala</p>
]]></description>
   </item>
   <item>
      <title>Endless Scroll</title>
      <link>https://forum.processing.org/two/discussion/25987/endless-scroll</link>
      <pubDate>Tue, 16 Jan 2018 02:33:14 +0000</pubDate>
      <dc:creator>grumo</dc:creator>
      <guid isPermaLink="false">25987@/two/discussions</guid>
      <description><![CDATA[<p>I have a collection of images that I want to appear and move as the user scrolls with the mouse wheel. I did a version with the mouseWheel event (updating the position of the images) but the scroll is rather slow and not smooth at all (I think because the continuous refreshing in draw() of few images with different alpha values). I wonder if is possible to put the images fixed in the HTML structure, so the scroll happens in a normal web page but controlling the images files (with parameters as alpha) and other events/texts from p5.js. Any ideas or examples? Thanks a lot.</p>
]]></description>
   </item>
   <item>
      <title>Inconsistant download of image</title>
      <link>https://forum.processing.org/two/discussion/25783/inconsistant-download-of-image</link>
      <pubDate>Tue, 02 Jan 2018 09:05:42 +0000</pubDate>
      <dc:creator>OhNoFlowNo</dc:creator>
      <guid isPermaLink="false">25783@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I'm calculating the mandelbrot set and would like to download i high resolution image. This is done by calculating a large image (the global img variable), assigning it to the downloadImage variable for storage and issuing a download. All this is working as intended, however the download doesn't always work. Especially when I try to render a large image with 5000 pixels in width the download sometimes does not start. Chrome recognizes that a download has been issued and shows the green wave like animation on the menu bar but the download window never appears. Since the download sometimes works fine and sometimes not, I have not been able to locate the problem so far.</p>

<p>Any imput is appreciated as I am stuck.</p>

<p>EDIT: The download happens in the function downloadImage()</p>

<pre><code>var ratio;
var mapSize;
var centerX;
var centerY;
var renderSpeed = 20;
var currentLine = 0;
var img;
var downloadImage;
var calcTime;
var downloadButton;

function setup() {

  mapSize = 2;
  centerX = -1;
  centerY = 0;

  setupCanvas();

  downloadButton = createButton('Download');
  downloadButton.position(5, 85);
  downloadButton.mousePressed(downloadImage);

  noLoop();
}

function setupCanvas()
{
  resizeCanvas(window.innerWidth, window.innerHeight);
  ratio = window.innerWidth / window.innerHeight;
  pixelDensity(1); // Enables fine rendering for HDPI screens
  loadPixels(); // Enables pixels[]
  updateMandelbrotSet(window.innerWidth, window.innerHeight, true);
  updateText();
}

function windowResized() {
  setupCanvas();
}

function downloadImage()
{
  updateMandelbrotSet(window.innerWidth, window.innerHeight, true);
  updateMandelbrotSet(5000, 5000 / ratio, false);
  downloadImage = img;
  //downloadImage.save('Mandelbrot','png');  
  updateText();

  var mimeType = 'image/png';
  var downloadMime = 'image/octet-stream';
  var imageData = downloadImage.canvas.toDataURL(mimeType);
  var extension = 'png';
  var filename = 'Mandelbrot';
  imageData = imageData.replace(mimeType, downloadMime);

  //Make the browser download the file
  p5.prototype.downloadFile(imageData, filename, extension);

}

function updateText() {fill(255, 255, 255, 255);
  text('Calculation time: ' + calcTime + ' ms', 5, 15);
  text('CenterX: ' + centerX, 5, 35);
  text('CenterY: ' + centerY, 5, 55);
  text('Size: ' + mapSize, 5, 75);
}

function updateMandelbrotSet(xWidth, yWidth, update) {
  var start = millis();
  img = createImage(xWidth, yWidth);
  img.loadPixels();
  for (var x = 0; x &lt; xWidth; x++) {
    for (var y = 0; y &lt; yWidth; y++) {

      var reOrg = map(x, 0, xWidth, centerX - mapSize * ratio, centerX + mapSize * ratio)
      var imOrg = map(y, 0, yWidth, centerY - mapSize, centerY + mapSize)
      var re = reOrg;
      var im = imOrg

      var nMax = 99; // Iteration count (precision)
      var n = 0;
      var z = 0;

      while (n &lt; nMax) {
        var reNew = re * re - im * im;
        var imNew = 2 * re * im;
        re = reNew + reOrg;
        im = imNew + imOrg;

        if (re * re + im * im &gt; 4)
        {
          break;
        }

        n++;
      }

      var pix = (x + y * xWidth) * 4;
      if (n == nMax) {
        img.pixels[pix + 0] = 0;
        img.pixels[pix + 1] = 0;
        img.pixels[pix + 2] = 0;
        img.pixels[pix + 3] = 255;
      } else {
        img.pixels[pix + 0] = ((n - 33)/33) * 255;
        img.pixels[pix + 1] = ((n - 66)/33) * 255;
        img.pixels[pix + 2] = ((n - 0)/33) * 255;
        img.pixels[pix + 3] = 255;
      }
    }
  }
  img.updatePixels();

  if (update)
  {
    image(img, 0, 0);
  }

  var end = millis();
  calcTime = end - start;
  console.log("This took: " + calcTime + "ms.")
}

function mouseWheel(event) {
  if (event.delta &lt; 0) {
    if (mapSize &gt; 5e-16) {
      x = map(mouseX, 0, window.innerWidth, centerX - mapSize * ratio, centerX + mapSize * ratio)
      centerX = centerX + (x - centerX) * 0.3;
      y = map(mouseY, 0, window.innerHeight, centerY - mapSize, centerY + mapSize)
      centerY = centerY + (y - centerY) * 0.3;
      mapSize = mapSize * 0.7; 
    }
  } else {
    x = map(mouseX, 0, window.innerWidth, centerX - mapSize * ratio, centerX + mapSize * ratio)
    centerX = centerX - (x - centerX) * 0.3;
    y = map(mouseY, 0, window.innerHeight, centerY - mapSize, centerY + mapSize)
    centerY = centerY - (y - centerY) * 0.3;
    mapSize = mapSize / 0.7; 
  }

  updateMandelbrotSet(window.innerWidth, window.innerHeight, true);
  updateText();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Zooming into where mouse pointer is</title>
      <link>https://forum.processing.org/two/discussion/25735/zooming-into-where-mouse-pointer-is</link>
      <pubDate>Wed, 27 Dec 2017 23:49:24 +0000</pubDate>
      <dc:creator>glennmarshall</dc:creator>
      <guid isPermaLink="false">25735@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to work out how the user can use the mouse wheel to zoom in and out of the screen with the mouse pointer being the centre of zooming.  I nearly have it working, except that after zooming, the screen content follows the pointer around as you move it.  I can't work out the math / code to offset this.  I need to use the translate / scale functions for my project.
Thanks!</p>

<pre><code>void setup(){
  size(500,500);
}

float zoom=1;

void draw(){
  background(200);

  translate(mouseX,mouseY);

  scale(zoom);

  translate(-(mouseX),-(mouseY));

  ellipse(20,200,500,300);
  rect(200,400,300,300);
  ellipse(400,200,100,100);

}

void mouseWheel(MouseEvent event) {
  float e = event.getCount();
  //println(e);
  zoom-=e/10;

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Get the amount of characters in one line of a textbox</title>
      <link>https://forum.processing.org/two/discussion/23837/get-the-amount-of-characters-in-one-line-of-a-textbox</link>
      <pubDate>Thu, 17 Aug 2017 05:39:13 +0000</pubDate>
      <dc:creator>Dinoswarleafs</dc:creator>
      <guid isPermaLink="false">23837@/two/discussions</guid>
      <description><![CDATA[<p>Hey! Right now I'm making a test in Processing, and half of it involves a prompt on screen to answer questions from. Right now it looks like <a rel="nofollow" href="http://i.imgur.com/C9tIkSY.png">this</a>.</p>

<p>Because I can't fit all the text of the prompt on screen with a reasonable font, I'm instead allowing the ability for the tester to scroll down and up the text. Here's a standalone example of what it would be like :</p>

<pre><code>String originalText = "Happy birthday to you\n" + 
                      "Happy birthday to you\n" +
                      "Happy birthday Dear Random User\n" +
                      "Happy Birthday to you.\n\n" +

                      "From good friends are true,\n" +
                      "From old friends and new,\n" +
                      "May good luck go with you,\n" +
                      "And happiness too.";
String displayText;
int scrollAmount;
PFont font;
float scrollMultiplier;

void setup() {
  size(800, 800);
  displayText = originalText;
  font = createFont("Arial", 35);  
  scrollMultiplier = 30;
}

void draw() {
  background(0);
  fill(255);
  textFont(font);
  text(displayText, 40, 40, 700, 600);

}

void mouseWheel(MouseEvent event) {
 float value = event.getCount();
 scrollAmount += (int) value * scrollMultiplier;
 scrollAmount = constrain(scrollAmount, 0, originalText.length());
 displayText = originalText.substring(scrollAmount, originalText.length());
}
</code></pre>

<p>This is most of what I need. However, I want it so the user scrolls line by line instead of what it is right now where the lines kinda shift around since I'm splicing at random places in the substring.</p>

<p>What I need is to get the amount of characters of a certain line on screen and have this be the amount mulitplied by e in the mouseWheel method (essentially set the amount of characters to scrollMultiplier). This way it adds or subtracts an entire line of text instead of an arbitrary 30.  The problem is ... I have no idea how to do this. I'm using the text option that takes four parameters as a box, with the specific line being</p>

<p>I'm not even sure if what I want is possible :| I can't just take the normal amount of characters that fit in a line since some are bigger than others and sometimes a line breaks midway to start a new paragraph. In short, I just need to get the amount of characters that are present on a certain line and have this value for scrolling purposes.</p>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Help with translation calculations</title>
      <link>https://forum.processing.org/two/discussion/22377/help-with-translation-calculations</link>
      <pubDate>Thu, 04 May 2017 01:21:56 +0000</pubDate>
      <dc:creator>Vanthex</dc:creator>
      <guid isPermaLink="false">22377@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys,
In this sketch, the user should be able to zoom in and out relative to the mouse's position. However the more you zoom in/out, the larger the error of translation there is.
gif link:
<a href="https://gyazo.com/bc19520eb98509299f9d0af9be548228" target="_blank" rel="nofollow">https://gyazo.com/bc19520eb98509299f9d0af9be548228</a></p>

<p>This is how I calculated the translation:
trans += getStriplength() * deltascale
getStriplength returns the length of the whole strip of objects while deltascale is the amount that is reduced each time when the mouse scrolls. Its default value is 0.2, which means the objects will be either 1.02 times bigger or 0.98 times smaller than the original.
Therefore I am getting the difference of the lengths of the strip before and after, and adding it to the offset. However as I mentioned before it doesn't work the more you zoom in/out. Any help will be appreciated!</p>

<p>Code:</p>

<pre><code>PImage backgroundImage;
PFont font;
int x = 0;
int xoffset = 0;
int deltax = 5;
float scale = 512/30;
float deltascale = 0.02;
ArrayList&lt;celestialObject&gt; ObjectList;
String[] objectfile;
String[] configfile;
int savetimer = 0;
static int screenwidth = 1920;
static int screenheight = 1080;
float trans = 0;

class celestialObject {
  String name;
  float diameter;
  String unit;
  String sprite;
  PImage img;
  int wid;
  int hei;
  int xpos;

  celestialObject(String Oname, float Odiameter, String Ounit, String Oimg) {
    name = Oname;
    diameter = Odiameter;
    unit = Ounit;
    sprite = Oimg;
    img = loadImage(Oimg);
    wid = img.width;
    hei = img.height;
  }
}

void setup() {
  size(1920, 1080);
  frameRate(200);
  objectfile = loadStrings("objects.txt");
  configfile = loadStrings("config.ini");
  backgroundImage = loadImage("background.png");
  font = createFont("Franklin Gothic Book Regular.ttf", 32);
  textFont(font, 32);
  textAlign(CENTER, CENTER);
  imageMode(CENTER);
  ObjectList = new ArrayList();
  readObjects();
  readConfig();
  loadOffset();
}

void addObject(String Aname, float Adiameter, String Aunit, String Aimg) {
  println("Loading "+Aname);
  if (Aimg.equals("null")) {
    ObjectList.add(new celestialObject(Aname, Adiameter, Aunit, "images/"+Aname+".png"));
  } else {
    ObjectList.add(new celestialObject(Aname, Adiameter, Aunit, "images/"+Aimg));
  }
}

void readObjects() {
  for (int i = 0; i &lt; objectfile.length; i++) {
    String[] currentObject = split(objectfile[i], ",");
    addObject(currentObject[0], float(currentObject[1]), currentObject[2], currentObject[3]);
  }
}

void readConfig() {
  for (int i = 0; i &lt; configfile.length; i++) {
    char slash = configfile[i].charAt(0);
    if (slash != '/') {
      //getting config values based on line number
      if (i == 1) {
        xoffset = int(configfile[i]);
      } else if (i == 3) {
        scale = float(configfile[i]);
      }
    }
  }
}

void loadOffset() {
  //for (int i = 0; i &lt;= xoffset; i++) {
  //  int x = 0 + xoffset;
  //  for ( celestialObject drawObject : ObjectList ) {         
  //    float dia;
  //    if (drawObject.unit.equals("km")) {
  //      dia = drawObject.diameter * 1000;
  //    } else {
  //      dia = drawObject.diameter;
  //    }
  //    int drawWidth = int(scale * dia);
  //    //checks if image is too small to be drawn
  //    if (x+drawObject.img.width &gt;= 0 &amp;&amp; x &lt;= 1500) {
  //      int drawWidth = int(scale * dia);
  //      int drawHeight = int(drawWidth * drawObject.hei / drawObject.wid);
  //      if (drawWidth &gt; 0 &amp;&amp; drawHeight &gt; 0) {
  //        //drawObject.img.resize(drawWidth, drawHeight);
  //        image(drawObject.img, x+(drawWidth/2), 400,drawWidth, drawHeight);
  //        //calculates font size relative to object's current size
  //        int textSize;
  //        //checks if the name or diameter is longer, then uses the longer one for calculation
  //        if (drawObject.name.length() &lt; str(drawObject.diameter).length()) {
  //          textSize = int(drawObject.img.width/str(drawObject.diameter).length());
  //        } else {
  //          textSize = int(drawObject.img.width/drawObject.name.length());
  //        }
  //        if (textSize &gt; 0) {
  //          textSize(textSize);
  //          float texty = 418+(drawObject.img.height/2);
  //          if (texty &lt; (418+(drawObject.img.height/2))) {
  //            texty = 418;
  //          }
  //          text(drawObject.name, x+(drawObject.img.width/2), texty);
  //          text(drawObject.diameter+drawObject.unit, x+(drawObject.img.width/2), texty+textSize);
  //        }
  //      }
  //    }
  //    drawObject.xpos = x;
  //    x += (drawObject.img.width*0.08 + drawObject.img.width);
  //  }
  //}
}

void draw() {
  image(backgroundImage, screenwidth/2, screenheight/2);
  int x = int(0 + xoffset + trans);
  for ( celestialObject drawObject : ObjectList ) {
    float dia;
    if (drawObject.unit.equals("km")) {
      dia = drawObject.diameter * 1000;
    } else {
      dia = drawObject.diameter;
    }
    int drawWidth = int(scale * dia);
    if (x+(scale*dia) &gt;= 0 &amp;&amp; x &lt;= screenwidth) {
      //checks if image is too small to be drawn 
      int drawHeight = int(drawWidth * drawObject.hei / drawObject.wid);
      if (drawWidth &gt; 0 &amp;&amp; drawHeight &gt; 0) {
        //drawObject.img.resize(drawWidth, drawHeight);
        image(drawObject.img, x+(drawWidth/2), screenheight/2, drawWidth, drawHeight);
        //calculates font size relative to object's current size
        int textSize;
        //checks if the name or diameter is longer, then uses the longer one for calculation
        if (drawObject.name.length() &lt; str(drawObject.diameter).length()) {
          textSize = int(drawWidth/str(drawObject.diameter).length());
        } else {
          textSize = int(drawWidth/drawObject.name.length());
        }
        if (textSize &gt; 0) {
          textSize(textSize);
          float texty = screenheight/2+18+(drawHeight/2);
          if (texty &lt; (screenheight/2+18+(drawHeight/2))) {
            texty = screenheight/2+18;
          }
          text(drawObject.name, x+(drawWidth/2), texty);
          text(drawObject.diameter+drawObject.unit, x+(drawWidth/2), texty+textSize);
        }
      }
    }
    drawObject.xpos = x;
    x += (drawWidth*0.08 + drawWidth);
  }
  //display deltax
  textSize(32);
  text(str(deltax), screenwidth-50, 10);
  text(str(deltascale), screenwidth-50, 50);
  //display Saved
  if (savetimer &gt; 0) {
    text("Saved", screenwidth-50, 90);
    //text(str(savetimer),1450,130);
  }
  if (savetimer &gt; 0) {
    savetimer -= 1;
  }
  //println(str(scale));
}

void mouseWheel(MouseEvent event) {
  float e = event.getCount();
  if (e &lt; 0) {
    scale *= (1 + deltascale);
    mouseX = xoffset;
    trans -= (getStriplength() * deltascale);
  } else if (e &gt; 0) {
    scale *= (1 - deltascale) ;
    mouseX = xoffset;
    trans += (getStriplength() * deltascale);
  }
}

void keyPressed() {
  if (key == CODED) {
    if (keyCode == LEFT) {
      xoffset += deltax;
    } else if (keyCode == RIGHT) {
      xoffset -= deltax;
    } else if (keyCode == UP) {
      deltax += 5;
    } else if (keyCode == DOWN) {
      deltax -= 5;
    }
  }
  if (key == 's') {
    for (int i = 0; i &lt; configfile.length; i++) {
      if (i == 1) {
        configfile[i] = str(xoffset);
      } else if (i == 3) {
        configfile[i] = str(scale);
      }
    }
    saveStrings("config.ini", configfile);
    savetimer = 500;
  } else if (key == 'q') {
    deltascale += 0.02;
  } else if (key == 'a') {
    deltascale -= 0.02;
  }
  if (deltax &lt; 0) {
    deltax = 0;
  } else if (deltascale &lt; 0) {
    deltascale = 0;
  }
}

float getStriplength() {
  float x = 0;
  int i = 0;
  for ( celestialObject getObject : ObjectList ) {
    float dia;
    if (getObject.unit.equals("km")) {
      dia = getObject.diameter * 1000;
    } else {
      dia = getObject.diameter;
    }
    int drawWidth = int(scale * dia);
    x += (drawWidth*0.08 + drawWidth);
    i++;
    //println(ObjectList.size());
    if (i == ObjectList.size()) {
       x -= drawWidth*0.08;
    }
    //println(x);
  }
  //println(x);
  return x;  
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How do I zoom in using p5?</title>
      <link>https://forum.processing.org/two/discussion/22345/how-do-i-zoom-in-using-p5</link>
      <pubDate>Tue, 02 May 2017 14:38:22 +0000</pubDate>
      <dc:creator>banana</dc:creator>
      <guid isPermaLink="false">22345@/two/discussions</guid>
      <description><![CDATA[<p>I think I can use mouseWheel() but need help getting started.</p>

<p>Also, first time here. I was wondering if topics here is mostly processing/java or p5js.</p>
]]></description>
   </item>
   <item>
      <title>Mouse with two scroll wheels</title>
      <link>https://forum.processing.org/two/discussion/22226/mouse-with-two-scroll-wheels</link>
      <pubDate>Wed, 26 Apr 2017 15:48:16 +0000</pubDate>
      <dc:creator>Alex_Pr</dc:creator>
      <guid isPermaLink="false">22226@/two/discussions</guid>
      <description><![CDATA[<p>I have a Logitech MX Master which has a vertical and horizontal scroll wheel. The following way of tracking wheel changes works only for the vertical wheel. Is there a way to do the same for the horizontal wheel?</p>

<pre><code>void mouseWheel(MouseEvent event) {
  float e = event.getCount();
}
</code></pre>

<p>Thanks in advance,
Alex</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>Touch Input and Performance Issues</title>
      <link>https://forum.processing.org/two/discussion/20179/touch-input-and-performance-issues</link>
      <pubDate>Tue, 10 Jan 2017 14:56:43 +0000</pubDate>
      <dc:creator>AstreinerBaum</dc:creator>
      <guid isPermaLink="false">20179@/two/discussions</guid>
      <description><![CDATA[<p>Hello, 
I made a very simple Gradient Scrolling site. But I have only Issues on mobile devices. On chrome it is  not doing anything and on firefox there are extreme performance issues (also there is a "you reached the end of the site animation")
Any ideas how it could be made better?
I guess I should go for native JS for such a simple site.</p>

<ol>
<li>Desktop: How do you find out if scrolled down or up? </li>
</ol>

<p>Here's the site: <a href="http://matthias.pitscher.xyz/scrollgrad.html" target="_blank" rel="nofollow">http://matthias.pitscher.xyz/scrollgrad.html</a></p>

<p>Here's the code:</p>

<pre><code>var rows;
function setup(){
  createCanvas(windowWidth, windowHeight);
  colorMode(HSB,360,100,100);
  background(0);
  rows = 10;
  noStroke();
}

var index = 0;
function draw(){
  for (var i = 0; i &lt; windowHeight; i+=rows) {
    var gradient = (i / windowHeight * 20 + index) % 360;
    fill(gradient, 70, 100);
    rect(0, i-rows, windowWidth, i);
  }
}

function mouseWheel() {
  index++;
  return false;
}

function touchMoved() {
    index++;
  return false;
}
function windowResized() {
    resizeCanvas(windowWidth, windowHeight);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Horizontal scrolling</title>
      <link>https://forum.processing.org/two/discussion/19168/horizontal-scrolling</link>
      <pubDate>Sun, 20 Nov 2016 00:44:03 +0000</pubDate>
      <dc:creator>aster94</dc:creator>
      <guid isPermaLink="false">19168@/two/discussions</guid>
      <description><![CDATA[<p>hello, i would like to add a horizontal scolling bar to this sketch since i "lost" some data at the end of the windows</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/683/2XVEWGDYBNHW.jpg" alt="partialSave" title="partialSave" /></p>

<p>i can't use the example in the reference since it uses an immage. Really i tried to use it but without good results. any idea? maybe i miss a library that could help me?</p>
]]></description>
   </item>
   <item>
      <title>mouseWheel function -&gt; event.WheelDelta is not working</title>
      <link>https://forum.processing.org/two/discussion/18325/mousewheel-function-event-wheeldelta-is-not-working</link>
      <pubDate>Wed, 28 Sep 2016 12:49:20 +0000</pubDate>
      <dc:creator>SimonSchmidt</dc:creator>
      <guid isPermaLink="false">18325@/two/discussions</guid>
      <description><![CDATA[<p>I tried using the example provided on the p5 page  (<a href="http://p5js.org/reference/#/p5.Element/mouseWheel" target="_blank" rel="nofollow">http://p5js.org/reference/#/p5.Element/mouseWheel</a>),
but it tells me "ReferenceError: event is not defined", which makes sense, but I don't know how to define event in order to get the WheelDelta information.</p>

<p>I tried doing function mouseWheel(MouseEvent event){}, but it's not working.</p>

<p>Does somebody have a solution for this?</p>
]]></description>
   </item>
   <item>
      <title>Why won't my code run? (hex grid)</title>
      <link>https://forum.processing.org/two/discussion/17690/why-won-t-my-code-run-hex-grid</link>
      <pubDate>Thu, 28 Jul 2016 23:11:26 +0000</pubDate>
      <dc:creator>cadavara</dc:creator>
      <guid isPermaLink="false">17690@/two/discussions</guid>
      <description><![CDATA[<p>I get a grey screen and then it times out. I commented the texture part out, but that didn't help.</p>

<pre><code>PImage img;
PImage newimg;

int radius = 100;
float alpha = 0;
float r = 0.5;
float seed = -0.6;
float segments = 6;
float part = segments/2;
float x, y;
float angle_steps;
float angle_deg;

int col = 2;
int row = 2;

void setup() {
  size(800, 600, P2D);
  smooth(6);
  textureMode(NORMAL);
  //img = loadImage("ilrae.jpg");
}

void draw() {
  background(255);
  hexGrid();
}

void hexGrid(){
  for(int y=0; y&lt;row+1; y++){
    for(int x=0; x&lt;col+1; y++){
      int hexHeight = radius*2;
      int hexWidth = (int) sqrt(3)/2 * hexHeight;      

      int xPos = x * hexWidth;
      int yPos = y * hexHeight;
      hexShape(radius, xPos, yPos);
    }
  }
}

void hexShape(int _radius, int _xPos, int _yPos) {
  noFill();
  stroke(0); 
  //noStroke();   

  pushMatrix();
  beginShape(TRIANGLE_FAN);
  translate(_xPos, _yPos);
  rotate(-PI/2);
  //texture(img);
  vertex(0, 0, 0.5, 0.5); // center
  for (int i=0; i&lt;segments+1; i++) {
    angle_steps = 360/segments;
    angle_deg = angle_steps * i;

    x = cos(radians(angle_deg)) * _radius;
    y = sin(radians(angle_deg)) * _radius;

    vertex(x,y);
    //if (i%2 == 0) {
    //  vertex(x, y, .5 + r * cos(alpha + PI / part), .5 + r * sin(alpha + PI / part));
    //} else {
    //  vertex(x, y, .5 + r * cos(alpha), .5 + r * sin(alpha));
    //}
  }
  endShape();
  popMatrix();

  alpha = 1.9*sin(seed);
  seed += 0.001;
}

//void mouseWheel(MouseEvent event) {
//  int e = event.getCount(); //returns UP:-1 DOWN:1
//  segments += (e*2)*-1;
//}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Hello! Which code is trigger events based on some text's position?</title>
      <link>https://forum.processing.org/two/discussion/16397/hello-which-code-is-trigger-events-based-on-some-text-s-position</link>
      <pubDate>Tue, 03 May 2016 06:56:36 +0000</pubDate>
      <dc:creator>talha</dc:creator>
      <guid isPermaLink="false">16397@/two/discussions</guid>
      <description><![CDATA[<p>I have a story that is read by mouseWheel scrolling. At the some words there could be events like as fading screen out, playing an audio while we are scrolling the text. How can i achieve this events based on the text position? This is the code is below;</p>

<pre><code>String[] headlines = {
"Aniden yerimden fırladım ve üzerine atladım. Ayağım takıldı ve düşmemle birlikte kafamı yere çarptım.  Uyandığımda sırılsıklamdım",
};
String c="Please scroll the mouse wheel to read the story";

PFont f;
PFont f2;
float x;
int index = 0;

void setup() {
  size(800, 450);
  textAlign(CENTER);
  f = createFont("calibri", 16, true); 
  f2 = createFont("calibri", 10); 
  x = width;
}

void draw() {
  background(245);

  stroke(255, 200, 0);
  fill(255, 200, 0);
  rect(293, 164, 220, 20);

  textFont(f, 16);        
  fill(100, 100, 100);
  text(headlines[index], x, 180); 

  textFont(f2, 10);
  fill(70);
  text(c, 400, 400);

  stroke(255, 255, 255);
  fill(255, 255, 255);
  rect(500, 164, 400, 20);
  rect(0, 164, 293, 20);

  if (x &lt; -textWidth(headlines[index])) {
    x = width; 
    index = (index + 1) % headlines.length;
  }
}

void mouseWheel(MouseEvent event) {
  x-=event.getCount();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How can I cause different events based on some text's position?</title>
      <link>https://forum.processing.org/two/discussion/16343/how-can-i-cause-different-events-based-on-some-text-s-position</link>
      <pubDate>Fri, 29 Apr 2016 12:21:22 +0000</pubDate>
      <dc:creator>talha</dc:creator>
      <guid isPermaLink="false">16343@/two/discussions</guid>
      <description><![CDATA[<p>I have a story that is read by mouseWheel scrolling. At the some words, there could be events like as fading screen out, playing an audio while we are scrolling the text. How can i achieve this events based on the text position?  I will be appreciate if you help me. This is the code i work on below;</p>

<pre><code>String[] headlines = {
"Aniden yerimden fırladım ve üzerine atladım. Ayağım takıldı ve düşmemle birlikte kafamı yere çarptım.  Uyandığımda sırılsıklamdım",
};
String c="Please scroll the mouse wheel to read the story";

PFont f;
PFont f2;
float x;
int index = 0;

void setup() {
  size(800, 450);
  textAlign(CENTER);
  f = createFont("calibri", 16, true); 
  f2 = createFont("calibri", 10); 
  x = width;
}

void draw() {
  background(245);

  stroke(255, 200, 0);
  fill(255, 200, 0);
  rect(293, 164, 220, 20);

  textFont(f, 16);        
  fill(100, 100, 100);
  text(headlines[index], x, 180); 

  textFont(f2, 10);
  fill(70);
  text(c, 400, 400);

  stroke(255, 255, 255);
  fill(255, 255, 255);
  rect(500, 164, 400, 20);
  rect(0, 164, 293, 20);

  if (x &lt; -textWidth(headlines[index])) {
    x = width; 
    index = (index + 1) % headlines.length;
  }
}

void mouseWheel(MouseEvent event) {
  x-=event.getCount();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to add mouse scroll action to my horizontal sliding text?</title>
      <link>https://forum.processing.org/two/discussion/16094/how-to-add-mouse-scroll-action-to-my-horizontal-sliding-text</link>
      <pubDate>Tue, 19 Apr 2016 06:09:57 +0000</pubDate>
      <dc:creator>talha</dc:creator>
      <guid isPermaLink="false">16094@/two/discussions</guid>
      <description><![CDATA[<p>Anybody can help me? Or what do u advice me? I got stuck</p>
]]></description>
   </item>
   <item>
      <title>triggering audio start/stop w/scroll</title>
      <link>https://forum.processing.org/two/discussion/16237/triggering-audio-start-stop-w-scroll</link>
      <pubDate>Mon, 25 Apr 2016 07:04:54 +0000</pubDate>
      <dc:creator>je5c</dc:creator>
      <guid isPermaLink="false">16237@/two/discussions</guid>
      <description><![CDATA[<p>been doing a lot of digging for relevant info, but i can't find good examples of audio files being triggered and paused in response to the viewport and/or scrolling. i assume processing would be the best bet. any tips/suggestions?</p>
]]></description>
   </item>
   <item>
      <title>Hello, I need assistance in making my scroll wheel change the size of my ellipse drawing tool.</title>
      <link>https://forum.processing.org/two/discussion/16029/hello-i-need-assistance-in-making-my-scroll-wheel-change-the-size-of-my-ellipse-drawing-tool</link>
      <pubDate>Fri, 15 Apr 2016 15:21:09 +0000</pubDate>
      <dc:creator>MatthewStone</dc:creator>
      <guid isPermaLink="false">16029@/two/discussions</guid>
      <description><![CDATA[<p>I just need a sample code to help me with making the scroll wheel change the size of my ellipse as I scroll up it enlarges and as I scroll down it goes smaller. Anything helps. Thanks!</p>

<p>import controlP5.*; <br />
ControlP5 cp5;<br />
<br />
int c = color(100);<br />
<br />
void setup() {<br />
  size(800, 800);<br />
  smooth(); <br />
  cp5 = new ControlP5( this );<br />
  cp5.addColorWheel("c", 596, 3, 200 ).setRGB(color(128, 0, 255));<br />
  noStroke();<br />
  background(0, 255, 255);<br />
<br />
  //Below is the drawing area black border.<br />
  stroke(0);<br />
  strokeWeight(8);<br />
  rect(10, 220, 780, 570);<br />
  fill(255);<br />
<br />
  PFont font;<br />
  font = loadFont("UrbanClass-10.vlw");<br />
<br />
  //Instructions are below in this code.<br />
  String s = "Your objective is to complete the following drawing in 2 minutes. If you don't finish then restart and try again! This is only a beta.";<br />
  fill(50);<br />
  text(s, 10, 10, 400, 100);  // Text wraps within text box<br />
<br />
  //Below is "Draw Here!" inside of rect.<br />
  textFont(font, 12);<br />
  fill(0);<br />
  text("Draw Here!", 360, 240);<br />
}<br />
<br /></p>

<p>void draw() {<br />
  frameRate(800);<br />
  println(mouseX + " : " + mouseY);<br />
  <br />
if ( mouseX &lt; 790 &amp;&amp; mouseY &gt; 10) {<br />
  <br />
  //Draw normal<br />
  if (mousePressed &amp;&amp; (mouseButton == LEFT)) {<br />
    ellipse(mouseX, mouseY, 5, 5);<br />
    fill(c);<br />
    noStroke();<br />
<br />
    //Eraser<br />
  } else if (mousePressed &amp;&amp; (mouseButton == RIGHT)) {<br />
    ellipse(mouseX, mouseY, 10, 10);<br />
    noStroke();<br />
    fill(255);<br />
  }  <br />
}<br />
}<br />
<br />
void mouseWheel(MouseEvent event) {<br />
  float e = event.getCount();<br />
  println(e);<br />
  ellipse(mouseX, mouseY, 10, 10);<br />
  fill(c);<br />
  noStroke();<br />
}<br /></p>
]]></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>
   <item>
      <title>control volume with mousewheel</title>
      <link>https://forum.processing.org/two/discussion/15294/control-volume-with-mousewheel</link>
      <pubDate>Sat, 05 Mar 2016 08:12:09 +0000</pubDate>
      <dc:creator>jondoh</dc:creator>
      <guid isPermaLink="false">15294@/two/discussions</guid>
      <description><![CDATA[<p>I have code which uses peasyCam for camera control and minim to play a music file. As part of the peasyCam controls, you can zoom in and out with the mouse wheel.</p>

<p>My question is in two parts.</p>

<ol>
<li><p>can the mouse wheel be used to control two things - the zoom and the volume? I want the music to increase as the user zooms in.</p></li>
<li><p>how can this be achieved using minim?</p></li>
</ol>

<p>Thank you in advance</p>
]]></description>
   </item>
   <item>
      <title>Kinect Particle Simple Open Ni</title>
      <link>https://forum.processing.org/two/discussion/15115/kinect-particle-simple-open-ni</link>
      <pubDate>Thu, 25 Feb 2016 13:59:30 +0000</pubDate>
      <dc:creator>phaidon</dc:creator>
      <guid isPermaLink="false">15115@/two/discussions</guid>
      <description><![CDATA[<p>Hello I found this code in open processing and i want to modify it to draw same particles in kinect user map,i have tried different methods,does anyone have any idea?And also does any know what the float det() is in the end?Thanks in advance</p>

<p>The original code
`    /**
     </p><p>Use mouse to control it. Use left button to organize it's movement, right to organize it's position. Scroll to change it's calmness</p>
     */

<pre><code>int n = 2000; // number of cells
float bd = 30; // base line length
float sp = 0.001; // rotation speed step
float sl = .9; // slow down rate

float bcg_color = 0;

Cell[] all = new Cell[n];

public class Cell {

  float x, y;
  float x_start, y_start;
  float s = 0; // spin velocity
  float c = 0; // current angle

  Cell(float x, float y) {
    this.x=x;
    this.y=y;
    this.x_start = x;
    this.y_start = y;
  }

  void sense() {
    if (pmouseX != 0 || pmouseY != 0)
      s += log(sp * .5 * abs(det(x, y, pmouseX, pmouseY, mouseX, mouseY)) / (dist(x, y, mouseX, mouseY) + 1) + 1);
    s *= sl + 0.01;
    c += s;
    float d = bd * s + .001;
    stroke((50 + abs(d)*5));
    line(x, y, x + d * cos(c), y + d * sin(c));
    x = (x + (.5 * d * cos(c)));
    y = (y + (.5 * d * sin(c)));
  }

  void reset() {
    x = x_start;
    y = y_start;
  }
}

void setup() {
  size(1000, 600, P2D);
  // for full-size web:
  //  size(window.innerWidth, window.innerHeight);
  int w = min(width - 300, 600);
  int h = min(height - 300, 400);
  for (int i = 0; i &lt; n; i++) {
    // float xx = random(w) + (width - w)/2;
    // float yy = random(h) + (height - h)/2);
    all[i] = new Cell(random(w) + (width - w)/2, random(h) + (height - h)/2);
  }
  bcg_color = map(sl, .85, .99, 40, 0);
}

void draw() {
  //  fill(max(min(1000 - millis()/10,255), bcg_color));
  background(bcg_color);
  //  text("Use mouse to control it. \nUse left button to organize it's movement, \nright to organize it's position\nScroll to change it's calmness", 100, 100);
  for (int i = 0; i &lt; n; i++)
    all[i].sense();
}

void mousePressed() {
  float c = random(0, 2*PI);
  if (mouseButton == LEFT) {
    for (int i=0; i&lt;n; i++)
      all[i].c = c;
  } else {
    for (int i = 0; i &lt; n; i++)
      all[i].reset();
  }
}

void mouseWheel(MouseEvent event) {
  float e = event.getCount();
  sl = max(min(sl + e/200, .99), .85);
  bcg_color = map(sl, .85, .99, 40, 0);
}

// for web scrolling
/*void mouseScrolled() {
 if(mouseScroll &gt; 0) {
 sl = max(min(sl + 1/200, .99), .85);
 bcg_color = map(sl, .85, .99, 40, 0);
 } else {
 sl = max(min(sl - 1/200, .99), .85);
 bcg_color = map(sl, .85, .99, 40, 0);
 }
 }
 */
float det(float x1, float y1, float x2, float y2, float x3, float y3) {
  return (float) ((x2-x1)*(y3-y1) - (x3-x1)*(y2-y1));
}
</code></pre>

<p>`</p>

<p>My code
`
    class Cell {</p>

<pre><code>  float x, y;
  float St_CellX, St_CellY;
  float s = 0;//spin velocity
  float c =0;//current  angle
  float sp = 0.001; // rotation speed step
  float sl = .9; // slow down rate
  float bd = 30; // base line length

  Cell(float x, float y) {

    this.x=x;
    this.y=y;
    this.St_CellX = x;
    this.St_CellY = y;
  }


  float det(float x1, float y1, float x2, float y2, float x3, float y3) {
    return (float) ((x2-x1)*(y3-y1) - (x3-x1)*(y2-y1));
  }


  void sense() {

    if (pmouseX != 0 || pmouseY != 0)
      s += log(sp * .5 * abs(det(x, y, pmouseX, pmouseY, mouseX, mouseY)) / (dist(x, y, mouseX, mouseY) + 1) + 1);
    s *= sl + 0.01;
    c += s;
    float d = bd * s + .001;
    stroke((50 + abs(d)*5));
    line(x, y, x + d * cos(c), y + d * sin(c));
    x = (x + (.5 * d * cos(c)));
    y = (y + (.5 * d * sin(c)));
  }

  void reset() {
    x = x_start;
    y = y_start;
  }
}
</code></pre>

<p>`</p>
]]></description>
   </item>
   <item>
      <title>Problem with 2D transformation..</title>
      <link>https://forum.processing.org/two/discussion/14621/problem-with-2d-transformation</link>
      <pubDate>Tue, 26 Jan 2016 07:47:10 +0000</pubDate>
      <dc:creator>somyungoh</dc:creator>
      <guid isPermaLink="false">14621@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I'm trying to implement screen zooming in/out by axis from mouse position.
My very first idea was this:</p>

<pre><code>    translate(-mouseX,-mouseY);
    scale(scaling);
    translate(mouseX,mouseY);
</code></pre>

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

<pre><code>//Code Starts
void settings(){
  size(600,400,OPENGL);
}

void setup(){
  background(0);

  scaleLevel=1;
  xAxis=0;
  yAxis=0;
}

void draw(){
  background(0);
  transform();
  drawRects();
}

void drawRects(){
  for(int i=0; i&lt;24;i++){
    for(int j=0; j&lt;15; j++){
      fill(255);
      rectMode(LEFT);
      rect(i*25,j*25,i*25+20,j*25+20);
    }
  }
}

void mouseWheel(MouseEvent event) {

    //Update Scale Axis
    xAxis = mouseX;
    yAxis = mouseY;

    //This method controls scaleLevel variable
    if(event.getCount()==-1)
      scaleLevel += 0.2;
    else if(event.getCount()==1)
      if(scaleLevel&gt;=1.2)
        scaleLevel -= 0.2;
      else
        scaleLevel = 1;

    System.out.println("Heatmap&gt;&gt; Scale Level: "+scaleLevel);
}

void transform(){
   translate(-1*xAxis,-1*yAxis);
   scale(scaleLevel);
}


float scaleLevel;
int xAxis;
int yAxis;
</code></pre>

<p>However, when I tested this, the axis seemed to move little bit more forward, which mouseX,Y wasn't the axis.
sperate transformation worked fine, but when I come all three together, the result goes unpredictable.
<img src="https://forum.processing.org/two/uploads/imageupload/645/5AME1455YKTP.jpg" alt="Untitled-1" title="Untitled-1" />
<img src="https://forum.processing.org/two/uploads/imageupload/453/CDTFM8YPPHI0.jpg" alt="Untitled-2" title="Untitled-2" /></p>
]]></description>
   </item>
   <item>
      <title>stroke weight controlled by mouseWheel</title>
      <link>https://forum.processing.org/two/discussion/14472/stroke-weight-controlled-by-mousewheel</link>
      <pubDate>Fri, 15 Jan 2016 10:42:46 +0000</pubDate>
      <dc:creator>monkeyspasm</dc:creator>
      <guid isPermaLink="false">14472@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys!
 I'm very new to processing, and what i'm trying to do with this code, is to simply change stroke weight using mouse wheel. I tried to look for the answers, but couldn't find anything that would help me, and I'm pretty sure, at the end of the day it is going to be a very simple command.</p>

<p>Could any of you help me out?</p>

<pre><code>void setup() {
    size(1000, 500);
    background(168, 100, 168);
}

void draw() {
    noCursor();
    println (mouseX +"," + mouseY);
    noStroke();
    fill(168, 100, 168);
    rect(0, 0, 50, displayHeight);
    rect(0, 0, displayWidth, 20);
    rect(950, 0, 200, displayHeight);
    rect(0, 480, displayWidth, 20);
    triangle(70, 0, 70, 200, 110, 0);
    triangle(130, 20, 90, 220, 130, 480);
    triangle(70, 260, 70, 480, 110, 480);
    triangle(130, 480, 170, 20, 130, 20);
    triangle(190, 20, 230, 480, 230, 20);
    quad(150, 480, 155, 460, 205, 460, 210, 480);
    triangle(160, 440, 200, 440, 180, 220);
    triangle(250, 20, 270, 220, 290, 20);
    rect(310, 20, 20, displayHeight);
    triangle(250, 480, 250, 440, 270, 480);
    triangle(270, 480, 290, 440, 290, 480);
    rect(350, 20, 20, displayHeight);
    rect(390, 20, 100, 440);
    rect(490, 20, 460, displayHeight);

    strokeWeight(20);
    stroke(249, 173, 129);
    line(pmouseX, pmouseY, mouseX, mouseY);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to crop an image in P5?</title>
      <link>https://forum.processing.org/two/discussion/14125/how-to-crop-an-image-in-p5</link>
      <pubDate>Wed, 23 Dec 2015 10:39:51 +0000</pubDate>
      <dc:creator>jordy</dc:creator>
      <guid isPermaLink="false">14125@/two/discussions</guid>
      <description><![CDATA[<p>I am working on a program in P5, an offshoot of Processing, that allows the user to upload an image, draw a line on top of the image, and then crop everything outside of the drawn shape out of the image.</p>

<p><a rel="nofollow" href="https://forum.processing.org/two/uploads/imageupload/614/208JHBXYM5BT.png" title="Screen Shot 2015-12-23 at 11.30.32">Screen Shot 2015-12-23 at 11.30.32</a>
<img src="https://forum.processing.org/two/uploads/imageupload/919/FP51RP5O3COA.png" alt="Screen Shot 2015-12-23 at 11.27.21" title="Screen Shot 2015-12-23 at 11.27.21" />
(The green line jitters around on purpose)</p>

<p>I managed to get the points of the drawn line into an array, as well as make a shape out of these points. However, the cropping of the image is still a problem.</p>

<p>Processing has this functionality in vertex:
(<a href="https://processing.org/reference/vertex_.html" target="_blank" rel="nofollow">https://processing.org/reference/vertex_.html</a>)</p>

<p>However, I don't believe P5 has this functionality. I really don't want to have to convert the entire sketch into Processing. Is there any way to do this in P5, or to quickly convert this sketch into processing?</p>

<pre><code>    // Make a variable to store the start image, as well as the drop image.
    var img;

    var cropX = [];
    var cropY = [];
    var pos = 25;
    // Make an array for all paths.
    var paths = [];

    // Make a bool for whether or not I am painting.
    var painting = false;

    // Int for how long until drawing the next circle
    var next = 10;

    // Make vars for vectors that determine where the line is drawn.
    var current;
    var previous;

    // Make ints for how much the lines dance around.
    var shake = 10;
    var minShake = shake * -1;
    var maxShake = shake * 1;

    // Make an int for the line thickness.
    var thickness = 2;
    var camera;
    var tracing = false;

    // Make vars to store the random values for colours into. 
    var rc1;
    var rc2;
    var rc3;

    // Variable for the framerate.
    var fr;

    // Variable that disables drawing lines when you didn't upload an image yet.
    var tracing = false;


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


    function preload() {

      //Load the starting image, and store it in img.
      img = loadImage("assets/startscreen.png");

      //Load the sound that plays when you export a screenshot.
      soundFormats('mp3');
      camera = loadSound('assets/camera.mp3');

    }


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


    function setup() {



      // Set the framerate so the lines don't jump about too quickly.
      fr = 20;

      // Setup a canvas
      var c = createCanvas(1680, 1050);

      // Store a random value out of 255 into the random colour values.
      rc1 = random(255);
      rc2 = random(255);
      rc3 = random(255);

      // Apply the right framerate
      frameRate(fr);

      // Add an event named drop, that runs function gotFile when a file is dropped onto the canvas
      c.drop(gotFile);

      // Store 0,0 vectors in current and previous.
      current = createVector(0, 0);
      previous = createVector(0, 0);

    };

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

    function draw() {


      // Colour the background dark grey.
      background(200);

      // Draw the loaded image at 0,0 coordinates.
    image(img, 0, 0);



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


      // Count if I've been painting for longer than the 'next' variable.
      // Also check if tracing is enabled (if I've dropped an image or not).
      // If these are true I can draw a new line.
      if (millis() &gt; next &amp;&amp; painting &amp;&amp; tracing) {

        // Grab mouse position and store it in variables mouseX and mouseY.  
        current.x = mouseX;
        current.y = mouseY;

        // Add new particle
        paths[paths.length - 1].add(current);

        // Update the 'next' variable, to allow itself 200 extra millisecond for drawing the actual line.
        next = millis() + 200;

        // Move the mouse values used to draw the end of the line
        // to a variable used to draw the start of the line,
        // so that the line is continuous.
        previous.x = current.x;
        previous.y = current.y;
        append(cropX, current.x);
        append(cropY, current.y);
      }

      // Make an integer called i, with a value of 0.
      // Add 1 to i for each item in the array paths.

      // Run this once for each item in the array.
      // Name each item in the array 'i' while working.
      // Display each item in the array.
      for (var i = 0; i &lt; paths.length; i++) {

        // Update the current object in the array.
        paths[i].update();

        // Display each item in the array.
        paths[i].display();
      } 
      noStroke();
      noFill();
         beginShape();

         for (var i = 0; i &lt; cropX.length; ++i) {
           vertex(cropX[i], cropY[i]);
         }
         endShape(CLOSE);


    }


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

    var ready = false;

    // Make a function called gotFile, using the variable file.
    function gotFile(file) {

      // Check if the dropped file is an image file
      if (file.type === 'image') {

        // Enable drawing lines.
        tracing = true;

        // if (ready) {
        //   img.remove();
        // }
        // Store the dropped image in the container which used to hold the startimage.
        img = createImg(file.data).style("opacity: 100; position: absolute; top: -10; right: -10; z-index: 100;draggable=false;");

        ready = true;

        // Error message in case not an image file.
      } else {
        println('Not an image file!');
      }
    }


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

    function mouseWheel(event) {
      //event.delta can be +1 or -1 depending
      //on the wheel/scroll direction
      print(event.delta);
      //move the square one pixel up or down
      pos += event.delta;
      //uncomment to block page scrolling
      return false;
    }

    function mouseDragged() {
    return false;
      }


    // If left mousebutton is pressed down,
    function mousePressed() {
      if (mouseButton == LEFT) {

        // set the variable counting when to place a new line to 0,
        next = 0;

        // set painting to true,
        painting = true;

        // store the mouse coordinates in mouseX and mouseY,
        previous.x = mouseX;
        previous.y = mouseY;

        // and add a new Path method to the array.
        paths.push(new Path());
      }
    }

    // When mouse is released, set painting to false, which disables any paths being drawn.
    function mouseReleased() {
      painting = false;
    }


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


    // Describe the Path function that should be pushed to the array.
    function Path() {

      // Create an array inside this function named particles.
      this.particles = [];
    }

    // Add the variable position to the function Path as its function'()' variable.
    Path.prototype.add = function(position) {

      // Add a new particle to this particle array with a position and hue.
      this.particles.push(new Particle(position, this.hue));
    }

    // Take the Path() function, and and add this command to it.
    Path.prototype.update = function() {

      // Make an integer called i, with a value of 0.
      // Add 1 to i for each item in the array paths.

      // Run this once for each item in the array.
      // Name each item in the array 'i' while working.
      // Display each item in the array.
      for (var i = 0; i &lt; this.particles.length; i++) {
        this.particles[i].update();
      }
    }

    // Display the Path array.
    Path.prototype.display = function() {

      // Loop through the array of particles backwards.
      for (var i = this.particles.length - 1; i &gt;= 0; i--) {

        // Display each of these particles.
        this.particles[i].display(this.particles[i + 1]);

      }

    }

    // Particles along the path
    function Particle(position, hue) {

      // Set the position of Particles to the mouseposition by creating a vector.
      this.position = createVector(position.x, position.y);
    }

    // Constantly update Particle.
    Particle.prototype.update = function() {}

    // Draw particle and connect it with a line
    // Draw a line to another
    Particle.prototype.display = function(other) {
      stroke(255, 255);

      // If we need to draw a line
      if (other) {
        stroke(rc1, rc2, rc3);
        strokeWeight(thickness);
        line(this.position.x + random(minShake, maxShake), this.position.y + random(minShake, maxShake), other.position.x + random(minShake, maxShake), other.position.y + random(minShake, maxShake));
      }
      if (keyIsDown(LEFT_ARROW) &amp;&amp; !camera.isPlaying()) {
        camera.play();
        save('myRemix.jpg');
        print(cropX);
        print(cropY)

      }

    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>mouseWheel: "block page scrolling" is not working in firefox;</title>
      <link>https://forum.processing.org/two/discussion/13538/mousewheel-block-page-scrolling-is-not-working-in-firefox</link>
      <pubDate>Mon, 16 Nov 2015 22:27:55 +0000</pubDate>
      <dc:creator>hellwood</dc:creator>
      <guid isPermaLink="false">13538@/two/discussions</guid>
      <description><![CDATA[<p>See the example:
<a href="http://p5js.org/reference/#/p5/mouseWheel" target="_blank" rel="nofollow">http://p5js.org/reference/#/p5/mouseWheel</a>
Edit and uncomment "return false" to block page scrolling.
This work correctly in Chrome and IE, but this does not work in Firefox: it scroll the entire page.
Is it a bug ?</p>
]]></description>
   </item>
   <item>
      <title>How to do this code?</title>
      <link>https://forum.processing.org/two/discussion/12566/how-to-do-this-code</link>
      <pubDate>Fri, 18 Sep 2015 00:45:37 +0000</pubDate>
      <dc:creator>ghostwarmen</dc:creator>
      <guid isPermaLink="false">12566@/two/discussions</guid>
      <description><![CDATA[<p>Hello,
I'm working on a code that is a drawing application. I need to have a button on the side that allow me to draw a pattern, and then a button that erases. I already have the clear canvas button, I just need some help figuring out how to complete the application. Here is the code:</p>

<pre>
//create variables for hsb color values
int  bright, dark;
boolean clearButtonOn; // clear button state
int activeBrush; 
static final int  pattern1=0;   //use as activeBrush state indicator
static final int  erase=1;      //use as activeBrush state indicator
int bwidth, bheight, menuX;  //menu dimensions
int  clearBtnY;  //clear button y postion
int  pattern1BtnY;// pattern1 button y position
int  eraseBtnY; //eraser button y position


void setup () {
    size (400, 300);
    colorMode(HSB);
    background (255, 0, 255);  //white in HSB
    bright=255; dark=180;  //brightness values for HSB hover change
    fill (255, 255,bright);        // start with red meaning it's off
    clearButtonOn=false;
    bwidth=100; bheight=height/3;  //set button width and height
    menuX=width-bwidth;  // x position for menu buttons
    clearBtnY=0;   // y position for clearBtn
    pattern1BtnY=clearBtnY + bheight;  //start y position for pattern1 Btn
    eraseBtnY=clearBtnY + (2* bheight);  //start y position for eraseBtn
    activeBrush=pattern1;
    smooth();
}

void draw () {
   if(clearButtonOn==true){  //check if clear button is active
     clearCanvas(0, 0,width, height);
   }
   drawBrushPattern();
   drawMenu(menuX,0, 100, height);
   //draw menu buttons last
   drawP1Button(menuX, pattern1BtnY, bwidth, bheight);
   drawEraseButton(menuX, eraseBtnY, bwidth, bheight);
   drawClearButton (menuX, clearBtnY,bwidth, bheight);   
}

//test to see what brush is active, call that function
void drawBrushPattern(){

}

// test if mousePressed, test if over canvas, draw some pattern at mouseX,mouseY
void drawPattern1(){

}

// test if mousePressed, test if over canvas, draw some pattern at mouseX,mouseY
void drawEraser(){

}
//draw a black rectangle as background for buttons
void drawMenu(int _x, int _y, int _width, int _height){
       fill(0);  //black
       strokeWeight(1);
       stroke(100);
       rect(_x, _y, _width, _height);
}

//draw the pattern for the clearCanvas button, make sure to include hover behavior
void drawClearButton (int _x, int _y, int _width, int _height) {
  fill(255);
  rect(_x, _y, _width, _height);  //background rect
  stroke(255, 255,bright);
   // check to see if the mouse is over the button
  if ((!mousePressed) &amp;&amp; (mouseX &gt; _x &amp;&amp; mouseX &lt; (_x + _width) &amp;&amp; (mouseY &gt; _y &amp;&amp; mouseY &lt; (_y+_height)))){
        stroke(255, 255, dark); // hover color
    }
   //draw button shape - Erase Symbol
    strokeWeight(12);
    float _center=_width/2;
    translate(_x+_center, _y+_center);
    ellipse(0, 0, _width-20,_width-20);
    rotate(degrees(-45));
    rectMode(CENTER);
    rect(0,0,70, 2);
    rectMode(CORNER);
    resetMatrix();
  }

  //draw shape for P1 button, should have 1 design when activeBrush==pattern1, and 
  // a different design when activeBrush != pattern1
 void drawP1Button(int _x, int _y, int _width, int _height){


 }

 //draw shape for P1 button, should have 1 design when activeBrush==pattern1, and 
  // a different design when activeBrush != pattern1
void drawEraseButton(int _x, int _y, int _width, int _height){
      fill(255);
      rect(_x,_y,_width,_height);

 }

void clearCanvas (int _x, int _y, int _width, int _height) {
     noStroke();
    fill(255,0,255,240);  
    rect (_x, _y, _width, _height );
    clearButtonOn=!clearButtonOn;  //change button state to off   
}

void mouseClicked (){
   //check global dimensions of clear button 
   if (mouseX &gt; menuX &amp;&amp; mouseX &lt; (menuX + bwidth) &amp;&amp; (mouseY &gt; clearBtnY &amp;&amp; mouseY &lt; (clearBtnY+bheight))){
      clearButtonOn=!clearButtonOn;   //change button state to on
      println ("clear button state " + clearButtonOn);
      } 
      //now check to see if mouse is over either other button and if so, then change state 
      //of activeBrush
      /*
      //if mouseX,mouseY on pattern1 : activeBrush==pattern1
     if(){

     }
     //if mouseX,mouseY on erase : activeBrush==erase
     else if(){

     }
      */
    }
</pre>

<p>Any help would be greatly appreciated! Thank you so much!!</p>
]]></description>
   </item>
   </channel>
</rss>