<?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 getcount() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=getcount%28%29</link>
      <pubDate>Sun, 08 Aug 2021 16:07:02 +0000</pubDate>
         <description>Tagged with getcount() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedgetcount%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>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>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>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>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>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 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>
   <item>
      <title>Why does image resize differently with copy()?</title>
      <link>https://forum.processing.org/two/discussion/12404/why-does-image-resize-differently-with-copy</link>
      <pubDate>Sat, 05 Sep 2015 03:09:41 +0000</pubDate>
      <dc:creator>heapster</dc:creator>
      <guid isPermaLink="false">12404@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to copy part of an image to a new location. If I call the coordinates explicitly it copies fine. If the coordinates are based on a calculation it tries to put in the remaining part of the image. Where am I going wrong? Yes, I am new to processing. I am running on linux. The following shows the two code examples. Thanks</p>

<p>Code 1 - The copy is called explicitly</p>

<pre><code>PImage photo;

void setup() {
  size(900, 360);
  photo = loadImage("Data/test.png");  // Load the image into the program
}

void draw() {
  background(0);
  image(photo, 0, 0);
  // Displays a part of the image to a new section of the window.
  copy(photo, 330, 0, 100, height, 750, 0, 100, height);  
}
</code></pre>

<p>Code 2 - The copy is based on an equation</p>

<pre><code>PImage photo;
float x;
int speed, z;

void setup() {
  size(900, 360);
  photo = loadImage("data/test.png");
  speed=30;
}

void mouseWheel(MouseEvent event) {
  float e = event.getCount();
  //Change direction
  x=x+(speed*e);
  //Check boundry
  if (x &lt; 0) {
    x = 540;
  } else if (x &gt; 540) {
    x = 0;
  }
  println(x);
}

void draw() 
{
  z=int(x);
  background(0);
  //z=(int)x;
  image(photo, 0, 0, 640, 360);
  copy(photo, z, 0, z+100, height, 750, 0, 100, height);
  line(z, 0, z, height);
  line(z+100, 0, z+100, height);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How do you use mouse wheel to change a variable</title>
      <link>https://forum.processing.org/two/discussion/12066/how-do-you-use-mouse-wheel-to-change-a-variable</link>
      <pubDate>Thu, 13 Aug 2015 14:01:36 +0000</pubDate>
      <dc:creator>Gromek999</dc:creator>
      <guid isPermaLink="false">12066@/two/discussions</guid>
      <description><![CDATA[<p>I want to create a sizeable paint brush in a paint program I am making, and I want the mousewheel to change the variable I have for the size of the brush I use. How do I go about doing this? :) I am new to programming</p>
]]></description>
   </item>
   <item>
      <title>crop image</title>
      <link>https://forum.processing.org/two/discussion/5618/crop-image</link>
      <pubDate>Thu, 05 Jun 2014 13:23:27 +0000</pubDate>
      <dc:creator>keren_m</dc:creator>
      <guid isPermaLink="false">5618@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I need to crop an image but the form of croping should be rounded.i dont have a clue to do it.
Thanks for any help.:)</p>
]]></description>
   </item>
   <item>
      <title>mouseWheel() syntax question SOLVED</title>
      <link>https://forum.processing.org/two/discussion/598/mousewheel-syntax-question-solved</link>
      <pubDate>Tue, 22 Oct 2013 23:56:30 +0000</pubDate>
      <dc:creator>vulture2600</dc:creator>
      <guid isPermaLink="false">598@/two/discussions</guid>
      <description><![CDATA[<p>Hello.
What is the proper syntax for mouseWheel() function?</p>

<p>I want to make this snippet of code work:</p>

<p>void mouseWheel(UP){</p>

<p>port.write("u");</p>

<p>}</p>

<p>void mouseWheel(DOWN){</p>

<p>port.write("d");</p>

<p>}</p>

<p>Thanks very much!</p>
]]></description>
   </item>
   </channel>
</rss>