<?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 translate() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=translate%28%29</link>
      <pubDate>Sun, 08 Aug 2021 20:05:16 +0000</pubDate>
         <description>Tagged with translate() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedtranslate%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>I may be dumb, but... how come this pgraphics image is cut off?</title>
      <link>https://forum.processing.org/two/discussion/28100/i-may-be-dumb-but-how-come-this-pgraphics-image-is-cut-off</link>
      <pubDate>Sun, 19 Aug 2018 06:53:47 +0000</pubDate>
      <dc:creator>Tsskyx</dc:creator>
      <guid isPermaLink="false">28100@/two/discussions</guid>
      <description><![CDATA[<pre><code>PGraphics p;
void setup() {
  size(600, 600);
  p = createGraphics(600, 600);
  p.beginDraw();
  p.rectMode(CENTER);
  translate(width/2, height/2);
  p.rect(0, 0, 50, 50);
  p.endDraw();
  image(p, 0, 0);
}
</code></pre>

<p>I have just begun and I'm already stuck :/</p>
]]></description>
   </item>
   <item>
      <title>Can i made a layers with translate(x,y,layer) ? without resize ?</title>
      <link>https://forum.processing.org/two/discussion/27891/can-i-made-a-layers-with-translate-x-y-layer-without-resize</link>
      <pubDate>Tue, 01 May 2018 09:18:51 +0000</pubDate>
      <dc:creator>GeorgeJava</dc:creator>
      <guid isPermaLink="false">27891@/two/discussions</guid>
      <description><![CDATA[<p>Here is example... i want to only use layer without resize :/</p>

<pre><code>ArrayList&lt;GameObject&gt; objects = new ArrayList &lt;GameObject&gt;();

void setup() {
  size(500, 500, P3D);
  objects.add(new GameObject(150,300,25));
  objects.add(new GameObject(200,300,-2));
}

void draw() {
  background(45);
  objects.get(0).layer = width/2 - mouseX;
  for (int i = objects.size()-1; i &gt;= 0; i--) {
    GameObject object = objects.get(i);
    pushMatrix();
    translate(object.x, object.y, object.layer);
    fill(object.c);
    noStroke();
    rect(0,0,100,100);
    popMatrix();
  }
}

class GameObject {
  int x, y, layer;
  color c = color(random(255),random(255),random(255));
  GameObject(int x, int y, int layer) {
    this.x = x;
    this.y = y;
    this.layer = layer;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Translations</title>
      <link>https://forum.processing.org/two/discussion/27897/translations</link>
      <pubDate>Wed, 02 May 2018 01:26:51 +0000</pubDate>
      <dc:creator>Maaother</dc:creator>
      <guid isPermaLink="false">27897@/two/discussions</guid>
      <description><![CDATA[<p>How would I modify this with a triangle and make sure the dots stay inside?</p>

<p>void setup() {
  size(200, 200);
}</p>

<p>void draw() {
  background(255);
  stroke(0);
  fill(175);</p>

<p>int mx = constrain(mouseX, 0, width);
  int my = constrain(mouseY, 0, height);</p>

<p>translate(mx, my);
  ellipse(0, 0, 8, 8);</p>

<p>translate(100, 0);
  ellipse(0, 0, 8, 8);</p>

<p>translate(0, 100);
  ellipse(0, 0, 8, 8);</p>

<p>translate(-100, 0);
  ellipse(0, 0, 8, 8);
}</p>
]]></description>
   </item>
   <item>
      <title>Linear algebra question - how to rotate a figure around point</title>
      <link>https://forum.processing.org/two/discussion/26303/linear-algebra-question-how-to-rotate-a-figure-around-point</link>
      <pubDate>Sat, 10 Feb 2018 19:21:10 +0000</pubDate>
      <dc:creator>djevazi</dc:creator>
      <guid isPermaLink="false">26303@/two/discussions</guid>
      <description><![CDATA[<p>Here is a sketch, in this sketch I tried to impement a rotation of a figure in 3 dimensions. The rotation should be around the point of mouse coordintates (please hold left button and move the mouse), but it don't work properly. I used following method - find mouse coordinates, calculate new point coodinates in new axis space, rotate all the points around this new center, return the translation of coordinates in normal coordinate space (hope the explanation makes sence). The question is - why my rotation is stange and not around the point?</p>

<pre><code>Figure figure=new Figure();
PVector mus;
PVector dirx;
PVector diry;
float anglx;
float angly;
float locX=0;
float locY=0;


void setup()
{
  size(500,500,P3D);
  ortho();
  dirx=new PVector(0,0,0);
  diry=new PVector(0,0,0);
}



void draw()
{
  mus=new PVector(mouseX-pmouseX,mouseY-pmouseY,0);
  mus.setMag(0.04);

  dirx = new PVector(1,0,0);
  dirx.add(mus.copy());
  dirx.setMag(1);

  diry = new PVector(0,1,0);
  diry.add(mus.copy());
  diry.setMag(1);


  background(200);
  figure.display();
}



void mousePressed()
{
  locX=mouseX;
  locY=mouseY;
}



void mouseDragged()
{

  ellipse(locX,locY,5,5);

  float ax = figure.A.x-locX;
  float bx = figure.B.x-locX;
  float cx = figure.C.x-locX;

  float ay= figure.A.y-locY;
  float by= figure.B.y-locY;
  float cy= figure.C.y-locY;



  {// rotation by X axis

  float nax=(figure.A.x*1)+(0)+(0);
  float nay=(0)+(ay*dirx.x)+(figure.A.z*dirx.y);
  float naz=(0)+(ay*-dirx.y)+(figure.A.z*dirx.x);

  float nbx=(figure.B.x*1)+(0)+(0);
  float nby=(0)+(by*dirx.x)+(figure.B.z*dirx.y);
  float nbz=(0)+(by*-dirx.y)+(figure.B.z*dirx.x);

  float ncx=(figure.C.x*1)+(0)+(0);
  float ncy=(0)+(cy*dirx.x)+(figure.C.z*dirx.y);
  float ncz=(0)+(cy*-dirx.y)+(figure.C.z*dirx.x);


  figure.A.x=nax;
  figure.A.y=nay+locY;
  figure.A.z=naz;
  figure.B.x=nbx;
  figure.B.y=nby+locY;
  figure.B.z=nbz;
  figure.C.x=ncx;
  figure.C.y=ncy+locY;
  figure.C.z=ncz;
  }


  {// rotation by Y axis


  float nax=(ax*diry.y)+(0)+(figure.A.z*-diry.x);
  float nay=(0)+(figure.A.y*1)+(0);
  float naz=(ax*diry.x)+(0)+(figure.A.z*diry.y);

  float nbx=(bx*diry.y)+(0)+(figure.B.z*-diry.x);
  float nby=(0)+(figure.B.y*1)+(0);
  float nbz=(bx*diry.x)+(0)+(figure.B.z*diry.y);

  float ncx=(cx*diry.y)+(0)+(figure.C.z*-diry.x);
  float ncy=(0)+(figure.C.y*1)+(0);
  float ncz=(cx*diry.x)+(0)+(figure.C.z*diry.y);


  figure.A.x=nax+locX;
  figure.A.y=nay;
  figure.A.z=naz;
  figure.B.x=nbx+locX;
  figure.B.y=nby;
  figure.B.z=nbz;
  figure.C.x=ncx+locX;
  figure.C.y=ncy;
  figure.C.z=ncz;

  }
}




class Figure
{
  PVector A;
  PVector B;
  PVector C;


  Figure()
  {
    A=new PVector(random(width*2, width*4), random(width*2, width*4), random(width*2, width*4));
    B=new PVector(random(width*2, width*4), random(width*2, width*4), random(width*2, width*4));
    C=new PVector(random(width*2, width*4), random(width*2, width*4), random(width*2, width*4));
  }


  void display()
  {

    stroke(255, 150);
    fill(#73C1C1);

    beginShape(TRIANGLES);
    vertex(A.x, A.y, A.z);
    vertex(B.x, B.y, B.z);
    vertex(C.x, C.y, C.z);
    endShape();

    fill(255);
    text("AX="+A.x, 10, 20);
    text("AY="+A.y, 10, 40);
    text("AZ="+A.z, 10, 60);

    text("BX="+B.x, 10, 100);
    text("BY="+B.y, 10, 120);
    text("BZ="+B.z, 10, 140);

    text("CX="+B.x, 10, 180);
    text("CY="+B.y, 10, 200);
    text("CZ="+B.z, 10, 220);

    text(locX, 10, 260);
    text(locY, 10, 280);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to "build" a triangle shape in the source code and paste a copy of it at sketch position (x,y)</title>
      <link>https://forum.processing.org/two/discussion/26245/how-to-build-a-triangle-shape-in-the-source-code-and-paste-a-copy-of-it-at-sketch-position-x-y</link>
      <pubDate>Mon, 05 Feb 2018 18:18:05 +0000</pubDate>
      <dc:creator>KleinerBrandy</dc:creator>
      <guid isPermaLink="false">26245@/two/discussions</guid>
      <description><![CDATA[<p>Hello everyone,</p>

<p>I am looking for a way to "build" a triangle shape (isosceles triangle) where I can specify the start point a (a1,a2), the length of the vertical direction towards the hypotenuse, and the length of the hypotenuse.</p>

<p>I then want to paste multiple triangles from that master shape into the sketch at positions I specify just with a point and the rotation of the triangle. For example 4 triangles in the middle of each side with the hypotenuse facing towards the middle of the sketch.</p>

<pre><code>position1(  0 , height/2 ) with 90° rotation
position2( width/2 , 0 ) with 0° rotation
position3( width , height/2 ) with 180° rotation
position4( width/2 , height ) with 270° rotation
</code></pre>

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

<p>Thanks a lot.</p>
]]></description>
   </item>
   <item>
      <title>Why Won't My Self-Made Functions Run?</title>
      <link>https://forum.processing.org/two/discussion/25913/why-won-t-my-self-made-functions-run</link>
      <pubDate>Thu, 11 Jan 2018 14:18:56 +0000</pubDate>
      <dc:creator>Jwartime</dc:creator>
      <guid isPermaLink="false">25913@/two/discussions</guid>
      <description><![CDATA[<p>I'm attempting to create a project for school where I make a flower using created functions. I can't get both functions to run simultaneously. I tried changing variables, constants, etc. Nothing is working. I can have one function run, but not the other. Please help</p>

<pre><code>void setup(){

  size(300,300);
}


void draw(){

  petals(40,40,200,0,0);

  stem(50,100);
}

//Making petal function

void petals(float x,float y,float a,float b,float c){

  fill(a,b,c);

  translate(width/2,height/2);

  ellipse(0,0,x,y);

  fill(a/2,b/2,c/2);

  ellipse(0,0,x/2,y/2);
}

//Making stem function

void stem(float b,float p){

  translate(width/2,height/2);

  fill(0,p,0);

  line(0,0,0,b);

} 
</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>P5js How to rotate an object about its center?</title>
      <link>https://forum.processing.org/two/discussion/24351/p5js-how-to-rotate-an-object-about-its-center</link>
      <pubDate>Mon, 02 Oct 2017 23:06:44 +0000</pubDate>
      <dc:creator>codedanddied</dc:creator>
      <guid isPermaLink="false">24351@/two/discussions</guid>
      <description><![CDATA[<p>I have this pretty Grid object. It can create the infinite set of black-and-white grid visuals. You can even move it with your mouse or keys if you call those functions on the object in draw().</p>

<pre><code>function Grid(xStart, yStart, vN, hN, vW, hW, vS, hS) {
    this.x = xStart;
    this.y = yStart;
    this.vertNum = vN;
    this.horizNum = hN;
    this.vertSpace = vS;
    this.horizSpace = hS;
    this.vertWidth = vW;
    this.horizWidth = hW;
    this.gridWidth = (vN - 1) * (vW + vS);
    this.gridHeight = (hN - 1) * (hW + hS);

    this.middleX = this.x + this.gridWidth / 2;
    this.middleY = this.y + this.gridHeight / 2;
    this.underneath = this.gridHeight + 10;
    //this.angleRotated = 0;

    this.moveWithMouse = function() {
        this.x = mouseX - this.middleX;
        this.y = mouseY - this.underneath;
    }

    this.moveWithArrowKeys = function() {
        if (keyIsDown(LEFT_ARROW)) this.x -= 1;
        if (keyIsDown(RIGHT_ARROW)) this.x += 1;
        if (keyIsDown(UP_ARROW)) this.y -= 1;
        if (keyIsDown(DOWN_ARROW)) this.y += 1;
    }

    this.rotation = function() {
        if (keyIsDown(188)) {
             // If comma key, rotate me counterclockwise!!!
        }
        if (keyIsDown(190)) {
            // If period key, rotate me clockwise!!!
        }
    }

    this.display = function() {
        noStroke();
        this.drawVerticals();
        this.drawHorizontals();
    }

    this.drawVerticals = function() {
        // fill(0, 200);
        for (var ix = 0; ix &lt; this.vertNum; ix++) {
            rect(this.x + (ix * (this.vertSpace + this.vertWidth)), this.y, this.vertWidth, this.gridHeight + this.horizWidth);
        }
    }

    this.drawHorizontals = function() {
        // fill(0, 50);
        for (var iy = 0; iy &lt; this.horizNum; iy++) {
            rect(this.x, this.y + (iy * (this.horizSpace + this.horizWidth)), this.gridWidth + this.vertWidth, this.horizWidth);
        }
    }
}
function draw() {
    background(255);
    stroke(0);
    fill(0);
    gridObjectName.display();
}
</code></pre>

<p>A grid object is instantiated in setup(). I show what I do in draw() above as well.</p>

<p>My question is how can I take this object, which is drawn in default rectMode(CORNER) from starting point (xStart, yStart), and has attributes 'middleX' and 'middleY' (='center'), and rotate it with about its center and most importantly, save that rotation to the object (so it draws correctly rotated every keypress)?</p>
]]></description>
   </item>
   <item>
      <title>Is it possible for a 3D box to "grow" on one side only?</title>
      <link>https://forum.processing.org/two/discussion/23271/is-it-possible-for-a-3d-box-to-grow-on-one-side-only</link>
      <pubDate>Fri, 30 Jun 2017 18:35:11 +0000</pubDate>
      <dc:creator>Rheibe</dc:creator>
      <guid isPermaLink="false">23271@/two/discussions</guid>
      <description><![CDATA[<p>Hello fellow programmers,</p>

<p>I am currently working on a side project and I was playing with the box() object.</p>

<p><img src="https://my.mixtape.moe/bauxgm.png" alt="" /></p>

<p>When I tweak the z parameter, both ends are affected.</p>

<p><img src="https://my.mixtape.moe/yusebu.png" alt="" /></p>

<p>Can I make it that only the top end is affected by the z parameter?</p>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>In P3D, the rendered and rotated ellipse at mouse position is hidden by half of another shape</title>
      <link>https://forum.processing.org/two/discussion/23183/in-p3d-the-rendered-and-rotated-ellipse-at-mouse-position-is-hidden-by-half-of-another-shape</link>
      <pubDate>Fri, 23 Jun 2017 17:54:25 +0000</pubDate>
      <dc:creator>ITISLTW</dc:creator>
      <guid isPermaLink="false">23183@/two/discussions</guid>
      <description><![CDATA[<p><img src="https://forum.processing.org/two/uploads/imageupload/928/GUHOD50S0KYV.png" alt="111" title="111" />
<img src="https://forum.processing.org/two/uploads/imageupload/634/4Y4GR0FOQSVR.png" alt="222" title="222" />
<img src="https://forum.processing.org/two/uploads/imageupload/209/MM2XC7534TFF.png" alt="333" title="333" /></p>

<p>Both ellipse and rectangle plane have same rotation, and ellipse's z index is 1 higher than rectangle's.
The wired thing is when the mouse position is below the rectangle's y position, the ellipse will be hidden behind the rectangle.</p>

<p>This trobules me a lot, anyone has a good idea?</p>

<p>Here is the code.</p>

<pre><code>void setup() {
  frameRate(60);
  size(1000, 1000, P3D);
  smooth(6);
}

void draw() {
  background(120);

  pushMatrix();
  pushStyle();
  noStroke();
  translate(width/2, height/2, 0);
  rotateX(1);
  rectMode(CENTER);
  rect(0, 0, 800, 800);
  fill(0);
  textAlign(CENTER, CENTER);
  textSize(120);
  text("TEST", 0, 0, 1);
  popStyle();
  popMatrix();

  pushMatrix();
  pushStyle();
  translate(mouseX, mouseY, 1);
  rotateX(1);
  fill(0);
  ellipse(0, 0, 50, 50);
  popStyle();
  popMatrix();

}
</code></pre>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>Problems rotating and scaling shapes</title>
      <link>https://forum.processing.org/two/discussion/22537/problems-rotating-and-scaling-shapes</link>
      <pubDate>Fri, 12 May 2017 02:32:42 +0000</pubDate>
      <dc:creator>TonyRamirez</dc:creator>
      <guid isPermaLink="false">22537@/two/discussions</guid>
      <description><![CDATA[<p>I created a shape by combining various primitives in a group. However the group's origin is in the top left of the group. There is no problem doing translations but rotation and scaling take place around the top left of the shape which (as far as I can figure) makes it difficult to rotate shapes around a more central point. Is there a way in Processing to redefine a shape's (or any other object's) local coordinates or apply a local transformation matrix?</p>
]]></description>
   </item>
   <item>
      <title>How can i make each rectangle rotate along the y-axis on their own x positions?</title>
      <link>https://forum.processing.org/two/discussion/21976/how-can-i-make-each-rectangle-rotate-along-the-y-axis-on-their-own-x-positions</link>
      <pubDate>Thu, 13 Apr 2017 15:07:59 +0000</pubDate>
      <dc:creator>preet04</dc:creator>
      <guid isPermaLink="false">21976@/two/discussions</guid>
      <description><![CDATA[<p>function setup(){
    createCanvas(1000, 400);
    rectMode(CENTER);
}
function draw(){
    background(240);</p>

<pre><code>translate(150, 150); 

rotate(radians(mouseY));

fill(0);
rect(0, 0, 100, 100);
rotate(radians(mouseY));
fill(0);
rect(200, 0, 100, 100);
rotate(radians(mouseY));
fill(0);
rect(400, 0, 100, 100);
</code></pre>

<p>}</p>
]]></description>
   </item>
   <item>
      <title>[SOLVED] Collision detection when using translate?</title>
      <link>https://forum.processing.org/two/discussion/21904/solved-collision-detection-when-using-translate</link>
      <pubDate>Sun, 09 Apr 2017 14:48:55 +0000</pubDate>
      <dc:creator>swhizzle</dc:creator>
      <guid isPermaLink="false">21904@/two/discussions</guid>
      <description><![CDATA[<p>Hey guys, so I've been stuck for a while now..</p>

<p>I am using translate to focus the view on the player. The problem is, I'm not sure how I would then calculate the distance between the player and the objects in the world if the point of origin is always the player's x and y.</p>

<p>Without translating I would just use "dist()" to see if there's any overlap, but I'm not sure how to apply this when using translate().</p>

<p>I tried in vain to draw the objects and then calculate their position in separate variables relative to the player but it was a complete headache; I'm convinced there is an easier way.</p>

<p>I understand there are libraries for games and collisions but that wouldn't be any fun! :)</p>

<p>I've stripped my code to the relative parts and put it here:
<a href="http://codepen.io/swhizzle/full/OpKyJQ/" target="_blank" rel="nofollow">http://codepen.io/swhizzle/full/OpKyJQ/</a></p>

<p>Any advice will be really appreciated!</p>

<p>Steve</p>
]]></description>
   </item>
   <item>
      <title>Print Example 6: Scale and segment an image translate() problem</title>
      <link>https://forum.processing.org/two/discussion/21795/print-example-6-scale-and-segment-an-image-translate-problem</link>
      <pubDate>Tue, 04 Apr 2017 12:01:19 +0000</pubDate>
      <dc:creator>jairo_asecas</dc:creator>
      <guid isPermaLink="false">21795@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I'm having problems with this technique.</p>

<p><a rel="nofollow" href="https://processing.org/tutorials/print/">https://processing.org/tutorials/print/</a></p>

<pre><code> /* 
     * Example 6: Scale and segment an image
     * 
     * Draws an image larger than the screen by tiling it into small sections.
     * The scaleValue variable sets amount of scaling: 1 is 100%, 2 is 200%, etc.
     */

    int scaleValue = 3;  // Multiplication factor
    int xoffset = 0;     // x-axis offset 
    int yoffset = 0;     // y-axis offset

    void setup() {
      size(600, 600);
      stroke(0, 100);
    }

    void draw() {
      scale(scaleValue);
      translate(xoffset * (-width/scaleValue), yoffset * (-height/scaleValue));
      line(10, 150, 500, 50);
      line(0, 600, 600, 0); 
      setOffset();
    }

    void setOffset() {
      save("lines-" + xoffset + "-" + yoffset + ".jpg");
      xoffset++;
      if (xoffset == scaleValue) {
        xoffset = 0;
        yoffset++;
        if (yoffset == scaleValue) {
          exit();
        } 
      }
      background(204);
    }
</code></pre>

<p>the problem is that I have to use translate() several times after this and it makes impossible exporting the image correctly. Example:</p>

<pre><code>void draw() {
  scale(scaleValue);
  translate(xoffset * (-width/scaleValue), yoffset * (-height/scaleValue));
  line(10, 150, 500, 50);
 translate(0,height/2);
  line(0, 600, 600, 0); 
  setOffset();
}
</code></pre>

<p>I've tried another ways like:
Example 4: accumulate many frames into one pdf
Example 5: high-resolution off-screen buffer</p>

<p>The problem is that I must use  "aa" &lt; fft.specSize() in my sketch and I can't enlarge it. Also there is a lot of transparency what makes it difficult to use a pdf/svg vector mode for exporting.</p>

<p>Thanks, sorry for my spanglish.</p>
]]></description>
   </item>
   <item>
      <title>New to programming (translate())</title>
      <link>https://forum.processing.org/two/discussion/21545/new-to-programming-translate</link>
      <pubDate>Thu, 23 Mar 2017 00:41:15 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">21545@/two/discussions</guid>
      <description><![CDATA[<p>Since I'm a noob, I know nothing but I am reading "Learning Processing" by Dan Shiffman and I'm confused about the translation stuff on page 230. On page 229, he translates a grid to (50, 50) and the top corner which is usually (0, 0) becomes (-50, -50), so okay translate() bends towards the left. Now for (0, 0) we need to move 50 pixels right on the x-axis and 50 pixels down the y-axis..... but on page 230, he does another example and translate rotates (100, 0). That would mean the usual (0, 0) is now (-100, 0) so the little circle (which is at (0, 0, 8, 8) should be 100 pixels to the right along the x-axis and not move down... but that's not where it is?  He has 4 examples and I'm not sure which one is which... Out of the 4 examples, I think he has the little circle at (100, 20, 8, 8).</p>

<p>Also he has translate(-100, 0) (OMG a negative) with an ellipse(0, 0, 8, 8) with a comment saying move 100 pixels left... let's just say I have no idea what that means. I would imagine translate(-100, 0) would make the top right usual (0, 0) area be (100, 0).</p>

<p>In another book I have "Getting Started with P5.js," the translation makes sense. Is the translation function different from Processing to P5.js?</p>
]]></description>
   </item>
   <item>
      <title>Trying to create multiple arms, with differente segments size, using controlP5 Library.</title>
      <link>https://forum.processing.org/two/discussion/21517/trying-to-create-multiple-arms-with-differente-segments-size-using-controlp5-library</link>
      <pubDate>Tue, 21 Mar 2017 13:40:01 +0000</pubDate>
      <dc:creator>Rperes2000</dc:creator>
      <guid isPermaLink="false">21517@/two/discussions</guid>
      <description><![CDATA[<p>Trying to create multiple arms, with different  segments size, using controlP5 Library to create a easy 'robot arm drive simulator', but the code only work if all arm are equal in segment size. If not we get a a arm segments Overlap!!</p>

<p>Could you give me a topic just to fixe my code?</p>

<p>Tks in advance.
Jose Peres.</p>

<p>// JPeres: 20-MAR-2017
import controlP5.*;
ControlP5 cp5;</p>

<p>float x, y;
float angle1, angle2, angle3 = 0.0;</p>

<p>float segLength  = 100;
float segLength1 = 100; // Must be equal to var segLength!!! - How to fix ?? 
float segLength2 = 100; // Must be equal to var segLength!!! - How to fix ??</p>

<p>int V01 = 0;
int V02 = 0;
int V03 = 0;</p>

<p>void setup() {
  size(1080, 640);
  strokeWeight(25);
  stroke(255, 160);</p>

<p>x = width * 0.40;
  y = height * 0.7;</p>

<p>cp5 = new ControlP5(this);</p>

<p>cp5.addSlider("V01")
    .setPosition(900, 80)
    .setSliderMode(Slider.FLEXIBLE)
    .setValue(0)
    .setSize(20, 300)
    .setRange(-90, 90);</p>

<p>cp5.addSlider("V02")
    .setPosition(940, 80)
    .setSliderMode(Slider.FLEXIBLE)
    .setValue(0)
    .setSize(20, 300)
    .setRange(-90, 90);</p>

<p>cp5.addSlider("V03")
    .setPosition(980, 80)
    .setSliderMode(Slider.FLEXIBLE)
    .setValue(0)
    .setSize(20, 300)
    .setRange(-90, 90);</p>

<p>cp5.addSlider("H00")
    .setPosition(280, height-40)
    .setSliderMode(Slider.FLEXIBLE)
    .setValue(0)
    .setSize(300, 30)
    .setRange(-90, 90);</p>

<p>cp5.addButton("ARM_RESET")
    .setPosition(900, height-100)
    .setSize(140, 40)
    .setValue(0)
    .activateBy(ControlP5.RELEASE);</p>

<p>cp5.addButton("ARM_HOME")
    .setPosition(900, height-50)
    .setSize(140, 40)
    .setValue(0)
    .activateBy(ControlP5.RELEASE);
}
void draw() {
  background(80);
  angle1 = ((-V01+90)/float(180)) * -PI;
  angle2 = (-90+V02/float(180)) * PI;</p>

<p>pushMatrix();
  segment(x, y, angle1); 
  segment(segLength1, 0, angle2);
  segment(segLength2, 0, angle3);</p>

<p>popMatrix();
  line(x, y, x, y+80);
  rect(0, y+80, width, y+80);
}
void segment(float x, float y, float a) {
  translate(x, y);
  rotate(a);
  line(0, 0, segLength, 0);
}
public void ARM_RESET(int value) {
  cp5.getController("V01").setValue(0);
  cp5.getController("V02").setValue(0);
  cp5.getController("V03").setValue(0);
  cp5.getController("H00").setValue(0);
}
public void ARM_HOME(int value) {
  cp5.getController("V01").setValue(90);
  cp5.getController("V02").setValue(-90);
  cp5.getController("V03").setValue(-90);
  cp5.getController("H00").setValue(0);
}
// That's the end!</p>
]]></description>
   </item>
   <item>
      <title>how to move a vertex design</title>
      <link>https://forum.processing.org/two/discussion/21190/how-to-move-a-vertex-design</link>
      <pubDate>Mon, 06 Mar 2017 01:11:11 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">21190@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I'm having trouble moving this design, not by animation but I want to move it to different places on the canvas with hard code. In this case, I'm trying to move it to coordinates (0,0) by using arguments and parameters. Thank you for your help.</p>

<pre><code>function setup() {
    createCanvas(
        window.innerWidth,
        window.innerHeight
    );
}

function draw() {
    background(0);
    ship(0, 0);
 }

function ship(x, y) {
    noFill();
    stroke(0, 255, 0);
    beginShape();
    vertex(200, 10);
    vertex(195, 10);
    vertex(195, 25);
    vertex(180, 25);
    vertex(180, 50);
    vertex(130, 50);
    vertex(130, 60);
    vertex(120, 60);
    vertex(120, 90); 
    vertex(280, 90);
    vertex(280, 60);
    vertex(270, 60);
    vertex(270, 50);
    vertex(220, 50);
    vertex(220, 25);
    vertex(205, 25);
    vertex(205, 10);
    vertex(200, 10)
    endShape();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>rotation around fixed point by angle</title>
      <link>https://forum.processing.org/two/discussion/21317/rotation-around-fixed-point-by-angle</link>
      <pubDate>Fri, 10 Mar 2017 17:28:14 +0000</pubDate>
      <dc:creator>ussef</dc:creator>
      <guid isPermaLink="false">21317@/two/discussions</guid>
      <description><![CDATA[<p>Hello, i want to know how to rotate a point by a specific angle
function prototype in javascript</p>

<pre><code>var point = {
    x: 1;
    y: 3;
};
angle in radian

function rotate(point, angle);
</code></pre>

<p>thanks a lot :D.</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>Scale + noFill not working ?</title>
      <link>https://forum.processing.org/two/discussion/20537/scale-nofill-not-working</link>
      <pubDate>Sun, 29 Jan 2017 16:43:04 +0000</pubDate>
      <dc:creator>marc_nostromo</dc:creator>
      <guid isPermaLink="false">20537@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to use scale and I'm puzzle by the result of the following code:</p>

<pre><code>void setup()
{
  size(1000, 600);
  noLoop();
}

void draw()
{
  scale(width/2, height/4);
  noFill();
  rect(0,0,1,1);
}
</code></pre>

<p>I'm expecting a unfilled rectange taking half the width and quarter the height but I'm seeing a filled rectange with strange boundaries.</p>

<p>Is there any reason or is this a bug ? The same happens with shapes.</p>
]]></description>
   </item>
   <item>
      <title>rotating an object and making it move with a variable</title>
      <link>https://forum.processing.org/two/discussion/19925/rotating-an-object-and-making-it-move-with-a-variable</link>
      <pubDate>Mon, 26 Dec 2016 03:36:27 +0000</pubDate>
      <dc:creator>cloudi</dc:creator>
      <guid isPermaLink="false">19925@/two/discussions</guid>
      <description><![CDATA[<p>Hello, im remaking the atari game Asteroids as a beginner coder and im struggling on the rotation bit of the ship. im very new to rotate() and im not to sure how to make my ship rotate left and right. i also want to make the ship move in the direction its pointing using a variable so i can make sure the ship never leaves the screen size. i've tried to use translate() but i've come to relise that i dont know how to track a translation. can i please get some help, thanks.</p>
]]></description>
   </item>
   <item>
      <title>Translate x,y,z</title>
      <link>https://forum.processing.org/two/discussion/19823/translate-x-y-z</link>
      <pubDate>Mon, 19 Dec 2016 10:58:34 +0000</pubDate>
      <dc:creator>leclerke</dc:creator>
      <guid isPermaLink="false">19823@/two/discussions</guid>
      <description><![CDATA[<p>I use translate() in my sketch pretty often. Now suddenly (since i switched to P2D) I get this message:</p>

<p>"translate() with x, y, and z coordinates can only be used with a renderer that supports 3D, such as P3D. Use a version without a z-coordinate instead."</p>

<p>But, I cannot find a translate() w/ a z-coordinate and i wouldn't need one.</p>

<p>Also the sketch is running, so processing won't point to the line w/ this problem. Is there way to find this line in a compiling report or something?</p>
]]></description>
   </item>
   <item>
      <title>Translate doesn't work with vertex</title>
      <link>https://forum.processing.org/two/discussion/18545/translate-doesn-t-work-with-vertex</link>
      <pubDate>Fri, 14 Oct 2016 18:11:37 +0000</pubDate>
      <dc:creator>Fuechsl</dc:creator>
      <guid isPermaLink="false">18545@/two/discussions</guid>
      <description><![CDATA[<p>Hey guys,</p>

<p>I'm completely new to processing, seems a magnificent tool!</p>

<p>But I have a problem which in the end comes to this prototype example:</p>

<pre><code>size (600,600);
translate(width/2, height/2);
background(255);
stroke(0);
noFill();

//does work
beginShape();
vertex(0,0);
vertex(20,0);
vertex(20,20);
vertex(0,20);
vertex(0,0);
endShape();

//doesn't work, no square drawn
beginShape();
vertex(0,0);
translate(50,0);
vertex(0,0);
translate(0,50);
vertex(0,0);
translate(-50,0);
vertex(0,0);
translate(0,-50);
vertex(0,0);
endShape();
</code></pre>

<p>It would be nice for my further application if the second square would be drawn correctly as well (I know, this example is stupid, but it's the easiest way to explain my problem I think).</p>

<p>Does translate not work together with vertex or beginshape/endshape?</p>

<p>Thanks a lot for your help!</p>

<p>Martin</p>
]]></description>
   </item>
   <item>
      <title>One-time translation for sketch setup?</title>
      <link>https://forum.processing.org/two/discussion/18056/one-time-translation-for-sketch-setup</link>
      <pubDate>Fri, 02 Sep 2016 23:25:31 +0000</pubDate>
      <dc:creator>jeremydouglass</dc:creator>
      <guid isPermaLink="false">18056@/two/discussions</guid>
      <description><![CDATA[<p>I want to set up a Processing sketch with a <strong>one-time</strong> translation. Is this possible?</p>

<p>To be clear, I already know how to achieve a sketch-wide translation effect (see below). What I want to know if there are ways to translate <strong>once</strong> efficiently (i.e. without constant push-pop-ing) and clearly (e.g. defining a setup translation in <code>setup()</code> or somewhere else outside the <code>draw()</code> loop.).</p>

<p>So, given this sketch of an upper-left rectangle:</p>

<pre><code>void draw(){
  rect(0,0,10,10);
}
</code></pre>

<p>...I want to shift everything once, then program the sketch within the translated frame of reference. The <a rel="nofollow" href="https://processing.org/reference/translate_.html">translate() documentation</a> says "If translate() is called within draw(), the transformation is reset when the loop begins again." -- which implied to me that calling <code>translate()</code> from before draw in <code>setup()</code> would not reset the translation. That approach does not appear to work, however:</p>

<pre><code>void setup(){
  //// THIS DOES NOT WORK
  translate(20,20);
}
void draw(){
  rect(0,0,10,10);
}
</code></pre>

<p>I'm not sure why it doesn't work. My best guess is that setup's translate is cleared at the end of the first draw loop. I also tried a <code>setup()</code> with <code>translate()</code> followed by a single <code>pushMatrix()</code> -- this doesn't work either, perhaps because the end of the draw loop clears the entire matrix stack.</p>

<p>The common working example I see is to push-and-pop every single draw loop, like this:</p>

<pre><code>void draw(){
 pushMatrix();
   translate(20,20);
   rect(0,0,10,10);
 popMatrix();
}
</code></pre>

<p>That creates the desired effect, but it pushes-and-pops n times a second to no purpose -- I just want to setup the translation once.</p>

<p>I've also seen some examples of using <code>pushMatrix()</code> from <code>setup()</code>, then using an inverted <code>popMatrix()</code>/<code>pushMatrix()</code> loop to retrieve it in the draw (e.g. for recording cumulative translations), like this:</p>

<pre><code>void setup(){
  translate(20,20);
  pushMatrix();
}
void draw(){
  popMatrix();
  rect(0,0,10,10);
  pushMatrix();
}
</code></pre>

<p>...and, like the previous example, that creates the desired effect, but again it pushes-and-pops n times a second for no reason.</p>

<p>Are there other ways to define a one-time translation? Any suggestions or feedback would be appreciated!</p>
]]></description>
   </item>
   <item>
      <title>How to understand Translate() function?</title>
      <link>https://forum.processing.org/two/discussion/17996/how-to-understand-translate-function</link>
      <pubDate>Sun, 28 Aug 2016 11:26:22 +0000</pubDate>
      <dc:creator>zheng</dc:creator>
      <guid isPermaLink="false">17996@/two/discussions</guid>
      <description><![CDATA[<p>I am confused about translate() function.</p>

<pre>
PImage bird;
float x,y;
float rot;

void setup(){
size(500,500);
bird= loadImage("bird.png");
x= 100;
y=100;
rot =0;
}
void draw(){
  background(255);
  pushMatrix();

  translate(x+bird.width/2,y+bird.height/2);
      rotate(rot);

  translate(-bird.width/2,-bird.height/2);
image(bird,0,0);

popMatrix();
rot = rot+0.1;

}

</pre>
]]></description>
   </item>
   <item>
      <title>How to set center of view at coordinates (x,y)</title>
      <link>https://forum.processing.org/two/discussion/17144/how-to-set-center-of-view-at-coordinates-x-y</link>
      <pubDate>Tue, 14 Jun 2016 18:15:40 +0000</pubDate>
      <dc:creator>jGrant615</dc:creator>
      <guid isPermaLink="false">17144@/two/discussions</guid>
      <description><![CDATA[<p>How do I get the page to be centered at whatever (x,y) coordinates of my choosing? I have a grid and objects moving along the grid. I would like to be able to isolate one of those objects, and make it so that at every refresh, the page is centered at that object's (x,y) coordinates.</p>
]]></description>
   </item>
   <item>
      <title>I need to rotate my image and then be able to move it properly</title>
      <link>https://forum.processing.org/two/discussion/16832/i-need-to-rotate-my-image-and-then-be-able-to-move-it-properly</link>
      <pubDate>Wed, 25 May 2016 21:33:22 +0000</pubDate>
      <dc:creator>redcardinal</dc:creator>
      <guid isPermaLink="false">16832@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I'm making a tank game and I need to be able to rotate the tanks with the arrow keys and then if I press forward, they will move towards the direction that they are facing. I managed to rotate them, but I can't figure out how to move them forwards according to their rotation.
Here is my code:</p>

<p><code>void draw() {
     if (keys[2]) {
          tankRotate1-=tankRSpeed1;
         } 
    if(keys[3]) {
      tankRotate1+=tankRSpeed1;
    }
    imageMode(CENTER);
    pushMatrix();
    translate(tankX1, tankY1);
    rotate(radians(tankRotate1));
    image(redTnak, 0, 0);
    popMatrix();
}</code></p>

<p>Let me know if more code is needed. I appreciate any help that I can get!</p>
]]></description>
   </item>
   <item>
      <title>Hey my friends (translate)</title>
      <link>https://forum.processing.org/two/discussion/15696/hey-my-friends-translate</link>
      <pubDate>Sat, 26 Mar 2016 09:24:57 +0000</pubDate>
      <dc:creator>AriElle</dc:creator>
      <guid isPermaLink="false">15696@/two/discussions</guid>
      <description><![CDATA[<p>I have the following question ! I want to make a figure out of cubes .
My problem is if I use this code I just get one box. The other box is 
missing. What is wrong with <img src="https://forum.processing.org/two/uploads/imageupload/818/GY00I31RXALX.jpg" alt="14589841968241913993459" title="14589841968241913993459" /></p>
]]></description>
   </item>
   <item>
      <title>using the line function with the arc function how do i draw a D in the middle of the screen</title>
      <link>https://forum.processing.org/two/discussion/15327/using-the-line-function-with-the-arc-function-how-do-i-draw-a-d-in-the-middle-of-the-screen</link>
      <pubDate>Mon, 07 Mar 2016 06:31:48 +0000</pubDate>
      <dc:creator>Dan123</dc:creator>
      <guid isPermaLink="false">15327@/two/discussions</guid>
      <description><![CDATA[<p>How would I use height/2 and Width/2 to center it on the screen?</p>
]]></description>
   </item>
   <item>
      <title>How to avoid crossing borders in a random polygon?</title>
      <link>https://forum.processing.org/two/discussion/15064/how-to-avoid-crossing-borders-in-a-random-polygon</link>
      <pubDate>Mon, 22 Feb 2016 20:34:47 +0000</pubDate>
      <dc:creator>Jonasan</dc:creator>
      <guid isPermaLink="false">15064@/two/discussions</guid>
      <description><![CDATA[<p>Hello,
I want to make a <strong>generative</strong> sketch. I want <strong>polygons</strong> (with a random number of corners) to grow on each other. I'm busy with <em>step one</em>. One random polygon. The basic idea works, but of course, by using random corners I get borders that <strong>cross each other</strong>. I don't want that, I want "<em>full</em>" polygons.</p>

<p>Is there a logical solution I don't think about right now?</p>

<p>I wanted to avoid using <strong>angles</strong>, but maybe that's the way. Or polygons built from <strong>overlapping triangles</strong>.</p>

<p>This what I have now:</p>

<pre><code>Polygon Polygon1;

void setup() {
  size(600, 600);
  Polygon1 = new Polygon();
    background(204, 100, 30);
  Polygon1.display();
}

class Polygon {
  int numbercorners= int(random(3, 8));
  float xpos = 300;
  float ypos = 300;

  Polygon() {
  }

  void display() {
    println(numbercorners);
    beginShape();
    float endcornerx=random(-40, +40);
    float endcornery=random(-40, +40);    
    vertex(xpos+endcornerx, ypos+endcornery);   
    for (int i = 0; i &lt; numbercorners-1; i++) {    
      vertex(xpos+random(-40, +40), ypos+random(-40, +40));
    }
    vertex(xpos+endcornerx, ypos+endcornery);  
    endShape();
  }
}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>