<?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: Example 5-4: Hold Down the Button</title>
	<atom:link href="http://www.learningprocessing.com/examples/chapter-5/example-5-4/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: Anonymous</title>
		<link>http://www.learningprocessing.com/examples/chapter-5/example-5-4/comment-page-1/#comment-20506</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Thu, 05 May 2011 18:34:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/wp/?page_id=346#comment-20506</guid>
		<description>These are equivalent.  if (button) is simple a shorter way of writing it.  Since a boolean variable can only be &quot;true&quot; or &quot;false&quot; by definition, asking if it is equal to true is redundant.</description>
		<content:encoded><![CDATA[<p>These are equivalent.  if (button) is simple a shorter way of writing it.  Since a boolean variable can only be &#8220;true&#8221; or &#8220;false&#8221; by definition, asking if it is equal to true is redundant.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Will Price</title>
		<link>http://www.learningprocessing.com/examples/chapter-5/example-5-4/comment-page-1/#comment-20503</link>
		<dc:creator>Will Price</dc:creator>
		<pubDate>Sat, 30 Apr 2011 22:03:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/wp/?page_id=346#comment-20503</guid>
		<description>For this bit &quot; if(button) &quot;
why does it not read &quot;if(button == true)&quot; 
</description>
		<content:encoded><![CDATA[<p>For this bit &#8221; if(button) &#8221;<br />
why does it not read &#8220;if(button == true)&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://www.learningprocessing.com/examples/chapter-5/example-5-4/comment-page-1/#comment-20393</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Fri, 11 Mar 2011 02:30:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/wp/?page_id=346#comment-20393</guid>
		<description>your second conditional needs to reference x1, not x.  Also, you&#039;ll want to use an if, else if, else structure, i.e.


  if (button1) {
    background(0,255,0);
  } else if (button2) {
    background(255,0,0);
  } else {
    background(0,0,255);
  }


Object-oriented programming will really make this easier.  See:

http://www.learningprocessing.com/exercises/chapter-9/exercise-9-8/</description>
		<content:encoded><![CDATA[<p>your second conditional needs to reference x1, not x.  Also, you&#8217;ll want to use an if, else if, else structure, i.e.</p>
<p>  if (button1) {<br />
    background(0,255,0);<br />
  } else if (button2) {<br />
    background(255,0,0);<br />
  } else {<br />
    background(0,0,255);<br />
  }</p>
<p>Object-oriented programming will really make this easier.  See:</p>
<p><a href="http://www.learningprocessing.com/exercises/chapter-9/exercise-9-8/" rel="nofollow">http://www.learningprocessing.com/exercises/chapter-9/exercise-9-8/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mhelke</title>
		<link>http://www.learningprocessing.com/examples/chapter-5/example-5-4/comment-page-1/#comment-20383</link>
		<dc:creator>mhelke</dc:creator>
		<pubDate>Wed, 09 Mar 2011 18:22:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/wp/?page_id=346#comment-20383</guid>
		<description>what if I want to have more than one of these rectangles? 
I tried this but it doesn&#039;t work...// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example 5-4: Hold down the button
boolean button1 = false;

int x = 800;
int y = 230;
int w = 10;
int h = 10;

boolean button2 = false;
int x1 = 200;
int y1 = 230;
int w1 = 10;
int h1 = 10;

PImage b;
PImage c;
PImage d;
PImage e;

void setup() {
  size(960,540); 
  noStroke();
}

void draw() {
  // The button is pressed if (mouseX,mouseY) is inside the rectangle and mousePressed is true.
  if (mouseX &gt; x &amp;&amp; mouseX  y &amp;&amp; mouseY  x &amp;&amp; mouseX  y &amp;&amp; mouseY &lt; y1+h1 &amp;&amp; mousePressed) {
    button2 = true; 
  } else {
    button2 = false;
  }

 if (button1) {
   b = loadImage(&quot;first.gif&quot;);
   background(b);
    noStroke();
  } else {
    c = loadImage(&quot;second.gif&quot;);
    background(c);
   
  }
  
   if (button2) {
   d = loadImage(&quot;first.jpeg&quot;);
   background(d);
    noStroke();
  } else {
    e = loadImage(&quot;second.jpeg&quot;);
    background(e);
   
  }
  
 fill(#e09554);
  rect(x,y,w,h);
  rect(x1,y1,w1,h1);
}</description>
		<content:encoded><![CDATA[<p>what if I want to have more than one of these rectangles?<br />
I tried this but it doesn&#8217;t work&#8230;// Learning Processing<br />
// Daniel Shiffman<br />
// <a href="http://www.learningprocessing.com" rel="nofollow">http://www.learningprocessing.com</a></p>
<p>// Example 5-4: Hold down the button<br />
boolean button1 = false;</p>
<p>int x = 800;<br />
int y = 230;<br />
int w = 10;<br />
int h = 10;</p>
<p>boolean button2 = false;<br />
int x1 = 200;<br />
int y1 = 230;<br />
int w1 = 10;<br />
int h1 = 10;</p>
<p>PImage b;<br />
PImage c;<br />
PImage d;<br />
PImage e;</p>
<p>void setup() {<br />
  size(960,540);<br />
  noStroke();<br />
}</p>
<p>void draw() {<br />
  // The button is pressed if (mouseX,mouseY) is inside the rectangle and mousePressed is true.<br />
  if (mouseX &gt; x &amp;&amp; mouseX  y &amp;&amp; mouseY  x &amp;&amp; mouseX  y &amp;&amp; mouseY &lt; y1+h1 &amp;&amp; mousePressed) {<br />
    button2 = true;<br />
  } else {<br />
    button2 = false;<br />
  }</p>
<p> if (button1) {<br />
   b = loadImage(&quot;first.gif&quot;);<br />
   background(b);<br />
    noStroke();<br />
  } else {<br />
    c = loadImage(&quot;second.gif&quot;);<br />
    background(c);</p>
<p>  }</p>
<p>   if (button2) {<br />
   d = loadImage(&quot;first.jpeg&quot;);<br />
   background(d);<br />
    noStroke();<br />
  } else {<br />
    e = loadImage(&quot;second.jpeg&quot;);<br />
    background(e);</p>
<p>  }</p>
<p> fill(#e09554);<br />
  rect(x,y,w,h);<br />
  rect(x1,y1,w1,h1);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick Mimran</title>
		<link>http://www.learningprocessing.com/examples/chapter-5/example-5-4/comment-page-1/#comment-9693</link>
		<dc:creator>Patrick Mimran</dc:creator>
		<pubDate>Tue, 02 Mar 2010 23:54:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/wp/?page_id=346#comment-9693</guid>
		<description>Thank you very much

Patrick</description>
		<content:encoded><![CDATA[<p>Thank you very much</p>
<p>Patrick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Shiffman</title>
		<link>http://www.learningprocessing.com/examples/chapter-5/example-5-4/comment-page-1/#comment-9687</link>
		<dc:creator>Daniel Shiffman</dc:creator>
		<pubDate>Tue, 02 Mar 2010 21:07:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/wp/?page_id=346#comment-9687</guid>
		<description>Yes, the default value of a boolean variable is false.  So


boolean button = false;


and


boolean button;


are the same.  However, it&#039;s a good habit to always initialize your variables, just so that your code is more clear.</description>
		<content:encoded><![CDATA[<p>Yes, the default value of a boolean variable is false.  So</p>
<p>boolean button = false;</p>
<p>and</p>
<p>boolean button;</p>
<p>are the same.  However, it&#8217;s a good habit to always initialize your variables, just so that your code is more clear.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick Mimran</title>
		<link>http://www.learningprocessing.com/examples/chapter-5/example-5-4/comment-page-1/#comment-9675</link>
		<dc:creator>Patrick Mimran</dc:creator>
		<pubDate>Tue, 02 Mar 2010 14:58:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningprocessing.com/wp/?page_id=346#comment-9675</guid>
		<description>i would like to understand something please , if a boolean is anyway only t or false why do we have to specify
true or false when we declare the variable name in this example .
Or if flase is specified when variable is declared why shouldn&#039;t we write only &quot;button&quot; instead of button = false when button false ?

Thank you

Patrick</description>
		<content:encoded><![CDATA[<p>i would like to understand something please , if a boolean is anyway only t or false why do we have to specify<br />
true or false when we declare the variable name in this example .<br />
Or if flase is specified when variable is declared why shouldn&#8217;t we write only &#8220;button&#8221; instead of button = false when button false ?</p>
<p>Thank you</p>
<p>Patrick</p>
]]></content:encoded>
	</item>
</channel>
</rss>

