<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Exercise 6-8: Nested for loop</title>
	<atom:link href="http://www.learningprocessing.com/exercises/chapter-6/exercise-6-8/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learningprocessing.com</link>
	<description>A Beginner's Guide to Programming Images, Animation, and Interaction by Daniel Shiffman</description>
	<lastBuildDate>Thu, 09 Feb 2012 16:27:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: maria</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-8/comment-page-1/#comment-20504</link>
		<dc:creator>maria</dc:creator>
		<pubDate>Sun, 01 May 2011 23:12:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=966#comment-20504</guid>
		<description>This is what I came up with:
float x=0;
float y=0;

void setup(){
  size(200,200);
  background(255);
  smooth();
  noStroke();
  //put this whole chunk under here into the void draw 
  //section for continuous random strobe!
  for(x = 0; x &lt; width; x+=10){
      for (y = 0; y &lt; height; y+=10){
        float r= random(255);
        float b= random(255);
        float g= random(255);
        fill(r,g,b);
        rect(x,y,20,20); 
}
  }
  }
If I put it in the void draw() section the colors change continuously. I think @NQATSi came up with a cool solution for that. Thanks for the &quot;fill(random(255),random(255),random(255));&quot; I don&#039;t know why that slipped my mind and I did it the long way...</description>
		<content:encoded><![CDATA[<p>This is what I came up with:<br />
float x=0;<br />
float y=0;</p>
<p>void setup(){<br />
  size(200,200);<br />
  background(255);<br />
  smooth();<br />
  noStroke();<br />
  //put this whole chunk under here into the void draw<br />
  //section for continuous random strobe!<br />
  for(x = 0; x &lt; width; x+=10){<br />
      for (y = 0; y &lt; height; y+=10){<br />
        float r= random(255);<br />
        float b= random(255);<br />
        float g= random(255);<br />
        fill(r,g,b);<br />
        rect(x,y,20,20);<br />
}<br />
  }<br />
  }<br />
If I put it in the void draw() section the colors change continuously. I think @NQATSi came up with a cool solution for that. Thanks for the &quot;fill(random(255),random(255),random(255));&quot; I don&#039;t know why that slipped my mind and I did it the long way&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-8/comment-page-1/#comment-20428</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Fri, 18 Mar 2011 00:39:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=966#comment-20428</guid>
		<description>You are right if you did this:


int x = 0;
int y = 0;
for (int i = 0; i &lt; 10; i++) {
  rect(x,y,10,10);
  x += 10;
  y += 10;
}


But because the loops are nested, i.e.


for (int x = 0; x &lt; width; x+=10) {
  for (int y = 0; y &lt; height; y+=10) {


You are saying &quot;For every column x, draw a rectangle at every row y.&quot;</description>
		<content:encoded><![CDATA[<p>You are right if you did this:</p>
<p>int x = 0;<br />
int y = 0;<br />
for (int i = 0; i &lt; 10; i++) {<br />
  rect(x,y,10,10);<br />
  x += 10;<br />
  y += 10;<br />
}</p>
<p>But because the loops are nested, i.e.</p>
<p>for (int x = 0; x &lt; width; x+=10) {<br />
  for (int y = 0; y &lt; height; y+=10) {</p>
<p>You are saying &#8220;For every column x, draw a rectangle at every row y.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Gonzalez</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-8/comment-page-1/#comment-20420</link>
		<dc:creator>David Gonzalez</dc:creator>
		<pubDate>Tue, 15 Mar 2011 23:28:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=966#comment-20420</guid>
		<description>I figured this out by trial and error, and came here thinking there was a more sensical way, turns out what I thought was nonsense is logical. I don&#039;t understand why these create a grid. If x and y are incrementing by 10 it seems like this code should result in a line of 10x10 rects going diagonally from upper right to lower left.

Would someone be willing to correct my thinking?</description>
		<content:encoded><![CDATA[<p>I figured this out by trial and error, and came here thinking there was a more sensical way, turns out what I thought was nonsense is logical. I don&#8217;t understand why these create a grid. If x and y are incrementing by 10 it seems like this code should result in a line of 10&#215;10 rects going diagonally from upper right to lower left.</p>
<p>Would someone be willing to correct my thinking?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: NQATSi</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-8/comment-page-1/#comment-15102</link>
		<dc:creator>NQATSi</dc:creator>
		<pubDate>Sat, 06 Nov 2010 13:57:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=966#comment-15102</guid>
		<description>Awesome!

If you put this inside draw(), you get a noise effect!
And I made a color gradient with nested loops:

size(200,200);
noStroke();
background(0);
colorMode(RGB,200,200,200);

for (int i=0;i&lt;width;i+=25) {
 _for (int j=0;j&lt;height;j+=25) {
 __fill(i,j,0);
 __rect(i,j,25,25);
 _}
}

very cool!! : )</description>
		<content:encoded><![CDATA[<p>Awesome!</p>
<p>If you put this inside draw(), you get a noise effect!<br />
And I made a color gradient with nested loops:</p>
<p>size(200,200);<br />
noStroke();<br />
background(0);<br />
colorMode(RGB,200,200,200);</p>
<p>for (int i=0;i&lt;width;i+=25) {<br />
 _for (int j=0;j&lt;height;j+=25) {<br />
 __fill(i,j,0);<br />
 __rect(i,j,25,25);<br />
 _}<br />
}</p>
<p>very cool!! : )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ps</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-8/comment-page-1/#comment-7177</link>
		<dc:creator>ps</dc:creator>
		<pubDate>Tue, 01 Dec 2009 01:57:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=966#comment-7177</guid>
		<description>Thank you!</description>
		<content:encoded><![CDATA[<p>Thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Shiffman</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-8/comment-page-1/#comment-7148</link>
		<dc:creator>Daniel Shiffman</dc:creator>
		<pubDate>Mon, 30 Nov 2009 02:01:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=966#comment-7148</guid>
		<description>Here&#039;s how it looks with a while loop.  Note the difference regarding where you increment x and y.
&lt;pre&gt;
int x = 0;
while (x &lt; width) {
  int y = 0;
  while (y &lt; height) {
    noStroke();
    fill(random(255));
    rect(x,y,10,10);
    y += 10;
  }
  x += 10;
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Here&#8217;s how it looks with a while loop.  Note the difference regarding where you increment x and y.</p>
<pre>
int x = 0;
while (x &lt; width) {
  int y = 0;
  while (y &lt; height) {
    noStroke();
    fill(random(255));
    rect(x,y,10,10);
    y += 10;
  }
  x += 10;
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: ps</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-8/comment-page-1/#comment-7142</link>
		<dc:creator>ps</dc:creator>
		<pubDate>Sun, 29 Nov 2009 22:00:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=966#comment-7142</guid>
		<description>I was able to complete first half of ex. 6-8. I cannot figure out how to re-create the same pattern using a &quot;while&quot; loop. This is one of the many attempts I&#039;ve made:

size(200,200);
background(255);

int r = 0;
int g = 0;
int b = 0;

int x = 0;
int y = 0;

while (x&lt;width)  {
  while(y&lt;height)  {
    rect(x,y,10,10);
    x+=10;
    y+=10;
  }
  println(&quot;x = &quot;+x);
  println(&quot;y = &quot;+y);
}

//  r = int(random(255));
//  g = int(random(255));
//  b = int(random(255));
//  fill(r,g,b);

Thanks!</description>
		<content:encoded><![CDATA[<p>I was able to complete first half of ex. 6-8. I cannot figure out how to re-create the same pattern using a &#8220;while&#8221; loop. This is one of the many attempts I&#8217;ve made:</p>
<p>size(200,200);<br />
background(255);</p>
<p>int r = 0;<br />
int g = 0;<br />
int b = 0;</p>
<p>int x = 0;<br />
int y = 0;</p>
<p>while (x&lt;width)  {<br />
  while(y&lt;height)  {<br />
    rect(x,y,10,10);<br />
    x+=10;<br />
    y+=10;<br />
  }<br />
  println(&quot;x = &quot;+x);<br />
  println(&quot;y = &quot;+y);<br />
}</p>
<p>//  r = int(random(255));<br />
//  g = int(random(255));<br />
//  b = int(random(255));<br />
//  fill(r,g,b);</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-8/comment-page-1/#comment-5337</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Tue, 06 Oct 2009 17:25:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=966#comment-5337</guid>
		<description>You just need to use 3 arguments to fill(), i.e.

&lt;pre&gt;
fill(random(255),random(255),random(255));
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>You just need to use 3 arguments to fill(), i.e.</p>
<pre>
fill(random(255),random(255),random(255));
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: ww</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-8/comment-page-1/#comment-5264</link>
		<dc:creator>ww</dc:creator>
		<pubDate>Fri, 02 Oct 2009 08:52:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=966#comment-5264</guid>
		<description>What should I do if i want to use random r,g,b to color them? I was told fill(random(r,g,b)); is not applicable..</description>
		<content:encoded><![CDATA[<p>What should I do if i want to use random r,g,b to color them? I was told fill(random(r,g,b)); is not applicable..</p>
]]></content:encoded>
	</item>
</channel>
</rss>

