<?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 imagemode() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=imagemode%28%29</link>
      <pubDate>Sun, 08 Aug 2021 17:14:11 +0000</pubDate>
         <description>Tagged with imagemode() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedimagemode%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How can I clone an image object?</title>
      <link>https://forum.processing.org/two/discussion/18109/how-can-i-clone-an-image-object</link>
      <pubDate>Thu, 08 Sep 2016 06:02:29 +0000</pubDate>
      <dc:creator>thinsoldier</dc:creator>
      <guid isPermaLink="false">18109@/two/discussions</guid>
      <description><![CDATA[<p>I want to load an image and draw it once with a mask and again without the mask.</p>

<p>I though I could load it then duplicate it as img2 and only apply the mask to the first img object.</p>

<p>Is that possible or is there a different way to do it?</p>

<pre><code>function preload() {
  img = loadImage("assets/moonwalk.jpg");
  imgMask = loadImage("assets/mask.png");
  img2 = ? ? ? ? ? ?; // how do i clone the first img?
}

function setup() {
  createCanvas(720, 400);
  img.mask(imgMask);
  imageMode(CENTER);
}

function draw() {
  background(250, 255, 3);
  image(img2, width/2, height/2);
  image(img, mouseX, mouseY);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to scale text and image to responsive canvas?</title>
      <link>https://forum.processing.org/two/discussion/28052/how-to-scale-text-and-image-to-responsive-canvas</link>
      <pubDate>Tue, 12 Jun 2018 14:07:48 +0000</pubDate>
      <dc:creator>LoCamillo</dc:creator>
      <guid isPermaLink="false">28052@/two/discussions</guid>
      <description><![CDATA[<p>Hi! I'm trying to do a big project, but I'm stuck in a part of it. The canvas I'm working on is responsive, but the text and image aren't. Here's a simple code that make what i'm needing.</p>

<blockquote class="Quote">
  <p>function setup(){
  createCanvas(windowWidth,windowHeight);
  logo = loadImage("logo.png");
  }</p>
  
  <p>function draw(){
  background(0);
  imageMode(CENTER);
  image(logo, windowWidth / 2, windowHeight / 3, 100, 100);
  imageMode(CORNER);
  textSize(30);
  textAlign(CENTER, CENTER);
  rectMode(CENTER);
  text('This is a string of text! This is a string of text!',windowWidth / 2, windowHeight / 2 , windowWidth, windowHeight);
  }</p>
</blockquote>

<p>This is what it looks on a laptop screen:
<img src="" alt="" />
<img src="https://forum.processing.org/two/uploads/imageupload/131/8PTD4KQT5CLB.PNG" alt="pic1" title="pic1" /></p>

<p>And this is what look on a responsive screen:
<img src="https://forum.processing.org/two/uploads/imageupload/190/1DAB0JKCVYFY.PNG" alt="pic2" title="pic2" /></p>

<p>I want to make the text and the image as big and legible than it is on responsive mode.  I know that I have to change the lines</p>

<blockquote class="Quote">
  <p>textSize(30);
  and 
  image(logo, windowWidth / 2, windowHeight / 3, 100, 100);</p>
</blockquote>

<p>but i don't know how. Any tips?</p>
]]></description>
   </item>
   <item>
      <title>Collisions, Sprites and Arrays.</title>
      <link>https://forum.processing.org/two/discussion/26681/collisions-sprites-and-arrays</link>
      <pubDate>Tue, 06 Mar 2018 21:24:24 +0000</pubDate>
      <dc:creator>CodeMendio</dc:creator>
      <guid isPermaLink="false">26681@/two/discussions</guid>
      <description><![CDATA[<p>Hi! I'm extremely new to Processing and wanted to learn how to use it. For a project of mine we were given the choice to use it so I went ahead and started to make a game with it. It's a game where your a spaceship trying to dodge enemy spaceships. <strong>Here's the code:</strong></p>

<pre><code>int Screen = 0;
int timersecs;
int milliseconds;
int shipX = 40, shipY = 300;
boolean intersect = false; 
PImage Ship;
PImage Enemy1;
PImage Enemy2;
PImage Enemy3;
PImage Enemy4;
PImage Enemy5;
PImage SpaceWarLoad;
PImage SpaceWarBack;
Ships s[];

void setup ()
{ 
 size(600,600);
 Ship = loadImage("Smallship.png");
 SpaceWarLoad = loadImage("SpaceWarLoad.png");
 SpaceWarBack = loadImage("SpaceWarBack.jpg");
 s = new Ships[5];
for (int z = 0; z &lt; 5; z++)
{ 
  s[z] = new Ships();
}
}

void draw ()
{                                             //Loading screen and Background
  if (Screen == 0)
  {
    imageMode(CENTER);
    image(SpaceWarLoad,width/2,height/2);
  }
else 
{
    imageMode(CENTER);
    image(SpaceWarBack,width/2,height/2);
    image(Ship, shipX, shipY);                        //Ship Sprite
    timer();
}
if (shipY &lt;= 30)        //Border control
{
  shipY=30;
}
else if (shipY &gt;= 560)
{
  shipY = 560;
}
 for (int z = 0; z &lt; 5; z++) //array to create 5 enemy ships
 {
   if (Screen == 1)
   {
       s[z].display();
   }
  }
}

void keyPressed()       //Movement
{ if (key==CODED) 
{
  if(keyCode==UP)
  { 
    shipY=(shipY)-10;
  }
  else if(keyCode==DOWN)
  { 
    shipY=(shipY)+10;
  }
}
}

class Ships
{
  float xposition, yposition, speed;
  int spriteSelector;
  Ships ()
  {
    command();
  }

void command()
{
  yposition = (int) random(30,561);
  xposition = 600; 
  speed = 5;
}

void display()
{  
  spriteSelector = (int) random(1,6);
  if (spriteSelector&gt;0)
  {
    if (spriteSelector&lt;2)
    {
    Enemy1 = loadImage("Smallship2.png");
    image(Enemy1, xposition, yposition);
    xposition = xposition-speed;
    }
  }
  if (spriteSelector&gt;1)
  {
    if (spriteSelector&lt;3)
    {
    Enemy1 = loadImage("Smallship3.png");
    image(Enemy1, xposition, yposition);
    xposition = xposition-speed;
    }
  }
  if (spriteSelector&gt;2)
  {
    if (spriteSelector&lt;4)
    {
    Enemy1 = loadImage("Smallship4.png");
    image(Enemy1, xposition, yposition);
    xposition = xposition-speed;
    }
  }
  if (spriteSelector&gt;3)
  {
    if (spriteSelector&lt;5)
    {
    Enemy1 = loadImage("Smallship5.png");
    image(Enemy1, xposition, yposition);
    xposition = xposition-speed;
    }
  }
  if (spriteSelector&gt;4)
  {
    if (spriteSelector&lt;6)
    {
    Enemy1 = loadImage("Smallship6.png");
    image(Enemy1, xposition, yposition);
    xposition = xposition-speed;
    }
  }
    if (shipX-xposition &gt; 0 &amp; shipY &gt;= yposition) 
    {
    intersect = true;
    }
    if (intersect == true)
     {
       image(Enemy1, shipX, shipY); 
     }
}
}


void mousePressed()        //Start state detection
{
  Screen=1;
}

void timer()               //Timer for score
{
  milliseconds = millis();
  timersecs = milliseconds/100;       //speed of timer
  textSize(20);
  text(timersecs,540, 600);
  text("Score:",480, 600);
  fill(#FFFFFF);
}
</code></pre>

<p>Now I've run into a couple of problems. The game loads in the enemy sprites through an array but I don't want it to be a one and done deal. Instead, I want the array to make 5 ships on the screen consistently, every 5 seconds (lets say). How would I do this?</p>

<p>Also, my hit detection is really bad. I tried treating the sprites like rectangles but it seems it didn't work. How would I go about making the collisions between the player controlled sprite and each of the sprites spawned by the array work?</p>
]]></description>
   </item>
   <item>
      <title>Gif Animation Library - Still having memory leaks</title>
      <link>https://forum.processing.org/two/discussion/26132/gif-animation-library-still-having-memory-leaks</link>
      <pubDate>Fri, 26 Jan 2018 17:09:29 +0000</pubDate>
      <dc:creator>fleetfox</dc:creator>
      <guid isPermaLink="false">26132@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I already asked this as a new post in an old discussion from two years ago, but as expected nobody answered! ;) So I try my luck again:</p>

<p>I would like to build a wooden frame with a display that shows gifs and jpgs when it is activated by a touch sensor. I am using an Up core board with win10 for this which really is a nice piece of hardware. I am using the gif library from 01010101's github account, which seems to be the newest version (<a href="https://github.com/01010101/GifAnimation" target="_blank" rel="nofollow">https://github.com/01010101/GifAnimation</a>) and works with processing 3.
Unfortunately this library seems to have a memory leak problem as already discussed in here: <a href="https://forum.processing.org/two/discussion/12452/animated-gif-slideshow" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/12452/animated-gif-slideshow</a>
To be honest this discussion did not help me to fix the memory leak problem with this library. I still get the error message after several gifs are shown. This is my test code I am using to explore possible solutions:</p>

<pre><code>import gifAnimation.*;

Gif myGif;
String[] filenames;
String path;

void setup() {

  fullScreen(P2D);
  frameRate(25);
  imageMode(CENTER);
  path = sketchPath();   
  path = path+"\\files\\GifDiv";       
  filenames = listFileNames(path);
  myGif = new Gif(this, path+"\\"+filenames[int(random(0,filenames.length)-1)]);

}

void draw() {

    if (frameCount == 1 ){
      myGif = new Gif(this, path+"\\"+filenames[int(random(0,filenames.length)-1)]);
      myGif.play();
      println(frameCount);
      println("first Play");
      image(myGif, displayWidth/2, displayHeight/2, myGif.width , myGif.height);    
    } else if (frameCount % 40 == 0){
      myGif.stop();
      myGif.dispose();     
      myGif = null;
      background(0);
      println(frameCount);
      println("clear Cache");
  } else if (frameCount % 40 == 1){
      myGif = new Gif(this, path+"\\"+filenames[int(random(0,filenames.length)-1)]);
      myGif.play();
      println(frameCount);
      println("new Play");
      image(myGif, displayWidth/2, displayHeight/2, myGif.width , myGif.height);
  } else{
    println(frameCount+" just Counting Frames");
    image(myGif, displayWidth/2, displayHeight/2, myGif.width , myGif.height);
  }

}

String[] listFileNames(String dir) {
  File file = new File(dir);
  if (file.isDirectory()) {
    String names[] = file.list();
    return names;
  } else {
    // If it's not a directory
    return null;
  }
}
</code></pre>

<p>The code might seem odd, but I wanted to test what happens when at one frame in time no gif is shown, disposed and set to null. My hope was that in this moment the memory would be cleared. It wasn't!!
The source of this problem might be the libraries dispose() command, which might not totally clear the memory!?  But this is the point where it ends for me as I am too stupid to write pure Java-Code, possibly fix this and compile another version of the library. So my hope is to find somebody here who is library coder and might be willing to help!</p>

<p>Best,
Tim</p>
]]></description>
   </item>
   <item>
      <title>How to move with object...</title>
      <link>https://forum.processing.org/two/discussion/24709/how-to-move-with-object</link>
      <pubDate>Mon, 23 Oct 2017 12:22:28 +0000</pubDate>
      <dc:creator>GeorgeJava</dc:creator>
      <guid isPermaLink="false">24709@/two/discussions</guid>
      <description><![CDATA[<p>I want to move image with lights ... but lights doesnt moving ...</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/515/BIJN0BAYJQ3J.png" alt="wtf" title="wtf" /></p>

<p>Here is code:</p>

<pre><code>PImage light, screen, bg, lightImage, mask;
PGraphics pg, lightMask;
int up, down, right, left;
float x, y, speed = 1;
color randomColor;
float camX=0, camY=0;
float  Ox1, Ox2, Oy1, Oy2;
int globalMX, globalMY;
void setup() {
  size(480, 270, P3D);
  frameRate(60);
  background(0);
  bg = loadImage("https://" + "ichef.bbci.co.uk/images/ic/480xn/p01lckx1.jpg");
  lightImage = loadImage("https://" + "i.stack.imgur.com/NaD6F.png");
  bg.resize(width, height);
  light = bg.copy();
  lightMask = createGraphics(width, height);
  randomColor = color(random(256), random(256), random(256));
  bullets = new ArrayList&lt;Bullet&gt;();
  reloadLights();
  x = width/2;
  y = height/2;
}
void draw() {  
  background(0);
  x += (right - left) * speed;
  y += (down - up) * speed;
  Ox1=camX-width+x;
  Ox2=camX+x;
  Oy1=camY-y;
  Oy2=camY+height-y;
  ortho(Ox1, Ox2, Oy1, Oy2);
  println(x + "  " + y);
  imageMode(CORNER);
  image(bg, 0, 0);
  pushMatrix();
  translate(x,y);
  screen = get(0, 0, width, height);
  popMatrix(); 
  fill(0, 125);
  noStroke();
  rectMode(CENTER);
  rect(x, y, width, height);
  screen.mask(lightMask);
  image(screen, 0,0);
  fill(255, 255, 0);
  textAlign(LEFT, TOP);
  textSize(39);
  text(int(frameRate) + " FPS", 5, 5);
  ellipse(globalMX,globalMY,20,20);
  //popMatrix();
}
void reloadLights() {
  pg = lightMask;
  pg.beginDraw();
  pg.background(0);
  pg.blendMode(ADD);
  for (int i = bullets.size()-1; i &gt;= 0; i--) {
    Bullet bullet = bullets.get(i);
    drawLight(bullet.x, bullet.y, bullet.r);
  }
  //mask = pg;
  pg.endDraw();
}
void drawLight(int xL, int yL, int rL) {
 // pushMatrix();
 // translate(x,y);
  pg.imageMode(CENTER);
  pg.image(lightImage, xL,yL, rL, rL);
  //popMatrix();
}
 
void mousePressed() {
  bullets.add( new Bullet(globalMX, globalMY, 50));
  reloadLights();
}
ArrayList&lt;Bullet&gt; bullets;
class Bullet {
  int x, y, r;
  public Bullet(int x_, int y_, int r_) {
    x = x_;
    y = y_;
    r = r_;
  }
}
void keyPressed() {
  if (key == 'a' || key == 'A') {
    left = 1;
  }
  if (key == 'd' || key == 'D') {
    right = 1;
  }
  if (key == 'w' || key == 'W') {
    up = 1;
  }
  if (key == 's' || key == 'S') {
    down = 1;
  }
}
void keyReleased() {
  if (key == 'a' || key == 'A') {
    left = 0;
  }
  if (key == 'd' || key == 'D') {
    right = 0;
  }
  if (key == 'w' || key=='W') {
    up = 0;
  }
  if (key == 's' || key == 'S') {
    down = 0;
  }
}
void mouseMoved() {
  globalMX=mouseX;
  globalMY=mouseY;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Is this a data-efficient way to display an animation (a sequence of images)?</title>
      <link>https://forum.processing.org/two/discussion/24239/is-this-a-data-efficient-way-to-display-an-animation-a-sequence-of-images</link>
      <pubDate>Sun, 24 Sep 2017 15:51:43 +0000</pubDate>
      <dc:creator>randomdude</dc:creator>
      <guid isPermaLink="false">24239@/two/discussions</guid>
      <description><![CDATA[<p>Hello! I am working on a project that involves a lot of 30-40 frame image sequences, so I am looking to discover the best way to implement them without eating up too much RAM. This is what I came up with, it seems short and simple enough and runs smoothly, but of course it's just a single animation following the mouse, so I can't know if it will be data-efficient with various multi-image sprites, and I need to know that before I can start working on creating and programming the sprites.</p>

<pre><code>PImage[] runner = new PImage[6];
int frame;
int displaytimer;
void setup() {
  frameRate(80);
  size(500, 500);
  for (int i = 0; i &lt; runner.length; i++) {
    runner[i] = loadImage("run"+(i+1)+".jpeg");
  }
}
void draw() {
  background(255);
  image(runner[frame], mouseX, mouseY, 100, 100);
  if (millis()&gt;displaytimer+180) {
    displaytimer = millis();
    if (frame&lt;5) {
      frame = frame+1;
    } else {
      frame = 0;
    }
  }
}
</code></pre>

<p>Note that the sequence is of 6 images named "run1" to "run6" in a consecutive order.</p>

<p>Any help would be greatly appreciated.</p>
]]></description>
   </item>
   <item>
      <title>splice</title>
      <link>https://forum.processing.org/two/discussion/23249/splice</link>
      <pubDate>Thu, 29 Jun 2017 02:12:23 +0000</pubDate>
      <dc:creator>1rulesupersedes</dc:creator>
      <guid isPermaLink="false">23249@/two/discussions</guid>
      <description><![CDATA[<p>I want to make the first image disappear when it reaches 10 images. I am thinking splice the array. However not sure where or how.</p>

<p>index.html</p>

<pre><code>    &lt;html&gt;
    &lt;head&gt;

      &lt;meta charset="UTF-8"&gt;
      &lt;script language="javascript" type="text/javascript" src="libraries/p5.js"&gt;&lt;/script&gt; 
      &lt;script language="javascript" src="libraries/p5.dom.js"&gt;&lt;/script&gt;
      &lt;script language="javascript" src="libraries/p5.sound.js"&gt;&lt;/script&gt;
      &lt;script language="javascript" src="images.js"&gt;&lt;/script&gt;
      &lt;script language="javascript" src="images_2.js"&gt;&lt;/script&gt;
    &lt;/head&gt; 
      &lt;!-- this line removes any default padding and style. you might only need one of these values set. --&gt;
      &lt;style&gt; 
      &lt;/style&gt;

    &lt;/head&gt;

    &lt;body&gt;

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

<p>============================================================================
images.js</p>

<pre><code>    var bubbles = [];
    var flowers = [];

    function preload(){

        for(var i = 0; i&lt; 6; i++){
            flowers[i] = loadImage("fet_pictures/" + i + ".jpg");
        }

    }

    function windowResized(){
        resizeCanvas(windowWidth, windowHeight);
    }

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

    function mousePressed(){
        var r = floor(random(0, flowers.length));
        var b = new Bubble(mouseX, mouseY, flowers[r]);
        bubbles.push(b);
    }

    function draw(){
        background(0);
        for(var i = bubbles.length -1; i &gt;= 0; i--){
            bubbles[i].update();
            bubbles[i].display();
        }
    }
</code></pre>

<p>============================================================================
images_2.js</p>

<pre><code>        function Bubble(x, y, img){
        this.x = x;
        this.y = y;
        this.img = img;
        this.lifespan = 255;

        this.display = function(){
            imageMode(CENTER);
            image(this.img, this.x, this.y);
            this.img.resize(100, 0);
            //ellipse(this.x, this.y, 48, 48);
        }

        this.update = function() {
            this.x = this.x + random(-1, 1);
            this.y = this.y + random(-1, 1);
           }
        }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Help with translation calculations</title>
      <link>https://forum.processing.org/two/discussion/22377/help-with-translation-calculations</link>
      <pubDate>Thu, 04 May 2017 01:21:56 +0000</pubDate>
      <dc:creator>Vanthex</dc:creator>
      <guid isPermaLink="false">22377@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys,
In this sketch, the user should be able to zoom in and out relative to the mouse's position. However the more you zoom in/out, the larger the error of translation there is.
gif link:
<a href="https://gyazo.com/bc19520eb98509299f9d0af9be548228" target="_blank" rel="nofollow">https://gyazo.com/bc19520eb98509299f9d0af9be548228</a></p>

<p>This is how I calculated the translation:
trans += getStriplength() * deltascale
getStriplength returns the length of the whole strip of objects while deltascale is the amount that is reduced each time when the mouse scrolls. Its default value is 0.2, which means the objects will be either 1.02 times bigger or 0.98 times smaller than the original.
Therefore I am getting the difference of the lengths of the strip before and after, and adding it to the offset. However as I mentioned before it doesn't work the more you zoom in/out. Any help will be appreciated!</p>

<p>Code:</p>

<pre><code>PImage backgroundImage;
PFont font;
int x = 0;
int xoffset = 0;
int deltax = 5;
float scale = 512/30;
float deltascale = 0.02;
ArrayList&lt;celestialObject&gt; ObjectList;
String[] objectfile;
String[] configfile;
int savetimer = 0;
static int screenwidth = 1920;
static int screenheight = 1080;
float trans = 0;

class celestialObject {
  String name;
  float diameter;
  String unit;
  String sprite;
  PImage img;
  int wid;
  int hei;
  int xpos;

  celestialObject(String Oname, float Odiameter, String Ounit, String Oimg) {
    name = Oname;
    diameter = Odiameter;
    unit = Ounit;
    sprite = Oimg;
    img = loadImage(Oimg);
    wid = img.width;
    hei = img.height;
  }
}

void setup() {
  size(1920, 1080);
  frameRate(200);
  objectfile = loadStrings("objects.txt");
  configfile = loadStrings("config.ini");
  backgroundImage = loadImage("background.png");
  font = createFont("Franklin Gothic Book Regular.ttf", 32);
  textFont(font, 32);
  textAlign(CENTER, CENTER);
  imageMode(CENTER);
  ObjectList = new ArrayList();
  readObjects();
  readConfig();
  loadOffset();
}

void addObject(String Aname, float Adiameter, String Aunit, String Aimg) {
  println("Loading "+Aname);
  if (Aimg.equals("null")) {
    ObjectList.add(new celestialObject(Aname, Adiameter, Aunit, "images/"+Aname+".png"));
  } else {
    ObjectList.add(new celestialObject(Aname, Adiameter, Aunit, "images/"+Aimg));
  }
}

void readObjects() {
  for (int i = 0; i &lt; objectfile.length; i++) {
    String[] currentObject = split(objectfile[i], ",");
    addObject(currentObject[0], float(currentObject[1]), currentObject[2], currentObject[3]);
  }
}

void readConfig() {
  for (int i = 0; i &lt; configfile.length; i++) {
    char slash = configfile[i].charAt(0);
    if (slash != '/') {
      //getting config values based on line number
      if (i == 1) {
        xoffset = int(configfile[i]);
      } else if (i == 3) {
        scale = float(configfile[i]);
      }
    }
  }
}

void loadOffset() {
  //for (int i = 0; i &lt;= xoffset; i++) {
  //  int x = 0 + xoffset;
  //  for ( celestialObject drawObject : ObjectList ) {         
  //    float dia;
  //    if (drawObject.unit.equals("km")) {
  //      dia = drawObject.diameter * 1000;
  //    } else {
  //      dia = drawObject.diameter;
  //    }
  //    int drawWidth = int(scale * dia);
  //    //checks if image is too small to be drawn
  //    if (x+drawObject.img.width &gt;= 0 &amp;&amp; x &lt;= 1500) {
  //      int drawWidth = int(scale * dia);
  //      int drawHeight = int(drawWidth * drawObject.hei / drawObject.wid);
  //      if (drawWidth &gt; 0 &amp;&amp; drawHeight &gt; 0) {
  //        //drawObject.img.resize(drawWidth, drawHeight);
  //        image(drawObject.img, x+(drawWidth/2), 400,drawWidth, drawHeight);
  //        //calculates font size relative to object's current size
  //        int textSize;
  //        //checks if the name or diameter is longer, then uses the longer one for calculation
  //        if (drawObject.name.length() &lt; str(drawObject.diameter).length()) {
  //          textSize = int(drawObject.img.width/str(drawObject.diameter).length());
  //        } else {
  //          textSize = int(drawObject.img.width/drawObject.name.length());
  //        }
  //        if (textSize &gt; 0) {
  //          textSize(textSize);
  //          float texty = 418+(drawObject.img.height/2);
  //          if (texty &lt; (418+(drawObject.img.height/2))) {
  //            texty = 418;
  //          }
  //          text(drawObject.name, x+(drawObject.img.width/2), texty);
  //          text(drawObject.diameter+drawObject.unit, x+(drawObject.img.width/2), texty+textSize);
  //        }
  //      }
  //    }
  //    drawObject.xpos = x;
  //    x += (drawObject.img.width*0.08 + drawObject.img.width);
  //  }
  //}
}

void draw() {
  image(backgroundImage, screenwidth/2, screenheight/2);
  int x = int(0 + xoffset + trans);
  for ( celestialObject drawObject : ObjectList ) {
    float dia;
    if (drawObject.unit.equals("km")) {
      dia = drawObject.diameter * 1000;
    } else {
      dia = drawObject.diameter;
    }
    int drawWidth = int(scale * dia);
    if (x+(scale*dia) &gt;= 0 &amp;&amp; x &lt;= screenwidth) {
      //checks if image is too small to be drawn 
      int drawHeight = int(drawWidth * drawObject.hei / drawObject.wid);
      if (drawWidth &gt; 0 &amp;&amp; drawHeight &gt; 0) {
        //drawObject.img.resize(drawWidth, drawHeight);
        image(drawObject.img, x+(drawWidth/2), screenheight/2, drawWidth, drawHeight);
        //calculates font size relative to object's current size
        int textSize;
        //checks if the name or diameter is longer, then uses the longer one for calculation
        if (drawObject.name.length() &lt; str(drawObject.diameter).length()) {
          textSize = int(drawWidth/str(drawObject.diameter).length());
        } else {
          textSize = int(drawWidth/drawObject.name.length());
        }
        if (textSize &gt; 0) {
          textSize(textSize);
          float texty = screenheight/2+18+(drawHeight/2);
          if (texty &lt; (screenheight/2+18+(drawHeight/2))) {
            texty = screenheight/2+18;
          }
          text(drawObject.name, x+(drawWidth/2), texty);
          text(drawObject.diameter+drawObject.unit, x+(drawWidth/2), texty+textSize);
        }
      }
    }
    drawObject.xpos = x;
    x += (drawWidth*0.08 + drawWidth);
  }
  //display deltax
  textSize(32);
  text(str(deltax), screenwidth-50, 10);
  text(str(deltascale), screenwidth-50, 50);
  //display Saved
  if (savetimer &gt; 0) {
    text("Saved", screenwidth-50, 90);
    //text(str(savetimer),1450,130);
  }
  if (savetimer &gt; 0) {
    savetimer -= 1;
  }
  //println(str(scale));
}

void mouseWheel(MouseEvent event) {
  float e = event.getCount();
  if (e &lt; 0) {
    scale *= (1 + deltascale);
    mouseX = xoffset;
    trans -= (getStriplength() * deltascale);
  } else if (e &gt; 0) {
    scale *= (1 - deltascale) ;
    mouseX = xoffset;
    trans += (getStriplength() * deltascale);
  }
}

void keyPressed() {
  if (key == CODED) {
    if (keyCode == LEFT) {
      xoffset += deltax;
    } else if (keyCode == RIGHT) {
      xoffset -= deltax;
    } else if (keyCode == UP) {
      deltax += 5;
    } else if (keyCode == DOWN) {
      deltax -= 5;
    }
  }
  if (key == 's') {
    for (int i = 0; i &lt; configfile.length; i++) {
      if (i == 1) {
        configfile[i] = str(xoffset);
      } else if (i == 3) {
        configfile[i] = str(scale);
      }
    }
    saveStrings("config.ini", configfile);
    savetimer = 500;
  } else if (key == 'q') {
    deltascale += 0.02;
  } else if (key == 'a') {
    deltascale -= 0.02;
  }
  if (deltax &lt; 0) {
    deltax = 0;
  } else if (deltascale &lt; 0) {
    deltascale = 0;
  }
}

float getStriplength() {
  float x = 0;
  int i = 0;
  for ( celestialObject getObject : ObjectList ) {
    float dia;
    if (getObject.unit.equals("km")) {
      dia = getObject.diameter * 1000;
    } else {
      dia = getObject.diameter;
    }
    int drawWidth = int(scale * dia);
    x += (drawWidth*0.08 + drawWidth);
    i++;
    //println(ObjectList.size());
    if (i == ObjectList.size()) {
       x -= drawWidth*0.08;
    }
    //println(x);
  }
  //println(x);
  return x;  
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Strange behavioral difference between rectangles and images</title>
      <link>https://forum.processing.org/two/discussion/21991/strange-behavioral-difference-between-rectangles-and-images</link>
      <pubDate>Fri, 14 Apr 2017 10:24:59 +0000</pubDate>
      <dc:creator>sai</dc:creator>
      <guid isPermaLink="false">21991@/two/discussions</guid>
      <description><![CDATA[<p>I am beginning to learn P5JS by creating a simple shooting game in which targets are loaded as random images and when clicked they disappear. The targets are objects that are loaded into an array and drawn each frame, and when one is clicked it is simply removed from the array and no longer drawn the next frame. I have run into a problem in which I can't get the images to be redrawn every frame, however if I replace the image with a rectangle it IS redrawn every frame.</p>

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

<pre><code>var target;

// Array the stores all targets
var targets = [];

// x and y spawn coordinates for targets
var x;
var y;
var targetX;
var targetY;

// Image that shows when a target is hit, an explosion etc
var deathImage;

function setup() {
    createCanvas(windowWidth, windowHeight);
    frameRate(2);
    imageMode(CENTER);
    cursor(CROSS);
}

function draw() {

    x = int(random(windowWidth));
    y = int(random(windowHeight));
    targetImage = createImg('assets/test.png').hide();

    targets.push(new Target(x, y, targetImage));
    fill(0, 255, 255);
    rectMode(CORNER);
    rect(0, 0, width, height);
    for (var i = 0; i &lt; targets.length; i++) {
            targets[i].display();
    }

}

// Target Class
function Target(x, y, targetImage) {
    this.display = function() {
            this.targetX = x;
            this.targetY = y;
            this.TargetPicture = targetImage;

            /* When I use an image here it only shows in a single frame and then dissapears, the targets[i].display(); for loop fails to redraw all the targets */
            image(this.TargetPicture, this.targetX, this.targetY, 200, 200);

            /*However if I draw rectangles it works as expected            
            fill(255,0,0);
            rectMode(CENTER);
            rect(x,y,200,200); */
    }
}

function mouseClicked() {
    for (var i = 0; i &lt; targets.length; i++) {
        var distanceChecker = dist(mouseX, mouseY, targets[i].targetX, targets[i].targetY);
        // If target is hit
        if (distanceChecker &lt; 150) {
            fill(255, 0, 255);
            // Show explosion when target hit
            deathImage = createImg('assets/deathImage.png').hide();
            image(deathImage, mouseX, mouseY, 300, 300);
            // Remove target from array
            targets.splice(i, 1);
        }
    }

}
</code></pre>

<p>What am I missing? Thanks in advance!</p>
]]></description>
   </item>
   <item>
      <title>how to make only *one* image rotate?</title>
      <link>https://forum.processing.org/two/discussion/21418/how-to-make-only-one-image-rotate</link>
      <pubDate>Wed, 15 Mar 2017 17:46:47 +0000</pubDate>
      <dc:creator>mdobbe</dc:creator>
      <guid isPermaLink="false">21418@/two/discussions</guid>
      <description><![CDATA[<p>Hey there! I'm writing some pretty simple code as the basis for a small interactive game. So far I'm just working on getting the background to function properly. What I am trying to do is have the "wheel" image (the color wheel) rotate every time the mouse is clicked. HOWEVER the way it is written right now the wheel does not rotate at all, and instead the "bg" image above it, which I want to remain static, is the one the rotates. Here are some pictures of what that looks like, with questions and code below:
<img src="https://forum.processing.org/two/uploads/imageupload/099/XO5GNNTXC6H0.JPG" alt="calendar1" title="calendar1" />
<img src="https://forum.processing.org/two/uploads/imageupload/781/741I6Q8AHT7L.JPG" alt="calendar2" title="calendar2" /> <br /></p>

<p>So I have a few questions:<br />
1) How do I write it so that the wheel image is the one that rotates?<br />
2) Why does the bg image that is incorrectly rotating rotating from the (0,0) position instead of the center, when I specified imageMode(CENTER)?<br />
3) How would you recommend making the image rotate once per click, instead of whenever the mouse is pressed?<br /></p>

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

<blockquote class="Quote">
  <p>PImage bg; <br />
  PImage wheel;<br />
  float x = width;<br />
  float y = height;<br />
  int a = 0;<br />
  <br />
  void setup() {<br />
    background(255);<br />
    size(750, 500);<br />
    imageMode(CENTER);<br />
    bg = loadImage("bg1.png");<br />
    wheel = loadImage("colorwheel.png");<br />
  }<br />
  void draw() {<br />
    background(255);<br />
     if(mousePressed){<br />
      a = (a+1);<br />
    }<br />
    wheel(750,0,a);<br />
    image(bg, 375, 250);<br />
  }<br />
  void wheel(int xloc, int yloc, int angle){<br />
      image(wheel, xloc, yloc);<br />
      rotate(angle);<br />
  }<br />
  <br />
  Thank you!</p>
</blockquote>
]]></description>
   </item>
   <item>
      <title>image processing/problem with multiple loop of draw</title>
      <link>https://forum.processing.org/two/discussion/21133/image-processing-problem-with-multiple-loop-of-draw</link>
      <pubDate>Fri, 03 Mar 2017 17:54:14 +0000</pubDate>
      <dc:creator>pietroLama</dc:creator>
      <guid isPermaLink="false">21133@/two/discussions</guid>
      <description><![CDATA[<p>Hi to all! these days i'm working against this little problem...I just can not understand why it does not work as I think.
the basic problem is simple and the effect works, except that when I try to save multiple frames of the same image the result does not change, which is very strange because the parameters in the loop of the draw varying!
can anyone tell me why!?!?
thanks to all!!!</p>

<p>here the code:</p>

<pre><code>PImage img, imgR, imgG, imgB, imgF;
int phase=1, phase2=phase*2, it=0;
String imgName="yolandi_2_-8000000";
String imgType="jpg";

void setup() {
  size(850, 1274, P2D);
  imageMode(CENTER);
  img=loadImage(imgName+"."+imgType);
  background(0);
  imgR=createImage(img.width, img.height, ARGB);
  imgG=createImage(img.width, img.height, ARGB);
  imgB=createImage(img.width, img.height, ARGB);
  imgF=createImage(img.width, img.height, ARGB);
}

void draw() {
  it++;
  img.loadPixels();
  phase+=1;
  phase2=phase*2;
  for (int i=0; i&lt;img.width-phase; i++) {
    for (int j=0; j&lt;img.height-phase; j++) {
      if (i&lt;width &amp;&amp; j+(2*phase2)&lt;height) {
        imgR.pixels[i+j*img.width]=color(red(img.pixels[i+j*img.width]), 0, 0);
        imgG.pixels[i+(j+phase)*img.width+phase]=color(0, green(img.pixels[i+j*img.width]), 0);
        imgB.pixels[i+(j+phase2)*img.width+phase2]=color(0, 0, blue(img.pixels[i+j*img.width]));
        imgF.pixels[i+j*img.width]=color(
          red(imgR.pixels[i+j*img.width]), 
          green(imgG.pixels[i+j*img.width]), 
          blue(imgB.pixels[i+j*img.width]));
      }
    }
  }
  println(it, phase, phase2);
  img.updatePixels();
  image(imgF, width/2, height/2);
  saveFrame("C:/Users/pietr/Documents/Processing/Sketch/effettiImmagini/imagePhase/frames/"+imgName+"+phase+"+phase+"_"+it+"."+imgType);
  if (it&gt;=30) {
    println("fine");
    exit();
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Alpha Mask Example</title>
      <link>https://forum.processing.org/two/discussion/19637/alpha-mask-example</link>
      <pubDate>Sat, 10 Dec 2016 10:39:37 +0000</pubDate>
      <dc:creator>danielpferreira</dc:creator>
      <guid isPermaLink="false">19637@/two/discussions</guid>
      <description><![CDATA[<p>I just checked this Alpha Mash Example:
<a href="http://p5js.org/examples/image-alpha-mask.html" target="_blank" rel="nofollow">http://p5js.org/examples/image-alpha-mask.html</a></p>

<p>It doesn't seem to be working properly. 
Or am I missing something?</p>

<p>(This is my first post in this forum, so sorry for any confusion)</p>
]]></description>
   </item>
   <item>
      <title>How to Resize images in a String and/or an Array and for images to stop glitching</title>
      <link>https://forum.processing.org/two/discussion/19143/how-to-resize-images-in-a-string-and-or-an-array-and-for-images-to-stop-glitching</link>
      <pubDate>Fri, 18 Nov 2016 17:45:44 +0000</pubDate>
      <dc:creator>Frostbite180</dc:creator>
      <guid isPermaLink="false">19143@/two/discussions</guid>
      <description><![CDATA[<p>Hey everyone. I am new to processing and new to this website. I'm working on a project with the end goal of being a dress-up game but right now I am just testing out some code to make sure whether or not I can actually code it. I did find some code that is useful but I am experiencing some problems with it and I was hoping someone could point me in the right direction.
My problem is that I cannot resize the images I am using within my sketch. I've played around with various numbers in my code but just can't seem to change anything. The images appear as squished tiny things but I would like them to be bigger (so I can actually see what they are :)   ). My other problem is that when one image drags over another one, they glitch and will 'jump' away from one another. If this cannot be fixed, it's fine but some more information as to why that is happening would be most kind.</p>

<p>For the most part, I do understand what it happening. I just want to know these few things will not work and how to fix them. Thank you in advance!</p>

<p>I've used the following examples to help me out so far:</p>

<p><a href="https://forum.processing.org/two/discussion/4229/help-with-dragging-and-dropping-multiple-images-in-an-array" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/4229/help-with-dragging-and-dropping-multiple-images-in-an-array</a>
<a href="https://processing.org/discourse/beta/num_1256052533.html" target="_blank" rel="nofollow">https://processing.org/discourse/beta/num_1256052533.html</a></p>

<p>My code is as follows:</p>

<pre><code>String[] images = {
  "Sprite.png", "Sprite2.png", "Sprite3.png"
};

float[] positions =new float [images.length*2] ;

// 0,1,2,3,4,5
// 4,5,6,7,8,9
float bx;
float by;
int bs = 40;
int bz = 30;
boolean bover = false;
boolean locked = false;
float bdifx = 0.0; 
float bdify = 0.0; 
PImage[] image1 = new PImage [images.length]; 
float newx, newy;
int whichImage;

void setup() 
{
  imageMode (CENTER);
  size(600, 400);
  bx = width/2.0;
  by = height/2.0;

  for (int i=0; i &lt; images.length; i++) {
    image1 [i]= loadImage(images[i]); //loads in the images
   // image (image1[i], random(width), random(height), 50, 50) ;
  } 

  for (int j=0; j &lt; images.length*2; j+=2) { //Positions for Images
    positions[j]= random(100);
    positions[j+1]= random(100);
  }
}

void draw() 
{ 
  background(255);
  // Test if the cursor is over the box 
  for (int i=0; i &lt; images.length; i++) {
    if (mouseX &gt; positions[i*2]-bs &amp;&amp; mouseX &lt; positions[i*2]+bs &amp;&amp; 
      mouseY &gt; positions[i*2+1]-bs &amp;&amp; mouseY &lt; positions[i*2+1]+bs) 
    {
      println ("mouseover image: "+i);
      whichImage=i;

      bover = true;  
      if (!locked) 
      { 
        stroke(255); 
        fill(153);
      }
      break;
    } 
    else
    {
      stroke(153);
      fill(153);
      bover = false;
    }
  }
  for (int j=0; j &lt; images.length; j++) {
    image (image1[j], positions[j*2], positions[j*2+1], 50, 50) ;
  }
}
void mousePressed() {
  if (bover) { 
    locked = true;
  } 
  else {
    locked = false;
  }
}
void mouseReleased() {
  locked = false;
}
void mouseDragged() {
  if (locked) {
    newx = mouseX; 
    newy = mouseY;
  } 
  positions [whichImage*2] = newx;
  positions [(whichImage*2)+1] = newy;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How can I stop the jumping over?</title>
      <link>https://forum.processing.org/two/discussion/19074/how-can-i-stop-the-jumping-over</link>
      <pubDate>Wed, 16 Nov 2016 18:29:15 +0000</pubDate>
      <dc:creator>Dracore</dc:creator>
      <guid isPermaLink="false">19074@/two/discussions</guid>
      <description><![CDATA[<p>I have this code, sorry I don't know how to format it,</p>

<pre><code>String[] images = {"life1.png", "life2.png", "life3.png"};
PImage Background; 
float[] positions =new float [images.length*2] ;
float bx;
float by;
int bs = 37;
int bz = 37;
boolean bover = false;
boolean locked = false;
float bdifx = 0.0; 
float bdify = 0.0; 
PImage[] image1 = new PImage [images.length]; 
float newx, newy;
int whichImage;

void setup() 
{
  imageMode (CENTER);
  fullScreen();
  Background = loadImage("Background.png");
  bx = width/2.0;
  by = height/2.0;
  for (int i=0; i &lt; images.length; i++) {
    image1 [i]= loadImage(images[i]); 
    image (image1[i], random(width), random(height), 75, 75) ;
  } 
  for (int j=0; j &lt; images.length*2; j+=2) {
    positions[j]= random(width);
    positions[j+1]= random(height);
  }
}

void draw() 
{ 
  background(Background);
  for (int i=0; i &lt; images.length; i++) {
    if (mouseX &gt; positions[i*2]-bs &amp;&amp; mouseX &lt; positions[i*2]+bs &amp;&amp; 
      mouseY &gt; positions[i*2+1]-bs &amp;&amp; mouseY &lt; positions[i*2+1]+bs) 
    {
      println ("mouseover image: "+i);
      whichImage=i;
      bover = true;  
      if (!locked) 
      { 
        stroke(255); 
        fill(153);
      }
      break;
    } 
    else
    {
      stroke(153);
      fill(153);
      bover = false;
    }
  }
  for (int j=0; j &lt; images.length; j++) {
    image (image1[j], positions[j*2], positions[j*2+1], 75, 75) ;
  }
}
void mousePressed() {
  if (bover) { 
    locked = true;
  } 
  else {
    locked = false;
  }
}

void mouseReleased() {
  locked = false;
}

void mouseDragged() {
  if (locked) {
    newx = mouseX; 
    newy = mouseY;
  }
  positions [whichImage*2] = newx;
  positions [(whichImage*2)+1] = newy;
}
</code></pre>

<p>It is working well, you can drag and drop the pictures around, but the problem is that If you are holding one picture and drag it over another, it drops that piece and picks up the one that you were moving over. Why does this happen, and how can I fix it?</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>Problem hitbox, collision between 2 rectangles</title>
      <link>https://forum.processing.org/two/discussion/17266/problem-hitbox-collision-between-2-rectangles</link>
      <pubDate>Wed, 22 Jun 2016 13:17:51 +0000</pubDate>
      <dc:creator>poisson86</dc:creator>
      <guid isPermaLink="false">17266@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I'm trying to have 2 rectangles which can collide each other. I have something that seems good to me but when the first one goes on the second, the image can go through the second but nothing happend until the middle of the image. I thought it was a problem with my coords but they are accurate so i'm pretty lost now.</p>

<p>Here you can take a look on this sample of my project : <a href="http://paste2.org/w4G3etCZ" target="_blank" rel="nofollow">http://paste2.org/w4G3etCZ</a></p>

<p>Have a good day :)</p>
]]></description>
   </item>
   <item>
      <title>I have been having null pointer exception error and string unmatching.</title>
      <link>https://forum.processing.org/two/discussion/16046/i-have-been-having-null-pointer-exception-error-and-string-unmatching</link>
      <pubDate>Sat, 16 Apr 2016 13:58:15 +0000</pubDate>
      <dc:creator>smnbsn</dc:creator>
      <guid isPermaLink="false">16046@/two/discussions</guid>
      <description><![CDATA[<pre><code>import processing.serial.*;
int slideStep = 75;    

PImage currentImage, nextImage; 


int imgIndex = 0; 
int slideOffset; 
String[] fileList ; 
Serial myPort;

class FilterImages implements java.io.FilenameFilter 
{ 

  public boolean accept(File dir, String fname) 
{
    String[] extensions = {".png", ".jpeg", ".gif", ".tga", ".jpg"};


    for (int i = 0; i &lt; extensions.length; i++) { 
      if (fname.toLowerCase().endsWith( extensions[i]))
     {
        return true;

      }
    } 
    return false;
  }
}


void loadFileNames()
 { 
  java.io.File dir = new java.io.File(dataPath(""));

  fileList = dir.list(new FilterImages());
}

void setup()

 {

  size(displayWidth, displayHeight); 
  loadFileNames();  
  imageMode(CENTER); 
  currentImage = loadImage(dataPath("") + fileList[0]);
  currentImage.resize(0, height);

  println(Serial.list()); 

  myPort = new Serial(this, Serial.list()[0], 9600); 
}


void advanceSlide() { 
  imgIndex++; 
  if (imgIndex &gt;= fileList.length) { 
    imgIndex = 0;
  }
  slideOffset = width;
}

void reverseSlide() {
  imgIndex--; 
  if (imgIndex &lt; 0) { 
    imgIndex = fileList.length - 1;
  }
  slideOffset = width * - 1; 
}

void draw() {


  background(0);
  image(currentImage, width/2, height/2); 


  if (slideOffset != 0) { 


    image(nextImage, slideOffset + width/2, height/2);
    if (slideOffset &gt; 0) { 
      slideOffset -= slideStep;
      if (slideOffset &lt; 0) {
        slideOffset = 0;
      }
    }
    if (slideOffset &lt; 0) { 
      slideOffset += slideStep;
      if (slideOffset &gt; 0) {
        slideOffset = 0;
      }
    }
    if (slideOffset == 0) { 
      currentImage = nextImage;
    }
  } 
  else {


    if (myPort.available() &gt; 0) {

      char inByte = myPort.readChar();
      print(inByte); 

      if (inByte == 'F') { 
        advanceSlide(); 
      }
      if (inByte == 'B') {
        reverseSlide();
      }


      nextImage = loadImage(dataPath("") + fileList[imgIndex]); 
      nextImage.resize(0, height);
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to Use Texture on PShape Vertices in a PGraphics Window</title>
      <link>https://forum.processing.org/two/discussion/15808/how-to-use-texture-on-pshape-vertices-in-a-pgraphics-window</link>
      <pubDate>Fri, 01 Apr 2016 21:20:34 +0000</pubDate>
      <dc:creator>zarfsnackler</dc:creator>
      <guid isPermaLink="false">15808@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,</p>

<p>I'm having trouble with a bit of code that looks like it should work fine, but doesn't.</p>

<p>I want to draw a texture on vertices, but all of this is happens inside a PGraphics window.  In the code below, the shape gets drawn just fine with a fill, but if it's a texture then nothing works.  However, when drawn outside of the window the texture works just fine.  You can check by using comment/uncomment on each section.</p>

<p>Is this a bug?  Or is there some unknown solution?</p>

<pre><code>PImage photo;
PGraphics mf;

void setup(){
  size(800, 600, P3D);
  mf = createGraphics(500, 315, P3D);
  background(100);
  photo = loadImage("test.png");
  textureMode(NORMAL);
  imageMode(CENTER);
}

void draw(){
  background(150);

  //pushMatrix();
  //translate(width/2, height/2);
  //noStroke();
  //beginShape();
  // texture(photo);
  // vertex(-mf.width/2, -mf.height/2, 0, 0);
  // vertex(mf.width/2, -mf.height/2, 1, 0);
  // vertex(mf.width/2, mf.height/2, 1, 1);
  // vertex(-mf.width/2, mf.height/2, 0, 1);
  //endShape();
  //popMatrix();

  mf.beginDraw();
   mf.background(50);
   mf.pushMatrix();
   mf.translate(mf.width/2 + 10, mf.height/2 + 10);
   mf.noStroke();
   mf.beginShape();
     //mf.texture(photo);
     mf.fill(255);
     mf.vertex(-mf.width/2, -mf.height/2, 0, 0);
     mf.vertex(mf.width/2, -mf.height/2, 1, 0);
     mf.vertex(mf.width/2, mf.height/2, 1, 1);
     mf.vertex(-mf.width/2, mf.height/2, 0, 1);
   mf.endShape();
   mf.popMatrix();
  mf.endDraw();

  pushMatrix();
  translate(width/2, height/2);
  image(mf, 0, 0);
  popMatrix();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to use fade effect with an image</title>
      <link>https://forum.processing.org/two/discussion/14569/how-to-use-fade-effect-with-an-image</link>
      <pubDate>Thu, 21 Jan 2016 13:10:15 +0000</pubDate>
      <dc:creator>Ríbó</dc:creator>
      <guid isPermaLink="false">14569@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,
I'm working on <a rel="nofollow" href="http://www.cleclic.com/wrentest5">this</a>.
After the images load (it takes a minute) a button should appear in the bottom right.  When you click the button, the image fades and another image appears.  What's happening there is a white rectangle is being repeatedly drawn at 20% opacity, giving a fade-out effect to the images.  That's what I want: but with a .png image; not a rect().</p>

<p>Can someone suggest how to achieve the same effect with a BackgroundImage.png instead of a white rectangle?
I've read a bunch of entries on fade in/out with images but no luck (but I'd say this must have been answered <em>somewhere</em> already.) uploaded the full code <a rel="nofollow" href="https://github.com/Macribo/G3/tree/master/G3">here</a>;
but below is the relevant part:</p>

<pre><code>    fill(255, 17);
      rect(0, 0, width, height);
      sceal.firstLoop(); 
</code></pre>

<p>and firstLoop() is a method of Storyboard.pde which says:</p>

<pre><code>float time = 0;
float a = 0;
float b = 50;
int nowFrame = 0;
int numFrames = 55;
int numConceptPics = 12;
PImage[] story = new PImage[numFrames];
PImage[] conceptPics = new PImage[numConceptPics];
//PImage[] bgImg= new PImage[1];
PImage taunt;

boolean redraw = true;
boolean toFade = false;
boolean showTaunt = false;
boolean runFirstLoop = true;
int setState = 0;

class Storyboard {




  void firstLoop() {

    if (setState ==0) {

      pushMatrix();
      image(story[nowFrame], 0, 0);

      popMatrix();
    }


    if (setState ==1) {

      pushMatrix();
      imageMode(CORNER);
      image (conceptPics[0], 0, 0);
      popMatrix();
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Remove image from array when use</title>
      <link>https://forum.processing.org/two/discussion/14310/remove-image-from-array-when-use</link>
      <pubDate>Thu, 07 Jan 2016 01:57:39 +0000</pubDate>
      <dc:creator>maxarch</dc:creator>
      <guid isPermaLink="false">14310@/two/discussions</guid>
      <description><![CDATA[<p>Hello all!
I have loaded 7 image in an array and create a function that chose and places that image ImagePosition(); . I use the function 7 times and I will like the image does not repeat, ex. 3.png is chosen first I will like that it is not coming back for the next 6 choice. Same thing for the other image 2,3,4,5,6 and 7.</p>

<p>My code at the moment look like that maybe I am not in the good pats to accomplish what I want. Thank in advance for information.</p>

<pre><code>PImage [] icone = new PImage[6]; 
float im1;
float im2;
float x;
float y; 
float s; 
float s2;
int ra;

int rx;
int ry;
int rs;

void setup() {
  frameRate(1);
  size(1000, 1000);
  imageMode(CENTER);
  for (int i = 0; i &lt; icone.length; i++) {
    icone[i] = loadImage (i+".png");
  }
} 

void draw() {
  background(200);

  ImagePosition();
  ImagePosition();
  ImagePosition();
  ImagePosition();
  ImagePosition();
  ImagePosition();
  ImagePosition();
}

void ImagePosition() {
  ra=int(random(6));
  x=(random (0, 10))*100;
  rx = round(x);
  y=(random (0, 10))*100;
  ry = round(y);
  s=(random (1, 5))*100;
  rs = round(s);
  image(icone[ra], rx, ry, rs, rs);

  if (s&lt; 200 ) {
    float i=0;
    float rx2; 
    float ry2; 
    i=0;
    rx2=rs;
    ry2=rs;

    while (i &lt; 9) {
      image(icone[ra], rx+rx2, ry+ry2, rs, rs);
      i= random(0, 10);

      float[] a = {-rs, 0, rs};
      float rb= ( random(0, 2));
      int rb2 = round(rb);
      rx2= rx2+ a[rb2];
      float[] b = {-rs, 0, rs};
      float rby= ( random(0, 2));
      int rb3 = round(rby);
      ry2= ry2+ b[rb3];
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How do I get rid of the white edges on these blurred ellipses?</title>
      <link>https://forum.processing.org/two/discussion/13817/how-do-i-get-rid-of-the-white-edges-on-these-blurred-ellipses</link>
      <pubDate>Mon, 07 Dec 2015 03:24:51 +0000</pubDate>
      <dc:creator>krashe1313</dc:creator>
      <guid isPermaLink="false">13817@/two/discussions</guid>
      <description><![CDATA[<p>So I'm working on a project that randomizes the color and placement of ellipses. Which works(?), based tweaking what I found in the Processing guides on their website. Problem is, if you look at the picture screen shot, where the circles overlap there is a white blurred edge rather than the color of one circle blurring into the next.</p>

<p>Any idea on how to fix this? Or do I need my eyes checked? Thanks!</p>

<pre><code>PImage cir;
    void setup() {
      size(400, 400);


      background(255);
      for(int x = 0; x &lt; 100; x++)
      {
        PGraphics pg = createGraphics(200,200);
        pg.beginDraw();
        pg.background(255,255,255,0);
        pg.fill(random(255), random(255), random(255));
        pg.noStroke();
        pg.ellipse(100,100,50,50);
        pg.filter(BLUR,5);
        pg.endDraw();
        cir = pg.get();
        imageMode(CENTER);
        image( cir, random(width), random(height));
       }
        println("done");
    }
    void draw() {

    }
</code></pre>

<p><img src="http://s21.postimg.org/n07lkzdfb/blurred_Circles.png" alt="" /></p>
]]></description>
   </item>
   <item>
      <title>Online sharing of p5.js sketches that contain image files</title>
      <link>https://forum.processing.org/two/discussion/13473/online-sharing-of-p5-js-sketches-that-contain-image-files</link>
      <pubDate>Tue, 10 Nov 2015 21:04:24 +0000</pubDate>
      <dc:creator>marcusround</dc:creator>
      <guid isPermaLink="false">13473@/two/discussions</guid>
      <description><![CDATA[<p>I'm having trouble finding somewhere that I can host a p5 sketch online which references images.</p>

<p>I tried using CodePen and uploading the images to imgur but this doesn't seem to work. The Chrome console says '403 forbidden' error from imgur.</p>

<p>Here is a barebones sketch which does not work.</p>

<p><a href="http://codepen.io/marcusround/pen/ojQeyR/" target="_blank" rel="nofollow">http://codepen.io/marcusround/pen/ojQeyR/</a></p>

<p>Does anybody have a solution?
Thanks!</p>
]]></description>
   </item>
   <item>
      <title>working with text()</title>
      <link>https://forum.processing.org/two/discussion/6038/working-with-text</link>
      <pubDate>Fri, 27 Jun 2014 17:04:43 +0000</pubDate>
      <dc:creator>MAVW</dc:creator>
      <guid isPermaLink="false">6038@/two/discussions</guid>
      <description><![CDATA[<p>I was wondering, is there a way to work with text() and have your sentences written in multiple lines</p>

<p>"like</p>

<p>this</p>

<p>example"</p>

<p>instead of</p>

<p>"like this example"</p>

<p>I read that it's possible to make a box using two more var. in text() but my text is all oriented by the center, and apparently, this method only allow me to orient it by the top left edge.(tried imageMode(CENTER); and textAlign(CENTER) none of them seem to affect the text using a box to wrap inside it.</p>

<p>SO, is there another way to do that OR there is a way I can use the box AND still orient it by the center?
Thank you for your time :)</p>
]]></description>
   </item>
   </channel>
</rss>