<?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-5: One line at a time</title>
	<atom:link href="http://www.learningprocessing.com/exercises/chapter-6/exercise-6-5/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>Fri, 10 Feb 2012 19:58:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ken Sherwood</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-5/comment-page-1/#comment-17991</link>
		<dc:creator>Ken Sherwood</dc:creator>
		<pubDate>Thu, 20 Jan 2011 21:56:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=1163#comment-17991</guid>
		<description>Found this initially confusing, until worked through to realize that instead of adding a line each pass through the &quot;for&quot; loop it is actually drawing: line1, then line1 + line2, then line1 + line2 + line3, etc.  Here is a variation that helps to visualize this, by changing the colors each time through the for loop: 

int endY = 0;
float colorR = 0;
float colorB = 0;
float colorG = 0;

void setup() {
  size(200,200);
  frameRate(1);

}

void draw() {
  background(255);
  colorR = random(255); //  Introduced to change line color each time through draw
  colorB = random(255); //
  colorG = random(255); //

  // y goes from 0 to whatever endY is
  for (int y = 0; y  height) {
    endY = 0;
 }</description>
		<content:encoded><![CDATA[<p>Found this initially confusing, until worked through to realize that instead of adding a line each pass through the &#8220;for&#8221; loop it is actually drawing: line1, then line1 + line2, then line1 + line2 + line3, etc.  Here is a variation that helps to visualize this, by changing the colors each time through the for loop: </p>
<p>int endY = 0;<br />
float colorR = 0;<br />
float colorB = 0;<br />
float colorG = 0;</p>
<p>void setup() {<br />
  size(200,200);<br />
  frameRate(1);</p>
<p>}</p>
<p>void draw() {<br />
  background(255);<br />
  colorR = random(255); //  Introduced to change line color each time through draw<br />
  colorB = random(255); //<br />
  colorG = random(255); //</p>
<p>  // y goes from 0 to whatever endY is<br />
  for (int y = 0; y  height) {<br />
    endY = 0;<br />
 }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carlos Lopez</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-5/comment-page-1/#comment-15884</link>
		<dc:creator>Carlos Lopez</dc:creator>
		<pubDate>Tue, 30 Nov 2010 02:13:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=1163#comment-15884</guid>
		<description>I&#039;ve got the answer! &quot;y&quot; does not meet the condition and 10 is added to &quot;endY&quot;, so the loop over and over... Thank you!

void draw (){
  background (255);
  for (int y = 0; y&lt; endY; y+= 10) {
    stroke (0);
    line (0, y, width, y)
  }
  endY += 10;</description>
		<content:encoded><![CDATA[<p>I&#8217;ve got the answer! &#8220;y&#8221; does not meet the condition and 10 is added to &#8220;endY&#8221;, so the loop over and over&#8230; Thank you!</p>
<p>void draw (){<br />
  background (255);<br />
  for (int y = 0; y&lt; endY; y+= 10) {<br />
    stroke (0);<br />
    line (0, y, width, y)<br />
  }<br />
  endY += 10;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carlos Lopez</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-5/comment-page-1/#comment-15883</link>
		<dc:creator>Carlos Lopez</dc:creator>
		<pubDate>Tue, 30 Nov 2010 01:59:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=1163#comment-15883</guid>
		<description>I don&#039;t understand why this piece of code works if &quot;y&quot; does not meet the condition of being less than &quot;endY&quot;. Both &quot;y&quot; and &quot;endY&quot; are 0. Shouldn&#039;t that make the &quot;for&quot; loop exit straight away?

// y goes from 0 to whatever endY is
  for (int y = 0; y &lt; endY; y+=10) {</description>
		<content:encoded><![CDATA[<p>I don&#8217;t understand why this piece of code works if &#8220;y&#8221; does not meet the condition of being less than &#8220;endY&#8221;. Both &#8220;y&#8221; and &#8220;endY&#8221; are 0. Shouldn&#8217;t that make the &#8220;for&#8221; loop exit straight away?</p>
<p>// y goes from 0 to whatever endY is<br />
  for (int y = 0; y &lt; endY; y+=10) {</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-5/comment-page-1/#comment-9611</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Sat, 27 Feb 2010 03:59:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=1163#comment-9611</guid>
		<description>Makes perfect sense. Thanks for the correction! By the way, your book is just fantastic.</description>
		<content:encoded><![CDATA[<p>Makes perfect sense. Thanks for the correction! By the way, your book is just fantastic.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Shiffman</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-5/comment-page-1/#comment-9610</link>
		<dc:creator>Daniel Shiffman</dc:creator>
		<pubDate>Sat, 27 Feb 2010 03:16:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=1163#comment-9610</guid>
		<description>The difference in the above is that i (which loops from 50 to 150) is a local variable and x (which loops from 0 to 200) is a global variable.  Meaning once x gets above 200, it stays above 200 because it is never reset to 0.  The following will make it a more analogous situation:

&lt;pre&gt;
int y = 80;
int spacing = 10;
int len = 20;

void setup() {
  size(200,200);
  background(255);
}

void draw() {
  int x = 20;
  while (x&lt;200){
    stroke(255,0, 0);
    line(x, y, x, y+len);
    x+=15;
    y++;
  }
  
  for (int i=50; i&lt;=150; i+=spacing) {
    stroke(0);
    line(i,y,i,y+len);
    y++;
  }
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>The difference in the above is that i (which loops from 50 to 150) is a local variable and x (which loops from 0 to 200) is a global variable.  Meaning once x gets above 200, it stays above 200 because it is never reset to 0.  The following will make it a more analogous situation:</p>
<pre>
int y = 80;
int spacing = 10;
int len = 20;

void setup() {
  size(200,200);
  background(255);
}

void draw() {
  int x = 20;
  while (x&lt;200){
    stroke(255,0, 0);
    line(x, y, x, y+len);
    x+=15;
    y++;
  }

  for (int i=50; i< =150; i+=spacing) {
    stroke(0);
    line(i,y,i,y+len);
    y++;
  }
}
</pre>
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-5/comment-page-1/#comment-9555</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Wed, 24 Feb 2010 22:32:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=1163#comment-9555</guid>
		<description>I&#039;m not sure if this is the perfect place to post this question, but one of my students ran into this seemingly glitchy problem. Can you explain why &#039;y&#039; continues to increment in the for loop and not in the while loop?

int y = 80;
int x = 20;
int spacing = 10;
int len = 20;

void setup() {
  size(200,200);
  background(255);
}

void draw() {
  while (x&lt;200){
    stroke(255,0, 0);
    line(x, y, x, y+len);
    x+=15;
    y++;
  }
  for (int i=50; i&lt;=150; i+=spacing) {
    stroke(0);
    line(i,y,i,y+len);
    y++;
  }
}</description>
		<content:encoded><![CDATA[<p>I&#8217;m not sure if this is the perfect place to post this question, but one of my students ran into this seemingly glitchy problem. Can you explain why &#8216;y&#8217; continues to increment in the for loop and not in the while loop?</p>
<p>int y = 80;<br />
int x = 20;<br />
int spacing = 10;<br />
int len = 20;</p>
<p>void setup() {<br />
  size(200,200);<br />
  background(255);<br />
}</p>
<p>void draw() {<br />
  while (x&lt;200){<br />
    stroke(255,0, 0);<br />
    line(x, y, x, y+len);<br />
    x+=15;<br />
    y++;<br />
  }<br />
  for (int i=50; i&lt;=150; i+=spacing) {<br />
    stroke(0);<br />
    line(i,y,i,y+len);<br />
    y++;<br />
  }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Shiffman</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-5/comment-page-1/#comment-8708</link>
		<dc:creator>Daniel Shiffman</dc:creator>
		<pubDate>Sun, 31 Jan 2010 18:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=1163#comment-8708</guid>
		<description>We are choosing to set the initial value of endY to 0.  If we did not initialize endY, Processing would give it a default value.  It just so happens that the default value is also 0 so either way we get the same result. Still, it&#039;s  a good habit to initialize your variables.</description>
		<content:encoded><![CDATA[<p>We are choosing to set the initial value of endY to 0.  If we did not initialize endY, Processing would give it a default value.  It just so happens that the default value is also 0 so either way we get the same result. Still, it&#8217;s  a good habit to initialize your variables.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-5/comment-page-1/#comment-8707</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Sun, 31 Jan 2010 18:07:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=1163#comment-8707</guid>
		<description>wow, this is one hard piece of code for me to understand.
Like Richard said, endY=0 is not neccessary to be called. How then does Processing know the value of endY in the beginning in order to + 10 every draw? I hope you get my question.</description>
		<content:encoded><![CDATA[<p>wow, this is one hard piece of code for me to understand.<br />
Like Richard said, endY=0 is not neccessary to be called. How then does Processing know the value of endY in the beginning in order to + 10 every draw? I hope you get my question.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-5/comment-page-1/#comment-5338</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Tue, 06 Oct 2009 17:27:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=1163#comment-5338</guid>
		<description>You&#039;ll need to use a variable to increment / decrement endY, i.e.

&lt;pre&gt;
  // Increment endY
  endY += dir;
&lt;/pre&gt;

Then you could change the direction of dir depending on certain conditions (like it reaching the bottom or top of the window)

&lt;pre&gt;
dir *= -1;
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>You&#8217;ll need to use a variable to increment / decrement endY, i.e.</p>
<pre>
  // Increment endY
  endY += dir;
</pre>
<p>Then you could change the direction of dir depending on certain conditions (like it reaching the bottom or top of the window)</p>
<pre>
dir *= -1;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: ww</title>
		<link>http://www.learningprocessing.com/exercises/chapter-6/exercise-6-5/comment-page-1/#comment-5261</link>
		<dc:creator>ww</dc:creator>
		<pubDate>Fri, 02 Oct 2009 08:00:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/?page_id=1163#comment-5261</guid>
		<description>I rewrote the code to draw lines down to up, it worked. But now I&#039;m confused what should I do if i want to draw lines up to down to up to down...</description>
		<content:encoded><![CDATA[<p>I rewrote the code to draw lines down to up, it worked. But now I&#8217;m confused what should I do if i want to draw lines up to down to up to down&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

