<?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 creategraphics() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/p2/feed.rss?Tag=creategraphics%28%29</link>
      <pubDate>Sun, 08 Aug 2021 15:51:20 +0000</pubDate>
         <description>Tagged with creategraphics() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedcreategraphics%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Using PGraphics class in Java without instantiating PApplet class</title>
      <link>https://forum.processing.org/two/discussion/20482/using-pgraphics-class-in-java-without-instantiating-papplet-class</link>
      <pubDate>Thu, 26 Jan 2017 13:31:15 +0000</pubDate>
      <dc:creator>NATALAN</dc:creator>
      <guid isPermaLink="false">20482@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I'd like to use PGraphics in a JavaFX Application, which means my Main-Class cannot extend from PApplet. Is there any example or any chance at all to make usage of PGraphics without instantiating the PApplet-Class? 
I also tried to runn the PApplet from another class, but it was a mess which didnt seem to work at all.</p>

<p>Thank you</p>
]]></description>
   </item>
   <item>
      <title>P5JS createGraphics scaling discrepancy?</title>
      <link>https://forum.processing.org/two/discussion/19905/p5js-creategraphics-scaling-discrepancy</link>
      <pubDate>Sat, 24 Dec 2016 17:31:11 +0000</pubDate>
      <dc:creator>schuelaw</dc:creator>
      <guid isPermaLink="false">19905@/two/discussions</guid>
      <description><![CDATA[<p>I'm seeing a scaling discrepancy between the default graphics context and a second context of the same size created with the "createGraphics()" function. I have a demonstration of the bug(?) up on OpenProcessing: <a rel="nofollow" href="https://www.openprocessing.org/sketch/396854">createGraphics</a></p>

<p>Might be an issue with my hardware since I'm using a surface pro 4 which has a high density display. If that's the case, is there a way to fix it? Thought it might be "devicePixelScaling()", but that's not available in p5js. Are people with regular density displays seeing the same behavior, or does it seem to work fine for you?</p>

<p>Thanks,</p>

<p>Albert</p>
]]></description>
   </item>
   <item>
      <title>How to clear a Graphics object?</title>
      <link>https://forum.processing.org/two/discussion/19806/how-to-clear-a-graphics-object</link>
      <pubDate>Sun, 18 Dec 2016 14:16:18 +0000</pubDate>
      <dc:creator>CosmicChild</dc:creator>
      <guid isPermaLink="false">19806@/two/discussions</guid>
      <description><![CDATA[<p>I'm using an object created with createGraphics to draw my sketch, separate from the canvas.</p>

<p>The problem is that I need to clear this object for every loop, reseting all values to 0 including alpha.
I cannot seem to find a way to do this.</p>

<p>Background() will reset colors to 0, but not alpha.</p>

<p>loadPixels() updatePixels() get() set() work with image objects but not with graphic objects.</p>

<p>clear() works only with canvas.</p>

<p>I've tried copy/pasting a transparent image or graphics but this doesn't work either.</p>

<p>Any ideas?</p>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Image transparency (alpha) via tint() is very slow.</title>
      <link>https://forum.processing.org/two/discussion/19438/image-transparency-alpha-via-tint-is-very-slow</link>
      <pubDate>Wed, 30 Nov 2016 23:45:59 +0000</pubDate>
      <dc:creator>brig</dc:creator>
      <guid isPermaLink="false">19438@/two/discussions</guid>
      <description><![CDATA[<p>Hi. I'm trying to adjust the alpha channel for images loaded using loadImage(). However, when I do so, FPS drops from 60FPS to 3FPS with just 4 images on screen.</p>

<p>Code I'm using is approximately: 
var path = "assets/video_placeholder.jpg"
var imgHandler = loadImage(path);
tint(255, 126);
image(imgHandler, 200, 200, 450, 450);</p>

<p>Is this expected? Other than using DOM to load images and applying CSS to control opacity, is there any better way to give transparency to images?</p>

<p>thx!</p>
]]></description>
   </item>
   <item>
      <title>How to Dynamically set PGraphics object size? (or workaround)</title>
      <link>https://forum.processing.org/two/discussion/18976/how-to-dynamically-set-pgraphics-object-size-or-workaround</link>
      <pubDate>Thu, 10 Nov 2016 23:06:14 +0000</pubDate>
      <dc:creator>JackWitherell</dc:creator>
      <guid isPermaLink="false">18976@/two/discussions</guid>
      <description><![CDATA[<p>Hey guys.</p>

<p>New to the forum, I've been working on a project for a few days now and I'm having trouble trying to make GUI. I want to only have to render it once, as to maintain efficiency, and I'm using built in draw functions. I thought that the best way to do this would be to use a PGraphics object like so...</p>

<p><code>//Window
int scWidth=800;
int scHeight=480;
int lat=4;
int dpb=12;
color [] colors = {#000000,#666666,#999999,#FFFFFF};
public class Location {
   int X;
   int Y;
   public Location(int tt, int tg) {
      X=tt;
      Y=tg;
   }
   public int getX( ) {
      return X;
   }
   public int getY( ) {
      return Y;
   }
}
Location cartesian = new Location( 3, 3 );
PGraphics drawGUI;
public class GridGUI{
  Location location;
  PGraphics GUI;
  public GridGUI(Location a, color [] colors){
    location=a;
    GUI=createGraphics(30,30);
    //rendering of GUI goes here. Tiny example, I want to create the size of the gui in here.
  }
  public void showGUI(){
    //wip, will just be simply be something like image(GUI, location.getX(), location.getY());
  }
  public void getColor(){
    //wip... its complicated... :)
  }
}
GridGUI defaultPalette= new GridGUI(cartesian, colors);
void settings(){
  size(scWidth,scHeight);
}
void setup(){
  surface.setResizable(true);
  background(220);
}
void draw(){
  stroke(0);
  fill(255);
}</code></p>

<p>I've obviously taken a lot of the code out so let me know if you need the full thing (you shouldn't need it)</p>

<p>For whatever reason Processing doesn't seem to let you create a PGraphics object in the scope of a class. It gives a nullptr exception on the createGraphics line during definition of the class. Removing the line where it generates the initialization of the object does nothing.</p>

<p>Basically what I'd like to do is create a graphics object outside of setup so I can have a constructor in a class with its own PGraphics buffer.</p>

<p>My current workaround is to make a large PGraphics object and set its boundaries in setup() and to create a PImage in the class instead.</p>

<p><code>drawGUI=createGraphics(3840,2160);</code>
[not expecting anyone to make a GUI frame over 4k resolution]</p>

<p>anyways, each instance of the class would then have a PImage object instead that it copies from the 4k buffer after it's drawn to.</p>

<p>Is there any way to define a PGraphics object in a class or function other than setup()? I can't seem to do it without a nullptr exception. I'd report this as a bug if it's not intended because it's a much desired feature for several other parts of the program I'm working on but if it's intended to have the size and context of each PGraphics object defined in setup then I'd be open to other workarounds.</p>
]]></description>
   </item>
   <item>
      <title>processing.js performance on different devices</title>
      <link>https://forum.processing.org/two/discussion/18498/processing-js-performance-on-different-devices</link>
      <pubDate>Tue, 11 Oct 2016 10:49:29 +0000</pubDate>
      <dc:creator>michelb</dc:creator>
      <guid isPermaLink="false">18498@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I am quite new to processing and I have been playing with it the last couple of weeks. I am working on a tiny project. The idea is to make a simple sequential animation. it is basically a few images, shapes, and text that appear in sequence. I have written the pde code (see below) and all works fine using the IDE. Now I want to port this on a website using processing.js (simply using processing.min.js and a canvas element).</p>

<p>It all works fine in the browser (chrome), but here is the problem the animation looks fine on a desktop, but on a tablet (a lenovo quad core) or Smasung Galaxy S3, the animation is all jerky (looks like the frame rate is dropping to unacceptable levels).
So my question is: Is this a normal behavior, is my animation simply too complex, or may be I am doing something wrong in my code that is making the animation so heavy for non-desktop devices (although for example I don't think I have too long for loops )?</p>

<p>Also, does anyone has any best practice and tips when trying to set up simple sequential animation like below?</p>

<p>In btw, the images are each around 20-30KB. may be this is also slowing down things !!</p>

<p>I will appreciate any help, thank you.</p>

<p>Michel.</p>

<p>PS: I could not find a place (such as jsfiddle) to put the code along with the images somewhere for people to visualize the animation :(.</p>

<hr />

<pre><code>PImage main,cloud,phone,send,hand,alert;

PFont f;
String message1 = "Hello there, this";
String message2 = "is a message.";
String message3 = "See you.";
int c;

float typeSpeed = 12;
float speedDot = 3.0;

float x;
float y;

float xCloud,yCloud,xPhone,yPhone;

int fr = 24;

float angle,anglePhone,scaleCloud,scaleSend,angleSend,scaleAlert,angleAlert;

float xDot,xDot2,yDot; // Dot2 is used on the right side of the cloud

float cloudWidth = 150;

int ringingDuration,sendDuration,clickDuration,alertDuration,inBtwLoops;

int diam=50;

boolean finishedTextDisplay;

int myFrameCount;

void setup() {  
  size(1000,400);  
  frameRate(fr);  
  /* <a href="/two/profile/pjs">@pjs</a> preload="data/main.png"; */
  /* <a href="/two/profile/pjs">@pjs</a> preload="data/cloud.png"; */
  /* <a href="/two/profile/pjs">@pjs</a> preload="data/phone.png"; */
  /* <a href="/two/profile/pjs">@pjs</a> preload="data/send.png"; */
  /* <a href="/two/profile/pjs">@pjs</a> preload="data/hand.png"; */
  /* <a href="/two/profile/pjs">@pjs</a> preload="data/alert.png"; */

  main = loadImage("data/main.png");
  cloud = loadImage("data/cloud.png"); 
  phone = loadImage("data/phone.png");
  send = loadImage("data/send.png");
  hand = loadImage("data/hand.png");
  alert = loadImage("data/alert.png");  

  f = createFont("Arial",14,true); textFont(f);  
  resetValues();  
}

void draw() {
  myFrameCount++; // each trip thry draw is 1 frame count
  imageMode(CORNERS);image(main,0,0);  
  displayCloud(0); 
  displayPhone(0);
  if (alertDuration == 0 || alertDuration &gt; fr) {displayAlert(0,false);} // displayAlert(scale,tinted) 

  if (finishedTextDisplay == false) {

        x = 195;
        y = 170;
        for (int i = 0; i &lt; message1.length(); i++) { // show letters 1 sec interval 
          //println("for loop");
          if (fr*i/typeSpeed &lt;= myFrameCount) {  
            c = 0; // show
          } 
          else {
            c = 255; // don't show
          }    
          fill(c);
          text(message1.charAt(i),x,y);    
          x += textWidth(message1.charAt(i));
          // println(textWidth(message3.charAt(i)));
        }

        x = 190;
        y = 170 + textAscent()+textDescent();        
        for (int i = 0; i &lt; message2.length(); i++) { // show letters 1 sec interval 
          //println("for loop");
          if (fr*i/typeSpeed &lt;= myFrameCount - ((fr/typeSpeed)*(message1.length()))) {
            c = 0; // show
          } 
          else {
            c = 255; // don't show
          }    
          fill(c);
          text(message2.charAt(i),x,y);    
          x += textWidth(message2.charAt(i)); 
        }

        x = 185;
        y = 170 + 2*(textAscent()+textDescent());

        for (int i = 0; i &lt; message3.length(); i++) { // show letters 1 sec interval 
          // println("for loop");
          if (fr*i/typeSpeed &lt;= myFrameCount - ((fr/typeSpeed)*(message1.length()+message2.length()))) {
            c = 0; // show
            if (i == message3.length()-1) { // last character shown --&gt; click button
                      finishedTextDisplay = true;
            }
          } 
          else {
            c = 255; // don't show
          }    
          fill(c);
          text(message3.charAt(i),x,y);    
          x += textWidth(message3.charAt(i)); 
        } // end for loop 
    } // if finishedTextDisplay

    else // characters are all dislayed 
    {
      // display strings
      // println("NO for loop");
      fill(0);
      x = 195;y = 170; text(message1,x,y);    
      x = 190;y = 170+textAscent()+textDescent(); text(message2,x,y);
      x = 185;y = 170+2*(textAscent()+textDescent()); text(message3,x,y);

      // display hand
      if (clickDuration &lt;= 0.5*fr) {
        // display bigger send button
        /*
        if (angle &lt;= PI) { 
          scaleSend = map(sin(angleSend), 0, 1, 0, 0.15); 
          displaySend(scaleSend);
          angleSend += 5*PI/100;       
        }
        */
        if (clickDuration &lt; 0.5*0.5*fr ) {scaleSend = clickDuration;}
        else {scaleSend = 0.5*fr - clickDuration;}
        // println(scaleSend);        
        scaleSend = map(scaleSend, 0, 0.5*0.5*fr, 0, 0.15); 
        displaySend(scaleSend);
        clickDuration++;

        tint(255,180);imageMode(CORNERS);image(hand,265,205);tint(255,255); 


      }
      else 
      {
                      displaySend(0);
                      // move on with simualtion
                      if (xDot &lt; xCloud - cloudWidth/2) { // not reached cloud yet
                        displayDot();
                        // println("dot");
                      }
                      else 
                      { // dot reached the cloud --&gt; no dot and grow cloud
                        // put the dot on the other side of the cloud
                        if (angle &lt;= PI) { // once inflate and deflates once, cloud stops moving
                          // println(scaleCloud);
                          scaleCloud = map(sin(angle), 0, 1, 0, 0.15); 
                          displayCloud(scaleCloud);
                          angle += 5*PI/100;
                          // println("cloud");
                        }                  
                        else 
                        { // dot on the other side                    
                          if (xDot2 &lt; xCloud + 165) { // not reached the arrow
                            displayDot2();
                            // println("dot 2");
                        }
                        else { // dot reached the phone --&gt; no dot , phone shakes
                             if (ringingDuration &lt; 4.5*fr) {
                               // println("ringing");
                               // displayPhone(random(-0.06,0.06)); // phone shakes
                               displayPhone(map(sin(anglePhone), -1, 1, -(PI/50), +(PI/50)));
                               anglePhone += (PI/2);

                               // rings
                               if ( (0 &lt; ringingDuration &amp;&amp; ringingDuration &lt;= 0.5*fr) || (ringingDuration &gt; 2.5*fr &amp;&amp; ringingDuration &lt;= 3*fr)) {                     
                                 displayRing(0);
                               }
                               if ( (0.5*fr &lt; ringingDuration &amp;&amp; ringingDuration &lt;= fr) || (ringingDuration &gt; 3*fr &amp;&amp; ringingDuration &lt;= 3.5*fr) ) {
                                 displayRing(0);
                                 displayRing(20);
                               }                         
                               if ( (fr &lt; ringingDuration &amp;&amp; ringingDuration &lt;= 1.5*fr) || (ringingDuration &gt; 3.5*fr &amp;&amp; ringingDuration &lt;= 4*fr)) {  
                                 displayRing(0);
                                 displayRing(20);
                                 displayRing(40);
                               }
                               if ( (ringingDuration &gt; 1.5*fr &amp;&amp; ringingDuration &lt;= 2.0*fr) || (ringingDuration &gt; 4*fr &amp;&amp; ringingDuration &lt;= 4.5*fr)) {  
                                 displayRing(0);
                                 displayRing(20);
                                 displayRing(40);
                                 // displayRing(60);
                               }
                               ringingDuration++;
                             }
                             else {
                                if (alertDuration &lt;= fr) {
                                    // alert beeps 2 times  
                                    if (alertDuration &gt;= 0 &amp;&amp; alertDuration &lt; fr/4 ) {scaleAlert = alertDuration;}
                                    if (alertDuration &gt;= fr/4 &amp;&amp; alertDuration &lt; 2*fr/4) {scaleAlert = 2*fr/4 - alertDuration;}
                                    if (alertDuration &gt;= 2*fr/4 &amp;&amp; alertDuration &lt; 3*fr/4) {scaleAlert = alertDuration - 2*fr/4;}
                                    if (alertDuration &gt;= 3*fr/4 &amp;&amp; alertDuration &lt;= fr) {scaleAlert = fr - alertDuration;}
                                    // else {scaleAlert = 0.5*fr - alertDuration;}
                                    // println(scaleAlert);        
                                    scaleAlert = map(scaleAlert, 0, 0.5*0.5*fr, 0, 0.15); 
                                    displayAlert(scaleAlert,true);
                                    alertDuration=alertDuration+1;                                
                                }    
                                else 
                                {
                                  // alertDuration = 0;
                                  // wait for a second a so before starting the animation again
                                  if (inBtwLoops &lt;= 2*fr) {
                                    inBtwLoops ++;
                                  }
                                  else {
                                    resetValues();
                                  }  
                                }
                             }
                          }  
                        }
                      }
      }

    }

}

void displayAlert(float scaleAlert, boolean tinted){
    pushMatrix();
    translate(222,386);
    imageMode(CENTER);
    scale(1+scaleAlert);
    if (tinted) {tint(217, 83, 79);} 
    image(alert,0,0); 
    tint(255,255);
    popMatrix();
}

void resetValues(){  
  angle=anglePhone=scaleCloud=scaleSend=angleSend=scaleAlert=angleAlert=0;  
  xCloud = width/2+85;
  yCloud = height/2-10;  
  xDot = xCloud - 170; 
  yDot = height/2;  
  xDot2 = xCloud + cloudWidth/2;  
  xPhone = xDot2 + 170 + 50;
  yPhone = height/2;  
  ringingDuration = sendDuration = clickDuration = alertDuration = inBtwLoops = 0;  
  finishedTextDisplay = false; 
  myFrameCount = 0;
}

void displayRing(int diamExtra){
  int alpha = round(map(diamExtra,0,40,255,50));
  strokeWeight(5.5);
  strokeCap(ROUND); 
  noFill();
  stroke(24, 188, 156, alpha);
  // arc(xPhone+10, yPhone - 69, diam+diamExtra, diam+diamExtra, -HALF_PI,0);
  arc(xPhone+10, yPhone - 69, diam+diamExtra, diam+diamExtra, -HALF_PI+(HALF_PI/7),0-(HALF_PI/7));
}

void displayCloud(float scaleCloud){
    pushMatrix();
    translate(xCloud,yCloud);
    imageMode(CENTER);
    scale(1+scaleCloud);
    image(cloud,0,0,150,150);
    popMatrix();
}

void displayPhone(float anglePhone){
    pushMatrix();
    translate(xPhone,yPhone);
    rotate(anglePhone);
    imageMode(CENTER);
    // scale(1+scaleCloud);
    image(phone,0,0,55,161);
    popMatrix();
}

void displayDot(){
    xDot+=speedDot;
    fill(21, 158, 130);
    stroke(21, 158, 130);
    ellipse(xDot,yDot,15,15);
}
void displayDot2(){
    xDot2+=speedDot;
    fill(21, 158, 130);
    stroke(21, 158, 130);
    ellipse(xDot2,yDot,15,15);
}

void displaySend(float scaleSend){
    pushMatrix();
    translate(275,215);
    imageMode(CENTER);
    scale(1+scaleSend);
    image(send,0,0,48,26);
    popMatrix();  
  /*
    pushMatrix();
    imageMode(CORNERS);
    tint(255,alpha);  // alpha=0: tranparent  
    image(send,250,205);
    tint(255,255); // 255: normal
    popMatrix();
  */  
} 
</code></pre>

<hr />
]]></description>
   </item>
   <item>
      <title>How to copy PImage into PImage with rotation and alpha</title>
      <link>https://forum.processing.org/two/discussion/18077/how-to-copy-pimage-into-pimage-with-rotation-and-alpha</link>
      <pubDate>Mon, 05 Sep 2016 12:00:57 +0000</pubDate>
      <dc:creator>fredciel</dc:creator>
      <guid isPermaLink="false">18077@/two/discussions</guid>
      <description><![CDATA[<p>Hi , I want to use processing to generate big images (with alpha) for print (16000x16000 pixels). In that process, I use one small PImage (with alpha channel) as a pencil. I need to copy millions of times this small PImage at different places, rotations, sizes, colors and blends in a big PImage with a good anti-aliasing.  I don't see any way to do that ... Any idea ?  thanks</p>
]]></description>
   </item>
   <item>
      <title>toxiclibs - toxiclibsSupport, PGraphics, setGraphics() - trying to use off screen buffer</title>
      <link>https://forum.processing.org/two/discussion/17857/toxiclibs-toxiclibssupport-pgraphics-setgraphics-trying-to-use-off-screen-buffer</link>
      <pubDate>Tue, 16 Aug 2016 12:39:27 +0000</pubDate>
      <dc:creator>B2000</dc:creator>
      <guid isPermaLink="false">17857@/two/discussions</guid>
      <description><![CDATA[<p>hello,</p>

<p>I am fairly new to Processing and in the early stages of learning Java.<br />
Thank you for this excellent library - it was crucial to the first major piece of software that I have written (used for an installation a couple of weeks ago).<br />
What I am trying to do is use an instance of PGraphics (called 'frame' in the code below) to draw to the off screen buffer and then save as a .png - for many reasons, but in this case to use transparency (drawing lines and shapes(triangles) on a transparent background).<br />
As soon as I either specify 'frame' in the constructor: "gfx = new ToxiclibsSupport (this, frame);" or use setGraphics(): "gfx.setGraphics(frame);" I get a draft rendering of the drawing - just black lines on a white background, no images, no shapes - for both the off screen buffer and the display.<br />
I have tried everything to the limits of my current knowledge and abilities including using the P2D renderer (specified in size() and in the createGraphics () for 'frame'). As soon as I remove 'frame' from the ToxiclibsSupport constructor or comment out setGraphics(), everything returns to normal, so clearly it is the addition of this PGraphics instance. I have included a very simplified example of my code.</p>

<p>Thank you for any help,</p>

<pre><code>ToxiclibsSupport gfx;
PGraphics frame;


void setup () {

  frame = createGraphics (width, height); 
  gfx = new ToxiclibsSupport(this, frame);
  //gfx.setGraphics(frame);

}


void draw () {

  frame.save (imageFileName + nf (frameCount++, 3) + ".png");

}



used in a function:


void drawTriangles () {

  frame.beginDraw();

  for (int i = 0 ; i &lt; triangleList.size () ; i++ ) {
    if (triangleList.get(i).on) {
      noStroke();
      colorSelect(i);
      gfx.polygon2D(triangleList.get(i).triangle);
    } else {
      noFill();
      stroke(white);
      gfx.polygon2D(triangleList.get(i).triangle);
    }
  }

  frame.endDraw();
  image(frame,0,0);  
}   
</code></pre>
]]></description>
   </item>
   <item>
      <title>Clearing text from sketch without clearing background</title>
      <link>https://forum.processing.org/two/discussion/17882/clearing-text-from-sketch-without-clearing-background</link>
      <pubDate>Wed, 17 Aug 2016 20:37:36 +0000</pubDate>
      <dc:creator>Dane</dc:creator>
      <guid isPermaLink="false">17882@/two/discussions</guid>
      <description><![CDATA[<p>Hey guys,</p>

<p>There is probably a really easy solution to this, but I have a sketch that I am drawing on using peril noise and a flow field of Pvectors. Each frame, lines are drawn onto the canvas. That all works fine. I am wanting to draw text on the screen also. I want to start the textSize at 0 and increment it every frame to give it the effect that it is coming at you. The text is being drawn to the screen every frame and the textSize is incrementing. However, there is a NEW text element drawn to the screen every frame. I would like the old text elements to be deleted after a new one has been drawn.</p>

<p>Is there another function other than clear() i could use to accomplish this?</p>

<p>Thanks,
Dane</p>
]]></description>
   </item>
   <item>
      <title>Shifted Mouse Coordinates</title>
      <link>https://forum.processing.org/two/discussion/17847/shifted-mouse-coordinates</link>
      <pubDate>Mon, 15 Aug 2016 06:48:07 +0000</pubDate>
      <dc:creator>Zac</dc:creator>
      <guid isPermaLink="false">17847@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to make a paint-style program with a canvas in the middle. However the mouse coordinates are shifted in the PGraphics when I click.</p>

<p>Can someone please have a look at this break down of the code and tell me where I am going wrong?</p>

<p>`PGraphics canvas;
int rect[] = new int[1];
int rect2[] = new int[1];</p>

<p>void setup() {
  size(1000, 750);
  canvas = createGraphics(500, 500);
  imageMode(CORNERS);
  rect[0] = 100;
  rect2[0] = 100;
}</p>

<p>void draw() {
  canvas.beginDraw();
  canvas.background(100);
  canvas.line(10, 0, 1100, 1100);
  for(int i = 0; i &lt; rect.length; i++)
  canvas.rect(rect[i], rect2[i], 10, 10);
  canvas.endDraw();
  image(canvas, 50, 50, 500, 500); 
}</p>

<p>void mouseClicked()
{
  rect = append(rect, mouseX);
  rect2 = append(rect2, mouseY);
  println(mouseX);
}
`</p>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>Using PGraphics for creating textures</title>
      <link>https://forum.processing.org/two/discussion/17698/using-pgraphics-for-creating-textures</link>
      <pubDate>Fri, 29 Jul 2016 22:16:41 +0000</pubDate>
      <dc:creator>cadavara</dc:creator>
      <guid isPermaLink="false">17698@/two/discussions</guid>
      <description><![CDATA[<p>I asked this before, but I haven't gotten much further. This time I took a more basic approach, but I just don't get it. How can you create a texture, using PGraphics?</p>

<p>The stupid() function works but createTexture() doesn't.</p>

<pre><code>PGraphics pg;
PImage img;

float size = 200;

void setup() {
  background(255);
  size(800, 600, P3D);
  textureMode(NORMAL);

  pg = createGraphics(100, 100, P3D);
  createTexture();
}

void draw() {
  background(255);  
  translate(width/2, height/2, 0);
  beginShape();
  texture(pg.get());
  fill(0);
  vertex(-size, -size, 0, 0, 0);
  vertex(size, -size, 0, 1, 0);
  vertex(size, size, 0, 1, 1);
  vertex(-size, size, 0, 0, 1);
  endShape();
}

void stupid(){
  pg.beginDraw();
  pg.background(255);
  pg.ellipse(pg.width/2, pg.height/2, 50, 50);
  pg.endDraw();
}

void createTexture() {
 pg.beginDraw();
 pg.background(255);
 pg.stroke(0);
 pg.noFill();
 drawCircle(width/2, height/2, 50);
 pg.endDraw();
}

void drawCircle(float x, float y, float d) {
  pg.ellipse(x, y, d, d);
  if (d &gt; 2) {
    drawCircle(x+d/2, y, d/2);
    drawCircle(x-d/2, y, d/2);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>applying a mask flips or rotate the image!</title>
      <link>https://forum.processing.org/two/discussion/14885/applying-a-mask-flips-or-rotate-the-image</link>
      <pubDate>Sat, 13 Feb 2016 02:23:26 +0000</pubDate>
      <dc:creator>gperez</dc:creator>
      <guid isPermaLink="false">14885@/two/discussions</guid>
      <description><![CDATA[<p>Hi. I'm developing in Eclipse. With a kinect (depth sensor).</p>

<p>Currently, I'm trying to mask images. But for some reason as soon I apply a filter, the image flips (or rotates 180º). And I just can't get them back to the current position.</p>

<p>This happens not only with mask() method, but also with other filters (with filter method itself or the blend() one)</p>

<p>I'm giving you an example code:</p>

<p>PGraphics mappingZone;<br />
..
mappingZone = applet.createGraphics(kinect.width, kinect.height, PApplet.P2D);<br />
..
filteredImg = applet.createImage(kinect.width, kinect.height, PApplet.P2D);
...</p>

<pre><code>  mappingZone.beginDraw();
  mappingZone.background(0);            
  mappingZone.image(mappingTexture, 0, 0);
  mappingZone.mask(filteredImg);    
  mappingZone.endDraw();        

  applet.image(mappingZone, 0, 0, applet.width, applet.height);
</code></pre>

<p>I tried several things to flip the image to the correct position, like: 
<code>mappingZone.scale(-1, -1);</code></p>

<p>But nothing works. However, applying a second filter usually return the image to the correct position. Any clue?</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/901/KLXBH3CSZDSK.jpg" alt="_pic-7016" title="_pic-7016" /></p>
]]></description>
   </item>
   <item>
      <title>How should I use PGraphics with retina / HD displays?</title>
      <link>https://forum.processing.org/two/discussion/16083/how-should-i-use-pgraphics-with-retina-hd-displays</link>
      <pubDate>Mon, 18 Apr 2016 19:11:11 +0000</pubDate>
      <dc:creator>helveticat</dc:creator>
      <guid isPermaLink="false">16083@/two/discussions</guid>
      <description><![CDATA[<p>My client has a new Mac that uses the "retina" display. To support this, I added the following line in <code>setup()</code>:</p>

<p><code>pixelDensity(displayDensity());</code></p>

<p>However, my code uses PGraphics objects defined as follows:</p>

<p><code>layers[0] = createGraphics( width, height);</code></p>

<p>(and so on for other layers).</p>

<p>I suspect the pixel density is not being inherited by the PGraphics objects in this instance. It's tough for me to debug this as I don't have access to an HD display so I am sending code back and forth to the client. My existing code runs fine on his old Mac (and every machine I have access to) but the layers are displaying at double size on the newer one.</p>

<p>Could someone provide some guidance to using Processing with displays where <code>displayDensity() != 1</code>?</p>

<p>BTW I tried explicitly using P2D in <code>size()</code> and <code>createGraphics()</code> as per a suggestion on another site but he gets an OpenGL error in that case (again, it works fine for me, but then so did my original code).</p>
]]></description>
   </item>
   <item>
      <title>How to make two different sketches run on one .pde, one on top of the other?</title>
      <link>https://forum.processing.org/two/discussion/16570/how-to-make-two-different-sketches-run-on-one-pde-one-on-top-of-the-other</link>
      <pubDate>Thu, 12 May 2016 18:06:15 +0000</pubDate>
      <dc:creator>ForeverNight</dc:creator>
      <guid isPermaLink="false">16570@/two/discussions</guid>
      <description><![CDATA[<p>I'm new to processing, and I've created two different pde files - a game, with a clear background, and an animated background. How could I get my background to play behind the game I have? Thanks</p>
]]></description>
   </item>
   <item>
      <title>Scaling/flipping PGraphics</title>
      <link>https://forum.processing.org/two/discussion/16382/scaling-flipping-pgraphics</link>
      <pubDate>Mon, 02 May 2016 07:54:15 +0000</pubDate>
      <dc:creator>G_D</dc:creator>
      <guid isPermaLink="false">16382@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to get two copies of a PGraphics - one displayed normally, the other flipped. I then want to convert my PGraphics to a PImage. I've got the following, but the second image isn't flipped...</p>

<pre><code>  PGraphics g;
  g = createGraphics(width, height, P3D);
  g.beginDraw();
  g.image(srcImg, 0, 0);
  g.endDraw();
  PImage output = g.get();

  PGraphics g2; 
  g2 = createGraphics(width, height, P3D);
  g2.beginDraw();
  g2.image(srcImg, 0, 0);
  g2.scale(-1,1);
  g2.endDraw();
  PImage output2 = g2.get();
</code></pre>
]]></description>
   </item>
   <item>
      <title>Can't seem to get a proscene 3D drawing inside a 2D canvas - python mode</title>
      <link>https://forum.processing.org/two/discussion/16220/can-t-seem-to-get-a-proscene-3d-drawing-inside-a-2d-canvas-python-mode</link>
      <pubDate>Sun, 24 Apr 2016 09:37:06 +0000</pubDate>
      <dc:creator>thepizzagui</dc:creator>
      <guid isPermaLink="false">16220@/two/discussions</guid>
      <description><![CDATA[<p>Hey guys,</p>

<p>I'm pretty inexperienced when it comes to python and it's probably the reason why I'm having trouble  but, the Issue i'm having is placing a 3D renderer (proscene) into a 2D "Canvas". The idea is to have the 3D window running along side a 2D sketch. Here's the code from my main.py:</p>

<pre><code>add_library('proscene')
from PlaneConstructor import ThreeDimensionalPlane
from PrismConstructor import RectangularPrism
from ReadFile import readFile

def setUpScene():
    scene.setGridVisualHint(False)
    scene.setAxesVisualHint(False)

    if scene.is3D():
        scene.setCameraType(Camera.Type.ORTHOGRAPHIC)

    scene.setRadius(150)
    scene.showAll()   

def setup():
    global scene, offset
    size(1200,1200,P3D)
    scene = Scene(this)

    listOfPlanes = readFile(fileName)    
    createSections(listOfPlanes)

    setUpScene()

    beamLength = calcBeamLength(listOfPlanes)
    offset = -1 * (float(beamLength) / 2)

def draw():
    background(140)
    drawSections(offset)
</code></pre>

<p>From what I've already read online, setup is where all the magic happens and I've tried implementing the solution from <a rel="nofollow" href="https://forum.processing.org/two/discussion/1297/3d-window-in-2d-sketch">3D window in 2D sketch</a>, however when running the code with the changes, the 3D image stays as 2D and I can't draw anything outside the 3D window.</p>

<p>What are some other ways of implementing this?</p>
]]></description>
   </item>
   <item>
      <title>PGraphics Memory Leaks</title>
      <link>https://forum.processing.org/two/discussion/16071/pgraphics-memory-leaks</link>
      <pubDate>Sun, 17 Apr 2016 21:16:45 +0000</pubDate>
      <dc:creator>MadScience2728</dc:creator>
      <guid isPermaLink="false">16071@/two/discussions</guid>
      <description><![CDATA[<p>Greetings,</p>

<p>I am writing a GUI from my artificial neural networks and Darwinist machine learning project, which involves using PGraphics as the "screens". This is to allow me flexibly in how I manipulate the scene. But there has been a memory leak.</p>

<p>I'm assuming this is a bug as I can't find any reason for this to happen, and it has been plaguing me for a while now. I simply cannot find a solution, I tried. The issue reports have nothing open, and the same issues that were posted are now closed, solved, and apparently fixed.
I wanted to come here and see what the community knows about it, and their potential solutions, otherwise I will file this as a core issue, and it will have to be re-opened.</p>

<p>For some reason even the most basic PGraphics object will cause a memory leak, as the below code can demonstrate. I have tried g.removeCache(); however this simply caused huge amounts of "leakage" when that operation was performed strangely enough. It <em>is</em> turning the object null however as you can see in the code. Sadly that was the only solution I could find. Apparently this did not happen in 1.5.x</p>

<p>Tested on Linux, and Windows, with graphics card and without, and on a separate computer as well. The leak persist.</p>

<p>Thank-you</p>

<pre><code>void setup()
{
  frameRate(60);
  size(640, 480, P3D);
  screen = createGraphics(width/2, height/2, P3D);
}

void draw()
{
  background(#0C1018);
  screen.beginDraw();
  screen.background(#00FFFF);
  screen.endDraw();
  image(screen, 0, 0);
  /*println(g.getCache(screen)); //prints processing.opengl.Texture@whatever
  g.removeCache(screen);
  println(g.getCache(screen)); //prints null
  println();*/
}
</code></pre>

<p>OS: Ubuntu 14.04 LTS
OS type: 64-bit
Processor: AMD A8-5500 APU with Radeon(tm) HD Graphics × 4 
Graphics: Gallium 0.4 on AMD CAICOS</p>
]]></description>
   </item>
   <item>
      <title>PGraphics saves messed up images after creating a new PGraphics object in a different size</title>
      <link>https://forum.processing.org/two/discussion/15878/pgraphics-saves-messed-up-images-after-creating-a-new-pgraphics-object-in-a-different-size</link>
      <pubDate>Wed, 06 Apr 2016 10:24:29 +0000</pubDate>
      <dc:creator>bckmnn</dc:creator>
      <guid isPermaLink="false">15878@/two/discussions</guid>
      <description><![CDATA[<p>Hi there,
below i attached a small program that generates PNGs. If i change the size of the new PGraphics objects the saved PNGs start to look messed up.</p>

<p>To reproduce the issue run the code from the bottom. Conversion will start an you will get pngs like this:</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/231/JU8OTVD7LAY6.png" alt="Bildschirmfoto 2016-04-06 um 12.12.56" title="Bildschirmfoto 2016-04-06 um 12.12.56" /></p>

<p>if you do a mouse click on the canvas, the size of the pngs that should be generated is changed and a few new items are added. The results look like in the screenshot below, some of the images are blank, some are distorted and they still have the old size.</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/010/KCHMBM2X2J5U.png" alt="Bildschirmfoto 2016-04-06 um 12.13.11" title="Bildschirmfoto 2016-04-06 um 12.13.11" /></p>

<p>Is there a way to avoid this behavior? is this a bug in processing? am i missing something?</p>

<p>Any input appreciated!</p>

<pre><code>PGraphics png;
ArrayList&lt;String&gt; cue = new ArrayList&lt;String&gt;();
boolean conversion = false;
int pngSize = 64;

void setup() {
  size(400, 400);
  println("creating 64px letters");
  cue.add("A");
  cue.add("B");
  cue.add("C");
  conversion = true;
}

public void mousePressed(){
  println("creating 128px letters");
  pngSize = 128;
  cue.add("A");
  cue.add("B");
  cue.add("C");
  cue.add("D");
  cue.add("E");
  cue.add("F");
  conversion = true;
}

void saveNextInCue(){
  String letter = cue.remove(0);
  println("pngSize value is "+pngSize);
  png = createGraphics( pngSize, pngSize);
  png.beginDraw();
  png.textSize(30);
  png.text(letter,30,30);
  png.fill(random(255),0,255);
  png.rect(0,0,10,10);
  png.endDraw();
  png.save(sketchPath(letter+".png"));
}

void draw() {
  int bg = color(255,0,0);
  if (!conversion){
    bg = color(0,255,0);
  }
  background(bg);
  if( conversion == true){
    saveNextInCue();
    if(cue.size() == 0){
      conversion = false;
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to fill a text with an image ?</title>
      <link>https://forum.processing.org/two/discussion/15701/how-to-fill-a-text-with-an-image</link>
      <pubDate>Sat, 26 Mar 2016 21:06:36 +0000</pubDate>
      <dc:creator>Furrane</dc:creator>
      <guid isPermaLink="false">15701@/two/discussions</guid>
      <description><![CDATA[<p>First let me show you what i'm trying to achieve : something similar to <a rel="nofollow" href="https://i.ytimg.com/vi/4ildDqCrT4c/maxresdefault.jpg">this</a>.</p>

<p>So that's rendering text using an image as "texture".</p>

<p>I don't know if there is some obvious way to do this I'm missing. I though it might be doable by changing the color of every pixel of the text with corresponding pixel of the source image.</p>

<p>Problem is, although I can access the image's pixel array I have no clue how to do it for the text.</p>

<p>Thanks to anyone that can help me =)</p>
]]></description>
   </item>
   <item>
      <title>Unexpected Results of  the function createGraphics</title>
      <link>https://forum.processing.org/two/discussion/15505/unexpected-results-of-the-function-creategraphics</link>
      <pubDate>Tue, 15 Mar 2016 13:36:57 +0000</pubDate>
      <dc:creator>DarkFlame</dc:creator>
      <guid isPermaLink="false">15505@/two/discussions</guid>
      <description><![CDATA[<p>I am working on a small demo about creating text clouds, and got stuck in the createGraphics().</p>

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

<pre><code>    PImage pic;
    PFont font;
    PGraphics pg;
    PGraphics manyC,finalSave;
    String[] words={"hello","world","hello","world","hello","world","hello","world","hello","world","hello","world"};
    PGraphics[] wordPic;


    void setup(){
      size(1800,1800);
      pic=loadImage("1.png");
      pic.filter(THRESHOLD,0.9);
      pic.resize(1800,0);
      pic.save("D://sample.png");


      font=createFont("微软雅黑",240);
      textFont(font);
      float strHt=textAscent()+textDescent();
      manyC      = createGraphics(pic.width,pic.height);
      finalSave  = createGraphics(pic.width,pic.height);
      //finalSave.smooth();

      wordPic=new PGraphics[words.length];
      int[] w =  new int[16];
      w[0] = 400;
      w[1] = 400;
      w[2] = 400;
      w[3] = 400;
      w[4] = 400;
      w[5] = 400;
      w[6] = 400;
      w[7] = 400;
      w[8] = 400;
      w[9] = 400;
      w[10] = 400;
      w[11] = 400;
      w[12] = 400;
      w[13] = 400;

      for(int i=0;i&lt;wordPic.length;i++){

        int wid = (int)textWidth(words[i]);
        println(wid);
        wordPic[i] = createGraphics(w[i],400);
        wordPic[i].beginDraw();
        wordPic[i].background(255);
        wordPic[i].textFont(font);
        wordPic[i].textAlign(LEFT,TOP);
        wordPic[i].fill(color(0,0,0));
        wordPic[i].text(words[i],0,0);
        wordPic[i].endDraw();

        if(wordPic[i].width&gt;=width){
          wordPic[i].resize(width,0);
        }
      }


      for(int i=0; i&lt;wordPic.length;i++){
        wordPic[i].save("D://wordpic"+i+".jpg");
      }
      println("over");
    }
</code></pre>

<p>the output is like that:
<img src="https://forum.processing.org/two/uploads/imageupload/372/PCBXICRIX3M7.png" alt="Image 1" title="Image 1" /></p>

<p>so far so good. However, if I adjust the value of w[], which changes the width value when calling the function createGraphics(), the unexpected result comes out!</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/010/1RGUS4LGHNDE.png" alt="Image 2" title="Image 2" />
<img src="https://forum.processing.org/two/uploads/imageupload/011/GI18MPB5I1TY.png" alt="Image 3" title="Image 3" /></p>

<p>All I did was changing some values of w[], like 800,1200.</p>

<p>well, I'm confused.</p>

<p>I'm trying to adjust the graphics width, like this: 
wordPic[i] = createGraphics((int)textWidth(words[i]),(int)strHt);
so I can handle them as small objects of the text Cloud.</p>

<p>And clearly, the results are not good enough.</p>

<p>So, is there anyone could help me about this problem?
tell me why this will happen, or how can I leave this problem alone and go ahead for my work?</p>
]]></description>
   </item>
   <item>
      <title>Suggested Workflow - PGraphics and Class instances</title>
      <link>https://forum.processing.org/two/discussion/15305/suggested-workflow-pgraphics-and-class-instances</link>
      <pubDate>Sat, 05 Mar 2016 20:10:07 +0000</pubDate>
      <dc:creator>rumlac</dc:creator>
      <guid isPermaLink="false">15305@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I have a sketch that uses instances of a class where the appearance of each iteration is generative(different). I am using an arraylist as the  instances of the class have a lifespan and an unknown number of instances are used.</p>

<p>My question is: Can/how I generate the each  instances and then instead of displaying it and having to recalculate the shape as it moves around with every frame, can I generate the shape and then display it as a pGraphic so that the sketch runs faster?</p>

<p>Having tried to implement this my issues are:</p>

<p>Which parts of the code need to be within the pg.beginDraw() and  pg.endDraw(); - i.e is it only things that refer to the shape and colour (so not the parts for moving the object around).</p>

<p>How do I set the initial area for creating the PGraphic:
PGraphics pg = createGraphics(100, 100); - This refers to a 100X100 square from 0, but my instances are being created at random locations.</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 make blurs run independently in custom functions?</title>
      <link>https://forum.processing.org/two/discussion/15068/how-to-make-blurs-run-independently-in-custom-functions</link>
      <pubDate>Tue, 23 Feb 2016 04:56:54 +0000</pubDate>
      <dc:creator>pchin14</dc:creator>
      <guid isPermaLink="false">15068@/two/discussions</guid>
      <description><![CDATA[<p>I'm fairly new to processing, and I am trying to make a space scene in which the stars in the background are blurred, and there is another very blurred large star. and it leaves the planet untouched. My problem is that when I apply a blur, it applies to all parts of the sketch. Is there a way to get around this?</p>

<p>Code:</p>

<pre><code>void setup () {
  size (900, 506);
  background (0, 0, 12);
  drawStars ();
  drawPlanets ();
  drawLargeStar ();
}

void draw () {
}

void drawPlanets () {
  drawPlanet (300, 110, 50);
  pushMatrix ();
  scale (.1);
  drawPlanet (1000, 1000, 100);
  popMatrix ();
}

void drawPlanet (int x, int y, int grey) {
  translate (x, y);
  stroke (0);
  fill (150, 150, 255);
  ellipse (0, 0, 708, 698);
  fill (255);
  ellipse (0, 0, 697, 687);
  fill (grey);
  ellipse (0, 0, 680, 680);
}

void drawStars () {
  for (int num = 0; num &lt; 400; num++) {
    fill (255);
    stroke (random (0, 255), random (0, 255), random (0, 255));
    ellipse (random (0, 900), random (0, 506), random (1, 8), random (1, 8));
  }
  filter(BLUR, 4);
}

void drawLargeStar () {
  fill (255);
  stroke (255);
  ellipse (450, 200, 150, 150);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Masking with an p5.Renderer Object gives an error</title>
      <link>https://forum.processing.org/two/discussion/14657/masking-with-an-p5-renderer-object-gives-an-error</link>
      <pubDate>Thu, 28 Jan 2016 23:39:50 +0000</pubDate>
      <dc:creator>mzeinstra</dc:creator>
      <guid isPermaLink="false">14657@/two/discussions</guid>
      <description><![CDATA[<p>I have a function that grabs an image out of an array an creates a mask for that image (an ellipse on a specific location):</p>

<p><code>function getMask(image, size, w, h) {
  var mask = createGraphics(1280, 720);
  var img = imgList[image];
  mask.fill(100);
  mask.ellipse(w, h, size, size);
  img.mask(mask);
  return img;
}</code></p>

<p>Running this gives me a</p>

<p><code>Uncaught TypeError: Cannot read property 'width' of undefined
p5.Renderer2D._copyHelper @ p5.js:14342
p5.copy @ p5.js:20920
p5.Image.copy @ p5.js:20575
p5.Image.mask @ p5.js:20632 
getMask @ sketch.js:55 // &lt;---- this line is 'img.mask(mask)'
draw @ sketch.js:63
p5.redraw @ p5.js:16075
(anonymous function) @ p5.js:11801
_runIfPreloadsAreDone @ p5.js:11718
_decrementPreload @ p5.js:11725
img.onload @ p5.js:19883</code></p>

<p>Do I need to convert mask to an PImage? How can I get this to work?</p>
]]></description>
   </item>
   <item>
      <title>Trying to have mousePressed 'graffiti' with a news ticker running behind - cannot stop fill.</title>
      <link>https://forum.processing.org/two/discussion/14289/trying-to-have-mousepressed-graffiti-with-a-news-ticker-running-behind-cannot-stop-fill</link>
      <pubDate>Wed, 06 Jan 2016 06:08:48 +0000</pubDate>
      <dc:creator>jondoh</dc:creator>
      <guid isPermaLink="false">14289@/two/discussions</guid>
      <description><![CDATA[<p>Hello.</p>

<p>I am trying to create a news ticker running across the screen but with the function of</p>

<pre><code>if (mousePressed == true) {
    line (mouseX, mouseY, pmouseX, pmouseY);
  }
</code></pre>

<p>I have the ticker working almost correctly OR the graffiti, but not both. I know that it is because the background is being re-drawn over the graffiti, but cannot for the life of me, work out how to adjust my code.</p>

<p>The full code (although I have removed some of the text array) is</p>

<pre><code>String[] tickerText =
{
  "children were some of the greatest victims", "I was a child soldier", 
};


color black;
color white;
int SZ; // initiate variables

PFont font;  // Global font variable
float x;  // horizontal location of headline
int index = 0;


void setup() {
  // sound 
  minim = new Minim(this); //define construction
  sound = minim.loadFile("Children_Playing_Sound.mp3");
  sound.loop(); // is looped
  black = (0); 
  white = (255);
  SZ = 800; //asign variables for colours and screen size

  size(SZ, SZ); // set size of screen
  font = createFont("CourierNewPS-BoldMT-48", 16, true);  
  x = 0; // ticker text enters screen from the right

  background(black);
  // fill(white);
}

void draw() {
  background(black);
  fill(white);

  // Display headline 
  textFont(font, 16);        
  textAlign(LEFT);
  text(tickerText[index], x, 180); 

  x = x - 3; 
  float w = textWidth(tickerText[index]); // takes length of text in tickerText to determine when the text is off-screen
  if (x &lt; -w) {
    x = width; 
    index = (index + 1) % tickerText.length;

    stroke (white);
    strokeWeight (20); // set thickness of 'paint'

    if (mousePressed == true) {
      line (mouseX, mouseY, pmouseX, pmouseY);
    }
  }
}
</code></pre>

<p>I have different code which creates the graffiti effect I want. Very basic mousePressed - draw. It's trying to combine the two that I've come unstuck.</p>

<p>Many thanks to anyone who can help me.</p>
]]></description>
   </item>
   <item>
      <title>How can I control my font?</title>
      <link>https://forum.processing.org/two/discussion/14299/how-can-i-control-my-font</link>
      <pubDate>Wed, 06 Jan 2016 13:39:58 +0000</pubDate>
      <dc:creator>jondoh</dc:creator>
      <guid isPermaLink="false">14299@/two/discussions</guid>
      <description><![CDATA[<p>I needed to learn to use PGraphics to achieve what I wanted in my code - scrolling text across the screen and the ability to "graffiti" it too".</p>

<p>However, since re-writing, my font, size, boldness etc won't change!</p>

<p>In my non-PGraphics code, I used</p>

<p><code>font = createFont("CourierNewPS-BoldMT-48", 44, true);</code></p>

<p>However, in my new code, it doesn't seem to use the values that 'font' has.</p>

<p>My new code is (sorry for the length - I have no idea where the font code should be)</p>

<pre><code>import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;
// import necessary libraries to play sound effect
String[] tickerText =
{
  "children were some of the greatest victims", "I was a child soldier", 
// ....
};

Minim minim;
AudioPlayer sound1; // variable name
AudioPlayer sound2;
PGraphics pg;
PFont font; //declare PFont object called font
PImage background; 
float x; // location of text on x axis
int index = 0;


void setup() {

  size(615, 762, P2D);

  font = createFont("CourierNewPS-BoldMT-48", 44, true);
  background = loadImage ("background_Text_Image.JPG"); // load background image
  minim = new Minim(this); //define construction
  sound1 = minim.loadFile("Children_Playing_Sound.mp3");
  sound1.loop(); // is looped

  pg = createGraphics(width, height, P2D);
  pg.beginDraw();
  pg.background(background); // draw background as imported image
  pg.endDraw(); 

  font = createFont("CourierNewPS-BoldMT-48", 44, true);

  x = 0; // the int x is used as the entry point for the text scrolling in
}

void draw() {
  if (mousePressed) { //function activated by mouse
    pg.beginDraw();
    pg.line(mouseX, mouseY, pmouseX, pmouseY);
    pg.stroke(random(255), random(255), random(255)); // stroke changed to random RBG values, each with a max of 255
    pg.strokeWeight (random(4, 8)); // random stroke weight, with a min of 4 and max of 8 pixels
    pg.endDraw();
  }
  background( pg.get() );
  textFont(font);  
  fill(255,0,0); //sets colour of font, red
  text(tickerText[index], x, height/2); //location of text on x axis - in this case mid-way


  x = x - 1; 
  float w = textWidth(tickerText[index]); // calculates the width of the text string - necessary for knowing when the text leaves the screen
  if (x &lt; -w) { // when x moves completely off the screen new text appears
    x = width; 
    index = (index + 1) % tickerText.length;

   }
}
</code></pre>

<p>Thank you in advance</p>
]]></description>
   </item>
   <item>
      <title>cut and move circles on the upper layer to see parts of the bottom layer, two images.</title>
      <link>https://forum.processing.org/two/discussion/14011/cut-and-move-circles-on-the-upper-layer-to-see-parts-of-the-bottom-layer-two-images</link>
      <pubDate>Wed, 16 Dec 2015 10:15:54 +0000</pubDate>
      <dc:creator>kyra</dc:creator>
      <guid isPermaLink="false">14011@/two/discussions</guid>
      <description><![CDATA[<p>Hello there!</p>

<p>I am an artist and a quite new in processing :)
I 'd like to achieve the following:
I have two different images. I want to put them as layers and then find a way to reveal parts of the bottom image with some circles cut in the upper layer. 
The circles should be of different size and should be moving freely on the canvas.</p>

<p>It's like having a spotlight searching something into the dark.
(This is why I have tried it with the brightness example, but I could not have the upper image since in this specific example is the black canvas.. so brightness doesn't work for me here.)</p>

<p>Any suggestions?</p>

<p>Thank you for your time :)</p>
]]></description>
   </item>
   <item>
      <title>Set background during animation (noobie)</title>
      <link>https://forum.processing.org/two/discussion/14113/set-background-during-animation-noobie</link>
      <pubDate>Tue, 22 Dec 2015 14:27:55 +0000</pubDate>
      <dc:creator>DFRgth456</dc:creator>
      <guid isPermaLink="false">14113@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I am sure that this question has been ask before. I had really tried to dig in (forum, friends) but I am still stuck.
I think it is a very simple thing and more a misunderstanding.
By the way sorry about my poor english.</p>

<p>I'm doing an animation like a twill fabric machine. Two objects go and goes leaving a colored "string" behind. Right to left, top o bottom. The color can be set with 'b' and 'n'. We can freeze with a press mouse. 
All is perfectly fine, by I would like set the background by a key (here 'c' and 'v', black or white), but it does not work, the background seems to run over the previous drewn string.
I tried by placing a rectangle at level -1, float, Matrix etc. nothing is working. I think it is a lack of logic P5 comprehension
Thanks a lot, have a nice day</p>

<pre><code>int x;
int y;
int deplaceX;
int deplaceY;
int changementX = 1;
float fond = 255;
int v=585; //X
int w=585; //Y
int deplaceV;
int deplaceW;
int f;


void setup(){
  size(600,600); 
  noStroke(); 
 background(f); 
}

void draw(){
  smooth();

 if ( key == 'f')  {
  f = 255; 
}


//FOND

/*background(fond);
  fond = changementX;

  if ( key == 'v') {

 changementX= 255;
}

  if ( key == 'c')  {
  changementX = 0;
}*/


//FORMES
  if ( key == 'n') fill(random(100,250),0,0);
  if ( key == 'b') fill(0,0, random(170,250));
  ellipse(x, y, 15, 15);
  rect(v, w, 15, 15);



///DESCEND CERCLE

  x=x+deplaceX+3;
  w=w+deplaceW-3;

if (x&gt;width)
{deplaceX= -20; //retour
y=y+20; //à la ligne
}

if(x&lt;20)
{
 deplaceX=1;
}

///VERSGAUCHE CARRE

if (w&lt;1)
{deplaceW= 20;
v=v-20;
}

if(w&gt;560)
{
deplaceW=-1;
}



}

//COMMANDES SOURIS
void mousePressed() {
  noLoop();  
}

void mouseReleased() {
  loop(); 
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to blend two images with blend() ?</title>
      <link>https://forum.processing.org/two/discussion/14036/how-to-blend-two-images-with-blend</link>
      <pubDate>Wed, 16 Dec 2015 23:34:52 +0000</pubDate>
      <dc:creator>01ivier</dc:creator>
      <guid isPermaLink="false">14036@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I want to blend img1 and img2.</p>

<p>With Processing, I do :</p>

<pre>
img1.blend(img2, sx, sy, sw, sh, dx, dy, dw, dh, mode);
</pre>

<p>But with p5.js, its seems I can only blend with the canevas :</p>

<pre>
blend(img2, sx, sy, sw, sh, dx, dy, dw, dh, mode);
</pre>

<p>If I specify the destination, with the syntax</p>

<pre>
img1.blend()
</pre>

<p>I get <strong>TypeError: this._renderer is undefined</strong></p>

<p>However, It works fine with copy(). I can do</p>

<pre>
img1.copy(img2, ...)
</pre>

<p>Any ideas ?</p>

<p>Thank you.</p>
]]></description>
   </item>
   <item>
      <title>How to use createGraphics buffer properly?</title>
      <link>https://forum.processing.org/two/discussion/13688/how-to-use-creategraphics-buffer-properly</link>
      <pubDate>Sat, 28 Nov 2015 00:27:39 +0000</pubDate>
      <dc:creator>zga</dc:creator>
      <guid isPermaLink="false">13688@/two/discussions</guid>
      <description><![CDATA[<p>I first copied the exercise from <a rel="nofollow" href="http://issuu.com/marioafonso/docs/algorithms_for_visual_design_using_">section 6.4</a> (document page 166) of <em>Algorithms for Visual Design using the Processing Language</em>.The code works, but it is slow to draw, obviously.</p>

<p>I then tried to use createGraphics as a kind of 'buffer' as outlined on the next section of the book, section 6.5 (document page 168). I've pasted my attempt below, which doesn't quite work.</p>

<p>My question is how does one integrate already working code with an off-screen buffer (something <a rel="nofollow" href="https://forum.processing.org/two/discussion/comment/54921/#Comment_54921">like this</a>)? Is there a general method, or do off-screen buffers use entirely different methods?</p>

<p>It can't be as simple as adding an extra line to the setup and draw functions, can it? What is the purpose of using elements like <code>pg.background</code>, if they seem to merely duplicate the information already in <code>background</code>?</p>

<p>Thanks,</p>

<p>frustrated guy new to processing</p>

<p>my attempt to replicate the example with a buffer:
</p>

<pre>
<span>PGraphics</span> pg;

<span>void</span> <span><b>setup</b></span>() {
&nbsp;&nbsp;<span>noSmooth</span>();
&nbsp;&nbsp;<span>size</span>(300,300, <span>P2D</span>);
&nbsp;&nbsp;pg&nbsp;=&nbsp;<span>createGraphics</span>(150,120, <span>P2D</span>);
}

&nbsp;&nbsp;<span>float</span> px[] = <span>new</span> <span>float</span> [300];
&nbsp;&nbsp;<span>float</span> py[] = <span>new</span> <span>float</span> [300];
&nbsp;&nbsp;<span>float</span> pr[] = <span>new</span> <span>float</span> [360];

<span>void</span> <span><b>draw</b></span>() {
&nbsp;&nbsp;<span>for</span>(<span>int</span> i=0; i&lt;<span>mouseY</span>; i++){
&nbsp;&nbsp;&nbsp;&nbsp;px[i]&nbsp;=&nbsp;<span>random</span>(<span>width</span>);
&nbsp;&nbsp;&nbsp;&nbsp;py[i]&nbsp;=&nbsp;<span>random</span>(<span>height</span>);
&nbsp;&nbsp;&nbsp;&nbsp;pr[i]&nbsp;=&nbsp;<span>random</span>(360);
&nbsp;&nbsp;}
&nbsp;&nbsp;<span>background</span>(255);
&nbsp;&nbsp;<span>for</span>(<span>int</span> i=0; i&lt;<span>mouseY</span>; i++){
&nbsp;&nbsp;&nbsp;&nbsp;<span>pushMatrix</span>();
&nbsp;&nbsp;&nbsp;&nbsp;<span>rectMode</span>(<span>CENTER</span>);
&nbsp;&nbsp;&nbsp;&nbsp;<span>translate</span>(px[i],py[i]);
&nbsp;&nbsp;&nbsp;&nbsp;<span>rotate</span>(<span>radians</span>(pr[i] + <span>mouseX</span>));
&nbsp;&nbsp;&nbsp;&nbsp;<span>rect</span>(0,0,5,500);
&nbsp;&nbsp;&nbsp;&nbsp;<span>popMatrix</span>();
&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;pg.<span>beginDraw</span>();
&nbsp;&nbsp;pg.<span>endDraw</span>();
&nbsp;&nbsp;
&nbsp;&nbsp;<span>image</span>(pg, 0, 0, <span>width</span>, <span>height</span>);
}

</pre>

<p></p>
]]></description>
   </item>
   </channel>
</rss>