<?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 position() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=position%28%29</link>
      <pubDate>Sun, 08 Aug 2021 17:43:49 +0000</pubDate>
         <description>Tagged with position() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedposition%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How do I load and draw an image once as opposed to every frame to display it in every frame?</title>
      <link>https://forum.processing.org/two/discussion/28119/how-do-i-load-and-draw-an-image-once-as-opposed-to-every-frame-to-display-it-in-every-frame</link>
      <pubDate>Tue, 18 Sep 2018 07:55:23 +0000</pubDate>
      <dc:creator>samuset</dc:creator>
      <guid isPermaLink="false">28119@/two/discussions</guid>
      <description><![CDATA[<p>My problem is this: I want to display an image in my p5js sketch, but when I display it, it has to draw it every single frame, which can slow down the page. I want to be able to put my image on the canvas and leave it there until further notice, as opposed to drawing it in every frame. Kind of like a noLoop() until further notice.</p>

<p>Edit: I do want the sketch to keep looping, though, that's the thing.</p>
]]></description>
   </item>
   <item>
      <title>How can I use the input value as a variable with two arguments?</title>
      <link>https://forum.processing.org/two/discussion/28070/how-can-i-use-the-input-value-as-a-variable-with-two-arguments</link>
      <pubDate>Mon, 09 Jul 2018 00:10:36 +0000</pubDate>
      <dc:creator>carlosponce</dc:creator>
      <guid isPermaLink="false">28070@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone,</p>

<p>I was able to plot complex functions using the method of domain coloring</p>

<p><a rel="nofollow" href="https://www.openprocessing.org/sketch/569018">https://openprocessing.org/sketch/569018</a></p>

<p>and now I have been trying to add two inputs for changing the real and imaginary components of the function after clicking a button, but it seems I am doing something wrong</p>

<p><a rel="nofollow" href="https://www.openprocessing.org/sketch/569019">https://openprocessing.org/sketch/569019</a></p>

<p>How can I use those inputs to update two variables each one with two arguments? Do I need to parse the text somehow?</p>

<p>Any help or advice would be appreciated. Thanks in advanced.</p>
]]></description>
   </item>
   <item>
      <title>How can I add a button in a Graphics Element?</title>
      <link>https://forum.processing.org/two/discussion/27765/how-can-i-add-a-button-in-a-graphics-element</link>
      <pubDate>Sat, 14 Apr 2018 14:59:01 +0000</pubDate>
      <dc:creator>Okaghana</dc:creator>
      <guid isPermaLink="false">27765@/two/discussions</guid>
      <description><![CDATA[<p>Ok. So I want to create a button inside a createGraphics element. Here is an example:</p>

<pre><code>var pb
var button
var x = 50
var y = 50

function setup() {
  createCanvas(200, 200);

    pg = createGraphics(100, 100);
    pg.background(100)

    button = createButton("Button")

    button.position(0,0)
    button.size(100,100)

}

function draw() {
  background(220);

    image(pg, x, y)

    x += random(-1, 1)
    y += random(-1, 1)
}
</code></pre>

<p>So basically I want to be the button "button" to be a part of "pb", so that the button gets moved around alongside with the darker Box.</p>

<p>I tried things like <code>button.parent(pg)</code> or <code>button = pg.createButton(100, 100)</code>, but none of those 2 methods worked :(</p>

<p>So how can I do this?</p>

<p>Sincerely Okaghana</p>
]]></description>
   </item>
   <item>
      <title>I would like to know how to have the background image looping infinitely.</title>
      <link>https://forum.processing.org/two/discussion/25387/i-would-like-to-know-how-to-have-the-background-image-looping-infinitely</link>
      <pubDate>Mon, 04 Dec 2017 23:51:44 +0000</pubDate>
      <dc:creator>chuckopo</dc:creator>
      <guid isPermaLink="false">25387@/two/discussions</guid>
      <description><![CDATA[<p>I am creating a top-down 2D infinite side-scrolling runner game. But I am struggling trying to have the background image looping infinitely, I want it to look like the background is moving from top to the bottom. Would anyone know how to do that? I am using javascript by the way.</p>

<pre><code>function gameScreen(){

  var score;
  var samurai;
  var ninjas;
  var planks;
  var backgroundImg;
  var pauseAreaClicked;
  var isPaused;
  var pauseCreated;
  var gameOverCreated;
  var firstRun;

  this.setup = function(){
    createCanvas(windowWidth, windowHeight);
    gameTheme.loop();
    samurai = new Samurai();
    ninjas = [];
    planks = [];
    score = 0;
    bg = bg1;
    //Create the Pause Button
    pauseAreaClicked = false;
    firstRun = true;
    isPaused = false;
    pauseButton = createButton("||");
    pauseButtonCSSSetup(pauseButton, 0.6);
    pauseButton.mousePressed(pauseGame);
  }

  this.keyPressed = function(){
    if(keyCode == RIGHT_ARROW){
      samurai.switchLanes("right");
    }

    else if(keyCode == LEFT_ARROW){
      samurai.switchLanes("left");
    }

    else if(keyCode == UP_ARROW){
      samurai.attack();
    }
  }

  this.reset = function(){
    this.setup();
  }

  this.getScore = function(){
    return score;
  }

  this.draw = function(){
    if(isPaused){
      gameTheme.stop();
      return;
    }

    //Background Setup
    background(bg);

    //Text
    fill(255);
    textAlign(CENTER, CENTER);
    textSize(25);
    text("Score: " + score, windowWidth/2, windowHeight * .05)

    //Watch for framerate
    // var fps = frameRate();
    // stroke(0);
    // text("FPS:" + fps.toFixed(2), windowWidth / 2, height - 20);

    samurai.update();
    samurai.show();

    if(frameCount % 10 == 0){
      samurai.animate();
    }

    //Update enemy position every frame.
    for(var i = ninjas.length - 1; i &gt;= 0; i--){
      ninjas[i].show();
      ninjas[i].update();

      //If enemies go offscreen delete them to free up memory.
      if(ninjas[i].offscreen()){
        ninjas.splice(i, 1);
        if(score &gt; 0)
          score -= ninjas[i].getHealth();
      }

      if(ninjas[i].collision(samurai) &amp;&amp; !ninjas[i].isPushed()){
        if(samurai.attacking){
          //Slice sound
          sliceSound.play();

          score++;
          ninjas[i].loseHealth();
          if(ninjas[i].getHealth() &gt;= 1){
            ninjas[i].pushBack();
          }
        }
        else{
          clear();
          removeElements();
          if(gameOverCreated){
            var oOver = this.sceneManager.findScene(gameOverScene).oScene;
            oOver.reset();
          }

          gameOverCreated = true;
          gameTheme.stop();

          this.sceneManager.showScene(gameOverScene);
        }
        if(!ninjas[i].isPushed()){
          ninjas.splice(i, 1);
        }
      }
    }
  }

  this.mousePressed = function(){
    if(!pauseAreaClicked){
      if(mouseX &gt; (windowWidth / 2) * 1.5){
        samurai.switchLanes("right");
      }

      else if(mouseX &lt; (windowWidth / 2) * 0.5){
        samurai.switchLanes("left");
      }

      else{
        samurai.attack();
      }
    }

    else{
      if(isPaused){
        isPaused = false;
      }

      else{
        isPaused = true;
        if(pauseCreated){
          oPause = this.sceneManager.findScene(pauseScreen).oScene;
          oPause.reset();
        }

        pauseCreated = true;
        gameTheme.stop();
        this.sceneManager.showScene(pauseScreen);
      }

      pauseAreaClicked = false;
    }
  }

    /**
      CSS STYLING FOR BUTTONS :D
    */
  function pauseButtonCSSSetup(button, YpositionMultiple){
    button.style("width", "35px");
    button.style("height", "35px");
    button.style("text-align", "center");
    button.style("font-size", "125%");
    button.style("font-weight", "bold")
    button.style("color", "#FFF");
    button.style("background", "00000000");
    button.style("border-radius", "4px");
    button.style("display", "inline-block");
    button.style("border", "none");
    button.style("outline", "none");

    //NOT CSS
    //Center Button
    button.position(windowWidth  &gt;&gt; 6, windowHeight/100);
  }

  function pauseGame(){
    pauseAreaClicked = true;
  }

  this.unpause = function(){
    gameTheme.loop();
    isPaused = false;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How do I use input values to animate my canvas (P5.js)</title>
      <link>https://forum.processing.org/two/discussion/24010/how-do-i-use-input-values-to-animate-my-canvas-p5-js</link>
      <pubDate>Sun, 03 Sep 2017 04:42:33 +0000</pubDate>
      <dc:creator>therealnemis</dc:creator>
      <guid isPermaLink="false">24010@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to follow this tutorial here: <a href="https://p5js.org/examples/dom-input-and-button.html" target="_blank" rel="nofollow">https://p5js.org/examples/dom-input-and-button.html</a></p>

<p>to create an animation where a ball is bounced up and down. With the variable Height as a number, the animation works, but when I try to add an input to it, it doesn't</p>

<p>code: <a href="https://codepen.io/anon/pen/JyzdXy" target="_blank" rel="nofollow">https://codepen.io/anon/pen/JyzdXy</a></p>
]]></description>
   </item>
   <item>
      <title>p5js and d3</title>
      <link>https://forum.processing.org/two/discussion/23325/p5js-and-d3</link>
      <pubDate>Wed, 05 Jul 2017 19:41:52 +0000</pubDate>
      <dc:creator>jrmasiero</dc:creator>
      <guid isPermaLink="false">23325@/two/discussions</guid>
      <description><![CDATA[<p>I have made a simple sketch that can be used for interactive data visualizations using p5js and d3 libraries.</p>

<p><em>index.html</em></p>

<pre><code>    &lt;!DOCTYPE html&gt;
    &lt;html lang="en"&gt;
        &lt;head&gt;
            &lt;meta charset="utf-8"&gt;
            &lt;title&gt;D3: Drawing divs with data&lt;/title&gt;
            &lt;!-- PLEASE NO CHANGES BELOW THIS LINE (UNTIL I SAY SO) --&gt;
      &lt;script language="javascript" type="text/javascript" src="libraries/p5.js"&gt;&lt;/script&gt;
      &lt;script language="javascript" type="text/javascript" src="p5_D3_v5.js"&gt;&lt;/script&gt;
      &lt;!-- OK, YOU CAN MAKE CHANGES BELOW THIS LINE AGAIN --&gt;
      &lt;script language="javascript" type="text/javascript" src="libraries/p5.dom.js"&gt;&lt;/script&gt;
            &lt;script src="<a href="http://d3js.org/d3.v3.min.js" target="_blank" rel="nofollow">http://d3js.org/d3.v3.min.js</a>" charset="utf-8"&gt;&lt;/script&gt;


        &lt;/head&gt;
        &lt;body&gt;
             &lt;div id="container"&gt;&lt;/div&gt;
             &lt;div id="container2"&gt;&lt;/div&gt;


        &lt;/body&gt;
    &lt;/html&gt;
</code></pre>

<p><strong>p5_D3_v5.js</strong></p>

<pre><code>var w = 1000;
var h = 700;

var posicao_tela_x = 200;
var posicao_tela_y = 50;

var svg;

var valores = [10,50,90,100,150,400];

var padding = 50;

var circles;

var cores;
var posX;
var posY;

function preload() {

  svg = d3.select("#container2")
            .append("svg")
            .attr("width", w)
            .attr("height", h);

}


function setup() {
  var tela = createCanvas(w,h);
  //SELECIONA O DIV NO BODY que estea em cima(vem depois) ou embaixo(vem antes)
  tela.parent("#container");
  tela.position(0, 0);

  //iMPORTANTE PARA POSICIONAR O D3 E O P5 NA TELA
  select("#container").position(posicao_tela_x, posicao_tela_y);
  select("#container2").position(posicao_tela_x, posicao_tela_y);

  cores = d3.scale.quantize()
  .domain([d3.min(valores), d3.max(valores)])
  .range(["red","green","blue"]);

  posX = d3.scale.linear()
  .domain([d3.min(valores), d3.max(valores)])
  .range([0 + padding, w - padding]);

  posY = d3.scale.linear()
  .domain([d3.min(valores), d3.max(valores)])
  .range([h - padding,0 + padding]);

  desenharData();        

}

function draw(){


noFill();
strokeWeight(5);
stroke(0);
rect(0,0,w,h);
noFill();
strokeWeight(5);
stroke(0);
rect(mouseX,mouseY,70,70);


}



function desenharData(){

  circles = svg.selectAll("circle")
  .data(valores)
  .enter()
  .append("circle");

  circles.attr("cx", function(d){
    return posX(d);
  })
  .attr("cy", function(d){
    return posY(d);
  })
  .attr("r", function(d){
    return d/2;
  })
  .attr("fill", function(d){
    return cores(d);
  });


}

function mouseClicked(){
shuffle(valores,true);
ReDesenharData();
}

function ReDesenharData(){


 circles = svg.selectAll("circle")
 .data(valores)
 .transition()
 .duration(500)
 circles.attr("cx", function(d){
    return posX(d);
  })
  .attr("cy", function(d){
    return posY(d);
  })
  .attr("r", function(d){
    return d/2;
  });



}
</code></pre>

<p>Depending on the div (container or conteiner2) you select() your p5 code will be in front or as background of the d3 data visualization. CLick the mouse to shuffle the<del></del> array.</p>
]]></description>
   </item>
   <item>
      <title>Button and text vertical centering</title>
      <link>https://forum.processing.org/two/discussion/23250/button-and-text-vertical-centering</link>
      <pubDate>Thu, 29 Jun 2017 03:20:13 +0000</pubDate>
      <dc:creator>reona396</dc:creator>
      <guid isPermaLink="false">23250@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I have a question about p5.js and p5.dom.js .</p>

<p>I want to add a button in my p5.js sketch using p5.dom.js,
and want that I place a button on vertical center with text.
So I write a code as follows.</p>

<pre><code>textAlign(CENTER, CENTER);
text(“HELLO!", width/2, height/2);

var button = createButton(“&lt;-");
button.position(width/4, height/2);
</code></pre>

<p>But the button and text have different  base line,
so I don’t get expected result.
What should I do for vertical centering button and text?</p>
]]></description>
   </item>
   <item>
      <title>I want to display a video. The sound plays but the screen is blank.</title>
      <link>https://forum.processing.org/two/discussion/22251/i-want-to-display-a-video-the-sound-plays-but-the-screen-is-blank</link>
      <pubDate>Thu, 27 Apr 2017 17:32:24 +0000</pubDate>
      <dc:creator>Brenda</dc:creator>
      <guid isPermaLink="false">22251@/two/discussions</guid>
      <description><![CDATA[<p>var fingers;</p>

<p>function setup() 
{
     createCanvas(1920, 1080);
     // specify multiple formats for different browsers
     fingers = createVideo(['assets/glen.mov']);
     //fingers.hide(); // by default video shows up in separate dom
                  // element. hide it and draw it to the canvas
                  // instead
    fingers.loop(); 
}</p>

<p>function draw() {
  background(150);
  image(fingers,10,10); // draw the video frame to canvas
  //filter('GRAY');
  image(fingers,150,150); // draw a second copy to canvas
}</p>
]]></description>
   </item>
   <item>
      <title>DOM interfering with Sketch Container</title>
      <link>https://forum.processing.org/two/discussion/21532/dom-interfering-with-sketch-container</link>
      <pubDate>Wed, 22 Mar 2017 06:11:46 +0000</pubDate>
      <dc:creator>yovendofruta</dc:creator>
      <guid isPermaLink="false">21532@/two/discussions</guid>
      <description><![CDATA[<p>My goal is to have these sketches centered in the horizontal direction, and one appear first on the page, then the second. Here is my script file. These two sketches in instance mode are identical save the image loaded into each one.</p>

<pre><code>var PH2 = function ( p ) {
    var mic;
    var img;
    var myCanvas;

    p.centerCanvas = function() {
        var x = (p.windowWidth - p.width) / 2;
        myCanvas.position(x, 0);
        }          

    p.preload = function() {
        img = p.loadImage('Sketches/PH2/1.jpg');
        }

    p.setup = function() {
        myCanvas = p.createCanvas(1000, 600);
        mic = new p5.AudioIn()
        mic.start();
        p.centerCanvas();
        }

    p.windowResized = function() {
        p.centerCanvas();
        }            

    p.draw = function() {
        if (p.mouseIsPressed) {
            micLevel = mic.getLevel();
            p.background('#fdfaee');
            p.textFont("Helvetica");
            p.text("do", 500*micLevel+200, 600*micLevel+300);
            p.fill('#f99991');
            }

        else {
            micLevel = mic.getLevel();
            p.background(255);    
            p.image(img, 200*micLevel*50+200, -50*micLevel*50, p.width/1.9, p.height);
            }
        }
    }
myp5 = new p5(PH2, 'PH2Contain');

var PH3 = function ( p ) {
    var mic;
    var img;
    var myCanvas;

    p.centerCanvas = function() {
        var x = (p.windowWidth - p.width) / 2;
        myCanvas.position(x, 0);
        }          

    p.preload = function() {
        img = p.loadImage('Sketches/PH3/2.jpg');
        }

    p.setup = function() {
        myCanvas = p.createCanvas(1000, 600);
        mic = new p5.AudioIn()
        mic.start();
        p.centerCanvas();
        }

    p.windowResized = function() {
        p.centerCanvas();
        }            

    p.draw = function() {
        if (p.mouseIsPressed) {
            micLevel = mic.getLevel();
            p.background('#fdfaee');
            p.textFont("Helvetica");
            p.text("you", 500*micLevel+700, 600*micLevel+300);
            p.fill('#bcf5ee');
            }

        else {
            micLevel = mic.getLevel();
            p.background(255);    
            p.image(img, 300*micLevel*50+200, -100*micLevel*50, p.width/1.9, p.height);
            }
        }
    }
myp5 = new p5(PH3, 'PH3Contain');
</code></pre>

<p>Here is my HTML</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;link rel="stylesheet" type="text/css" href="PaintStyle.css"&gt;.
        &lt;script src="Resources/p5.js"&gt;&lt;/script&gt;
        &lt;script language="javascript" type="text/javascript" src="Resources/p5.dom.js"&gt;&lt;/script&gt;
        &lt;script language="javascript" type="text/javascript" src="Resources/p5.sound.js"&gt;&lt;/script&gt;
        &lt;script language="javascript" type="text/javascript" src="Sketches/PH2/PH2.js"&gt;&lt;/script&gt;
        &lt;title&gt;painthead&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;

&lt;div id="PH2Contain"&gt;&lt;/div&gt;
&lt;p&gt;hello hello&lt;/p&gt;
&lt;div id="PH3Contain"&gt;&lt;/div&gt;  

    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>If I do not include the centering operations the sketches appear correct but are aligned left (and I want them centered). Whenever I include the function to center the sketch I only see the second sketch centered with "hello hello" to the left of it. With this method I am assuming in myCanvas.position(x,y) the y value is relative to the beginning of the div, but this must not be the case?</p>
]]></description>
   </item>
   <item>
      <title>Centering Sketch using p5.dom</title>
      <link>https://forum.processing.org/two/discussion/21513/centering-sketch-using-p5-dom</link>
      <pubDate>Tue, 21 Mar 2017 05:43:51 +0000</pubDate>
      <dc:creator>yovendofruta</dc:creator>
      <guid isPermaLink="false">21513@/two/discussions</guid>
      <description><![CDATA[<p>I am attempting to center a sketch in an html page using the dom library. I have followed the reference (<a href="https://p5js.org/reference/#/p5.Element/position" target="_blank" rel="nofollow">https://p5js.org/reference/#/p5.Element/position</a>), as well as instructions on GitHub (<a href="https://github.com/processing/p5.js/wiki/Positioning-your-canvas" target="_blank" rel="nofollow">https://github.com/processing/p5.js/wiki/Positioning-your-canvas</a>), but have had no luck. When I run my code I receive the error messages</p>

<pre><code>Uncaught TypeError: Cannot read property 'prototype' of undefined
    at p5.dom.js:71
    at p5.dom.js:34
    at p5.dom.js:35
</code></pre>

<p>and</p>

<pre><code>Uncaught TypeError: myCanvas.position is not a function
    at setup (paint.html:24)
    at p5.&lt;anonymous&gt; (p5.js:9111)
    at p5.&lt;anonymous&gt; (p5.js:9041)
    at new p5 (p5.js:9323)
    at _globalInit (p5.js:5602)
</code></pre>

<p>Here is my code (I've included HTML for convenience).</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;script language="javascript" type="text/javascript" src="p5.dom.js"&gt;&lt;/script&gt;
        &lt;script src="p5.js"&gt;&lt;/script&gt;
        &lt;script language="javascript" type="text/javascript" src="p5.sound.js"&gt;&lt;/script&gt;
        &lt;title&gt;painthead&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;

      &lt;script&gt;

  var mic;
  var myCanvas;            

  function setup() {
  mic = new p5.AudioIn()
  mic.start();
  myCanvas = createCanvas(1000, 600);    
  myCanvas.position(50, 100); //this breaks the code
  img = loadImage('1.jpg');

}

function draw() {

  background(255);

  if(mouseIsPressed) {
    micLevel = mic.getLevel();
    var c = color('#f99991');
    var v = color('#fdfaee');
    background(v);
    textFont("Helvetica");
    text("do", 500*micLevel+200, 600*micLevel+300);
    fill(c);
  }

  else {
  micLevel = mic.getLevel();  
  image(img, 200*micLevel*50, -50*micLevel*50, img.width/2, img.height/2);
  }
}


        &lt;/script&gt;
</code></pre>

<p>I realize that <code>myCanvas.position(50, 100)</code> will not center the sketch but I am testing the function to make sure it works.</p>
]]></description>
   </item>
   <item>
      <title>how to display GIF in the background?</title>
      <link>https://forum.processing.org/two/discussion/20792/how-to-display-gif-in-the-background</link>
      <pubDate>Tue, 14 Feb 2017 10:35:35 +0000</pubDate>
      <dc:creator>Berlina</dc:creator>
      <guid isPermaLink="false">20792@/two/discussions</guid>
      <description><![CDATA[<p>I would like to create a disco light effect on a dance gif. So the gif is on the bottom layer, then a rectangle is flashing on top according to framerate. But somehow the gif is alway on the top, even though I place it before the rectangle. Could someone help me review the code?</p>

<pre><code>var img;  
function preload() {   
img = createImg("dancegif.gif");
}

function setup(){
    createCanvas(window.innerWidth,window.innerHeight); 
}

function draw(){
    background(255);

  img.position(0,0);

    // flashing effect 
    noStroke();
    if(frameCount % 7 &lt; 3 ){
      noFill(); //pic 33%  12 
    } else if(frameCount % 7 &gt; random(3,4) ){
        fill(255);//white 33% 56 
    } else{
        fill(0);//black 34% 
    }
    rect(0,0,window.innerWidth,window.innerHeight);

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to create editable text on p5.js canvas</title>
      <link>https://forum.processing.org/two/discussion/19944/how-to-create-editable-text-on-p5-js-canvas</link>
      <pubDate>Tue, 27 Dec 2016 11:38:06 +0000</pubDate>
      <dc:creator>Mysterion</dc:creator>
      <guid isPermaLink="false">19944@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I'm fairly new to Javascript and p5, and I'm trying to create an interactive graph. So far, I've got the node/edge addition/removal down, but I want to add editable text to the canvas. More specifically, every time you create a node or an edge, I want to display a string next to it showing its 'weight'. If you click the string, you can also type in a new weight, and press enter to change it.</p>

<p>So far, I've tried several approaches to getting editable text, but I'm kinda stuck.</p>

<p>In my first attempt, I tried to make the text a html element via createInput() (using CSS to make the input box transparent) and basically 'overlay' it on top of my canvas. The problem with this was that html elements use different coordinate system to the canvas, so I couldn't get them to sync properly.</p>

<p>In my second attempt, I read about fillText(), but this required canvas.getContext("2d") to be called, and that didn't work with var canvas = createCanvas(). Instead, I would have to use var canvas = document.getElementById("canvas"), where "canvas" was the ID of the canvas html environment. However, for some reason, when I used document.getElementById, my canvas became really small and no attempts to change its dimensions or position worked.</p>

<p>So yeah, I'm kinda stuck. What is the recommended way of adding editable text?</p>
]]></description>
   </item>
   <item>
      <title>Responsive Web Design (How To: Fit Canvas to a DIV's Width &amp; Height)</title>
      <link>https://forum.processing.org/two/discussion/19767/responsive-web-design-how-to-fit-canvas-to-a-div-s-width-height</link>
      <pubDate>Thu, 15 Dec 2016 15:40:03 +0000</pubDate>
      <dc:creator>kreendurron</dc:creator>
      <guid isPermaLink="false">19767@/two/discussions</guid>
      <description><![CDATA[<p>I’m attempting to position a canvas inside of a specific div.
I also want that canvas to resize responsively to the size of that div.</p>

<p>I’ve seen examples online for tying the position of the canvas to a div and then using the windowWidth &amp; Height… but that only sizes according to the window size.</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/842/2IR762QYYRU0.JPG" alt="Capture" title="Capture" /></p>
]]></description>
   </item>
   <item>
      <title>generate JSONArray</title>
      <link>https://forum.processing.org/two/discussion/19765/generate-jsonarray</link>
      <pubDate>Thu, 15 Dec 2016 12:51:42 +0000</pubDate>
      <dc:creator>doeroe</dc:creator>
      <guid isPermaLink="false">19765@/two/discussions</guid>
      <description><![CDATA[<p>Hi there,</p>

<p>do you know, how to generate a JSONArray with p5? 
According to the p5 reference, there must be a way to save a .json file containing several JSONobjects with saveJSON, but there is no example for the syntax of that JSONArray (only for JSON-Objects).</p>

<p>I really appreciate any help!</p>
]]></description>
   </item>
   <item>
      <title>review of a quick UI prototype</title>
      <link>https://forum.processing.org/two/discussion/17725/review-of-a-quick-ui-prototype</link>
      <pubDate>Tue, 02 Aug 2016 14:22:36 +0000</pubDate>
      <dc:creator>dima</dc:creator>
      <guid isPermaLink="false">17725@/two/discussions</guid>
      <description><![CDATA[<p>I put together a very quick UI (button hover, button press) demo. From purely javascript perspective it's OK. However, I am trying to figure out if this the way I should proceed with creating UI elements within the canvas or if I am making way too much work for myself and there are better ways to accomplish this task. I am very new to P5 so would love some council from more experienced devs. Aware of p5.dom but looking to eventually implement a canvas-only UI solution.</p>

<p><a href="http://codepen.io/Digi-D/pen/VjGmRE" target="_blank" rel="nofollow">http://codepen.io/Digi-D/pen/VjGmRE</a></p>
]]></description>
   </item>
   <item>
      <title>How to know which is clicked on:  arrayDiv[i].mousePressed(function)?</title>
      <link>https://forum.processing.org/two/discussion/17088/how-to-know-which-is-clicked-on-arraydiv-i-mousepressed-function</link>
      <pubDate>Fri, 10 Jun 2016 13:06:55 +0000</pubDate>
      <dc:creator>mirror</dc:creator>
      <guid isPermaLink="false">17088@/two/discussions</guid>
      <description><![CDATA[<p>I am coding like the below.
There are a lot of clickable squares on the screen as the image at the bottom shows.
I would like to know which one was clicked.
But I can not get any value which was clicked from "myBlock[i].mousePressed(whichBlock);".
I wonder how to give a value to the "whichBlock" function that I defined.</p>

<pre><code>    var myBlock=[];
    var blockNumber=50;

    function setup(){
      for(var i=0;i&lt;blockNumber;i++){
        myBlock[i]=createDiv(i);
        myBlock[i].size(30,30);
        myBlock[i].position(random(windowWidth*0.8),random(windowHeight*0.8));
        myBlock[i].style("background-color","#FAA");
        myBlock[i].style("border","1px solid #444");

        myBlock[i].mousePressed(whichBlock);
        //this does not send the value which is mousePressed to the function below.
      }
    }

    function whichBlock(n){
      alert(n);
      //myBlock[n].hide();  //I want to do this if possible.
    }
</code></pre>

<p><img src="https://forum.processing.org/two/uploads/imageupload/507/HV7W014354XF.png" alt="sample" title="sample" /></p>
]]></description>
   </item>
   <item>
      <title>placing slider relative to canvas in instance mode</title>
      <link>https://forum.processing.org/two/discussion/17074/placing-slider-relative-to-canvas-in-instance-mode</link>
      <pubDate>Thu, 09 Jun 2016 21:00:29 +0000</pubDate>
      <dc:creator>aatish</dc:creator>
      <guid isPermaLink="false">17074@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to place a slider in a p5 sketch running in instance mode. However, the slider position is calculated relative to the html page, and not relative to the origin of the canvas. So for example if the canvas is in a different location, the slider won't move with it.</p>

<p>How can I place the slider relative to the canvas? (i.e. in a manner similar to other p5 objects, like images, etc.)</p>

<p>Here's my test code:</p>

<pre><code>var testslider = function(p){

    var slider;

    p.setup = function() {
      p.createCanvas(400, 400);
      p.background(200);
      slider = p.createSlider(0, 255, 100);
      slider.position(0, 20);
    }

    p.draw = function() {
    }

}
</code></pre>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>How can I make this idea possible? (sound alphabet)</title>
      <link>https://forum.processing.org/two/discussion/16855/how-can-i-make-this-idea-possible-sound-alphabet</link>
      <pubDate>Fri, 27 May 2016 17:33:40 +0000</pubDate>
      <dc:creator>jeremy_wilde</dc:creator>
      <guid isPermaLink="false">16855@/two/discussions</guid>
      <description><![CDATA[<p>Hi. I'm 22yo design major student.</p>

<p>Sorry for the bad english. I might be suck to understand.
I try to make some kind of interaction work that by writing some words,
It becomes a short melody on processing. And you can see your typewriting like usual web environment.
It don't have to be a certain word and I try to make them sound when enterkey pressed.</p>

<p>this is the example)</p>

<p>In blank space, cursor blinking. You write some short sentences. 
  You press enterkey. It becomes little melody that matched the keycode that you pressed.
  Like if you write 'a little butterfly' It became 'a' note melody~ 'l' note melody~ 'i' note melody~.</p>

<p>I used Pfont function for the text and Minim for the sound part.
However I can't make them work togher.</p>

<p>A little example will helps me to understand, I really appreciate.</p>

<p>Thanks for reading this mess.</p>
]]></description>
   </item>
   <item>
      <title>p5.dom.js how to position checkbox label?</title>
      <link>https://forum.processing.org/two/discussion/16743/p5-dom-js-how-to-position-checkbox-label</link>
      <pubDate>Sat, 21 May 2016 20:15:30 +0000</pubDate>
      <dc:creator>shiihs</dc:creator>
      <guid isPermaLink="false">16743@/two/discussions</guid>
      <description><![CDATA[<p>Hi all, [spoiler: newbie alert],</p>

<p>I create a checkbox cb using createCheckbox with a label argument. Then I try to position my checkbox+label using cb.position(x,y) but somewhat to my surprise only the actual checkbox changes place, the label on the other hand remains on its original position.
What is the best way to reposition the label as well?</p>

<pre><code>var cb;

function setup() {
  cb = createCheckbox('enabled', false);
}

function draw() {
  cb.position(400, 400);
}
</code></pre>

<p>Thanks!
(I'm using p5.js v0.4.23 March 04, 2016 and p5.dom.js v0.2.9 March 3, 2016)</p>
]]></description>
   </item>
   <item>
      <title>How do I make a button created using createButton() stay on the canvas?</title>
      <link>https://forum.processing.org/two/discussion/15530/how-do-i-make-a-button-created-using-createbutton-stay-on-the-canvas</link>
      <pubDate>Thu, 17 Mar 2016 01:57:40 +0000</pubDate>
      <dc:creator>mryoho</dc:creator>
      <guid isPermaLink="false">15530@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I have the following code, where I want to create a p5 canvas, attach it to a div (with id of 'shootingstar'), and then create a button on that canvas.</p>

<pre><code>function setup() {
    var myCanvas = createCanvas(400, 400);
    myCanvas.parent('shootingstar');

    resetButton = createButton('reset');
    resetButton.position(300, 300);
    resetButton.mousePressed(reset);
}
</code></pre>

<p>The problem is, the button is rendering as if the canvas.parent() command has had no effect. How do I get the button to be positioned relative to the top left corner of the canvas?</p>

<p>I should mention that I'm trying to keep this as simple as possible because first year students are going to be using it.</p>

<p>Any thoughts would be awesome! Thank you!</p>
]]></description>
   </item>
   <item>
      <title>Status bar with movie and ControlP5</title>
      <link>https://forum.processing.org/two/discussion/13716/status-bar-with-movie-and-controlp5</link>
      <pubDate>Mon, 30 Nov 2015 20:49:52 +0000</pubDate>
      <dc:creator>Jose_Aparecido</dc:creator>
      <guid isPermaLink="false">13716@/two/discussions</guid>
      <description><![CDATA[<p>Hello guys,</p>

<p>I'm trying to put a bar to control the time / position when running a film, based on this example:
<a href="https://forum.processing.org/two/discussion/8103/using-a-controlp5-slider-as-video-progress-bar" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/8103/using-a-controlp5-slider-as-video-progress-bar</a></p>

<p>To show the bar as the elapsed time, ran regular ...</p>

<p>But how do if you want to advance the film? It did not work when I tried movie.position () (as sound).</p>

<p>Someone could give a tip, or where can I find some documentation on the subject?</p>

<p>Below the code I am using as an example:</p>

<pre><code>import controlP5.*;
import processing.video.*;                              

ControlP5 cp5;
Movie movie1;

float md, mt;

int progress;
boolean play;

void setup() {
  size(600, 400);
  cp5 = new ControlP5(this);

  movie1 = new Movie(this, "D:/Projetos/Videos/Branca_de_Neve.mpg");
  movie1.play();

  ProgressBar p; // custom Controller class, see implementation below
  p = new ProgressBar(cp5, "progress"); // "progress" here will be linked to variable progress
  //p.setPosition(100, 300).setSize(200, 20).setRange(0, 1000).listen(true);
  p.setPosition(70, 330).setSize(350, 10).setRange(0,  (int) movie1.duration()).listen(true);

  // callback listener for TimeLine object   
  p.addCallback(new CallbackListener() {
    public void controlEvent(CallbackEvent theEvent) {
      if(theEvent.getAction() == ControlP5.ACTION_PRESS) {
        float x = theEvent.getController().getPointer().x();
        float a1 = 0;
        float a2 = theEvent.getController().getWidth();
        float b1 = theEvent.getController().getMin();
        float b2 = theEvent.getController().getMax();
        float val = map(x,a1,a2,b1,b2);
        theEvent.getController().setValue(val);
        println("now change movie time to ", val, movie1.time());

        //movie1.position(); //????
      }
    }
  }
  );

  // a toggle to switch between play and pause mode
  cp5.addToggle("play")
     .setPosition(10,375)
     .setSize(50,19)
     .getCaptionLabel().align(CENTER,CENTER);
}


void draw() {
  background(0);
  if (play) {
    // update the progressBar value/position
    // replace with audio-track position: progress = player.position();

    if (movie1.available()) movie1.read();
    image(movie1, 70, 40);

    //progress++;
    progress = (int) movie1.time();
  }
}

class ProgressBar extends Controller&lt;ProgressBar&gt; {

  public ProgressBar(ControlP5 theControlP5, String theName) {
    super(theControlP5, theName);

    setView(new ControllerView&lt;ProgressBar&gt;() {
      public void display(PGraphics pg, ProgressBar c) {

        pg.fill(!isMouseOver() ? c.getColor().getForeground():c.getColor().getActive());
        pg.rect(0, 0, c.getWidth(), c.getHeight());

        float val = map(c.getValue(),c.getMin(), c.getMax(), 0, c.getWidth()); 
        pg.fill(255);
        pg.rect(0, 0, val, c.getHeight());
      }
    }
    );
  }

  public ProgressBar setValue(float theValue) {
    return super.setValue(constrain(theValue, getMin(), getMax()));
  }

  public ProgressBar setRange(int theStart, int theEnd) {
    _myMin = theStart;
    _myMax = theEnd;
    return this;
  }
}
</code></pre>

<p>Thanks for listening</p>
]]></description>
   </item>
   <item>
      <title>Manipulating DOM elements with templates using P5 for seamless transitions</title>
      <link>https://forum.processing.org/two/discussion/13179/manipulating-dom-elements-with-templates-using-p5-for-seamless-transitions</link>
      <pubDate>Thu, 22 Oct 2015 16:32:53 +0000</pubDate>
      <dc:creator>kenyanburnham</dc:creator>
      <guid isPermaLink="false">13179@/two/discussions</guid>
      <description><![CDATA[<p>Before I ask my question I have to do a little explaining...</p>

<p>My purpose and goal for using P5.js to load in templates and display them in the DOM in order to manipulate them to appear as if they are being assembled and dissembled between "god page" transitions (a Backbone Framework). The view for each route would use P5.js's position() method to move the newly copied and created DOM elements to their final resting state on the page by appending them off the visible screen (and promptly disabling scrolling using the overflow hidden method on the body) and then slowly transitioning them back to their intended position on the screen with easement.</p>

<p>Currently I have a non-P5.js version of this where I use a margin large enough not to be visible in a random direction (this part I already have working) and then using the JQuery animate method to slowly reduce the margin making the appearance of DOM elements assembling on the page. Removing the elements from the DOM was easy, but appending them is way more difficult which is why I wanted to use P5.js as the agent that does the movement and transition.</p>

<p>Using JQuery's $.get() method I am able to grab templates from files, then I use P5's createElement() to create a DIV with the template as my content. i.e "createElement("div",template)". From there I am able to give it an attribute("id", "dash1") and append it to the DOM and it renders fine as a DOM element, however, if I create multiple instances of this object the two rendered objects stack on themselves in the body even when I try to append one to the other. I have assigned both an ID attribute, so in non-P5 instances this method of grabbing templates and inserting them into each other would work fine. However, in P5.js I assume the created elements are treated differently in Setup() and I was wondering if anyone would be able to shed some light on the subject.</p>

<p>That was a lot of explanation for a small question, but hopefully it explains thoroughly what I am trying to do.</p>
]]></description>
   </item>
   <item>
      <title>removing an image once it's drawn?</title>
      <link>https://forum.processing.org/two/discussion/12119/removing-an-image-once-it-s-drawn</link>
      <pubDate>Mon, 17 Aug 2015 08:37:42 +0000</pubDate>
      <dc:creator>brig</dc:creator>
      <guid isPermaLink="false">12119@/two/discussions</guid>
      <description><![CDATA[<p>Hi there. P5 newbie here. Am trying to place an image and then remove it later (on user input). I can place it just fine,</p>

<p>image(myimages[imgselected], 0, 0);</p>

<p>But then, don't seem to be able to remove it. Don't see a remove image function available. And when I try to just move it offscreen, it seems to make a copy of it at the new location. Ie:</p>

<p>image(myimages[imgselected], -1000, -1000);</p>

<p>Just makes a copy of the image at -1000,-1000 and leaves the original in-tact at 0,0.</p>

<p>I have noLoop() turned on, in case this is an issue with not hitting the draw loop?</p>

<p>thx for any pointers.</p>
]]></description>
   </item>
   <item>
      <title>save() not working on any canvas?</title>
      <link>https://forum.processing.org/two/discussion/11786/save-not-working-on-any-canvas</link>
      <pubDate>Tue, 21 Jul 2015 18:56:16 +0000</pubDate>
      <dc:creator>just_in_peru</dc:creator>
      <guid isPermaLink="false">11786@/two/discussions</guid>
      <description><![CDATA[<p>I'm running 05.js 0.4.6 and am attempting the save() function to download a image from the canvas and am getting the error:
<code>Uncaught TypeError: Cannot read property 'toDataURL' of undefined</code></p>

<p>Example of JS (not my actual javascript being used):</p>

<pre><code>function setup() {

//Creating the webpage interface 
var canvas = createCanvas(1280, 1280);
canvas.parent('container');
canvas.position(0,0);
textSize(14);


//Variable center of screen
centerx = width/2;
centery = height/2; 

//Creating the # of authors input (will be replced with CSV data)
but = createInput("10");
but.position((200-176)/2,10);
save('test.png');
}
</code></pre>

<p>This is being drawn within the HTML.
Running this just leads to that error. What should I do to fix? Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Anyone know how to make a transparent background??</title>
      <link>https://forum.processing.org/two/discussion/7726/anyone-know-how-to-make-a-transparent-background</link>
      <pubDate>Tue, 21 Oct 2014 01:58:48 +0000</pubDate>
      <dc:creator>spaghetti</dc:creator>
      <guid isPermaLink="false">7726@/two/discussions</guid>
      <description><![CDATA[<p>Does anyone know how to make a transparent background?
I'm trying to use HTML/CSS to make my background a full screen image, but when I do that, my canvas starts drawing MS paint style... I want to know how to get rid of that by making the background transparent.</p>

<p>Or maybe a better way to get an image in p5js to be a fullscreen background without scaling the width? I tried using:</p>

<pre><code>image(img, 0, 0);
img.resize(0, height);
</code></pre>

<p>but for some reason this function gives me errors.</p>
]]></description>
   </item>
   <item>
      <title>center html element relative to coordinates</title>
      <link>https://forum.processing.org/two/discussion/8254/center-html-element-relative-to-coordinates</link>
      <pubDate>Wed, 19 Nov 2014 14:10:23 +0000</pubDate>
      <dc:creator>kempowski</dc:creator>
      <guid isPermaLink="false">8254@/two/discussions</guid>
      <description><![CDATA[<p>hello,
last few days i got into p5.js and wondered, if there's a way to center an created html element on the canvas. 
equal to an "text:align" in css or like some sort of "rectMode".</p>

<p>if my way of thinking is going in the wrong direction, please tell me…i'm getting a bit confused by mixing these different languages.</p>
]]></description>
   </item>
   <item>
      <title>Position the p5.js canvas on different parts of the page</title>
      <link>https://forum.processing.org/two/discussion/7868/position-the-p5-js-canvas-on-different-parts-of-the-page</link>
      <pubDate>Thu, 30 Oct 2014 07:09:36 +0000</pubDate>
      <dc:creator>grigorMalo</dc:creator>
      <guid isPermaLink="false">7868@/two/discussions</guid>
      <description><![CDATA[<p>Hello,
I was searching around to find a way to specify the location the p5.js canvas will have on the page but i didn't find anything. I've called the sketch in this way:</p>

<p><code>&lt; script language=" javascript " src="sketch.js" &gt;&lt; /script &gt;</code></p>

<p>and the canvas gets automatically drawn after all the HTML elements in the body section. I would like to position it somewhere between my other html elements. Could anyone help me on how to do this?</p>

<p>Thanks in advance.</p>
]]></description>
   </item>
   </channel>
</rss>