<?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 fill() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=fill%28%29</link>
      <pubDate>Sun, 08 Aug 2021 17:40:21 +0000</pubDate>
         <description>Tagged with fill() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedfill%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How to draw a transparent PGraphics image? [SOLVED]</title>
      <link>https://forum.processing.org/two/discussion/18818/how-to-draw-a-transparent-pgraphics-image-solved</link>
      <pubDate>Tue, 01 Nov 2016 04:22:19 +0000</pubDate>
      <dc:creator>ITman496</dc:creator>
      <guid isPermaLink="false">18818@/two/discussions</guid>
      <description><![CDATA[<p><strong>EDIT:  I do not believe this should be moved to / belongs in the Raspberry Pi category.  The Pi is my motivation for doing this but I am running this at the moment on a normal windows install of Processing.  The Pi is irrelevant for the time being.</strong></p>

<p>I am using processing to make some gauge meters.  My usual method is to draw a lot of primitives, but now that I'm trying to move to use the Raspberry Pi, I've noticed that my previous techniques are too intensive for it and the FPS drop makes it unusable.</p>

<p>So I'm trying a new technique.  To simply draw an overlay to stamp over a primitive that represents the meter, to reduce the math required.  This presents a problem, however, as I can't appear to figure out how to 'draw' transparency into a PGraphics thing.  I want transparency where black is, essentially.  How do I achieve this? I want the ring of black in the square gauge to be transparent and to show whatever I have behind it, in this case, the white pie graph.  I will then draw text on top of this, and it should be a pretty clean way to draw gauges.</p>

<p>Thank you for the help!</p>

<pre><code>PGraphics gaugeoverlay;

void setup() {
  size(500, 500);
  gaugeoverlay = createGraphics(200, 200); gaugeoverlay.beginDraw();
  gaugeoverlay.background(0);
  gaugeoverlay.endDraw();

  drawgauge();
}

void draw() {
  fill(255);
  noStroke();
  arc(100, 100, 170, 170, 0, PI+QUARTER_PI, PIE);

  image(gaugeoverlay, 0, 0);
}

void drawgauge() {
  gaugeoverlay.beginDraw();
  gaugeoverlay.fill(100);
  gaugeoverlay.noStroke();
  gaugeoverlay.rect(10, 10, 180, 180, 10);
  gaugeoverlay.fill(0);
  gaugeoverlay.ellipse(100, 100, 170, 170);
  gaugeoverlay.fill(100);
  gaugeoverlay.ellipse(100, 100, 150, 150);
  gaugeoverlay.endDraw();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Is it possible to set multiple colours within a single function?</title>
      <link>https://forum.processing.org/two/discussion/19410/is-it-possible-to-set-multiple-colours-within-a-single-function</link>
      <pubDate>Wed, 30 Nov 2016 00:53:19 +0000</pubDate>
      <dc:creator>jabobob</dc:creator>
      <guid isPermaLink="false">19410@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone.</p>

<p>Basically I am using string arrays to generate a piece of text randomly and am calling them into a text function by writing;</p>

<p>text(sentences1[n] + sentences2[m], 400, 400);</p>

<p>Is there any way of colouring the output of each array with a different colour? So that one sentence could be blue and the next red for example?</p>
]]></description>
   </item>
   <item>
      <title>Changing font color when mouse pressed</title>
      <link>https://forum.processing.org/two/discussion/26876/changing-font-color-when-mouse-pressed</link>
      <pubDate>Fri, 16 Mar 2018 09:38:58 +0000</pubDate>
      <dc:creator>abigailvjacinto</dc:creator>
      <guid isPermaLink="false">26876@/two/discussions</guid>
      <description><![CDATA[<p>Hi! 
1. I've been trying to add a code such that the font color changes when the mouse clicks on the text. However, nothing's happening.
2. I want to change the font style from Arial, but nothing happens also when I substitute another font name.</p>

<p>This is the link I got the code from (<a href="http://learningprocessing.com/examples/chp17/example-17-06-textbreakingup" target="_blank" rel="nofollow">http://learningprocessing.com/examples/chp17/example-17-06-textbreakingup</a>) Here's the code:</p>

<pre><code>// Example 17-6: Text breaking up 

PFont f;
String message = "click mouse to shake it up";

// An array of Letter objects
Letter[] letters;

void setup() {
  size(480, 270);

  // Load the font
  f = createFont("Arial", 20);
  textFont(f);

  // Create the array the same size as the String
  letters = new Letter[message.length()];

  // Initialize Letters at the correct x location
  int x = 125;
  for (int i = 0; i &lt; message.length (); i ++ ) {
    // Letter objects are initialized with their location within the String as well as what character they should display.
    letters[i] = new Letter(x, 140, message.charAt(i)); 
    x += textWidth(message.charAt(i));
  }
}

void draw() {
  background(255);
  for (int i = 0; i &lt; letters.length; i ++ ) {

    // Display all letters
    letters[i].display();

    // If the mouse is pressed the letters shake
    // If not, they return to their original location
    if (mousePressed) {
      letters[i].shake();
    } else {
      letters[i].home();
    }
  }
}

// A class to describe a single Letter
class Letter {
  char letter;

  // The object knows its original " home " location
  float homex,homey;

  // As well as its current location
  float x,y;

  Letter(float x_, float y_, char letter_) {
    homex = x = x_;
    homey = y = y_;
    letter = letter_;
  }

  // Display the letter
  void display() {
    fill(0);
    textAlign(LEFT);
    text(letter,x,y);
  }

  // Move the letter randomly
  void shake() {
    x += random(-2,2);
    y += random(-2,2);
  }

  // At any point, the current location can be set back to the home location by calling the home() function.
  void home() { 
    x = homex;
    y = homey;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Does loadPixels() take "fill()" function into account ?</title>
      <link>https://forum.processing.org/two/discussion/26382/does-loadpixels-take-fill-function-into-account</link>
      <pubDate>Fri, 16 Feb 2018 15:53:46 +0000</pubDate>
      <dc:creator>ToJah</dc:creator>
      <guid isPermaLink="false">26382@/two/discussions</guid>
      <description><![CDATA[<p>Hi there, ready to look at a beginner's problem ?</p>

<p>I wrote (what i thought would be) a simple function : get (x, y)-point's color values :</p>

<p><code>function getPix(_x, _y) {
  loadPixels();
  let off = (_x + _y * width) * pixelDensity() * 4;
  let result = [ pixels[off], pixels[off + 1], pixels[off + 2], pixels[off + 3] ];
  return result;
}</code></p>

<p>The function seems to work fine : console.log(off) sends back the right index, according to the "_x" &amp; "_y" values, and i get the background's RGBA values.</p>

<p>Now, in <code>Draw</code>, i have an object displaying something. (say a blue square at 0, 0)</p>

<p><code>var col = color(0, 0, 255, 255);
obj.show() {
fill(col);
rect(0, 0, 10, 10);
}</code></p>

<p>But if i am to call <code>getPix(0, 0);</code> again, i still get my background's color as a result : how comes ?
My guess is : loadPixels() loads before my object is shown, but since i'm using this function for the first time, i surely have some misconceptions about the way it works.</p>

<p>The original code is slightly more complex, and i may give it if needed, but this exemple is still pretty much alike.</p>

<p>Thanks for any answer to come :)</p>
]]></description>
   </item>
   <item>
      <title>Can someone explain this code to me?</title>
      <link>https://forum.processing.org/two/discussion/25614/can-someone-explain-this-code-to-me</link>
      <pubDate>Mon, 18 Dec 2017 05:18:48 +0000</pubDate>
      <dc:creator>newcode123</dc:creator>
      <guid isPermaLink="false">25614@/two/discussions</guid>
      <description><![CDATA[<p>This code was given to us in class as an example, but my prof has a rough accent and its hard to understand her. here is the code:</p>

<pre><code>/* Colour Morph
   Example for COMP 1010

   Draw a bar across the centre of the window, with height
   BAR_HEIGHT, that consists of NUM_STEPS rectangles of
   equal width, with the left one having the colour set by
   INIT_RED, INIT_GREEN, INIT_BLUE, and the right one set by
   FINAL_RED, FINAL_GREEN, and FINAL_BLUE, and changing
   smoothly in between.
*/

size(700,200); //Make it wide but not too tall.

final int NUM_STEPS = 8; //The number of different coloured bars to use
final int BAR_HEIGHT = 150; //The height of the bar
final float BAR_WIDTH = (float)width/NUM_STEPS; //The width of each small slice
final float INIT_RED=156, INIT_GREEN=63, INIT_BLUE=178; //Initial colour
final float FINAL_RED=25, FINAL_GREEN=162, FINAL_BLUE=159; //Final colour

for(int i=0; i&lt;NUM_STEPS; i++){
  //i will be 0,1,...,NUMSTEPS-1
  float position = i/(NUM_STEPS-1.0); //A value from 0.0 to 1.0
  float redValue = INIT_RED+(FINAL_RED-INIT_RED)*position;
  float greenValue = INIT_GREEN+(FINAL_GREEN-INIT_GREEN)*position;
  float blueValue = INIT_BLUE+(FINAL_BLUE-INIT_BLUE)*position;
  fill(redValue,greenValue,blueValue);
  stroke(redValue,greenValue,blueValue); //Make the outline match, too.
  rect(i*BAR_WIDTH,(height-BAR_HEIGHT)/2,BAR_WIDTH,BAR_HEIGHT);
}//for
</code></pre>

<p>In the loop, why do we use those operations? If I was asked to code this on an exam, how would I know to do that?? I dont get the logic behind it</p>
]]></description>
   </item>
   <item>
      <title>Giving background images to shapes (ie. rect(),ellipse()..)</title>
      <link>https://forum.processing.org/two/discussion/19919/giving-background-images-to-shapes-ie-rect-ellipse</link>
      <pubDate>Sun, 25 Dec 2016 17:59:11 +0000</pubDate>
      <dc:creator>Thebndjames</dc:creator>
      <guid isPermaLink="false">19919@/two/discussions</guid>
      <description><![CDATA[<p>Hello p5.js forums! :) 
So i have been wondering if there was a built in function that gives a background image to a certain shape, like, let's say i want to draw a 100x100 rect and give it a fill of an image.
normally with colors, we use the following :
<code>fill(255);
rect(0,0,100,100);</code>
The rectangle will appear to be white, well, i was hoping for a function like the following :
<code>fillImg("url: ('/assets/prog.jpg')");
rect(0,0,100,100);</code>
Now, i'm fully aware of the image(); and the loadImage(); functions, but those are not as functional as using a background image for say a triangle(); 
Now in normal javascript, you can use fillStyle to give a shape a background image, so i think we should be able to construct a function to do so in p5.js
<code>var shape=document.getElementById("myCanvas").getContext("2d");
var img=document.getElementById("img");
var bg=shape.createPattern(img,"no-repeat");
shape.rect(0,0,150,100);
shape.fillStyle=bg;</code>
someting like shape.fillStyle would be very helpful in p5.js :)
I hope my idea was clear enough for you understanding :)</p>
]]></description>
   </item>
   <item>
      <title>Messed up "if" statements with draw()?</title>
      <link>https://forum.processing.org/two/discussion/18252/messed-up-if-statements-with-draw</link>
      <pubDate>Thu, 22 Sep 2016 22:04:09 +0000</pubDate>
      <dc:creator>snarski</dc:creator>
      <guid isPermaLink="false">18252@/two/discussions</guid>
      <description><![CDATA[<p>Edit: Solved -- question can be deleted.</p>

<p>I believe I'm misunderstanding something about how the <code>draw()</code> function works. Below is a minimal working example of what I have in mind. The conditional 'if' statement seems to be reversing the fill colour. Rectangles should be in red, ellipses in blue.</p>

<p>Instead, the rectangle shows up in blue, while the circle shows up in red. If I only <code>display(0)</code> or <code>display(1)</code>, then the correct colour shows up. Any thoughts?</p>

<p>Thanks for any help!</p>

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

void draw() {
  display(0);
  display(1);
}

void display(int i) {    
    if(i == 0) {      
      rect(20, 20, 40, 40);
      fill(200, 0, 0); // rectangles are red!
    }
    if(i == 1) {
      ellipse(100, 100, 20, 20);
      fill(0, 0, 200); // circles are blue!
    }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Array of Colors</title>
      <link>https://forum.processing.org/two/discussion/17621/array-of-colors</link>
      <pubDate>Sat, 23 Jul 2016 01:10:10 +0000</pubDate>
      <dc:creator>mads2</dc:creator>
      <guid isPermaLink="false">17621@/two/discussions</guid>
      <description><![CDATA[<p>Trying to set up a colored grid where each square alternates between 1 of 5 colors every second or two. Can't seem to figure out how to call on the "fill" for all of the modules within my code. The variable c1 is where my colors are. I feel like I'm close..? Also these squares will be changing size later based on frequencies from the song input, which is why I've set it up this way so far.</p>

<pre><code>var song;


var c1r1 = {
  x:100,
  y:100
  }

var c2r1 = {
  x:260,
  y:100
  }

var c3r1 = {
  x:420,
  y:100
  }

var c4r1 = {
  x:570,
  y:100
}

var c5r1 = {
  x:720,
  y:100
}

var c1r2 = {
  x:100,
  y:260
  }

var c2r2 = {
  x:260,
  y:260
  }

var c3r2 = {
  x:420,
  y:260
  }

var c4r2 = {
  x:570,
  y:260
  }

var c5r2 = {
  x:720,
  y:260
}

var c1r3 = {
  x:100,
  y:420
}

var c2r3 = {
  x:260,
  y:420
}

var c3r3 = {
  x:420,
  y:420
}

var c4r3 = {
  x:570,
  y:420
}

var c5r3 = {
  x:720,
  y:420
}

var c1r4 = {
  x:100,
  y:580
}

var c2r4 = {
  x:260,
  y:580
}

var c3r4 = {
  x:420,
  y:580
}

var c4r4 = {
  x:570,
  y:580
}

var c5r4 = {
  x:720,
  y:580
}

var c1 = [
  fill(243, 158, 34),
  fill(57, 178, 136), 
  fill(239, 73, 36),
  fill(234, 130, 36),
  fill(66, 104, 177)
  ];


function preload() {
  song = loadSound('assets/findingnemoegg.mp3');
}


function setup () {
  createCanvas (windowWidth, windowHeight);
  song.loop();
  background (18,21,34);

    for (var i = 0; i &lt; 4; i++) {
      c1[i] = [];
    }


}



function draw () {

  noStroke();
  for (var i = 0; i &lt; 4; i++) {
    fill(c1[i]);
  }

  rect(c1r1.x, c1r1.y, 50, 50, 12);
  rect(c2r1.x, c2r1.y, 50, 50, 12);
  rect(c3r1.x, c3r1.y, 50, 50, 12);
  rect(c1r2.x, c1r2.y, 50, 50, 12);
  rect(c2r2.x, c2r2.y, 50, 50, 12);
  rect(c3r2.x, c3r2.y, 50, 50, 12);
  rect(c4r1.x, c4r1.y, 50, 50, 12);
  rect(c5r1.x, c5r1.y, 50, 50, 12);
  rect(c4r2.x, c4r2.y, 50, 50, 12);
  rect(c5r2.x, c5r2.y, 50, 50, 12);
  rect(c1r3.x, c1r3.y, 50, 50, 12);
  rect(c2r3.x, c2r3.y, 50, 50, 12);
  rect(c3r3.x, c3r3.y, 50, 50, 12);
  rect(c4r3.x, c4r3.y, 50, 50, 12);
  rect(c5r3.x, c5r3.y, 50, 50, 12);
  rect(c1r4.x, c1r4.y, 50, 50, 12);
  rect(c2r4.x, c2r4.y, 50, 50, 12);
  rect(c3r4.x, c3r4.y, 50, 50, 12);
  rect(c4r4.x, c4r4.y, 50, 50, 12);
  rect(c5r4.x, c5r4.y, 50, 50, 12);



}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Beginner's question about the FILL command</title>
      <link>https://forum.processing.org/two/discussion/17029/beginner-s-question-about-the-fill-command</link>
      <pubDate>Tue, 07 Jun 2016 19:33:20 +0000</pubDate>
      <dc:creator>Boekenknul</dc:creator>
      <guid isPermaLink="false">17029@/two/discussions</guid>
      <description><![CDATA[<p>This is driving me insane and I cannot seem to find any explanation.</p>

<p>Why are (in the following code) multiple shapes in the fill color (150)  even though the fill command is the last command in the DRAW zone. I thought only subsequent shapes would be filled in that color - but it is also filling in earlier shapes in the same (150) grey.</p>

<pre><code>void setup() {
    size(640,420);
    background(240);
    smooth();
}

void draw() {

  //body of zork
  rectMode(CENTER);
  rect(320,210,80,120);

  //head of zork
  ellipse(320,118,65,65);

  //eyes of zork
  //fill(50);
  ellipse(307,115,10,20);
  ellipse(333,115,10,20);
  fill(150);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How do I place different colored ellipses on a map while using latitude and longitude?</title>
      <link>https://forum.processing.org/two/discussion/13829/how-do-i-place-different-colored-ellipses-on-a-map-while-using-latitude-and-longitude</link>
      <pubDate>Mon, 07 Dec 2015 22:15:00 +0000</pubDate>
      <dc:creator>rpifer94</dc:creator>
      <guid isPermaLink="false">13829@/two/discussions</guid>
      <description><![CDATA[<p>This is a for a school assignment so I'm really new to Processing, but I'm wanting to use 4 different colored ellipses to convey information being taken from an xml sheet and plotting them on a map using latitude and longitude. I have the coding working but only for one color, is there a way to change this so I can control multiple colors at once?</p>

<pre><code> PShape baseMap;
 String csv[];
  String myData[][];

  //Setup BaseMap and csv info

  void setup() {
    size(3000, 1700);
    noLoop();
    baseMap = loadShape("WorldMap.svg");
    csv = loadStrings("WeatherCoordinates.csv");
    myData = new String[csv.length][5];
    for(int i=0; i&lt;csv.length; i++) {

      myData[i] = csv[i].split(",");


 }
 }


 //draw
 void draw() {
   shape(baseMap, 0, 0, width, height);
   noStroke();


   for(int i=0; i&lt;myData.length; i++){
     fill(25, 30, 255, 70);
     noStroke();
     float graphLong = map(float(myData[i][3]), -180, 180, 0, width);
     float graphLat = map(float(myData[i][2]), 90, -90, 0, height);
     float markerSize = 5*(float(myData[i][0]));
    println(graphLong + " / " + graphLat);  
    ellipse(graphLong, graphLat, markerSize, markerSize);


   if(i&lt;25){
     fill(0);
     text(myData[i][1], graphLong + markerSize + 30, graphLat);
     noFill();
     stroke(0);
     line(1.2*graphLong+markerSize, graphLat, graphLong+markerSize, graphLat);
      }
     }
   }
 }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Is there a way to target children within a .SVG file?</title>
      <link>https://forum.processing.org/two/discussion/12954/is-there-a-way-to-target-children-within-a-svg-file</link>
      <pubDate>Mon, 12 Oct 2015 01:25:42 +0000</pubDate>
      <dc:creator>Uraeu5</dc:creator>
      <guid isPermaLink="false">12954@/two/discussions</guid>
      <description><![CDATA[<p>My question maybe poorly worded, I just started teaching myself programming about a month ago or so, so you'll have to forgive me.</p>

<p>Basically I want to load multiple complex svg files and change the alphas of individual children within each svg without having to load each child separately.  The following code I wrote as a simplified example of what I want to achieve just not how I'd like to achieve it.  I think there might be an easier way to do this.  Thanks.</p>

<pre><code>PShape circle;
PShape tp;
PShape bm;
void setup(){
size(600,600);
background(#0066CC);
circle = loadShape("circle.svg");
tp = circle.getChild("top");
bm = circle.getChild("bottom");

tp.disableStyle();
fill(#000000, 100);
stroke(#995C1F);
shape(tp,0,0,width,height);

bm.disableStyle();
fill(#B2B247);
stroke(#995C1F);
shape(bm,0,0,width,height);


}
</code></pre>

<p><img src="http://forum.processing.org/two/uploads/imageupload/446/G1AVG62MF35N.jpg" alt="circle" title="circle" /></p>
]]></description>
   </item>
   <item>
      <title>Using fill() on objects with for loop</title>
      <link>https://forum.processing.org/two/discussion/12991/using-fill-on-objects-with-for-loop</link>
      <pubDate>Tue, 13 Oct 2015 21:31:04 +0000</pubDate>
      <dc:creator>lgouvin</dc:creator>
      <guid isPermaLink="false">12991@/two/discussions</guid>
      <description><![CDATA[<p>I'm creating a game in Processing which allows you to color a grid of rectangles as they become highlighted one by one.</p>

<p>I'm trying to color an array of objects using a for loop and the fill() function, but when I use it, it colors not only colors the current rectangle in the array (which would be correct), but also all previous rectangles. I want it to only color the current rectangle.</p>

<pre><code>    void setup () {
      size (1200, 700);
      background (255, 255, 255);
      smooth();
      rect = new Rectangle [count]; //creates a grid of possible rectangles, based on the dimensions of the screen
      for (int i = 0; i&lt;= (count-1); i++) {
        fill (255, 255, 255);
        ypos = ypos + heigh;
        if (ypos &gt;= 700) {
          ypos = 0;
          xpos = xpos + wid;
        }
        rect[i] = new Rectangle(xpos, ypos, wid, heigh, redPressed, greenPressed, yellowPressed, bluePressed, blackPressed);
      }
      int now = millis();
    }

    void draw() {
      for (int i = 0; i &lt; control; i++) {
        if (keyPressed) { //detects if key is pressed and colors the current rectangle that way
          if (key == 'r' ||key == 'R') {
            fill (255, 0, 0);
          }
          if (key == 'g' ||key == 'G') {
            fill (0, 255, 0);
          }
          if (key == 'y' || key == 'Y') {
            fill (255, 255, 0);
          }
          if (key == 'b' || key == 'B') {
            fill (0, 0, 255);
          }
          if (key == 'k' || key == 'K') {
            fill (0, 0, 0);
          }
        }
        stroke (0, 0, 0);
        rect (rect[i].xpos, rect[i].ypos, rect[i].xdim, rect[i].ydim); //draws the current rectangle, moving through the grid
      }
      if (millis() - now &gt;= wait) { //causes a 1 second delay between rectangles
        now = millis();
        control++;
        if (control &gt; (count-1)) {
          control = (count-1);
          i = 0;
        }
      }
    }
</code></pre>

<p>Thanks in advance!</p>
]]></description>
   </item>
   <item>
      <title>Growing Circle on Mouse Move</title>
      <link>https://forum.processing.org/two/discussion/12899/growing-circle-on-mouse-move</link>
      <pubDate>Thu, 08 Oct 2015 22:20:44 +0000</pubDate>
      <dc:creator>emmjay</dc:creator>
      <guid isPermaLink="false">12899@/two/discussions</guid>
      <description><![CDATA[<p>Hello.</p>

<p>I am new to processing and I need help. I want to make an active processing program that makes a circle grow in size when you move the mouse away from the center of the screen, and shrinks in size when the mouse is moved back towards the center of the screen. Also, i want the circle to gradually get darker in color when moving away from the center of the screen.</p>
]]></description>
   </item>
   <item>
      <title>How can I change the colour of a square when it is clicked</title>
      <link>https://forum.processing.org/two/discussion/12825/how-can-i-change-the-colour-of-a-square-when-it-is-clicked</link>
      <pubDate>Sun, 04 Oct 2015 20:38:21 +0000</pubDate>
      <dc:creator>onlinebigbird</dc:creator>
      <guid isPermaLink="false">12825@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I am trying to change the colour of two squares when clicked. I would like to be able to change them independently of eachother. If the square clicked is black I would like it to turn yellow, and vice-versa. Just to mention, my sketchpad is embedded in a webpage, hence the 'processing.'</p>

<p>The coordinates for the top square are: x: 290, x:290+20, y260 and y260+20.</p>

<p>I <em>think</em> I need to insert this line of code somewhere in the function but I'm not sure how to write it correctly.<br />
&amp;&amp; mouseX&gt;290 &amp;&amp; mouseX&lt;290+20 &amp;&amp; mouseY&gt;260 &amp;&amp; mouseY&lt;260+20</p>

<p>The coordinates for the bottom square are: x: 290, x:290+20, y320 and y320+20.
&amp;&amp; mouseX&gt;290 &amp;&amp; mouseX&lt;290+20 &amp;&amp; mouseY&gt;320 &amp;&amp; mouseY&lt;320+20</p>

<p>Also, I am not sure of the correct syntax for writing the RGB value in teh function. If I put brackets it doesn't work, but if I have no brackets it just changes between white and black.</p>

<p><strong>This is what I have so far</strong>:</p>

<pre><code>function doodle (processing) {
      processing.setup = function () {
      processing.size (500, 500);
     processing.background (138, 153, 245)
}

             processing.draw = function () {
            /* top window
     */
     processing.fill (top);
    processing.rect (290, 260, 20, 20);

     /* bottom window
     */
    processing.fill (bottom);   
    processing.rect (290, 320, 20, 20); 

    }

    processing.mouseClicked = function () {
        if 
            (bottom ==0) {
            bottom = (255, 183, 51);
        } else {
            bottom = 0;
        }
    }

            processing.mouseClicked = function () {
        if 
            (top ==0) {
            top = (255, 183, 51);
        } else {
            top = 0;
        }
    }
</code></pre>

<p>}</p>

<p>var top = 0;
var bottom = 0;
var canvas = document.getElementById('sketch');
new Processing (canvas, doodle);</p>

<hr />

<p>thank you!****</p>
]]></description>
   </item>
   <item>
      <title>Checkerboard Problems</title>
      <link>https://forum.processing.org/two/discussion/12625/checkerboard-problems</link>
      <pubDate>Mon, 21 Sep 2015 20:56:00 +0000</pubDate>
      <dc:creator>annpatrick</dc:creator>
      <guid isPermaLink="false">12625@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to create a checkerboard (320x320, 8 rows/columns) that uses loops to fill in the colors (black and red). My current issue is it's duplicating at the top (and I'm not really sure why it's running at all).</p>

<p>Full disclosure, my current code is based on several helpful forum answers:</p>

<p>` 
      int squareSize = 40; // Dimensions ask for 40x40
      int cols, rows;</p>

<pre><code>  void setup() {
  size(320, 320); // Specified by assignment

  // Initialize columns and rows
  cols = 8; // Specified by assignment | size/squareSize
  rows = 8; // Specified by assignment | size/squareSize
  }

  void draw() {

  // Begin loop for columns
  for (int i = 0; i &lt; cols; i++) {
  // Begin loop for rows
  for (int j = 0; j &lt; rows; j++) {

  // Scaling up to draw a rectangle at (x,y)
  int x = i*squareSize; // width
  int y = j*squareSize; // height

  // For every column and row, a rectangle is drawn at an (x,y) location scaled and sized by videoScale.
  rect(x,y,squareSize,squareSize);

  // Begin fill controls
  if ((i+j) % 2 == 0) { // Even is red
    fill(250, 0, 0);
  }

  else { // Odd is black
    fill(0); } 
  }
 }
 }
</code></pre>

<p>`</p>

<p>My results are: <img src="http://i60.tinypic.com/xkyk47.jpg" alt="" />. Firstly, I'm not even sure why this code works past the first two rows: ((i + j) % 2) should always == 0 given rows and cols are set up to always create an even result, which means I should be getting all red squares, I think.</p>

<p>If someone could explain a) why I'm getting these results and/or b) what I should look into fixing (is it my for loops? do I need more if statements?) to make it generate a proper checkerboard pattern, I'd appreciate it very much.</p>
]]></description>
   </item>
   <item>
      <title>Is it possible to create an indexed list (array) of RGB values for "fill()"?</title>
      <link>https://forum.processing.org/two/discussion/12490/is-it-possible-to-create-an-indexed-list-array-of-rgb-values-for-fill</link>
      <pubDate>Sun, 13 Sep 2015 00:04:29 +0000</pubDate>
      <dc:creator>SteveC</dc:creator>
      <guid isPermaLink="false">12490@/two/discussions</guid>
      <description><![CDATA[<p>I'm creating a (10 bar) bar graph inside a 'for' loop, and want to 'fill' each bar in a different colour from an indexed list (or array) of RGB colours.
I'm sure it must be possible, but everything I've tried has failed. :(</p>

<p>Does anyone know how this could be done?</p>

<p>To help it make sense, this is the size statement:  size(600,200);</p>

<p>Here's the 'for' loop:-</p>

<p><code>for(Index=0;Index&lt;10;Index++)
        {
            InBuffer[Index]=MyPort.read();
            fill(&lt;*indexed RGB value*&gt;);
            rect(Index*60,200,60,-InBuffer[Index]);
        }</code></p>

<p>(This is my first 'real' sketch.)</p>

<p>Thanks in advance, guys.</p>
]]></description>
   </item>
   <item>
      <title>Error with fill(float)</title>
      <link>https://forum.processing.org/two/discussion/12438/error-with-fill-float</link>
      <pubDate>Tue, 08 Sep 2015 14:59:01 +0000</pubDate>
      <dc:creator>w1jp</dc:creator>
      <guid isPermaLink="false">12438@/two/discussions</guid>
      <description><![CDATA[<p>I am getting an error stating fill(int) is expecting an int.</p>

<p>I am trying to leverage the fill(float gray) method and I have changed my colorMode(RGB, 1.0).</p>

<pre><code>// ©Jon Pellant 2015

// globals
float span = 4.0;

void setup() {
  //
  size (400, 400);
  colorMode(RGB, 1.0);
  for (int i = 0; i &lt; width; i++) {
    for (int j = 0; j &lt; height; j++) {
      // draw a point
      fill(ImprovedPerlinNoise.noise(span/i, span/j, 0)); // ImprovedPerlinNoise returns double
      point (i,j);
    }
  } 
}
</code></pre>

<p>! It appears that the code interpreter is not working on my post.</p>
]]></description>
   </item>
   <item>
      <title>Trying to fade into background</title>
      <link>https://forum.processing.org/two/discussion/11572/trying-to-fade-into-background</link>
      <pubDate>Sun, 05 Jul 2015 19:10:45 +0000</pubDate>
      <dc:creator>SimplyEnvision</dc:creator>
      <guid isPermaLink="false">11572@/two/discussions</guid>
      <description><![CDATA[<p>Hi there!</p>

<p>Here's a bit of a stupid question I can't figure out:</p>

<p>So I'm trying to paint circles that fade away with time. So it was suggested to me that the easiest way to do this was to just paint the background with a high transparency, so that it looks like everything is fading. So I think that to do this background(0,0,0,1) should paint the background on barely visible.</p>

<p>This is the related code:</p>

<pre><code>    if (runMode == 6) {
      backgroundCounter++;
      if (flagNoteFrequency == 1) {
        background(0);
        flagNoteFrequency++;
      }
      colorMode(HSB, 100);
      if (backgroundCounter == 300){
        background(0,0,0,1);
        backgroundCounter = 0;
      }
      for (int i = 0; i &lt; bands; i++) {
        float[][] dominantFreq = dominantFreq(filter((limitFreq/bands) * (i), (limitFreq/bands) * (i+1), filter.fftArray));
        //float[][] dominantFreq = dominantFreq(arrayResult);

        noteFrequency(dominantFreq, i+1, bands);
      }
    }  
  }
</code></pre>

<p>So basically, I use the flagNoteFrequency to paint a black background once at the start. And then I use a counter to slow down the fading, background(0,0,0,1); should then paint a nearly transparent "black background" on top of what was there previously. <strong>However, when I run this it just paints over completely opaque</strong> after 5 seconds (300 from the counter / 60 fps).
noteFrequency takes care of drawing the circles.</p>

<p>I'm doing something wrong with background(0,0,0,1); I tried also background(0,0,0,0.0000000001) and similar but that's not the issue. I've looked up the alpha and 0 should be transparent, right?</p>
]]></description>
   </item>
   <item>
      <title>[SOLVED] Is stroke applied after fill?</title>
      <link>https://forum.processing.org/two/discussion/11140/solved-is-stroke-applied-after-fill</link>
      <pubDate>Wed, 03 Jun 2015 19:45:19 +0000</pubDate>
      <dc:creator>khoma</dc:creator>
      <guid isPermaLink="false">11140@/two/discussions</guid>
      <description><![CDATA[<p>Hi</p>

<p>I'm creating a simple breakout game where in when a block is hit it moves out of the screen at a certain pace, and then disappears. I would like said block to be drawn on top of any block that is still stationary. It works only partially. For some reason the fill of the moving block is drawn on top of the fill of the stationary block, but the stroke of the stationary block shows through the moving block. Image here:
<img src="http://s11.postimg.org/dwxsombhf/processing_stroke_fill.png" alt="" /></p>

<p>The moving blocks are drawn after the stationary blocks. The code for drawing a block looks like this:</p>

<pre><code>    @ Override
    public void draw() {
        if (doomed) {
            x += velocity * cos(angle);
            y += velocity * sin(angle);
        }
        if (x &lt; 0 || x &gt; width || y &lt; 0 || y &gt; height) {
            dead = true;
        } else {
            strokeCap(SQUARE);
            fill(red, green, blue);
            stroke(0);
            rect(x, y, w, h);
            noStroke();
            fill(red + lowerColor, green + lowerColor, blue + lowerColor);
            triangle(x, y + blockHeight, x + blockWidth, y + blockHeight, x + blockWidth, y);
            fill(red + upperColor, green + upperColor, blue + upperColor);
            rect(x + bevel * cos(bevelAngle), y + bevel * sin(bevelAngle), blockWidth - 2 * bevel * cos(bevelAngle), blockHeight - 2 * bevel * sin(bevelAngle));
        }
    }
</code></pre>

<p>The main draw loop called by processing looks like this, where blockArray contain all the stationary blocks, and doomedBlockArray contains all the moving blocks:</p>

<pre><code>@ Override
public void draw() {
    if (firstRun &amp;&amp; frame != null) {                    // Lock frame size
        frame.setResizable(false);
        firstRun = false;
    }

    background(230);                                    // Clear frame

    if (blockArray.size() == 0) {
        levelUp();
    }

    blockIterator = blockArray.iterator();              // Draw stationary blocks
    while (blockIterator.hasNext()) {
        blockIterator.next().draw();
    }

    doomedBlockIterator = blockArrayOfDoom.iterator();  // Draw moving blocks
    while (doomedBlockIterator.hasNext()) {
        block = doomedBlockIterator.next();
        if (block.isDead()) {
            doomedBlockIterator.remove();               // Remove if block is outside screen
        } else {
            block.draw();
        }
    }

    drawableIterator = drawablesArray.iterator();       // Draw anything else
    while (drawableIterator.hasNext()) {
        drawableIterator.next().draw();
    }
}
</code></pre>

<p>As you can see, the "doomed" blocks are drawn after the regular blocks, and yet the stroke from the regular blocks overlap the doomed blocks. Is this normal, can it be avoided?</p>

<p>Any help much appreciated!</p>

<p>Edit:</p>

<p>Solved after changing from P3D to P2D renderer!</p>
]]></description>
   </item>
   <item>
      <title>help (serpentining)</title>
      <link>https://forum.processing.org/two/discussion/10936/help-serpentining</link>
      <pubDate>Thu, 21 May 2015 14:22:13 +0000</pubDate>
      <dc:creator>ZulrahSeto</dc:creator>
      <guid isPermaLink="false">10936@/two/discussions</guid>
      <description><![CDATA[<p>could someone help me get started on this project?</p>

<ol>
<li><p>Make a row of 20 squares. Make their fill colour gradually change from white to black, slowly over time.</p></li>
<li><p>Now make them go back to white, slowly over time.</p></li>
<li><p>Now make it look as though the change occurs as a "wave" of white moving through the row of boxes, from left to right (and then wraps). (If this sounds weird, don't worry, I'll explain at the board.)</p></li>
<li><p>CHALLENGE: Now, instead of a single row, make it a 20x20 grid of squares! The "ripple" propagates through the grid, one row at a time: left to right in row 1, then right to left in row 2, etc. This is called "serpentining", for reasons which may or may not be obvious :)</p></li>
</ol>
]]></description>
   </item>
   <item>
      <title>Issue with color alpha</title>
      <link>https://forum.processing.org/two/discussion/10291/issue-with-color-alpha</link>
      <pubDate>Mon, 13 Apr 2015 00:05:22 +0000</pubDate>
      <dc:creator>Ucodia</dc:creator>
      <guid isPermaLink="false">10291@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I was trying to process a PImage to change particular pixels to become transparent but I could not get it to work. For example this would only turn the pixels to black:</p>

<pre><code>img.loadPixels();
for (int x = 0; x &lt; img.width; x++) {
    for (int y = 0; y &lt; img.height; ++y) {
        if (x &lt; y)
            img.set(x, y, color(0, 0));
    }
}
img.updatePixels();
</code></pre>

<p>So I tried in a simpler sketch and realized that the 3 rectangles in this sample would have different fill, one transparent, one almost transparent and one black (not expected with alpha to 0):</p>

<pre><code>size(500, 200);
fill(0, 0);
rect(100, 50, 100, 100);
fill(color(0, 1));
rect(200, 50, 100, 100);
fill(color(0, 0));
rect(300, 50, 100, 100);
</code></pre>

<p>Can someone explain why does the pixels turn black instead of being transparent?</p>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Low alpha values making transparent fills imperfect</title>
      <link>https://forum.processing.org/two/discussion/10180/low-alpha-values-making-transparent-fills-imperfect</link>
      <pubDate>Sat, 04 Apr 2015 17:42:32 +0000</pubDate>
      <dc:creator>ikarth</dc:creator>
      <guid isPermaLink="false">10180@/two/discussions</guid>
      <description><![CDATA[<p>I've got the following code:</p>

<pre><code>void setup() {
  size(400, 400);
  colorMode(RGB,255,255,255,255);
  background(color(51, 85, 204));
  noStroke();  
}

void draw() {
  fill(color(255), 1);
  rect(0,0,width/2, height);
  fill(color(255), 100);
  rect((width/2) - 10, (height/2) - 10, 20, 20); 
}
</code></pre>

<p>My expectation is that the alpha value on the left rect would result in a transparent rectangle that gradually fades to white, but it seems to stop at an off-white. Increasing the alpha gets it closer to white, but any low value (below 35 or so) seems to result in an imperfect fading effect.</p>

<p>Is this just a result of the color values being integers rather than floats, or is there something else going on? And is there any way to fix this, other than just increasing the alpha?</p>
]]></description>
   </item>
   </channel>
</rss>