<?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 vertex() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=vertex%28%29</link>
      <pubDate>Sun, 08 Aug 2021 17:57:55 +0000</pubDate>
         <description>Tagged with vertex() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedvertex%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>get the vertex to scale properly in rotating shape</title>
      <link>https://forum.processing.org/two/discussion/27779/get-the-vertex-to-scale-properly-in-rotating-shape</link>
      <pubDate>Mon, 16 Apr 2018 10:15:53 +0000</pubDate>
      <dc:creator>Per</dc:creator>
      <guid isPermaLink="false">27779@/two/discussions</guid>
      <description><![CDATA[<p>I got this rectangle shape drawn by vertex. Im creating the rectangle simply by offsetting one of the sides with the width of the rectangle. To get the edges of the rectangle to always be in 90 degrees according to the sides Im first calculating the theta and are then using the theta to calculate how much the side shall shrink or grow.</p>

<p>Im getting side of the rectangle correct in and are always 90 degrees but the scaling of the width is not correct and cant really figure out how to solve that.</p>

<p>Any hint?</p>

<pre><code>void setup() {
  size(500, 500, P2D); 
  background(255);
  //noCursor();
}

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

void gradientRectangle() {
  int rectWidth = 25; 
  float x1 = mouseX;
  float y1 = mouseY;
  float x2 = 250;
  float y2 = 250;
  color from = color(255, 0, 0);
  color to = color(0);

  // calculate the theta
  float adjecent = x2-x1;
  float opposite = y2-y1;

  float tanValue = opposite / adjecent;
  float theta = atan(tanValue); // in radians
  float angle = degrees(theta); // in degrees
  println("theta: "+ theta + " tanValue " + tanValue + " angle: " + angle);

  // calculate the change of the side of the second triangle
  float opposite2 = tan(theta) * rectWidth;
  println("opposite2: " + opposite2);

  // draw the shape
  beginShape();
  noStroke();  
  strokeWeight(5);

  fill(from);   
  vertex(x2, y2);  // övre till höger
  fill(to);
  vertex(x1, y1); // övre vänstra
  fill(to);
  vertex(x1+opposite2, y1-rectWidth); // undre vänstra
  fill(from);
  vertex(x2+opposite2, y2-rectWidth); // undre till höger
  endShape();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>P2D and vertex in P5 doesnt behave the same as in Processing?</title>
      <link>https://forum.processing.org/two/discussion/27758/p2d-and-vertex-in-p5-doesnt-behave-the-same-as-in-processing</link>
      <pubDate>Fri, 13 Apr 2018 18:57:27 +0000</pubDate>
      <dc:creator>Per</dc:creator>
      <guid isPermaLink="false">27758@/two/discussions</guid>
      <description><![CDATA[<p>In processing I can make a gradient on the vertex through the P2D renderer. But in P5 I get no gradient. Is it possible to do the same thing through the vertex in P5?</p>

<p>Processing sketch:</p>

<pre><code>color[] col = { color(255, 0, 0), color(0, 255, 0), color(0, 0, 255), color(0, 0, 0), color(255), color(125)}; 

void setup() { 
  size(200, 200, P2D);  
}

void draw() {
  background(col[1]);
  gradient();
}

void gradient() {
  beginShape();
  fill(255, 0, 0);
  vertex(100, 100);
  fill(0, 255, 0);
  vertex(400, 100);
  fill(0, 0, 255);
  vertex(mouseX, mouseY);
  endShape();
}
</code></pre>

<p>P5 sketch:</p>

<pre><code>var col;

function setup() {
  var col = [color(255, 0, 0), color(0, 255, 0), color(0, 0, 255), color(0, 0, 0), color(255), color(125)];
  createCanvas(200, 200, P2D);
}

function draw() {
  // background(col[1]);
  gradient();
}

function gradient() {
  beginShape();
  fill(255, 0, 0);
  vertex(100, 100);
  fill(0, 255, 0);
  vertex(400, 100);
  fill(0, 0, 255);
  vertex(mouseX, mouseY);
  endShape();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>processing.py Z-Buffer problems when drawing triangle mesh</title>
      <link>https://forum.processing.org/two/discussion/27691/processing-py-z-buffer-problems-when-drawing-triangle-mesh</link>
      <pubDate>Wed, 04 Apr 2018 18:01:18 +0000</pubDate>
      <dc:creator>empwilli</dc:creator>
      <guid isPermaLink="false">27691@/two/discussions</guid>
      <description><![CDATA[<p>Hi folks,</p>

<p>I'm currently trying around with terrain generation using perlin noise. Therefore, I generate a map of 3d vertices in a shape and render the shape with a texture (see the below code).</p>

<p>However, when rotating the map, it seems like parts of the mesh are rendered in wrong order, since there are artefacts and overlaps. See the following three images for the same szene, rotated by a few degrees.</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/059/82DDIR6HK8CT.png" alt="first" title="first" />
<img src="https://forum.processing.org/two/uploads/imageupload/420/1WR00X6IXK1U.png" alt="second" title="second" />
<img src="https://forum.processing.org/two/uploads/imageupload/204/E4NIQ6M8N6DH.png" alt="third" title="third" /></p>

<p>I really think its a problem due to my code (it has been ages since I last did some real 3d coding), for what its worth: I'm running this code on a arch linux system (kernel 4.15.14-1-ARCH) and I've got a integrated intel hd graphics card.</p>

<p>The code I use to render this scene is the following (I skipped some parts for brevity):
<strong>edit:</strong> I've added the parts missing for letting the example run. Thanks to jeremydouglass for the comment!</p>

<pre><code>scale = 20
zangle = 0
l_width = 100
l_height = 100

def setup():
    size(1024, 768, P3D)
    background(52)

def calc_elevation(w, h, octaves=4):
    elevation = []

    for y in range(0, h):
        column = []
        for x in range(0, w):
            nx = map(x, 0, w, 0, 1)
            ny = map(y, 0, h, 0, 1)
            frequency = 1
            hight_value = 0
            for _ in range(octaves):
                hight_value += 1 / frequency * noise(5 * nx * frequency, 5 * ny * frequency)
                frequency *= 2
            hight_value = pow(hight_value, 3.0)
            column.append(hight_value)
        elevation.append(column)
    return elevation

def keyPressed():
    global zangle
    if key == 'a':
        zangle += -PI / 10
    elif key == 'd':
        zangle += PI / 10

def draw():
    global zangle

    background(52)
    textSize(20)
    translate(width/2, height/2, -600)
    rotateX(PI / 2 * 0.8)
    rotateZ(zangle)

    elevation = calc_elevation(l_width, l_height, 2)
    max_height = max([max(list) for list in elevation])

    noStroke()
    mesh = createShape()

    img = createImage(100, 100, RGB)
    for y in range(100):
        for x in range(100):
            img.pixels[y * 100 + x] = color((float(x) / float(100)) * 255, (1 - (float(x) / float(100))) * 255, 0)

    mesh.setTexture(img)
    mesh.beginShape(TRIANGLE)
    for y in range(-l_height / 2, l_width / 2 - 1):
        for x in range(-l_width / 2, l_width / 2 - 1):
            mesh.vertex((x + 1) * scale,
                        y * scale,
                        (elevation[y + l_height / 2][x + 1 + l_width / 2] - (max_height / 2)) * scale * 50,
                        map(x + 1, -l_width / 2, l_width / 2, 0, img.width),
                        map(y, -l_height / 2, l_height / 2, 0, img.height)
                        )
            mesh.vertex(x * scale,
                        y * scale,
                        (elevation[y + l_height / 2][x + l_width / 2] - (max_height / 2)) * scale * 50,
                        map(x, -l_width / 2, l_width / 2, 0, img.width),
                        map(y, -l_height / 2, l_height / 2, 0, img.height)
                        )
            mesh.vertex(x * scale, 
                        (y + 1) * scale, 
                        (elevation[y + 1 + l_height / 2][x + l_width / 2] - (max_height / 2)) * scale * 50,
                        map(x, -l_width / 2, l_width / 2, 0, img.width),
                        map(y + 1, -l_height / 2, l_height / 2, 0, img.height)
                        )

            mesh.vertex((x + 1) * scale,
                        y * scale,
                        (elevation[y + l_height / 2][x + 1 + l_width / 2] - (max_height / 2)) * scale * 50,
                        map(x + 1, -l_width / 2, l_width / 2, 0, img.width),
                        map(y, -l_height / 2, l_height / 2, 0, img.height)
                        )
            mesh.vertex(x * scale,
                        (y + 1) * scale,
                        (elevation[y + 1 + l_height / 2][x + l_width / 2] - (max_height / 2)) * scale * 50,
                        map(x, -l_width / 2, l_width / 2, 0, img.width),
                        map(y + 1, -l_height / 2, l_height / 2, 0, img.height)
                        )
            mesh.vertex((x + 1) * scale, 
                        (y + 1) * scale, 
                        (elevation[y + 1 + l_height / 2][x + 1 + l_width / 2] - (max_height / 2)) * scale * 50,
                        map(x + 1, -l_width / 2, l_width / 2, 0, img.width),
                        map(y + 1, -l_height / 2, l_height / 2, 0, img.height)
                        )
    mesh.endShape(TRIANGLE)
    shape(mesh, 0, 0)
</code></pre>

<p><strong>edit:</strong> If removing the "noStroke" option, the problem becomes even more obvious. It seems as if some of the vertices are rendered on top of others...</p>
]]></description>
   </item>
   <item>
      <title>P5 back and forth animation</title>
      <link>https://forum.processing.org/two/discussion/25782/p5-back-and-forth-animation</link>
      <pubDate>Tue, 02 Jan 2018 06:07:48 +0000</pubDate>
      <dc:creator>Amorris</dc:creator>
      <guid isPermaLink="false">25782@/two/discussions</guid>
      <description><![CDATA[<p>I have this sketch:</p>

<pre><code>let h = 0;
let k = 0;
let step = 0.05;
let r = 200;
let points = [];
let i = 0;
let forward = true;

function setup() {
  createCanvas(windowWidth, windowHeight);
}

function draw() {
  background(81);
  translate(width / 2, height / 2);
  noFill();
  strokeWeight(1);
  stroke(255);

  beginShape();
  for (let theta = TWO_PI; theta &gt; PI; theta -= step) {
    let x = h + r * Math.cos(theta);
    let y = k - r * Math.sin(theta);
    vertex(x, y);
    points.push(createVector(x, y));
  }
  endShape();

  strokeWeight(10);
  stroke(0);
  point(points[i].x, points[i].y);
}
</code></pre>

<p>That shows a dot moving from one side of an arc to another. When it gets to the end, however it teleports back to the start. I want to make it swing back and forth on the arc. I have tried it using the length of the points array, but that seems to be massively overflowed and it contains duplicate points. Is there a way to do this, or a better way to do what I have done?</p>
]]></description>
   </item>
   <item>
      <title>create a shape with an array of vertices</title>
      <link>https://forum.processing.org/two/discussion/25027/create-a-shape-with-an-array-of-vertices</link>
      <pubDate>Wed, 15 Nov 2017 20:18:29 +0000</pubDate>
      <dc:creator>guyshalev</dc:creator>
      <guid isPermaLink="false">25027@/two/discussions</guid>
      <description><![CDATA[<p>hello,
i am trying to create a shape with an array of pre-made vertices. here is the code:</p>

<pre><code>function setup() {
  createCanvas(600, 600);
  background(150);    
}

function createVertices() {
  let vertices = [];
  let angle = TWO_PI / 6;
  for (let a = 0; a &lt; TWO_PI; a += angle) {
    var sx = 50 + cos(a) * 20;
    var sy = 50 + sin(a) * 20;
    vertices.push(vertex(sx, sy));
  }
  return vertices;
}

function draw() {
  var verticesArray = createVertices();
  polygon(50, 50, 20, verticesArray);
}

function polygon(x, y, radius, ver) {
  beginShape();
  let vertices = [];
  for (var i = 0; i &lt; ver.length - 1; i++) {
    vertices.push(vertex(ver[i], ver[i + 1]));
  }
  endShape(CLOSE);
}
</code></pre>

<p>function polygon() doesn't draw a hexagon in this way, but only if i copy the code in createVertices() function.
what is the problem?</p>
]]></description>
   </item>
   <item>
      <title>beginShape(args): tutorial or documentation of 'args'</title>
      <link>https://forum.processing.org/two/discussion/22374/beginshape-args-tutorial-or-documentation-of-args</link>
      <pubDate>Wed, 03 May 2017 22:30:16 +0000</pubDate>
      <dc:creator>bob97086</dc:creator>
      <guid isPermaLink="false">22374@/two/discussions</guid>
      <description><![CDATA[<p>I would like to see at least a brief summary of how to sequence the calls to vertex() to satisfy the different options for <code>beginShape(option)</code>. <code>option</code> can be POINTS, LINES, etc., but I've found only rare examples in forum code postings -- always lacking any discussion.
Thanks.</p>
]]></description>
   </item>
   <item>
      <title>TypeError: undefined is not an object (evaluating 'bunker.x')</title>
      <link>https://forum.processing.org/two/discussion/21362/typeerror-undefined-is-not-an-object-evaluating-bunker-x</link>
      <pubDate>Mon, 13 Mar 2017 01:03:23 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">21362@/two/discussions</guid>
      <description><![CDATA[<p>Hello, does anyone know how I can get the computer to understand my bunker x, y variables? I would rather use other.x, other.y. other.r than bunker.x, bunker.y, and bunker.r but either way I'm lost.</p>

<pre><code>var bunkers = [];
var b1;

function setup() {
      createCanvas(window.innerWidth, window.innerHeight);
      b1 = new Bubble(250, 200);
        for (var i = 0; i &lt; 4; i++){
           bunkers[i] = new Bunker(i*294 + 247, height-140);
   }
}

function draw() {
      background(0);

      for (var i = 0; i &lt; 4; i++){
            bunkers[i].show();
  }
      b1.update();
      b1.display();

      if (b1.intersects(bunkers[i])){
            bunkers[i].changeColor();
    }
}
function Bubble(x, y) {
      this.x = x;
      this.y = y;
      this.r = 48;
      this.col = color(255);
      this.changeColor = function() {
            this.col = color(random(255), random(255), random(255))

    }
      this.display = function() {
            stroke(255);
            fill(this.col);
            ellipse(this.x, this.y, this.r * 2, this.r * 2);

    }

       this.intersects = function(bunker) {
             var d = dist(this.x, this.y, bunker.x, bunker.y);
       if (d &lt; this.r + bunker.r) {
                  return true;
        } else {
                  return false;

        }
 }

       this.update = function() {
            this.x = this.x + random(-5, 5);
            this.y = this.y + random(-5, 5);

    }

}

function Bunker(x, y) {
       this.x = x;
      this.y = y;
      this.r = 60;
       this.show = function(){
          push();
          translate(this.x-257, this.y-68);
          noStroke();
          fill(0, 100, 0);
          beginShape();
          vertex(200, 50);
          vertex(208, 50);
          vertex(208, 42);
          vertex(216, 42);
          vertex(216, 34);
          vertex(224, 34);
          vertex(224, 26);
          vertex(290, 26);
          vertex(290, 34);
          vertex(298, 34);
          vertex(298, 42);
          vertex(306, 42);
          vertex(306, 50);
          vertex(314, 50);
          vertex(314, 110);
          vertex(290, 110);
          vertex(290, 102);
          vertex(282, 102);
          vertex(282, 94);
          vertex(274, 94);
          vertex(274, 86);
          vertex(240, 86);
          vertex(240, 94);
          vertex(232, 94);
          vertex(232, 102);
          vertex(224, 102);
          vertex(224, 110);
          vertex(200, 110);
          endShape(CLOSE);
          pop();
   } 
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>TypeError: undefined is not an object</title>
      <link>https://forum.processing.org/two/discussion/21303/typeerror-undefined-is-not-an-object</link>
      <pubDate>Fri, 10 Mar 2017 04:26:08 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">21303@/two/discussions</guid>
      <description><![CDATA[<p>Stuck again. Does anyone know how to fix this error?</p>

<p>Thank you.</p>

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

   function setup(){
      createCanvas(window.innerWidth, window.innerHeight);
       for (var i = 0; i &lt; 4; i++) {
           bunkers[i] = new Bunker(i*294 + 247, height-150);
     }     
   } 

  function draw(){
      background(0);
      for (var i = 0; i &lt; 5; i++) {
         bunkers[i].show();    
  }   
} 
 function Bunker(x, y){
      this.show = function(){
          push();
          translate(x-257, y-68);
          noStroke();
          fill(0, 100, 0);
          beginShape();
          vertex(200, 50);
          vertex(208, 50);
          vertex(208, 42);
          vertex(216, 42);
          vertex(216, 34);
          vertex(224, 34);
          vertex(224, 26);
          vertex(290, 26);
          vertex(290, 34);
          vertex(298, 34);
          vertex(298, 42);
          vertex(306, 42);
          vertex(306, 50);
          vertex(314, 50);
          vertex(314, 110);
          vertex(290, 110);
          vertex(290, 102);
          vertex(282, 102); 
          vertex(282, 94);
          vertex(274, 94);
          vertex(274, 86);
          vertex(240, 86);
          vertex(240, 94);
          vertex(232, 94);
          vertex(232, 102);
          vertex(224, 102);
          vertex(224, 110);
          vertex(200, 110);
          endShape(CLOSE);
          pop();
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>beginShape() with fill gradient</title>
      <link>https://forum.processing.org/two/discussion/13381/beginshape-with-fill-gradient</link>
      <pubDate>Tue, 03 Nov 2015 13:28:45 +0000</pubDate>
      <dc:creator>p_bogdan03</dc:creator>
      <guid isPermaLink="false">13381@/two/discussions</guid>
      <description><![CDATA[<p>Hello,
I cannot seem to replicate the following in p5js to make a gradient. Can anybody help me with why is this?</p>

<p><code>void setup() {
  size(128, 128, OPENGL);
  background(128);
  noStroke();
  beginShape();
  fill(0);
  vertex(30, 20);
  vertex(85, 20);
  fill(0,255,0);
  vertex(85, 75);
  vertex(30, 75);
  endShape();
}</code></p>
]]></description>
   </item>
   <item>
      <title>Reading text files</title>
      <link>https://forum.processing.org/two/discussion/20584/reading-text-files</link>
      <pubDate>Tue, 31 Jan 2017 22:51:38 +0000</pubDate>
      <dc:creator>Nekios</dc:creator>
      <guid isPermaLink="false">20584@/two/discussions</guid>
      <description><![CDATA[<p>So I have a text file with 2 numbers on every line, which is the x coordinate and y coordinate of a point. I have trouble reading the text file and using all the coordinates to draw my shape. help plz!!!</p>

<pre><code>Here is how the text file looks like:
320.859 283.133
313.715 287.457
310.332 295.332
302.996 300.285
296.805 307.137
292.359 297.824
286.586 304.398
.........(with 700 more lines)
</code></pre>

<p>And my code:</p>

<pre><code>void setup() {
  size(400, 400);
  background(0);
  stroke(255);
  strokeJoin(ROUND);
  strokeWeight(2);
  String[] dots = loadStrings("design.txt");

  beginShape();
  for (int i = 0; i &lt; dots.length; i+= 1) {
    vertex(float(dots[i]), float(dots[i]));
  }
  endShape(CLOSE);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Map delimiters: can't make vertex() to draw them</title>
      <link>https://forum.processing.org/two/discussion/19398/map-delimiters-can-t-make-vertex-to-draw-them</link>
      <pubDate>Tue, 29 Nov 2016 17:01:30 +0000</pubDate>
      <dc:creator>mmammana</dc:creator>
      <guid isPermaLink="false">19398@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,
I am trying to make a map of Buenos Aires neighbourhoods. 
I've created a csv file with some coordinates to delimit some of the neighbourhoods. I want the program to draw and fill the limits, using beginShape/vertex/endShape.
The coordinates are loaded into a table, and then, two loops read each row/column and get the values for each neighbourhood (one row per neighbourhood, with 4 pairs of values, for a 4 sided polygon each).
When all the vertex points are drawn for that polygon, the inner loop ends, and the program runs the endShape(CLOSE) to close the limits, and starts the next row (that's why I put the endShape(CLOSE) outside the inner loop).</p>

<p>I can't figure out why it is not working. I've put a println() to check if the values retrieved in each iteration are ok. The values are ok, but vertex does not draw the polygon. I've also tried leaving the image (svg) out, because perhaps, the loop draws it behind the map, but again, no success. 
Maybe the endShape should not be outside the second loop, meaning that all code between beginShape and endShape must remain together?
Any idea? Thanks so much in advance,
Marcelo</p>

<p>This is the program (Processing 2):</p>

<pre><code>PShape mapaBA;
Table table;

void setup(){
  size(800,800);
  noLoop();
  table = loadTable("barrios.csv"); // coords for some neighborhoods limits
  mapaBA = loadShape("CABA.svg"); // map of Buenos Aires city
}

void draw(){
    shape(mapaBA,0,0,width,height);
    for (int i=0;i&lt;table.getRowCount();i++){ 
      for (int e =0;e&lt;table.getColumnCount()-1;e=e+2){ 
          beginShape();
          int x = table.getInt(i,e);
          int y = table.getInt(i,e+1);
          println(i, e, x,y); // just to test if values are ok
          vertex(x,y); // should draw a polygon that delimites a neighbourhood, based on coords
        }
          endShape(CLOSE);
    }

}
</code></pre>

<p>The csv file contains the following values:</p>

<pre><code>642,320,554,326,564,365,643,355
647,355,563,364,561,401,648,393
559,403,612,400,617,438,567,468
649,394,612,398,618,440,659,431
</code></pre>
]]></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>Is it possible to use vertex( x, y, z ) in P5.js ?</title>
      <link>https://forum.processing.org/two/discussion/17185/is-it-possible-to-use-vertex-x-y-z-in-p5-js</link>
      <pubDate>Fri, 17 Jun 2016 10:49:36 +0000</pubDate>
      <dc:creator>nznz</dc:creator>
      <guid isPermaLink="false">17185@/two/discussions</guid>
      <description><![CDATA[<p>I want to do something like this :</p>

<p><img src="https://upload.wikimedia.org/wikipedia/commons/3/36/Normal_map_example.png" alt="" /></p>

<p>is it possible at this point ? or not at all ?</p>
]]></description>
   </item>
   <item>
      <title>Texture a Circle for my solar system!</title>
      <link>https://forum.processing.org/two/discussion/16870/texture-a-circle-for-my-solar-system</link>
      <pubDate>Sun, 29 May 2016 04:28:00 +0000</pubDate>
      <dc:creator>solarSytemFan</dc:creator>
      <guid isPermaLink="false">16870@/two/discussions</guid>
      <description><![CDATA[<p>Having trouble getting correct texture loading.</p>

<pre><code>PImage IMG;
PShape SHP;


int numDetail = 360;
float rot = TWO_PI/numDetail;

void setup() {
  size(400, 400, P3D);
  IMG = loadImage("earth.jpg");
  smooth();
}

void draw() {
  background(255);
  translate(width/2, height/2);
  float radCircle = 200;
  beginShape();
  texture(IMG);
  for (int i=0; i&lt;numDetail; i++) {
    float angle = i*rot;
    float x = cos(angle);
    float y = sin(angle);
    vertex(x*radCircle, y*radCircle, x*radCircle, y*radCircle);
  }
  endShape(CLOSE);
}
</code></pre>

<p><img src="https://forum.processing.org/two/uploads/imageupload/171/S2Q0ZYMFCA0Z.jpg" alt="earth" title="earth" /></p>
]]></description>
   </item>
   <item>
      <title>How cookie cut an image onto a non-rectangular shape</title>
      <link>https://forum.processing.org/two/discussion/15846/how-cookie-cut-an-image-onto-a-non-rectangular-shape</link>
      <pubDate>Tue, 05 Apr 2016 01:08:39 +0000</pubDate>
      <dc:creator>naxon</dc:creator>
      <guid isPermaLink="false">15846@/two/discussions</guid>
      <description><![CDATA[<p>I have defined a shape using vertex(xcord, ycord) several times. How do I fit an image within the confines of this shape so that it is cropped within it?</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>
   <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>Change Particle texture on the fly</title>
      <link>https://forum.processing.org/two/discussion/13323/change-particle-texture-on-the-fly</link>
      <pubDate>Fri, 30 Oct 2015 16:37:30 +0000</pubDate>
      <dc:creator>robo</dc:creator>
      <guid isPermaLink="false">13323@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I am currently using the Particles example by Dan Shiffman and I would like to change the Particle texture by keypress to a different PNG.
As the PNG is loaded n the setup-phase I can't do this there. Is there a way to switch a texture which has already been loaded (maybe in some internal buffer)?
Or should I change the code so that I load all images upfront and the try to adapt the Particle system?</p>

<p>Any help is greatly appreciated, maybe someone has already coded a similar thing?</p>

<p>Thanks,
Robo</p>
]]></description>
   </item>
   <item>
      <title>relearning How to understand Vertex, Translate, Pushmatrix and Popmatrix ?</title>
      <link>https://forum.processing.org/two/discussion/13148/relearning-how-to-understand-vertex-translate-pushmatrix-and-popmatrix</link>
      <pubDate>Wed, 21 Oct 2015 12:40:06 +0000</pubDate>
      <dc:creator>mod345</dc:creator>
      <guid isPermaLink="false">13148@/two/discussions</guid>
      <description><![CDATA[<p>i am trying to relearn processing but i cant get my head around these functions.</p>

<p>im using 1.5.1 processing.</p>

<p>Vertex shape goes (0,0) (1,0) (1,1) (0,1)
but why? shouldnt it go
vertex (0,0) (1,0) (0,1) (1,1)
when creating a shape.
this seems like the logical way ?</p>

<p>Translate: if i translate to (0,0,0) in a loop its always (0,0,0)
but if i translate to (4,0,0) it pushes X so 4 8 12 16 etc
can anyone explain why this is?</p>

<p>Pushmatrix and popmatrix 
if i use these functions in a loop it effects the object.
i cant understand these functions, i know they have a stack.
where is the stack ? how big is the stack ?</p>

<p>how does translate and push and pop work together?
if i pushmatrix before translate it act differently.
is pushmatrix just a buffer stack which is similar to a loop?</p>

<p>its driving me nuts trying to understand these function again.</p>
]]></description>
   </item>
   <item>
      <title>int function for a line</title>
      <link>https://forum.processing.org/two/discussion/12957/int-function-for-a-line</link>
      <pubDate>Mon, 12 Oct 2015 10:42:49 +0000</pubDate>
      <dc:creator>honzojd</dc:creator>
      <guid isPermaLink="false">12957@/two/discussions</guid>
      <description><![CDATA[<p>Hello I would like to define one line (for example as a X) and then just use X when needed.
I would like to have something like this:</p>

<p>int x = in.right.get(i)*30;
vertex(207+x,227+x);</p>

<p>is there some way please?</p>
]]></description>
   </item>
   <item>
      <title>Ease out rotation speed</title>
      <link>https://forum.processing.org/two/discussion/13019/ease-out-rotation-speed</link>
      <pubDate>Wed, 14 Oct 2015 21:06:17 +0000</pubDate>
      <dc:creator>hazyy</dc:creator>
      <guid isPermaLink="false">13019@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone, I made a star object that rotates constantly in the display(). It also has another function, called puntos() where I want to Increase the rotation speed briefly, and I want to add an ease out. (I mean, i want the rotation speed to suddenly increase but I want it to make it return to the previous speed with an ease out).
I don't know how to do it since I only applied easing to distances and my brain is not very creative atm.</p>

<p>Thanks everyone for your time and help.
 I'm adding my star object (based on the PShape tutorial by Daniel Shiffman).</p>

<p>`// A class to describe a Star shape</p>

<p>class Star {
  float rotationSpeed;
  PShape s;
  float x, y;
  float starBorder;
  color starFilling;
  float starStroke; 
  float opacity;</p>

<p>Star() {
    rotationSpeed = 0;
    opacity = 50;
    x = width/2;
    y = height/2; 
    starBorder = 0;
    starFilling = color(255);
    starStroke = 0;</p>

<p>}</p>

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

<pre><code>opacity = random(180,200);
    // First create the shape
s = createShape();
s.beginShape();
s.fill(starFilling,opacity);
s.stroke(starStroke);
s.strokeWeight(starBorder);
s.vertex(0, -50);
s.vertex(14, -20);
s.vertex(47, -15);
s.vertex(23, 7);
s.vertex(29, 40);
s.vertex(0, 25);
s.vertex(-29, 40);
s.vertex(-23, 7);
s.vertex(-47, -15);
s.vertex(-14, -20);
s.endShape(CLOSE);

// The shape is complete

// Locating and drawing the shape
pushMatrix();
translate(x, y);
scale(2);
rotate(radians(rotationSpeed));
rotationSpeed+= -0.1;
shape(s);
popMatrix();
</code></pre>

<p>}</p>

<p>void puntos() { 
    rotationSpeed+=-15; /* HERE I want to increase suddenly the roation speed to +-15 and ease out. This void is also supposed to last a few seconds, once the rotation speed comes back to normal*/
    opacity = 255;</p>

<p>}</p>

<p>}`</p>
]]></description>
   </item>
   <item>
      <title>Why is the result upside down</title>
      <link>https://forum.processing.org/two/discussion/13016/why-is-the-result-upside-down</link>
      <pubDate>Wed, 14 Oct 2015 19:04:47 +0000</pubDate>
      <dc:creator>clankill3r</dc:creator>
      <guid isPermaLink="false">13016@/two/discussions</guid>
      <description><![CDATA[<p>It might be due the time since it's getting a bit late...
I know I could remove the 1.0 but it is somewhere else where it goes wrong I guess..</p>

<pre><code>#version 410

uniform mat4 transform;

in vec4 vertex;
in vec2 texCoord;

out vec2 vertTexCoord;

void main() {

    vertTexCoord = vec2(texCoord.x, 1.0 - texCoord.y);
    gl_Position = transform * vertex;
}
</code></pre>

<p>// ----</p>

<pre><code>#version 410


uniform sampler2D texture;

in vec2 vertTexCoord;

out vec4 fragColor;

void main() {
    fragColor = texture(texture, vertTexCoord);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Need help to remove shapes touchings (sort of collision detection)</title>
      <link>https://forum.processing.org/two/discussion/12919/need-help-to-remove-shapes-touchings-sort-of-collision-detection</link>
      <pubDate>Fri, 09 Oct 2015 22:01:28 +0000</pubDate>
      <dc:creator>zhidogolonoga</dc:creator>
      <guid isPermaLink="false">12919@/two/discussions</guid>
      <description><![CDATA[<p>Hello!
I'm quite new to programming and I have a problem with sketch. I've made a class of pyramids and trying to make it not to touch each other, but it doesn't work well... The mistake is 99% in <em>void collision_det()</em> method.
I would be so grateful if anyone helps me.</p>

<pre><code>import processing.opengl.*;
   Pyramid[] piramide;
   float[] n= new float [150];
   float[] m= new float [150];

void setup() {
  piramide = new Pyramid[150];
  size(900, 600, OPENGL);
for (int i=0; i&lt;piramide.length;i++) {
  n[i]=random(width);
  m[i]=random(height);
    piramide[i] = new Pyramid(n[i], m[i], random(20), random(5,15),(random(5,30)*0.001));

}
}

void draw() {
  smooth();
  lights();
  background(30,25,30);
for (int i=0; i&lt;piramide.length;i++) {
    Pyramid thisPyr = piramide[i];
    thisPyr.collision_det();
    thisPyr.rotacion();
  }
}


class Pyramid {
  float x, y, z, t, s;
  float theta=0.0;
  float alph;

  Pyramid(float tempX, float tempY, float tempZ, float tempT, float tempS) {
    x= tempX;
    y= tempY;
    z= tempZ;
    t= tempT;
    s= tempS;
  }

  void drawPiramide() {
    pushMatrix();

    translate(x, y);

    beginShape(TRIANGLES);
    noStroke();


   fill(220,220,220);
   vertex(0, t*2, 0); 
   vertex(0, 0, -t);
   vertex(-t, 0, 0);

   fill(250,250,250);
   vertex(0, t*2, 0);
   vertex(0, 0, -t);
   vertex(t, 0, 0);

   fill(220,220,220);
   vertex(0, t*2, 0);
   vertex(t, 0, 0);
   vertex(0, 0, t);

   fill(250,250,250);
   vertex(0, t*2, 0);
   vertex(0, 0, t);
   vertex(-t, 0, 0);

   fill(250,250,250);
   vertex(0, -t*2, 0);
   vertex(0, 0, -t);
   vertex(-t, 0, 0);

   fill(220,220,220);
   vertex(0, -t*2, 0);
   vertex(0, 0, -t);
   vertex(t, 0, 0);


   fill(250,250,250);
   vertex(0, -t*2, 0);
   vertex(t, 0, 0);
   vertex(0, 0, t);

   fill(220,220,220);
   vertex(0, -t*2, 0);
   vertex(0, 0, t);
   vertex(-t, 0, 0);

    rotateY(theta); 

    endShape();

    popMatrix();
  }

  void rotacion() { 
    theta+=0.002+s;
  }


  void collision_det() {
     boolean touching = false;


for (int i=0; i&lt;piramide.length;i++) {
Pyramid thisPyr = piramide[i];
for (int k=1; k&lt;piramide.length; k++)
{
Pyramid otherPyr = piramide[k];
float dis = dist(thisPyr.x, thisPyr.y, otherPyr.x, otherPyr.y);
if ((dis - 0.1) &lt; t*4) {
touching = true;
break;
}

if (touching == false) {
piramide[i].drawPiramide();
 }
 }
  }
}

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Directional Light on Shape Changed Direction or Bug?</title>
      <link>https://forum.processing.org/two/discussion/12900/directional-light-on-shape-changed-direction-or-bug</link>
      <pubDate>Fri, 09 Oct 2015 01:08:38 +0000</pubDate>
      <dc:creator>macksix</dc:creator>
      <guid isPermaLink="false">12900@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I have some simple code with a shape I made and notices that the directional light axis are flipped with Processing v3 as compared to Processing v2.2.1. This is also contrary to the documentation now. Is this intentional or is it a bug? If it is a bug, I will file an issue for it.  Thanks!</p>

<pre>
// Testing directional lighting

void settings() {
        size(600, 600, P3D);
    }

void setup() {
        frameRate(60);
        noStroke();
    }

void draw() {
        // For Processing v2.2.1, z = -1 is correct for directional light
        // For Processing v3, z = 1 is correct for directional light 
        directionalLight(255, 255, 255, 0, 0, 1);
        background(0);
        fill(color(160, 220, 50));
        translate((width / 2), (height / 2));
        float m = (frameCount * 0.01f);
        rotateY(m);
        
        beginShape(QUAD_STRIP);
        normal(-0.289784f, 0, 0.957092f);
        vertex(50, 20, 0);
        normal(-0.289784f, 0, 0.957092f);
        vertex(50, 75, 0);
        normal(0.289784f, 0, 0.957092f);
        vertex(80, 20, 0);
        normal(0.289784f, 0, 0.957092f);
        vertex(80, 75, 0);
        normal(1, 0, 0);
        vertex(110, 20, -45);
        normal(1, 0, 0);
        vertex(110, 75, -45);
        normal(0.289784f, 0, -0.957092f);
        vertex(80, 20, -90);
        normal(0.289784f, 0, -0.957092f);
        vertex(80, 75, -90);
        normal(-0.289784f, 0, -0.957092f);
        vertex(50, 20, -90);
        normal(-0.289784f, 0, -0.957092f);
        vertex(50, 75, -90);
        normal(-1, 0, 0);
        vertex(20, 20, -45);
        normal(-1, 0, 0);
        vertex(20, 75, -45);
        normal(-0.289784f, 0, 0.957092f);
        vertex(50, 20, 0);
        normal(-0.289784f, 0, 0.957092f);
        vertex(50, 75, 0);
        endShape();
    }
</pre>
]]></description>
   </item>
   <item>
      <title>How I can rotate the cylinders from the same angle?</title>
      <link>https://forum.processing.org/two/discussion/12533/how-i-can-rotate-the-cylinders-from-the-same-angle</link>
      <pubDate>Wed, 16 Sep 2015 00:14:03 +0000</pubDate>
      <dc:creator>edwins04</dc:creator>
      <guid isPermaLink="false">12533@/two/discussions</guid>
      <description><![CDATA[<p>/* to convert degrees to radians not start me all from the angle 0. How I can I can put them to begin with the same angle?</p>

<p>I tried with the map function, but I feel the same.  */</p>

<p>float p=0;  // angle 1
float d=180; // ange 2
float w=180; // angle 3
float topRadius=10;
float bottomRadius=10;
float tall=100;
float sides=100;
float cpx, cpy,angle = 0,angle1,angle2;
int e;
float rx = 0;
float ry =0;
int gridSize=40;
float angulo=0;
void setup() {
  size(1080, 660, P3D);
}
void draw() {
  background(0);
  fill(255, 255, 255);</p>

<p>lights();
   translate(width / 2, height / 2,0);</p>

<p>fill(255,0,0);
   sphere(15);</p>

<pre><code> noStroke();
</code></pre>

<p>fill(255, 255, 255);
  translate(0, 0, 0);
   angle = radians(p) ;
 beginShape(QUAD_STRIP);
  for (int i = 0; i &lt; sides + 1; ++i) { 
    vertex(topRadius<em>cos(angle), 0, topRadius</em>sin(angle));
    vertex(bottomRadius<em>cos(angle), tall</em>0.8,bottomRadius<em>sin(angle));
    angle += TWO_PI / sides;
    rotateX(angle);
 }
endShape(); 
translate(0,tall</em>0.8,0);
fill(255,0,0);
sphere(15);
fill(255, 255, 255);
  angle1 = radians(d); 
  beginShape(QUAD_STRIP);
  for (int i = 0; i &lt; sides + 1; ++i) {<br />
    vertex(topRadius<em>cos(angle1), 0, topRadius</em>sin(angle1));
    vertex(bottomRadius<em>cos(angle1), tall</em>0.6,bottomRadius*sin(angle1));
    angle1 += TWO_PI / sides;
    rotateX(angle1);
  }
  endShape();</p>

<p>translate(0,tall<em>0.6,0);
  fill(255,0,0);
sphere(13);
fill(255, 255, 255);
  angle2 = radians(w); 
  beginShape(QUAD_STRIP);
  for (int i = 0; i &lt; sides + 1; ++i) {<br />
    vertex(topRadius</em>cos(angle2), 0, topRadius<em>sin(angle2));
    vertex(bottomRadius</em>cos(angle2), tall<em>0.5,bottomRadius</em>sin(angle2));
    angle2 += TWO_PI / sides;
    rotateX(angle2);
  }
  endShape();
  translate(0,tall*0.5,0);
  fill(255,0,0);
sphere(10);
println(angle, angle1, angle2);
}</p>
]]></description>
   </item>
   <item>
      <title>Why doesn't the shape rotate 45 degrees?</title>
      <link>https://forum.processing.org/two/discussion/12018/why-doesn-t-the-shape-rotate-45-degrees</link>
      <pubDate>Sun, 09 Aug 2015 19:11:00 +0000</pubDate>
      <dc:creator>applepie</dc:creator>
      <guid isPermaLink="false">12018@/two/discussions</guid>
      <description><![CDATA[<p>Why doesn't the wood paneled square rotate by 45 degrees instead of nothing showing up when the sketch is run?
I understand that objects need to be translated to the origin in order to be rotated about their centers.  Is that correct?</p>

<pre><code>void setup()
{
  size(400,400,P2D);
  stroke(0);
  line(width/2,0,width/2,height);
  line(0,height/2,width,height/2);

  noStroke();
  drawSquare(width/2,height/2,100,"wood1.jpg",1000);
}

void drawSquare(float centerX, 
                float centerY,  
                float squareSize, 
                String textureName, 
                float textureSize) {
  PImage img = loadImage(textureName);
  PShape s = createShape();
  s.beginShape();
  s.texture(img);

  s.vertex(centerX-squareSize/2, centerY-squareSize/2, 0, 0);
  s.vertex(centerX+squareSize/2, centerY-squareSize/2, textureSize, 0);
  s.vertex(centerX+squareSize/2, centerY+squareSize/2, textureSize, textureSize);
  s.vertex(centerX-squareSize/2, centerY+squareSize/2, 0, textureSize);
  s.endShape();
  s.translate(-centerX,-centerY);
  s.rotate(radians(45));
  s.translate(centerX,centerY);
  shape(s);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to render Point Cloud efficiently?</title>
      <link>https://forum.processing.org/two/discussion/11949/how-to-render-point-cloud-efficiently</link>
      <pubDate>Mon, 03 Aug 2015 13:01:57 +0000</pubDate>
      <dc:creator>Jikid</dc:creator>
      <guid isPermaLink="false">11949@/two/discussions</guid>
      <description><![CDATA[<p>Hello!</p>

<p>For random point cloud generated in realtime, what data structure in Processing is appropriate for its rendering?
I tried with PShape, but only got 10~15 FPS for 20,000 points.</p>

<pre>
PShape boxCloud;

void setup() {
  size(400, 400, P3D);
  smooth();
}

void draw() {
  background(0);
  translate(width/2, height/2);
  gen();
  shape(boxCloud);
}

void gen()
{
  boxCloud = createShape();
  boxCloud.beginShape(POINTS);
  boxCloud.stroke(255);
  for (int i = 0; i &lt; 20000; i++) {
    boxCloud.vertex(random(-50, 50), random(-50, 50), random(-50, 50));
  }
  boxCloud.endShape();
}
</pre>

<p>I've test ofMesh in openFrameworks, it can run at almost 60 FPS rendering 200,000 points.
Is it possible to do that in Processing?</p>
]]></description>
   </item>
   <item>
      <title>random rotation angle and  startpoint when i run my sketch</title>
      <link>https://forum.processing.org/two/discussion/11565/random-rotation-angle-and-startpoint-when-i-run-my-sketch</link>
      <pubDate>Sat, 04 Jul 2015 17:24:20 +0000</pubDate>
      <dc:creator>urs</dc:creator>
      <guid isPermaLink="false">11565@/two/discussions</guid>
      <description><![CDATA[<p>can i make it so that.....every time when i run it, 
DIFFERENT ROTATION ANGLE and  SRARTPOINT?</p>

<p>"shape(s, 25, 25);(startpoint)"</p>

<pre><code>PShape s;  // The PShape object

void setup() {
  size(100, 100, P2D);
  // Creating a custom PShape as a square, by
  // specifying a series of vertices.
  s = createShape();
  s.beginShape();
  s.fill(0, 0, 255);
  s.noStroke();
  s.vertex(0, 0);
  s.vertex(0, 50);
  s.vertex(50, 50);
  s.vertex(50, 0);
  s.endShape(CLOSE);
}

void draw() {
  shape(s, 25, 25);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Is there a way to return a point at a PShape percentage independent of vertices?</title>
      <link>https://forum.processing.org/two/discussion/11151/is-there-a-way-to-return-a-point-at-a-pshape-percentage-independent-of-vertices</link>
      <pubDate>Thu, 04 Jun 2015 13:59:36 +0000</pubDate>
      <dc:creator>dimitre</dc:creator>
      <guid isPermaLink="false">11151@/two/discussions</guid>
      <description><![CDATA[<p>Is there a way to return a point at a PShape percentage independent of vertices?
I remember in Nodebox you can use a float from 0 to 1 to navigate through a shape but I don't know if it is possible with Processing now. any ideas?
Thank you</p>
]]></description>
   </item>
   <item>
      <title>I'd like to manipulate a UVSphere using mathematical equations</title>
      <link>https://forum.processing.org/two/discussion/10692/i-d-like-to-manipulate-a-uvsphere-using-mathematical-equations</link>
      <pubDate>Thu, 07 May 2015 16:36:23 +0000</pubDate>
      <dc:creator>originalsurfmex</dc:creator>
      <guid isPermaLink="false">10692@/two/discussions</guid>
      <description><![CDATA[<p>After reading Choma's inspiration book Morphing and looking at his web based tool <a rel="nofollow" href="http://www.morphingbook.com/tool.html">http://www.morphingbook.com/tool.html</a>, I'm trying to build my own version that creates surfaces.  I'm having problems figuring out how to input mathematical formulas though.</p>

<p>The example below has a few test sliders to manipulate common values, however I'd like to able to use text-based mathematical inputs.  I can't see how toggles and sliders can replace mathematical combinations of sin, cos, phi, theta, exponents and their relationships.</p>

<p>The beauty of the web based tool is that bad math will only result in no-sketch.  I'm not sure how to even do this in processing's java mode.  Can anyone help with this?  Thanks.</p>

<p>(as a side note, the UV sphere my code generates has problems with the QUAD_STRIP.  try dragging down the transparency to zero and you'll see the weirdness.)</p>

<pre><code>import controlP5.*;
import peasy.test.*;
import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;
PeasyCam camera;
ControlP5 cp5;
Slider uMinSlider;
Slider uMaxSlider;
Slider vMinSlider;
Slider vMaxSlider;

/* 
 phi = u
 theta = v
 */

float stepLat, stepLon, radius, phi, theta, u, v;
float uMin, uMax, vMin, vMax, u2Mult, v2Mult, transparency;
float xVMult, yVMult, zVMult, xUMult, yUMult, zUMult; 
int myColor = color(255, 0, 0);

void setup() {
  size(1000, 1000, OPENGL);
  smooth(8);
  strokeWeight(1);
  //noFill();  
  radius = width/20;

  camera = new PeasyCam(this, 0, 0, 0, width * 0.2);
  cp5 = new ControlP5(this);
  uMinSlider = cp5.addSlider("uMin");
  uMinSlider.setPosition(40, 40).setSize(200, 20).setRange(0.0, 2.0).setValue(0.0);
  uMaxSlider = cp5.addSlider("uMax");
  uMaxSlider.setPosition(40, 60).setSize(200, 20).setRange(0.0, 2.0).setValue(2.0);
  vMinSlider = cp5.addSlider("vMin");
  vMinSlider.setPosition(40, 80).setSize(200, 20).setRange(0.0, 2.0).setValue(0.0);
  vMaxSlider = cp5.addSlider("vMax");
  vMaxSlider.setPosition(40, 100).setSize(200, 20).setRange(0.0, 2.0).setValue(2.0);
  vMaxSlider = cp5.addSlider("stepLat");
  vMaxSlider.setPosition(40, 120).setSize(200, 20).setRange(1, 25).setValue(5);
  vMaxSlider = cp5.addSlider("stepLon");
  vMaxSlider.setPosition(40, 140).setSize(200, 20).setRange(1, 25).setValue(5);
  vMaxSlider = cp5.addSlider("v2Mult");
  vMaxSlider.setPosition(40, 160).setSize(200, 20).setRange(0, 50).setValue(1);
  vMaxSlider = cp5.addSlider("u2Mult");
  vMaxSlider.setPosition(40, 180).setSize(200, 20).setRange(0, 50).setValue(0);  
  vMaxSlider = cp5.addSlider("transparency");
  vMaxSlider.setPosition(40, 200).setSize(200, 20).setRange(0, 255).setValue(255);

  vMaxSlider = cp5.addSlider("xVMult");
  vMaxSlider.setPosition(width - 400, 40).setSize(100, 20).setRange(-5, 5).setValue(1);
  vMaxSlider = cp5.addSlider("xUMult");
  vMaxSlider.setPosition(width - 200, 40).setSize(100, 20).setRange(-5, 5).setValue(1);

  vMaxSlider = cp5.addSlider("yVMult");
  vMaxSlider.setPosition(width - 400, 60).setSize(100, 20).setRange(-5, 5).setValue(1);
  vMaxSlider = cp5.addSlider("yUMult");
  vMaxSlider.setPosition(width - 200, 60).setSize(100, 20).setRange(-5, 5).setValue(1);

  vMaxSlider = cp5.addSlider("zVMult");
  vMaxSlider.setPosition(width - 200, 80).setSize(100, 20).setRange(-5, 5).setValue(1);
  //vMaxSlider = cp5.addSlider("zUMult");
  //vMaxSlider.setPosition(width - 200, 140).setSize(100, 20).setRange(-5, 5).setValue(1);

  cp5.addTextfield("xValue").setPosition(width - 400, 120).setSize(300, 20).setAutoClear(false);
  cp5.addBang("Submit").setPosition(width - 400, 160).setSize(40, 20);  

  cp5.setAutoDraw(false);
}

void draw() {
  background(155);
  gui();
  stroke(255, 200, 200);
  fill(255, 155, 155, transparency);
  lights();
  //camcam.draw();

  for (float i = (degrees (vMin * PI)); i &lt;= (degrees(vMax * PI)); i += stepLon) {
    beginShape(QUAD_STRIP);
    for (float j = (degrees (uMin * PI)); j &lt;= (degrees(uMax * PI)); j += stepLat) {
      float v = i * ((2 * PI) / (degrees(2.0 * PI)));
      float u = j * ((2 * PI) / (degrees(2.0 * PI)));
      float v2 = (i + (stepLon * v2Mult)) * ((2 * PI)  / (degrees(2.0 * PI)));
      //u2Mult = 0 for a UVSPHERE
      float u2 = (j + (stepLat * u2Mult)) * ((2 * PI) / (degrees(2.0 * PI)));
      //THESE DO OTHER COOL THINGS!
      //float v2 = (i += stepLon) * ((2 * PI)  / (degrees(2.0 * PI)));
      //float u2 = (j += stepLat) * ((2 * PI) / (degrees(2.0 * PI)));
      float x2 = radius * (sin(v * xVMult) * cos(u * xUMult));
      float y2 = radius * (sin(v * yVMult) * sin(u * yUMult));
      float z2 = radius * (cos(v * zVMult));  
      float x3 = radius * (sin(v2 * xVMult) * cos(u2 * xUMult));
      float y3 = radius * (sin(v2 * yVMult) * sin(u2 * yUMult));
      float z3 = radius * (cos(v2 * zVMult));  
      vertex(x2, y2, z2);
      vertex(x3, y3, z3);
    }
    endShape();
  }
}

void gui() {
  camera.beginHUD();
  hint(ENABLE_DEPTH_TEST);
  cp5.draw();
  hint(DISABLE_DEPTH_TEST);
  camera.endHUD();
}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>