<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Predator Interactive &#187; Instinct Graphics Package</title>
	<atom:link href="http://www.predatorinteractive.com/category/instinct-graphics-package/feed" rel="self" type="application/rss+xml" />
	<link>http://www.predatorinteractive.com</link>
	<description>2D Game Programming Resources for Noobs</description>
	<lastBuildDate>Wed, 21 Jul 2010 00:18:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Instinct Graphics Package &#8211; Overview</title>
		<link>http://www.predatorinteractive.com/instinct-graphics-package/the-instinct-graphics-package-previe</link>
		<comments>http://www.predatorinteractive.com/instinct-graphics-package/the-instinct-graphics-package-previe#comments</comments>
		<pubDate>Thu, 18 Jun 2009 08:31:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Instinct Graphics Package]]></category>
		<category><![CDATA[instinct]]></category>

		<guid isPermaLink="false">http://www.predatorinteractive.com/predatorinteractive/?p=26</guid>
		<description><![CDATA[Great for beginners at either C++ or game programming.  Check out what this package can do!]]></description>
			<content:encoded><![CDATA[<div id="wp_zdytfp_container_26" style="width:100%; height:470px; text-align:center; margin:auto;">
<div id="v_wp_zdytfp_container_26" style="width:100%; height:100%;">ZD YouTube FLV Player</div>
</div>
<script type="text/javascript">
var flashvars = {
vurl: "http://www.predatorinteractive.com/wp-content/uploads/2009/06/instinctpackageintro.flv",
autoplay: "yes",
yturl: "http://www.predatorinteractive.com/wp-content/plugins/zd-youtube-flv-player/fl_youTubeProxy.php"
};
var params = {
wmode: "transparent",
allowFullScreen: "true"
};
var attributes = {
id: "my_wp_zdytfp_container_26",
name: "my_wp_zdytfp_container_26"
};
swfobject.embedSWF("http://www.predatorinteractive.com/wp-content/plugins/zd-youtube-flv-player/flash/zdytflv-player-dark.swf", "v_wp_zdytfp_container_26", "630", "470", "9.0.0", false, flashvars, params, attributes);
</script>

<div style="float:left;margin:0px 0px 5px 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-8758858260781245";
/* 468x60, created 6/19/09 */
google_ad_slot = "6950501204";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p><span style="color:    #ffffff;">h</span></p>
<p><span style="color: #ffffff;"><br />
</span></p>
<h2><span style="text-decoration: underline;">The Instinct Graphics Package</span></h2>
<p>The Instinct Graphics Package is an easy to use and free 2D graphics programming framework for C++.  It can be used simply to output something to a screen or as a package for making 2D games.  It is completely free to use whether it is for personal use or for educational purposes.  For educational use or for general questions, feel free to contact us ratadero@predatorinteractive.com</p>
<h3><span style="text-decoration: underline;">Tutorials and Videos</span></h3>
<p>For videos and tutorials on installing and using the Instinct Graphics package, click <strong><a href="http://www.predatorinteractive.com/category/videos/instinct-graphics-package">here</a></strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.predatorinteractive.com/instinct-graphics-package/the-instinct-graphics-package-previe/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>1. Installing The Instinct Graphics Package &#8211; Windows</title>
		<link>http://www.predatorinteractive.com/instinct-graphics-package/1-installing-instinct-graphics-package</link>
		<comments>http://www.predatorinteractive.com/instinct-graphics-package/1-installing-instinct-graphics-package#comments</comments>
		<pubDate>Fri, 19 Jun 2009 01:16:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Instinct Graphics Package]]></category>
		<category><![CDATA[codeblocks]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[instinct]]></category>
		<category><![CDATA[mingw]]></category>
		<category><![CDATA[package]]></category>

		<guid isPermaLink="false">http://www.predatorinteractive.com/predatorinteractive/?p=33</guid>
		<description><![CDATA[Install a code environment, compiler, and the Instinct Graphics Package for Windows in about 5 minutes time.]]></description>
			<content:encoded><![CDATA[<div id="wp_zdytfp_container_33" style="width:100%; height:470px; text-align:center; margin:auto;">
<div id="v_wp_zdytfp_container_33" style="width:100%; height:100%;">ZD YouTube FLV Player</div>
</div>
<script type="text/javascript">
var flashvars = {
vurl: "http://www.predatorinteractive.com/wp-content/uploads/2009/06/instinctinstall.mp4",
autoplay: "yes",
yturl: "http://www.predatorinteractive.com/wp-content/plugins/zd-youtube-flv-player/fl_youTubeProxy.php"
};
var params = {
wmode: "transparent",
allowFullScreen: "true"
};
var attributes = {
id: "my_wp_zdytfp_container_33",
name: "my_wp_zdytfp_container_33"
};
swfobject.embedSWF("http://www.predatorinteractive.com/wp-content/plugins/zd-youtube-flv-player/flash/zdytflv-player-dark.swf", "v_wp_zdytfp_container_33", "630", "470", "9.0.0", false, flashvars, params, attributes);
</script>

<p><span style="color: #ffffff;">h</span></p>
<p><span style="color: #ffffff;"><br />
</span></p>
<h2><span style="text-decoration: underline;"><strong>Insta</strong></span><span style="text-decoration: underline;"><strong>lling The Instinct Graphics Package &#8211; Windows</strong></span></h2>
<p>Before we can use the Instinct Graphics Package on Windows, let&#8217;s go ahead and get ourselves a nice programming environment and then get the Graphics Package resources.</p>
<h3><span style="text-decoration: underline;">Installing the Code::Blocks IDE with the MinGW C++ Compiler</span></h3>
<p>So first thing is first, let&#8217;s download Code::Blocks with the bundled C++ Compiler so we have a place to make our programs.</p>
<p><strong>To download the Code::Blocks IDE and MinGW Compiler: <a title="Download Here" href="http://downloads.sourceforge.net/project/codeblocks/Binaries/8.02/codeblocks-8.02mingw-setup.exe?use_mirror=cdnetworks-us-2">Click Here</a></strong></p>
<p>Go ahead and walk through the simple installation steps and once that is done let&#8217;s try making a sample C++ program.</p>
<h3><span style="text-decoration: underline;"><strong>Using Code::Blocks</strong></span></h3>
<p>So once you have fully installed Code::Blocks and the MinGW compiler, go ahead and click &#8220;New-&gt;Empty File&#8221;.  A blank file should pop up for you to write your own C++ program.  Go ahead and write a Hello World program in there to make sure everything installed and is working correctly.</p>
<pre style="padding-left: 30px;"><span style="color: #049d0a;">#include &lt;iostream&gt;

<span style="color: #0000ff;">using namespace</span> <span style="color: #000000;">std</span><span style="color: #ff0000;">;</span>
</span><span style="color: #0000ff;">
int</span> main<span style="color: #ff0000;">()</span><span style="color: #ff0000;">
{
</span><span style="color: #0000ff;">    <span style="color: #000000;">cout</span> <span style="color: #ff0000;">&lt;&lt;</span> "Hello World" <span style="color: #ff0000;">&lt;&lt;</span> <span style="color: #000000;">endl</span><span style="color: #ff0000;">;</span>
    return</span> <span style="color: #ff00ff;">0</span><span style="color: #ff0000;">;</span><span style="color: #ff0000;">
}</span></pre>
<p>Once you have finished typing this, go ahead and click on the button that looks like <a href="http://www.predatorinteractive.com/?attachment_id=543"><img class="alignnone size-full wp-image-543" title="build" src="http://www.predatorinteractive.com/wp-content/uploads/2010/05/build.PNG" alt="build" width="24" height="23" /></a> which will compile and run your program.</p>
<p>It will ask you to save the file,  just put it anywhere and call it &#8220;main.cpp&#8221;.  Don&#8217;t worry about putting it in a special place for now, you can delete this file once we are done here.</p>
<p>If you happened to have a compiler error, Code::Blocks will show you, just go ahead and fix it and press build and run again until there are no more errors.</p>
<p>When your Hello World program runs, you should see something similar to this:</p>
<p style="text-align: center;"><a rel="attachment wp-att-544" href="http://www.predatorinteractive.com/instinct-graphics-package/1-installing-instinct-graphics-package/attachment/helloworld"><img class="aligncenter size-full wp-image-544" title="helloworld" src="http://www.predatorinteractive.com/wp-content/uploads/2010/05/helloworld.PNG" alt="helloworld" width="550" height="277" /></a></p>
<p>If you see the words Hello World in a terminal, then you have successfully installed Code::Blocks and the MinGW compiler!</p>
<h3><span style="text-decoration: underline;">Wait, I Can&#8217;t Get My Program To Work, It Keeps Saying Cannot Find mingw32-g++.exe</span></h3>
<p>If your program wont even attempt to compiler or run and you get a message similar to the one above, then something probably went wrong with your installation.  First thing to check is to see if Code::Blocks knows where the MinGW compiler is at.</p>
<p>Go ahead and click &#8220;Settings-&gt;Compiler and Debugger&#8221;.  In the window that pops up, click the &#8220;Toolchain Executables&#8221; tab.  There will be a section for the Compilers installation directory.  Go ahead and click &#8220;auto detect&#8221; and make sure the path listed there exists on your computer.  If it does not exist, perhaps you installed this on another disk drive and should try to find it on there and point Code::Blocks there if you can find it.</p>
<p>If after all that things still don&#8217;t work, perhaps the installation itself just failed and go run the installer once again and remember where you told it to install.</p>
<h3><span style="text-decoration: underline;">Getting the Instinct Graphics Package</span></h3>
<p>Instinct Graphics Package Project Folder: <a href="http://www.predatorinteractive.com/wp-content/uploads/2009/12/instinct.zip">Download Here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.predatorinteractive.com/instinct-graphics-package/1-installing-instinct-graphics-package/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://www.predatorinteractive.com/wp-content/uploads/2009/06/instinctinstall.mp4" length="15310158" type="video/mp4" />
		</item>
		<item>
		<title>2. Basic Commands and Drawing Shapes</title>
		<link>http://www.predatorinteractive.com/instinct-graphics-package/2-basic-commands-and-drawing-shapes</link>
		<comments>http://www.predatorinteractive.com/instinct-graphics-package/2-basic-commands-and-drawing-shapes#comments</comments>
		<pubDate>Fri, 19 Jun 2009 21:42:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Instinct Graphics Package]]></category>
		<category><![CDATA[drawing]]></category>
		<category><![CDATA[shapes]]></category>
		<category><![CDATA[start]]></category>
		<category><![CDATA[win]]></category>

		<guid isPermaLink="false">http://www.predatorinteractive.com/predatorinteractive/?p=125</guid>
		<description><![CDATA[Learn how to draw shapes in full out color.  Draw lines to circles to on screen text in no time.]]></description>
			<content:encoded><![CDATA[<div id="wp_zdytfp_container_125" style="width:100%; height:470px; text-align:center; margin:auto;">
<div id="v_wp_zdytfp_container_125" style="width:100%; height:100%;">ZD YouTube FLV Player</div>
</div>
<script type="text/javascript">
var flashvars = {
vurl: "http://www.predatorinteractive.com/wp-content/uploads/2009/06/instinctbasicshapes.flv",
autoplay: "yes",
yturl: "http://www.predatorinteractive.com/wp-content/plugins/zd-youtube-flv-player/fl_youTubeProxy.php"
};
var params = {
wmode: "transparent",
allowFullScreen: "true"
};
var attributes = {
id: "my_wp_zdytfp_container_125",
name: "my_wp_zdytfp_container_125"
};
swfobject.embedSWF("http://www.predatorinteractive.com/wp-content/plugins/zd-youtube-flv-player/flash/zdytflv-player-dark.swf", "v_wp_zdytfp_container_125", "630", "470", "9.0.0", false, flashvars, params, attributes);
</script>

<p><span style="color:  #ffffff;">h</span></p>
<p><span style="color: #ffffff;"><br />
</span></p>
<h2><span style="text-decoration: underline;"><strong>Basic Commands and Drawing Shapes</strong></span></h2>
<p>First thing is first when trying out the Instinct Graphics Package.  Let&#8217;s learn what is needed to be set up prior to drawing anything.</p>
<h3><span style="text-decoration: underline;">Starting Code to Use</span></h3>
<p><strong>To begin coding a Instinct Graphics Package program, you must first have at least this starting code set up:</strong></p>
<pre style="padding-left: 30px;"><span style="color: #049d0a;">#include "instinct.h"</span><span style="color: #0000ff;">

int</span> instinct_main<span style="color: #ff0000;">()</span><span style="color: #ff0000;">
{</span><span style="color: #0000ff;">
    return</span> <span style="color: #ff00ff;">0</span><span style="color: #ff0000;">;</span><span style="color: #ff0000;">
}</span></pre>
<p><strong>The Instinct Project folder will have this already precoded.  However if you are coding this from scratch you must type the code above.</strong></p>
<p>The <strong><span style="color: #000000;">&#8220;instinct_main<span style="color: #ff0000;">()</span>&#8220;</span></strong> function acts similar to the standard <strong><span style="color: #0000ff;"><span style="color: #000000;">&#8220;</span>int</span> main<span style="color: #ff0000;">()<span style="color: #000000;">&#8220;</span></span></strong> function that console programs use.</p>
<h3><span style="text-decoration: underline;"><strong>Shapes</strong></span></h3>
<p><strong>There are different ways to draw shapes to the screen. The shapes we can draw are:</strong></p>
<ul>
<li>Point</li>
<li>Line</li>
<li>Circle</li>
<li>Rect</li>
<li>Triangle</li>
<li>Message</li>
</ul>
<p><img class="alignnone size-full wp-image-455" title="shapeswindow" src="http://www.predatorinteractive.com/wp-content/uploads/2009/06/shapeswindow.png" alt="shapeswindow" width="400" height="416" /></p>
<p><strong>The constructors you can use for each are as follows:</strong></p>
<ul>
<li>Point<span style="color: #ff0000;">(</span><span style="color: #0000ff;">double</span> x<span style="color: #ff0000;">,</span> <span style="color: #0000ff;">double</span> y<span style="color: #ff0000;">)</span></li>
<li>Line<span style="color: #ff0000;">(</span><span style="color: #0000ff;">Point</span> start<span style="color: #ff0000;">,</span> <span style="color: #0000ff;">Point</span> end<span style="color: #ff0000;">)</span></li>
<li>Circle<span style="color: #ff0000;">(</span><span style="color: #0000ff;">Point</span> center<span style="color: #ff0000;">,</span> <span style="color: #0000ff;">double</span> radius<span style="color: #ff0000;">)</span></li>
<li>Rect<span style="color: #ff0000;">(</span><span style="color: #0000ff;">Point</span> lower_left<span style="color: #ff0000;">, </span><span style="color: #0000ff;">double</span> width<span style="color: #ff0000;">,</span> <span style="color: #0000ff;">double</span> height<span style="color: #ff0000;">)</span></li>
<li>Triangle<span style="color: #ff0000;">(</span><span style="color: #0000ff;">Point</span> p1<span style="color: #ff0000;">,</span> <span style="color: #0000ff;">Point</span> p2<span style="color: #ff0000;">,</span> <span style="color: #0000ff;">Point </span>p3<span style="color: #ff0000;">)</span></li>
<li>Message<span style="color: #ff0000;">(</span><span style="color: #0000ff;">Point</span> lower_left<span style="color: #ff0000;">,</span> <span style="color: #0000ff;">string</span> text<span style="color: #ff0000;">)</span></li>
</ul>
<h3><span style="text-decoration: underline;">Colors</span></h3>
<p><strong>The Colors that are available to use on the shapes are:</strong></p>
<p><img class="alignnone size-full wp-image-391" title="colors" src="http://www.predatorinteractive.com/wp-content/uploads/2009/06/colors.png" alt="colors" width="261" height="366" /></p>
<p>The default color for shapes is <strong>BLACK</strong>. Each object can use the <strong>&#8220;set_color<span style="color: #ff0000;">(</span>Color color<span style="color: #ff0000;">)</span>&#8220;</strong> member function to change their color.<strong><br />
</strong><em>Example:</em></p>
<ul>
<li> pt<span style="color: #ff0000;">.</span>set_color<span style="color: #ff0000;">(</span>BLUE<span style="color: #ff0000;">);</span></li>
<li>line2<span style="color: #ff0000;">.</span>set_color<span style="color: #ff0000;">(</span>GREEN<span style="color: #ff0000;">);</span></li>
<li>c<span style="color: #ff0000;"><span style="color: #000000;">irc</span>.</span>set_color<span style="color: #ff0000;">(</span>YELLOW<span style="color: #ff0000;">);</span></li>
<li>etc.</li>
</ul>
<p>Or you can add an extra parameter to the end of any of the shape constructors to specify their starting color instead.<strong><br />
</strong><em>Example:</em></p>
<ul>
<li> Circle circ <span style="color: #ff0000;">=</span> Circle<span style="color: #ff0000;">(</span>Point<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">5</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">5</span><span style="color: #ff0000;">)</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">2</span><span style="color: #ff0000;">,</span> YELLOW<span style="color: #ff0000;">);</span></li>
<li>Line l2 <span style="color: #ff0000;">=</span> Line<span style="color: #ff0000;">(</span>Point<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">0</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">0</span><span style="color: #ff0000;">),</span> Point<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">5</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">5</span><span style="color: #ff0000;">),</span> ORANGE<span style="color: #ff0000;">);</span></li>
</ul>
<h3><span style="text-decoration: underline;">Filling in Objects with Color</span></h3>
<p><span style="text-decoration: underline;"><img class="alignnone size-medium wp-image-445" title="filledin" src="http://www.predatorinteractive.com/wp-content/uploads/2009/06/filledin-300x57.png" alt="filledin" width="300" height="57" /><br />
</span></p>
<p>All the objects except the Line can either be outlined or filled in with color.  To set whether a object is filled in with color or not, you can use the <strong>&#8220;set_filled_in<span style="color: #ff0000;">(</span><span style="color: #0000ff;">bool</span> is_filled<span style="color: #ff0000;">)<span style="color: #000000;">&#8220;</span></span></strong>member  function.<br />
<em>Example:</em></p>
<ul>
<li> circ<span style="color: #ff0000;">.</span>set_filled_in<span style="color: #ff0000;">(</span><span style="color: #0000ff;">true</span><span style="color: #ff0000;">);</span></li>
<li>r<span style="color: #ff0000;"><span style="color: #000000;">ect</span>.</span>set_filled_in<span style="color: #ff0000;">(</span><span style="color: #0000ff;">false</span><span style="color: #ff0000;">);</span></li>
<li>etc.</li>
</ul>
<p>So the Circle circ will be filled in with it&#8217;s color while the Rect rect will only be outlined with it&#8217;s color.</p>
<p>Similarly to the colors, you can add that parameter to the end of a constructor if the constructor already has the color included.<br />
<em>Example:</em></p>
<ul>
<li>Circle circ <span style="color: #ff0000;">=</span> Circle<span style="color: #ff0000;">(</span>Point<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">5</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">5</span><span style="color: #ff0000;">),</span> <span style="color: #ff00ff;">2</span><span style="color: #ff0000;">,</span> YELLOW<span style="color: #ff0000;">, </span><span style="color: #0000ff;">true</span><span style="color: #ff0000;">);</span></li>
<li>Rect rect <span style="color: #ff0000;">=</span> Rect<span style="color: #ff0000;">(</span>Point<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">1</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">2</span><span style="color: #ff0000;">), </span><span style="color: #ff00ff;">5</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">5</span><span style="color: #ff0000;">,</span> BLUE<span style="color: #ff0000;">,</span> <span style="color: #0000ff;">true</span><span style="color: #ff0000;">);</span></li>
</ul>
<p>So both the Circle circ and the Rect rect will be filled in with color since they added <em><span style="color: #0000ff;">true</span></em> after the color argument in their constructors.</p>
<h3><span style="text-decoration: underline;">The &#8220;win&#8221; Object</span></h3>
<p>When it comes to manipulating the window or drawing shapes to the window, you must use the &#8220;<strong>win</strong>&#8221; object that is already created.  We will use the &#8220;<strong>win</strong>&#8221; object to draw shapes, change the background color, get user input, play audio, etc.</p>
<h3><span style="text-decoration: underline;"><strong>Drawing and Outputting Shapes</strong></span></h3>
<p>To actually draw shapes to the window, first you have to add them to the window buffer.  You do this by using the insertion operator on the <strong>&#8220;win&#8221;</strong> object.<br />
<em>Example:</em></p>
<ul>
<li> win <span style="color: #ff0000;">&lt;&lt;</span> circ<span style="color: #ff0000;">;</span></li>
<li>win <span style="color: #ff0000;">&lt;&lt;</span> r<span style="color: #ff0000;"><span style="color: #000000;">ect</span>;</span></li>
</ul>
<p>This adds the Circle circ and then the Rect rect onto the windows drawing buffer.  You can add more than one object to the buffer at a time.<br />
<em>Example:</em></p>
<ul>
<li> win <span style="color: #ff0000;">&lt;&lt;</span> circ <span style="color: #ff0000;">&lt;&lt;</span> rect <span style="color: #ff0000;">&lt;&lt;</span> l<span style="color: #ff0000;"><span style="color: #000000;">ine2</span>;</span></li>
<li>win <span style="color: #ff0000;">&lt;&lt;</span> pt <span style="color: #ff0000;">&lt;&lt;</span> t<span style="color: #ff0000;"><span style="color: #000000;">riangle</span>;</span></li>
</ul>
<p>Then once you are ready to draw everything in the buffer, use the<strong> &#8220;win<span style="color: #ff0000;">.</span>output_buffer<span style="color: #ff0000;">()</span>&#8221; </strong>command to output everything in the buffer to the screen.<br />
<em>Example:</em></p>
<ul>
<li>win <span style="color: #ff0000;">&lt;&lt;</span> circ <span style="color: #ff0000;">&lt;&lt;</span> r<span style="color: #000000;">ect<span style="color: #ff0000;">;</span></span><br />
win <span style="color: #ff0000;">&lt;&lt;</span> line3 <span style="color: #ff0000;">&lt;&lt;</span> p<span style="color: #000000;">t2</span><span style="color: #ff0000;">;</span><br />
win<span style="color: #ff0000;">.</span>output_buffer<span style="color: #ff0000;">();</span></li>
</ul>
<p>The above example in lines 1 and 2 add Circle circ, Rect rect, Line line3, and Point pt2 onto the buffer to be drawn.  Then the final line outputs all of the shapes that we just put in the buffer (as well as any other shapes that were previously in the buffer) onto the screen all at once.</p>
<h3><span style="text-decoration: underline;">Changing the Background Color</span></h3>
<p>To change the background color of the window, you must use the <strong><span style="color: #000000;">&#8220;</span>win<span style="color: #ff0000;">.</span>set_background_color<span style="color: #ff0000;">(</span>Color color<span style="color: #ff0000;">)</span></strong><span style="color: #ff0000;">;</span><strong><span style="color: #000000;">&#8220;</span></strong> function.<br />
<em>Example:</em></p>
<ul>
<li>win<span style="color: #ff0000;">.</span>set_background_color<span style="color: #ff0000;">(</span>BLACK<span style="color: #ff0000;">);</span></li>
<li>win<span style="color: #ff0000;">.</span>set_background_color<span style="color: #ff0000;">(</span>RED<span style="color: #ff0000;">);</span></li>
</ul>
<p><img class="alignnone size-medium wp-image-449" title="backgroundcolor" src="http://www.predatorinteractive.com/wp-content/uploads/2009/06/backgroundcolor-290x300.png" alt="backgroundcolor" width="290" height="300" /></p>
<p>So the first example above will change the background color of the window to <strong>BLACK</strong>. Be careful when changing the background that you do not draw any shapes the same color as the background. If you set the background to <strong>BLACK</strong>, any <strong>BLACK</strong> shapes won&#8217;t be seen on the background.</p>
<h3><span style="text-decoration: underline;">Changing the Title on the Program</span></h3>
<p>The last little thing you can do to your program is change the title of your window.  You do this by using the <strong>&#8220;win<span style="color: #ff0000;">.</span>set_title<span style="color: #ff0000;">(</span><span style="color: #0000ff;">string</span> new_title<span style="color: #ff0000;">)<span style="color: #000000;">&#8220;</span></span></strong> function.<br />
<em>Example:</em></p>
<ul>
<li> win<span style="color: #ff0000;">.</span>set_title<span style="color: #ff0000;">(</span><span style="color: #0000ff;">&#8220;My Cool Program&#8221;</span><span style="color: #ff0000;">);</span></li>
<li>win<span style="color: #ff0000;">.</span>set_title<span style="color: #ff0000;">(</span><span style="color: #0000ff;">&#8220;Space Wars!&#8221;</span><span style="color: #ff0000;">);</span></li>
</ul>
<p style="text-align: center;"><img class="size-full wp-image-448 aligncenter" title="title" src="http://www.predatorinteractive.com/wp-content/uploads/2009/06/title.png" alt="title" width="555" height="92" /></p>
<p>So that&#8217;s all the basics for drawing shapes, colors, outputting, and changing the title.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.predatorinteractive.com/instinct-graphics-package/2-basic-commands-and-drawing-shapes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>3. Getting Basic User Input</title>
		<link>http://www.predatorinteractive.com/instinct-graphics-package/3-getting-user-input</link>
		<comments>http://www.predatorinteractive.com/instinct-graphics-package/3-getting-user-input#comments</comments>
		<pubDate>Fri, 19 Jun 2009 23:32:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Instinct Graphics Package]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[user input]]></category>

		<guid isPermaLink="false">http://www.predatorinteractive.com/?p=140</guid>
		<description><![CDATA[All the basics for asking the user for input.  ]]></description>
			<content:encoded><![CDATA[<div id="wp_zdytfp_container_140" style="width:100%; height:470px; text-align:center; margin:auto;">
<div id="v_wp_zdytfp_container_140" style="width:100%; height:100%;">ZD YouTube FLV Player</div>
</div>
<script type="text/javascript">
var flashvars = {
vurl: "http://www.predatorinteractive.com/wp-content/uploads/2009/06/instinctbasicinput.flv",
autoplay: "yes",
yturl: "http://www.predatorinteractive.com/wp-content/plugins/zd-youtube-flv-player/fl_youTubeProxy.php"
};
var params = {
wmode: "transparent",
allowFullScreen: "true"
};
var attributes = {
id: "my_wp_zdytfp_container_140",
name: "my_wp_zdytfp_container_140"
};
swfobject.embedSWF("http://www.predatorinteractive.com/wp-content/plugins/zd-youtube-flv-player/flash/zdytflv-player-dark.swf", "v_wp_zdytfp_container_140", "630", "470", "9.0.0", false, flashvars, params, attributes);
</script>

<p><span style="color:   #ffffff;">h</span></p>
<p><span style="color: #ffffff;"><br />
</span></p>
<h2><span style="text-decoration: underline;">Getting Basic User Input</span></h2>
<p>There are four main ways to pause the program and ask the user for a value.</p>
<ul>
<li>Getting an int value</li>
<li>Getting a double value</li>
<li>Getting a string value</li>
<li>Getting a point on the screen</li>
</ul>
<h3><span style="text-decoration: underline;">Getting an int value</span></h3>
<p>To ask for an int, use the function: <strong> win<span style="color: #ff0000;">.</span>get_int<span style="color: #ff0000;">(</span>string prompt<span style="color: #ff0000;">);</span></strong><br />
Example:</p>
<ul>
<li> <span style="color: #0000ff;">int</span> age <span style="color: #ff0000;">=</span> win<span style="color: #ff0000;">.</span>get_int<span style="color: #ff0000;">(</span><span style="color: #0000ff;">&#8220;How old are you?&#8221;</span><span style="color: #ff0000;">);</span></li>
<li><span style="color: #0000ff;">int</span> radius <span style="color: #ff0000;">=</span> win<span style="color: #ff0000;">.</span>get_int<span style="color: #ff0000;">(</span><span style="color: #0000ff;">&#8220;Enter a value for the radius.&#8221;</span><span style="color: #ff0000;">);</span></li>
</ul>
<p>In example 1, the program will pause and display the message &#8220;<span style="color: #000000;"><strong><em>How old are you?</em></strong></span>&#8221; at the top of the screen. The user will then type in a numerical value and press enter.  That value typed will then be returned and stored in the variable <em><strong>age</strong></em>.</p>
<p style="text-align: center;"><a rel="attachment wp-att-369" href="http://www.predatorinteractive.com/?attachment_id=369"></a><img class="aligncenter size-full wp-image-371" title="getint" src="http://www.predatorinteractive.com/wp-content/uploads/2009/06/getint.JPG" alt="getint" width="553" height="116" /></p>
<h3><span style="text-decoration: underline;">Getting a double value</span></h3>
<p>To ask for a double, use the function:  <strong>win<span style="color: #ff0000;">.</span>get_double<span style="color: #ff0000;">(</span>string prompt<span style="color: #ff0000;">);</span></strong><br />
Example:</p>
<ul>
<li> <span style="color: #0000ff;">double</span> price <span style="color: #ff0000;">=</span> win<span style="color: #ff0000;">.</span>get_double<span style="color: #ff0000;">(</span><span style="color: #0000ff;">&#8220;How much does the car cost?&#8221;</span><span style="color: #ff0000;">);</span></li>
<li><span style="color: #0000ff;">double</span> mass <span style="color: #ff0000;">=</span> win<span style="color: #ff0000;">.</span>get_double<span style="color: #ff0000;">(</span><span style="color: #0000ff;">&#8220;How much does the ball weigh?&#8221;</span><span style="color: #ff0000;">);</span></li>
</ul>
<p>In example 1, the program will pause and display the message &#8220;<span style="color: #000000;"><strong><em>How much does the car cost?</em></strong></span>&#8221; at the top of the screen. The user will then type in a numerical double value and press enter.  That value typed will then be returned and stored in the variable <strong><em>price</em></strong>.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-374" title="getdouble" src="http://www.predatorinteractive.com/wp-content/uploads/2009/06/getdouble.JPG" alt="getdouble" width="543" height="111" /></p>
<h3><span style="text-decoration: underline;">Getting a string value</span></h3>
<p>To ask for a string, use this function:  <strong>win<span style="color: #ff0000;">.</span>get_string<span style="color: #ff0000;">(</span>string prompt<span style="color: #ff0000;">);</span></strong><br />
Example:</p>
<ul>
<li> <span style="color: #0000ff;">string</span> name <span style="color: #ff0000;">=</span> win<span style="color: #ff0000;">.</span>get_string<span style="color: #ff0000;">(</span><span style="color: #0000ff;">&#8220;What is your name?&#8221;</span><span style="color: #ff0000;">);</span></li>
<li><span style="color: #0000ff;">string</span> part <span style="color: #ff0000;">=</span> win<span style="color: #ff0000;">.</span>get_string<span style="color: #ff0000;">(</span><span style="color: #0000ff;">&#8220;Which part would you like to buy?&#8221;</span><span style="color: #ff0000;">);</span></li>
</ul>
<p>In example 1, the program will pause and display the message &#8220;<span style="color: #000000;"><strong><em>What is your name?</em></strong></span>&#8221; at the top of the screen. The user will then type in a string value and press enter.  That value typed will then be returned and stored in the variable <strong><em>name</em></strong>.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-375" title="getstring" src="http://www.predatorinteractive.com/wp-content/uploads/2009/06/getstring.JPG" alt="getstring" width="538" height="107" /></p>
<h3><span style="text-decoration: underline;">Getting a Point on the screen</span></h3>
<p>To ask for a point on the window, use this function:  <strong>win<span style="color: #ff0000;">.</span>get_click<span style="color: #ff0000;">(</span>string prompt<span style="color: #ff0000;">);</span></strong><br />
Example:</p>
<ul>
<li> <span style="color: #0000ff;">Point</span> location <span style="color: #ff0000;">=</span> win<span style="color: #ff0000;">.</span>get_click<span style="color: #ff0000;">(</span><span style="color: #0000ff;">&#8220;Click where you want to start.&#8221;</span><span style="color: #ff0000;">);</span></li>
<li><span style="color: #0000ff;">Point</span> end_point <span style="color: #ff0000;">=</span> win<span style="color: #ff0000;">.</span>get_click<span style="color: #ff0000;">(</span><span style="color: #0000ff;">&#8220;Click on the screen for the end point of the line to make.&#8221;</span><span style="color: #ff0000;">);</span></li>
</ul>
<p>In example 1, the program will pause and display the message &#8220;<span style="color: #000000;"><strong><em>Click where you want to start.</em></strong></span>&#8221; at the top of the screen. The user will then click a location on the screen.  That Point location on the screen will be returned and stored in the variable <strong><em>location</em></strong>.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-376" title="getclick" src="http://www.predatorinteractive.com/wp-content/uploads/2009/06/getclick.JPG" alt="getclick" width="548" height="102" /></p>
<h3><span style="text-decoration: underline;">Changing the color of the displayed message</span></h3>
<p>Similar to  drawing objects, you can also specify a color for all the prompts.  The default color is <strong>BLACK</strong>.  To set the color of the prompts, just add a color to the end of the function.<br />
Example:</p>
<ul>
<li> win<span style="color: #ff0000;">.</span>get_int<span style="color: #ff0000;">(</span><span style="color: #0000ff;">&#8220;How old are you?&#8221;</span><span style="color: #ff0000;">,</span> BLUE<span style="color: #ff0000;">)</span><span style="color: #ff0000;">;</span></li>
<li>win<span style="color: #ff0000;">.</span>get_double<span style="color: #ff0000;">(</span><span style="color: #0000ff;">&#8220;What is the weight of the ball?&#8221;</span><span style="color: #ff0000;">,</span> GREEN<span style="color: #ff0000;">);</span></li>
<li>win<span style="color: #ff0000;">.</span>get_click<span style="color: #ff0000;">(</span><span style="color: #0000ff;">&#8220;Click where you want to start.&#8221;</span><span style="color: #ff0000;">,</span> WHITE<span style="color: #ff0000;">);</span></li>
</ul>
<p>So for example 1, the message &#8220;<span style="color: #000000;"><strong><em>How old are you?</em></strong></span>&#8221; will be displayed at the top of the screen in the color <span style="color: #000000;"><strong>BLUE</strong></span> instead of <strong>BLACK</strong>.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-377" title="getintcolor" src="http://www.predatorinteractive.com/wp-content/uploads/2009/06/getintcolor.JPG" alt="getintcolor" width="554" height="109" /></p>
<p>Those are all the basics for getting user input. Soon it will be Instinct to you!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.predatorinteractive.com/instinct-graphics-package/3-getting-user-input/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>4. Clearing the Screen and Functions for Shapes</title>
		<link>http://www.predatorinteractive.com/instinct-graphics-package/clearing-the-screen-and-putting-it-all-together</link>
		<comments>http://www.predatorinteractive.com/instinct-graphics-package/clearing-the-screen-and-putting-it-all-together#comments</comments>
		<pubDate>Sun, 21 Jun 2009 22:32:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Instinct Graphics Package]]></category>
		<category><![CDATA[clearing]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[instinct]]></category>
		<category><![CDATA[shapes]]></category>

		<guid isPermaLink="false">http://www.predatorinteractive.com/?p=193</guid>
		<description><![CDATA[Learn how to clear the screen to draw new stuff and see more functions for shapes.]]></description>
			<content:encoded><![CDATA[<div id="wp_zdytfp_container_193" style="width:100%; height:470px; text-align:center; margin:auto;">
<div id="v_wp_zdytfp_container_193" style="width:100%; height:100%;">ZD YouTube FLV Player</div>
</div>
<script type="text/javascript">
var flashvars = {
vurl: "http://www.predatorinteractive.com/wp-content/uploads/2009/06/instinctclearingandfunctions.flv",
autoplay: "yes",
yturl: "http://www.predatorinteractive.com/wp-content/plugins/zd-youtube-flv-player/fl_youTubeProxy.php"
};
var params = {
wmode: "transparent",
allowFullScreen: "true"
};
var attributes = {
id: "my_wp_zdytfp_container_193",
name: "my_wp_zdytfp_container_193"
};
swfobject.embedSWF("http://www.predatorinteractive.com/wp-content/plugins/zd-youtube-flv-player/flash/zdytflv-player-dark.swf", "v_wp_zdytfp_container_193", "630", "470", "9.0.0", false, flashvars, params, attributes);
</script>

<p><span style="color:   #ffffff;">h</span></p>
<p><span style="color: #ffffff;"><br />
</span></p>
<h2><span style="text-decoration: underline;">Clearing the Screen and Functions for Shapes</span></h2>
<p>Here is a quick overview of how to clear the screen and other functions you have for shapes.</p>
<h3><span style="text-decoration: underline;">Why Do We Need To Clear the Screen?</span></h3>
<p>So what exactly do we mean by clearing the screen.  Well if we did the following code:</p>
<p style="padding-left: 30px;">win <span style="color: #ff0000;">&lt;&lt;</span> Circle<span style="color: #ff0000;">(</span>Point<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">5</span><span style="color: #ff0000;">, </span><span style="color: #ff00ff;">5</span><span style="color: #ff0000;">),</span> <span style="color: #ff00ff;">2</span><span style="color: #ff0000;">);</span><br />
win<span style="color: #ff0000;">.</span>output_buffer<span style="color: #ff0000;">();</span></p>
<p>Naturally we will draw a circle to the screen.  But if we do the following code right afterward:</p>
<p style="padding-left: 30px;">win <span style="color: #ff0000;">&lt;&lt;</span> Rect<span style="color: #ff0000;">(</span>Point<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">2</span><span style="color: #ff0000;">, </span><span style="color: #ff00ff;">2</span><span style="color: #ff0000;">), </span><span style="color: #ff00ff;">3</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">3</span><span style="color: #ff0000;">);</span><br />
win<span style="color: #ff0000;">.</span>output_buffer<span style="color: #ff0000;">();</span></p>
<p>It will then draw a Rectangle to the screen.  However, the circle we initially outputted will still be on there as well. If we want to only have the Rectangle on the screen by itself, we have to clear the circle that we drew before hand. To do that, we need to make sure the buffer is empty prior to inserting the Rect object.</p>
<h3><span style="text-decoration: underline;">Clearing the Screen</span></h3>
<p>To clear the buffer we use the following function: <strong>win<span style="color: #ff0000;">.</span>clear_buffer<span style="color: #ff0000;">();</span></strong></p>
<p>This will clear all of the objects off of the buffer so we can begin inserting new ones to draw.  So now if we do the following code:</p>
<p style="padding-left: 30px;">win <span style="color: #ff0000;">&lt;&lt;</span> Circle<span style="color: #ff0000;">(</span>Point<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">5</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">5</span><span style="color: #ff0000;">),</span> <span style="color: #ff00ff;">2</span><span style="color: #ff0000;">);<br />
</span>win<span style="color: #ff0000;">.</span>output_buffer<span style="color: #ff0000;">();</span></p>
<p style="padding-left: 30px;">win<span style="color: #ff0000;">.</span>clear_buffer<span style="color: #ff0000;">();</span><br />
win <span style="color: #ff0000;">&lt;&lt;</span> Rect<span style="color: #ff0000;">(</span>Point<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">2</span><span style="color: #ff0000;">,</span><span style="color: #ff00ff;"> 2</span><span style="color: #ff0000;">), </span><span style="color: #ff00ff;">3</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">3</span><span style="color: #ff0000;">);</span><br />
win<span style="color: #ff0000;">.</span>output_buffer<span style="color: #ff0000;">();</span></p>
<p>First the circle is added to the buffer and drawn to the screen.  Then everything will be cleared from the buffer with <strong>win<span style="color: #ff0000;">.</span>clear_buffer<span style="color: #ff0000;">()</span></strong>.  This does <strong>NOT</strong> clear the screen, this just clears the drawing buffer.  Then the Rect is added to the empty drawing buffer.  And then finally, the Rect is outputted to the screen by itself with the second call of <strong>win<span style="color: #ff0000;">.</span>output_buffer<span style="color: #ff0000;">();</span></strong></p>
<hr />
<h2><span style="text-decoration: underline;"><span style="color: #ff0000;"><span style="color: #000000;">More Functions for Shapes</span></span></span></h2>
<p><strong><span style="color: #ff0000;"><span style="color: #000000;">Every shape in the Instinct Graphics Package can use the following functions:</span></span></strong></p>
<ul>
<li>obj<span style="color: #ff0000;">.</span>move<span style="color: #ff0000;">(</span><span style="color: #0000ff;">double</span> dx<span style="color: #ff0000;">,</span><span style="color: #0000ff;"> double</span> dy<span style="color: #ff0000;">);<span style="color: #000000;"> </span></span></li>
<li><span style="color: #ff0000;"><span style="color: #000000;">obj<span style="color: #ff0000;">.</span>get_color<span style="color: #ff0000;">();</span></span></span></li>
<li><span style="color: #ff0000;"><span style="color: #000000;">obj<span style="color: #ff0000;">.</span>is_filled_in<span style="color: #ff0000;">();</span></span></span></li>
<li><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;">obj<span style="color: #ff0000;">.</span>set_visibility<span style="color: #ff0000;">(</span><span style="color: #0000ff;">double</span> percent<span style="color: #ff0000;">);</span></span></span></span></span></span></span></li>
<li><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;">obj<span style="color: #ff0000;">.</span>get_visibility<span style="color: #ff0000;">();</span><br />
</span></span></span></span></span></span></li>
</ul>
<p>You can also use these functions below which were covered in Tutorial <strong><a href="http://www.predatorinteractive.com/instinct-graphics-package/2-basic-commands-and-drawing-shapes" target="_blank">2. Basic Commands and Drawing Shapes.</a></strong></p>
<ul>
<li>obj<span style="color: #ff0000;">.</span>set_color<span style="color: #ff0000;">(</span>Color color<span style="color: #ff0000;">); </span></li>
<li>obj<span style="color: #ff0000;">.</span>set_filled_in<span style="color: #ff0000;">(</span>bool is_filled<span style="color: #ff0000;">); </span></li>
</ul>
<h3><span style="text-decoration: underline;">Function:</span> obj<span style="color: #ff0000;">.</span>move<span style="color: #ff0000;">(</span><span style="color: #0000ff;">double</span> dx<span style="color: #ff0000;">,</span> <span style="color: #0000ff;">double</span> dy<span style="color: #ff0000;">);</span></h3>
<p><span style="text-decoration: underline;"><strong><span style="color: #ff0000;"> </span></strong></span><strong><span style="color: #ff0000;"><span style="color: #000000;">Definition: Moves the shape dx units in the x direction and dy units in the y direction.</span></span></strong></p>
<ul>
<li><span style="color: #ff0000;"><span style="color: #000000;">c<span style="color: #ff0000;"><span style="color: #000000;">irc</span>.</span>move<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">5</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">4</span><span style="color: #ff0000;">);</span></span></span></li>
<li><span style="color: #ff0000;"><span style="color: #000000;">message<span style="color: #ff0000;">.</span>move<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">-2</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">3</span><span style="color: #ff0000;">);</span></span></span></li>
<li><span style="color: #ff0000;"><span style="color: #000000;">triangle<span style="color: #ff0000;">.</span>move<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">0</span><span style="color: #ff0000;">,</span><span style="color: #ff00ff;"> -1</span><span style="color: #ff0000;">);</span><br />
</span></span></li>
</ul>
<p>So for the first example, we moved the Circle circ <span style="color: #ff00ff;">5</span> units in the x direction and<span style="color: #ff00ff;"> 4</span> units in the y direction.</p>
<h3><span style="text-decoration: underline;">Function:</span> obj<span style="color: #ff0000;">.</span>get_color<span style="color: #ff0000;">();</span></h3>
<p><span style="color: #ff0000;"><span style="color: #000000;"><strong>Definition: Returns the color of the shape.</strong></span></span></p>
<ul>
<li> <span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #0000ff;">if</span><span style="color: #ff0000;">(</span>circ<span style="color: #ff0000;">.</span>get_color<span style="color: #ff0000;">() <span style="color: #000000;"><span style="color: #ff0000;">==</span> YELLOW<span style="color: #ff0000;">)</span></span><br />
</span></span></span></li>
<li><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;">Color rect_color <span style="color: #ff0000;">=</span> rect<span style="color: #ff0000;">.</span>get_color<span style="color: #ff0000;">();</span></span><br />
</span></span></span></li>
</ul>
<p>So for the first example, the <span style="color: #0000ff;">if</span> statement is <span style="color: #0000ff;">true</span> if the color of circ is YELLOW.</p>
<h3><span style="text-decoration: underline;">Function:</span> obj<span style="color: #ff0000;">.</span>is_filled_in<span style="color: #ff0000;">();</span></h3>
<p><strong>Definition: Returns whether or not the shape is filled in with color.  <span style="color: #0000ff;">True</span> means it is filled in, <span style="color: #0000ff;">false</span> means it is outlined with color.</strong></p>
<ul>
<li>rect<span style="color: #ff0000;">.</span>is_filled_in<span style="color: #ff0000;">();</span></li>
<li><span style="color: #0000ff;">if</span><span style="color: #ff0000;">(</span>circ<span style="color: #ff0000;">.</span>is_filled_in<span style="color: #ff0000;">())</span></li>
</ul>
<p>The first example returns <span style="color: #0000ff;">true</span> if the Rect rect is filled in, and <span style="color: #0000ff;">false</span> if it is just outline with color.</p>
<h3><span style="text-decoration: underline;">Function:</span> obj<span style="color: #ff0000;">.</span>set_visibility<span style="color: #ff0000;">(</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #0000ff;">double</span> percent</span>);</span></h3>
<p><span style="color: #ff0000;"><strong><span style="color: #000000;">Definition: Sets the visibility of the shape to the percent amount passed in.  A percent value of <span style="color: #ff00ff;">1.0</span> means the shape is fully visible (100% visible). A percent value of <span style="color: #ff00ff;">0.5</span> means the shape is half visible (50% visible). A percent value of <span style="color: #ff00ff;">0.0</span> means the shape is fully invisible (0% visible).<br />
</span></strong></span></p>
<ul>
<li><span style="color: #ff0000;"><span style="color: #000000;">circ<span style="color: #ff0000;">.</span>set_visibility<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">0.75</span><span style="color: #ff0000;">);</span></span></span></li>
<li><span style="color: #ff0000;"><span style="color: #000000;">message<span style="color: #ff0000;">.</span>set_visibility<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">0.10</span><span style="color: #ff0000;">);</span></span></span></li>
</ul>
<p>The first example sets the visibility of circ to 75%.  So the Circle circ is parcially see-through but mostly visible.</p>
<h3><span style="text-decoration: underline;">Function:</span> obj<span style="color: #ff0000;">.</span>get_visibility<span style="color: #ff0000;">();</span></h3>
<p><strong>Definition: Returns the visibility amount of the shape.</strong></p>
<ul>
<li><span style="color: #0000ff;">if</span><span style="color: #ff0000;">(</span>circ<span style="color: #ff0000;">.</span>get_visibility<span style="color: #ff0000;">() ==</span> <span style="color: #ff00ff;">0.0</span><span style="color: #ff0000;">)</span></li>
<li>rect<span style="color: #ff0000;">.</span>set_visibility<span style="color: #ff0000;">(</span>rect<span style="color: #ff0000;">.</span>get_visiblity<span style="color: #ff0000;">()</span> <span style="color: #ff0000;">-</span> <span style="color: #ff00ff;">0.1</span><span style="color: #ff0000;">);</span></li>
</ul>
<p><span style="color: #000000;">The first example, the <span style="color: #0000ff;">if</span> statement is <span style="color: #0000ff;">true</span> if the visibility of circ is <span style="color: #ff00ff;">0.0</span> (invisible).</span></p>
<hr />
<h2><span style="color: #000000;"><span style="text-decoration: underline;">Functions Specific to each Shape</span></span></h2>
<p><span style="color: #000000;">Each shape also has its own set of specific functions that it&#8217;s shape type.  In other words, there are functions specific to Rects and functions specific to Circles, etc.  So let&#8217;s look at all of those:</span></p>
<h3><span style="text-decoration: underline;"><span style="color: #000000;">Point<br />
</span></span></h3>
<p><span style="color: #000000;">The Point shape has these specific functions it can call as well:</span></p>
<ul>
<li><span style="color: #000000;">pt<span style="color: #ff0000;">.</span>get_x<span style="color: #ff0000;">();</span></span></li>
<li><span style="color: #000000;">pt<span style="color: #ff0000;">.</span>get_y<span style="color: #ff0000;">();</span></span></li>
<li><span style="color: #000000;">pt<span style="color: #ff0000;">.</span>set_x<span style="color: #ff0000;">(</span><span style="color: #0000ff;">double</span> new_x<span style="color: #ff0000;">);</span></span></li>
<li><span style="color: #000000;">pt<span style="color: #ff0000;">.</span>set_y<span style="color: #ff0000;">(</span><span style="color: #0000ff;">double</span> new_y<span style="color: #ff0000;">);</span></span></li>
</ul>
<h3><span style="text-decoration: underline;">Circle</span></h3>
<p>The Circle shape has these specific functions it can call as well:</p>
<ul>
<li>circ<span style="color: #ff0000;">.</span>get_center<span style="color: #ff0000;">();</span></li>
<li>circ<span style="color: #ff0000;">.</span>get_radius<span style="color: #ff0000;">();</span></li>
<li>circ<span style="color: #ff0000;">.</span>set_radius<span style="color: #ff0000;">(</span>double new_radius<span style="color: #ff0000;">);</span></li>
<li>circ<span style="color: #ff0000;">.</span>set_center<span style="color: #ff0000;">(</span>Point new_center<span style="color: #ff0000;">);</span></li>
</ul>
<h3><span style="text-decoration: underline;">Line</span></h3>
<p>The Line shape has these specific functions it can call as well:</p>
<ul>
<li>line<span style="color: #ff0000;">.</span>get_start<span style="color: #ff0000;">();</span></li>
<li>line<span style="color: #ff0000;">.</span>get_end<span style="color: #ff0000;">();</span></li>
<li>line<span style="color: #ff0000;">.</span>set_start<span style="color: #ff0000;">(</span>Point new_start<span style="color: #ff0000;">);</span></li>
<li>line<span style="color: #ff0000;">.</span>set_end<span style="color: #ff0000;">(</span>Point new_end<span style="color: #ff0000;">);</span></li>
</ul>
<h3><span style="text-decoration: underline;">Triangle</span></h3>
<p>The Triangle shape has these specific functions it can call:</p>
<ul>
<li>tri<span style="color: #ff0000;">.</span>get_p1<span style="color: #ff0000;">();</span></li>
<li>tri<span style="color: #ff0000;">.</span>get_p2<span style="color: #ff0000;">();</span></li>
<li>tri<span style="color: #ff0000;">.</span>get_p3<span style="color: #ff0000;">();</span></li>
<li>tri<span style="color: #ff0000;">.</span>set_p1<span style="color: #ff0000;">(</span>Point new_p1<span style="color: #ff0000;">);</span></li>
<li>tri<span style="color: #ff0000;">.</span>set_p2<span style="color: #ff0000;">(</span>Point new_p2<span style="color: #ff0000;">);</span></li>
<li>tri<span style="color: #ff0000;">.</span>set_p3<span style="color: #ff0000;">(</span>Point new_p3<span style="color: #ff0000;">);</span></li>
</ul>
<h3><span style="text-decoration: underline;">Message</span></h3>
<p>The Message shape has these specific functions it can call:</p>
<ul>
<li>message<span style="color: #ff0000;">.</span>get_text<span style="color: #ff0000;">();</span></li>
<li>message<span style="color: #ff0000;">.</span>get_lower_left<span style="color: #ff0000;">();</span></li>
<li>message<span style="color: #ff0000;">.</span>set_text<span style="color: #ff0000;">(</span><span style="color: #000000;">string</span> text<span style="color: #ff0000;">);<br />
</span>message<span style="color: #ff0000;">.</span>set_text<span style="color: #ff0000;">(</span><span style="color: #0000ff;">int </span>text<span style="color: #ff0000;">);</span><br />
message<span style="color: #ff0000;">.</span>set_text<span style="color: #ff0000;">(</span><span style="color: #0000ff;">double</span> text<span style="color: #ff0000;">); </span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.predatorinteractive.com/instinct-graphics-package/clearing-the-screen-and-putting-it-all-together/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5. Window and Coordinate Resizing</title>
		<link>http://www.predatorinteractive.com/instinct-graphics-package/5-window-and-coordinate-resizing</link>
		<comments>http://www.predatorinteractive.com/instinct-graphics-package/5-window-and-coordinate-resizing#comments</comments>
		<pubDate>Tue, 23 Jun 2009 05:00:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Instinct Graphics Package]]></category>
		<category><![CDATA[coord]]></category>
		<category><![CDATA[win]]></category>
		<category><![CDATA[window size]]></category>

		<guid isPermaLink="false">http://www.predatorinteractive.com/?p=228</guid>
		<description><![CDATA[Functions that will allow you to change both the coordinate system and actual window size.]]></description>
			<content:encoded><![CDATA[<div id="wp_zdytfp_container_228" style="width:100%; height:470px; text-align:center; margin:auto;">
<div id="v_wp_zdytfp_container_228" style="width:100%; height:100%;">ZD YouTube FLV Player</div>
</div>
<script type="text/javascript">
var flashvars = {
vurl: "http://www.predatorinteractive.com/wp-content/uploads/2009/06/instinctwindowresize.mp4",
autoplay: "yes",
yturl: "http://www.predatorinteractive.com/wp-content/plugins/zd-youtube-flv-player/fl_youTubeProxy.php"
};
var params = {
wmode: "transparent",
allowFullScreen: "true"
};
var attributes = {
id: "my_wp_zdytfp_container_228",
name: "my_wp_zdytfp_container_228"
};
swfobject.embedSWF("http://www.predatorinteractive.com/wp-content/plugins/zd-youtube-flv-player/flash/zdytflv-player-dark.swf", "v_wp_zdytfp_container_228", "630", "470", "9.0.0", false, flashvars, params, attributes);
</script>

<p><span style="color:   #ffffff;">h</span></p>
<p><span style="color: #ffffff;"><br />
</span></p>
<h2><span style="text-decoration: underline;"><strong>Window and Coordinate Resizing<br />
</strong></span></h2>
<p>So we have seen how to draw the basic shapes and how to get user input to build some more interesting programs.   Now let&#8217;s figure out how to modify our coordinate window and the physical window size.</p>
<h3><span style="text-decoration: underline;">Setting the Coordinate System</span></h3>
<p>If you remember from before, our default coordinate system is (0, 0) in the bottom left corner, and (10, 10) in the top right corner.</p>
<p style="text-align: center;"><a href="http://www.predatorinteractive.com/?attachment_id=548"><img class="aligncenter size-full wp-image-548" title="coord" src="http://www.predatorinteractive.com/wp-content/uploads/2010/05/coord.PNG" alt="coord" width="412" height="430" /></a></p>
<p>We do have a function for changing the coordinate system: <strong><br />
win<span style="color: #ff0000;">.</span>coord<span style="color: #ff0000;">(</span><span style="color: #0000ff;">double</span> ll_x, <span style="color: #0000ff;">double</span> ll_y, <span style="color: #0000ff;">double</span> ur_x, <span style="color: #0000ff;">double</span> ur_y<span style="color: #ff0000;">);<br />
</span></strong><span style="color: #000000;"><em>Example:</em></span><strong><span style="color: #ff0000;"> </span></strong></p>
<ul>
<li>win<span style="color: #ff0000;">.</span>coord<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">0</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">0</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">10</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">10</span><span style="color: #ff0000;">);</span> <span style="color: #999999;">//Default coordinate system</span></li>
<li>win<span style="color: #ff0000;">.</span>coord<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">0</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">0</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">50</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">50</span><span style="color: #ff0000;">);</span></li>
<li>win<span style="color: #ff0000;">.</span>coord<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">-124.5</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">76</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">92.4</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">-33.7</span><span style="color: #ff0000;">);</span></li>
</ul>
<p>So for example three up there, our coordinate system would be this after that call:</p>
<p style="text-align: center;"><a href="http://www.predatorinteractive.com/?attachment_id=549"><img class="aligncenter size-full wp-image-549" title="coord2" src="http://www.predatorinteractive.com/wp-content/uploads/2010/05/coord2.PNG" alt="coord2" width="413" height="430" /></a></p>
<p>So the first two values of <strong>win<span style="color: #ff0000;">.</span>coord<span style="color: #ff0000;">(</span>ll_x,  ll_y, ur_x, ur_y<span style="color: #ff0000;">)</span></strong> are the X and Y of the lower left corner of the  coordinate system on the screen and the second two values are the X and Y  of the upper left corner.</p>
<h3><span style="text-decoration: underline;">Changing the Screen Size</span></h3>
<p>As you have probably noticed, our default physical window is a square:</p>
<p style="text-align: center;"><a rel="attachment wp-att-551" href="http://www.predatorinteractive.com/instinct-graphics-package/5-window-and-coordinate-resizing/attachment/squaresize"><img class="aligncenter size-full wp-image-551" title="squaresize" src="http://www.predatorinteractive.com/wp-content/uploads/2010/05/squaresize.PNG" alt="squaresize" width="330" height="344" /></a></p>
<p style="text-align: center;">
<p><strong>The default size of our window is <span style="color: #ff00ff;">500 </span>pixels for the width and <span style="color: #ff00ff;">500</span> pixels for the height.</strong></p>
<p>If you ever want to change the size of your window<strong>, (not the coordinate system)</strong>, you can use this function: <strong>win<span style="color: #ff0000;">.</span>set_window_size<span style="color: #ff0000;">(</span><span style="color: #0000ff;">int</span> width<span style="color: #ff0000;">, </span><span style="color: #0000ff;">int</span> height<span style="color: #ff0000;">);<br />
</span></strong><span style="color: #ff0000;"><span style="color: #000000;"><em>Example:</em></span></span></p>
<ul>
<li><span style="color: #ff0000;"><span style="color: #000000;">win<span style="color: #ff0000;">.</span>set_window_size<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">500</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">500</span><span style="color: #ff0000;">);</span> <span style="color: #808080;">//Default window size</span></span></span></li>
<li><span style="color: #ff0000;"><span style="color: #000000;">win<span style="color: #ff0000;">.</span>set_window_size<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">800</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">600</span><span style="color: #ff0000;">);</span></span></span></li>
<li><span style="color: #ff0000;"><span style="color: #000000;">win<span style="color: #ff0000;">.</span>set_window_size<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">1280, </span><span style="color: #ff0000;"> </span> <span style="color: #ff00ff;">720</span><span style="color: #ff0000;">);</span></span></span></li>
</ul>
<p><strong>If you are looking for a decent wide window size, standards like </strong><strong><span style="color: #ff00ff;">800</span> x <span style="color: #ff00ff;">600</span>, <span style="color: #ff00ff;">1024</span> x <span style="color: #ff00ff;">768</span>, <span style="color: #ff00ff;">1280</span> x <span style="color: #ff00ff;">720</span> are good sizes to use.</strong></p>
<p>To get an idea of what resizing the window would do, here is what the window would look like after running the second example above (<span style="color: #ff00ff;">800</span> x <span style="color: #ff00ff;">600</span>):</p>
<p style="text-align: center;"><a href="http://www.predatorinteractive.com/?attachment_id=550"></a><a rel="attachment wp-att-550" href="http://www.predatorinteractive.com/instinct-graphics-package/5-window-and-coordinate-resizing/attachment/rectwindow"><img class="aligncenter size-full wp-image-550" title="rectwindow" src="http://www.predatorinteractive.com/wp-content/uploads/2010/05/rectwindow.PNG" alt="rectwindow" width="523" height="408" /></a></p>
<p>Ut oh! The window looks bigger but the circle no longer looks correct.  The reason is because we stretched the window without changing our coordinate system.</p>
<h3><span style="text-decoration: underline;"><strong>Choosing Coordinate Systems for Certain Window Sizes</strong></span></h3>
<p><strong>To get the best results, you should use window sizes and coordinate sizes that are of the same ratio.</strong></p>
<p>The reason the default window size and coordinate size look alright is because both are ratio <strong>1 : 1</strong>.</p>
<ul>
<li>Default Coordinate System: <span style="color: #ff00ff;">10</span> by <span style="color: #ff00ff;">10</span>.  <span style="color: #ff00ff;">10</span> / <span style="color: #ff00ff;">10</span> =&gt;  <span style="color: #ff00ff;">1</span> / <span style="color: #ff00ff;">1 </span> =&gt; <strong> 1 : 1</strong></li>
<li>Default Window Size: <span style="color: #ff00ff;">500</span> by <span style="color: #ff00ff;">500</span>.  <span style="color: #ff00ff;">500</span> / <span style="color: #ff00ff;">500</span> =&gt;  <span style="color: #ff00ff;">1</span> /<span style="color: #ff00ff;"> 1</span> =&gt;  <strong>1 : 1</strong></li>
</ul>
<p>Since both the coordinate system and window size are of the same ratio <strong>1 : 1</strong>, everything drawn looks normal.</p>
<p><strong>But why did it look stretched when we changed the window size to <span style="color: #ff00ff;">800</span> x <span style="color: #ff00ff;">600</span>?</strong></p>
<ul>
<li>Default Coordinate System: <span style="color: #ff00ff;">10</span> by <span style="color: #ff00ff;">10</span>.  <span style="color: #ff00ff;">10</span> / <span style="color: #ff00ff;">10</span> =&gt; <span style="color: #ff00ff;">1</span> / <span style="color: #ff00ff;">1</span> =&gt;  <strong>1 : 1</strong></li>
<li>New Window Size: <span style="color: #ff00ff;">800</span> by <span style="color: #ff00ff;">600</span>.   <span style="color: #ff00ff;">800 </span>/<span style="color: #ff00ff;"> 600</span> =&gt; <span style="color: #ff00ff;">4</span> / <span style="color: #ff00ff;">3</span> =&gt;  <strong>4 : 3</strong></li>
</ul>
<p>The reason the circle looked stretched was because the coordinate size and window size had different ratios. <strong>1 : 1</strong> and <strong>4 : 3</strong></p>
<p><strong>Solution? Choose a coordinate system that has the same ratio as your window.</strong></p>
<p><strong>win<span style="color: #ff0000;">.</span>coord<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">0</span><span style="color: #ff0000;">, </span><span style="color: #ff00ff;">0</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">40</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">30</span><span style="color: #ff0000;">); </span></strong><span style="color: #ff0000;"><span style="color: #999999;">//Change the coordinate system</span></span><strong><br />
</strong></p>
<ul>
<li>New Coordinate System: <span style="color: #ff00ff;">40</span> by <span style="color: #ff00ff;">30</span>.  <span style="color: #ff00ff;">40</span> / <span style="color: #ff00ff;">30</span> =&gt; <span style="color: #ff00ff;">4</span> / <span style="color: #ff00ff;">3</span> =&gt;  <strong>4 : 3</strong></li>
<li>New Window Size: <span style="color: #ff00ff;">800</span> by <span style="color: #ff00ff;">600</span>.   <span style="color: #ff00ff;">800 </span>/<span style="color: #ff00ff;"> 600</span> =&gt; <span style="color: #ff00ff;">4</span> / <span style="color: #ff00ff;">3</span> =&gt;  <strong>4 : 3</strong></li>
</ul>
<p>Now our coordinate system and window size have the same ratio <strong>4 : 3</strong>! Draw a circle in the center of our new coordinate system.</p>
<ul>
<li>win <span style="color: #ff0000;">&lt;&lt;</span> Circle<span style="color: #ff0000;">(</span>Point<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">20</span><span style="color: #ff0000;">,</span><span style="color: #ff00ff;"> 15</span><span style="color: #ff0000;">),</span> <span style="color: #ff00ff;">5</span><span style="color: #ff0000;">, </span>BLUE<span style="color: #ff0000;">,</span> <span style="color: #0000ff;">true</span><span style="color: #ff0000;">);</span></li>
</ul>
<p style="text-align: center;"><a href="http://www.predatorinteractive.com/?attachment_id=552"><img class="aligncenter size-full wp-image-552" title="widefix" src="http://www.predatorinteractive.com/wp-content/uploads/2010/05/widefix.PNG" alt="widefix" width="523" height="410" /></a></p>
<p style="text-align: left;">Viola! Everything looks normal again!  So now you know how to change your coordinate window and your physical window size. <strong>And remember! Try to use the same ratios for both to make things draw proportionally correct!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.predatorinteractive.com/instinct-graphics-package/5-window-and-coordinate-resizing/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://www.predatorinteractive.com/wp-content/uploads/2009/06/instinctwindowresize.mp4" length="28898718" type="video/mp4" />
		</item>
		<item>
		<title>6. Creating and Drawing Images</title>
		<link>http://www.predatorinteractive.com/instinct-graphics-package/6-creating-and-drawing-images</link>
		<comments>http://www.predatorinteractive.com/instinct-graphics-package/6-creating-and-drawing-images#comments</comments>
		<pubDate>Tue, 23 Jun 2009 05:02:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Instinct Graphics Package]]></category>
		<category><![CDATA[drawing]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[sprites]]></category>

		<guid isPermaLink="false">http://www.predatorinteractive.com/?p=231</guid>
		<description><![CDATA[All the basics about where to put your images, how to draw them, and helpful hints about transparency.]]></description>
			<content:encoded><![CDATA[<div id="wp_zdytfp_container_231" style="width:100%; height:470px; text-align:center; margin:auto;">
<div id="v_wp_zdytfp_container_231" style="width:100%; height:100%;">ZD YouTube FLV Player</div>
</div>
<script type="text/javascript">
var flashvars = {
vurl: "http://www.predatorinteractive.com/wp-content/uploads/2009/06/instinctimages.mp4",
autoplay: "yes",
yturl: "http://www.predatorinteractive.com/wp-content/plugins/zd-youtube-flv-player/fl_youTubeProxy.php"
};
var params = {
wmode: "transparent",
allowFullScreen: "true"
};
var attributes = {
id: "my_wp_zdytfp_container_231",
name: "my_wp_zdytfp_container_231"
};
swfobject.embedSWF("http://www.predatorinteractive.com/wp-content/plugins/zd-youtube-flv-player/flash/zdytflv-player-dark.swf", "v_wp_zdytfp_container_231", "630", "470", "9.0.0", false, flashvars, params, attributes);
</script>

<p><span style="color:   #ffffff;">h</span></p>
<p><span style="color: #ffffff;"><br />
</span></p>
<p>All the basics about where to put your images, how to draw them, and helpful hints about transparency.</p>
<p><strong>Image Types</strong></p>
<p>JPEG &#8211; Does no transparency.</p>
<p>GIF &#8211; Does either full transparency or full opaque.</p>
<p>PNG &#8211; Does any level of transparency and opacity.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.predatorinteractive.com/instinct-graphics-package/6-creating-and-drawing-images/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://www.predatorinteractive.com/wp-content/uploads/2009/06/instinctimages.mp4" length="6667316" type="video/mp4" />
		</item>
		<item>
		<title>7. Basic Animation and Timers</title>
		<link>http://www.predatorinteractive.com/instinct-graphics-package/7-basic-animation-and-timers</link>
		<comments>http://www.predatorinteractive.com/instinct-graphics-package/7-basic-animation-and-timers#comments</comments>
		<pubDate>Tue, 23 Jun 2009 05:06:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Instinct Graphics Package]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[ball]]></category>
		<category><![CDATA[bouncing]]></category>
		<category><![CDATA[frame]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[timer]]></category>

		<guid isPermaLink="false">http://www.predatorinteractive.com/?p=233</guid>
		<description><![CDATA[How to generally setup your program for doing animations and using Timers to ensure the program runs the same across different computers.]]></description>
			<content:encoded><![CDATA[<div id="wp_zdytfp_container_233" style="width:100%; height:470px; text-align:center; margin:auto;">
<div id="v_wp_zdytfp_container_233" style="width:100%; height:100%;">ZD YouTube FLV Player</div>
</div>
<script type="text/javascript">
var flashvars = {
vurl: "http://www.predatorinteractive.com/wp-content/uploads/2009/06/instinct_animation.mp4",
autoplay: "yes",
yturl: "http://www.predatorinteractive.com/wp-content/plugins/zd-youtube-flv-player/fl_youTubeProxy.php"
};
var params = {
wmode: "transparent",
allowFullScreen: "true"
};
var attributes = {
id: "my_wp_zdytfp_container_233",
name: "my_wp_zdytfp_container_233"
};
swfobject.embedSWF("http://www.predatorinteractive.com/wp-content/plugins/zd-youtube-flv-player/flash/zdytflv-player-dark.swf", "v_wp_zdytfp_container_233", "630", "470", "9.0.0", false, flashvars, params, attributes);
</script>

<p><span style="color:   #ffffff;">h</span></p>
<p><span style="color: #ffffff;"><br />
</span></p>
<h2><span style="text-decoration: underline;">Basic Animation and Timers</span></h2>
<p>Prior to actually getting into the animation code, let&#8217;s take a quick look at timers.</p>
<h3><span style="text-decoration: underline;">Timers</span></h3>
<p>To create a timer which has a time value of zero, simply type: <strong>&#8220;Timer name_of_timer<span style="color: #ff0000;">;</span><span style="color: #000000;">&#8220;</span></strong><br />
Example:</p>
<ul>
<li>Timer animation_timer<span style="color: #ff0000;">;</span></li>
<li>Timer stopwatch<span style="color: #ff0000;">;</span></li>
</ul>
<p><span style="color: #000000;">The basic functions of timers are as follow:</span></p>
<ul>
<li><span style="color: #000000;">timer<span style="color: #ff0000;">.</span>start<span style="color: #ff0000;">();</span> <span style="color: #808080;">//Makes the timer starting ticking.</span><br />
</span></li>
<li><span style="color: #000000;">timer<span style="color: #ff0000;">.</span>stop<span style="color: #ff0000;">(); </span><span style="color: #808080;">//Stops the timer from ticking.</span></span></li>
<li><span style="color: #000000;">timer<span style="color: #ff0000;">.</span>reset<span style="color: #ff0000;">();</span> <span style="color: #808080;">//Resets the time value of the timer to zero regardless if it is running or not.</span></span></li>
</ul>
<p><span style="color: #000000;">To get the number of <em><strong>milliseconds</strong></em> on the timer, use the member function: <strong>&#8220;timer<span style="color: #ff0000;">.</span>get_time<span style="color: #ff0000;">();<span style="color: #000000;">&#8220;</span><br />
</span></strong><span style="color: #ff0000;"><span style="color: #000000;">Example:</span></span></span></p>
<ul>
<li><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #0000ff;">int</span> milliseconds <span style="color: #ff0000;">=</span> timer<span style="color: #ff0000;">.</span>get_time<span style="color: #ff0000;">();</span></span></span></span></li>
<li><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;">win <span style="color: #ff0000;">&lt;&lt;</span> Message<span style="color: #ff0000;">(</span>Point<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">5</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">5</span><span style="color: #ff0000;">),</span> timer<span style="color: #ff0000;">.</span>get_time<span style="color: #ff0000;">());</span></span></span></span></li>
<li><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #0000ff;">if</span><span style="color: #ff0000;">(</span>timer.get_time<span style="color: #ff0000;">()</span> <span style="color: #ff0000;">&gt;</span> <span style="color: #ff00ff;">1000</span><span style="color: #ff0000;">)</span></span></span></span></li>
</ul>
<p>To add time to the timer use the <strong>&#8220;timer<span style="color: #ff0000;">.</span>add_time<span style="color: #ff0000;">(</span><span style="color: #0000ff;">double</span> milliseconds<span style="color: #ff0000;">);<span style="color: #000000;">&#8220;</span></span></strong><span style="color: #000000;"> </span>member function.<br />
Example:</p>
<ul>
<li>timer<span style="color: #ff0000;">.</span>add_time<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">20000</span><span style="color: #ff0000;">);</span></li>
<li>timer<span style="color: #ff0000;">.</span>add_time<span style="color: #ff0000;">(</span>penalty_time<span style="color: #ff0000;">);</span></li>
</ul>
<p><span style="color: #000000;">To check if the time has passed some number of milliseconds use:<strong><span style="color: #000000;"> &#8220;</span><span style="color: #0000ff;">bool</span> timer<span style="color: #ff0000;">.</span>has_passed<span style="color: #ff0000;">(</span><span style="color: #0000ff;">double</span> milliseconds<span style="color: #ff0000;">);<span style="color: #000000;">&#8220;</span><br />
</span></strong><span style="color: #ff0000;"><span style="color: #000000;">Example:</span></span></span></p>
<ul>
<li><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #0000ff;">if</span><span style="color: #ff0000;">(</span>timer<span style="color: #ff0000;">.</span>has_passed<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">15000</span><span style="color: #ff0000;">));</span></span></span></span></li>
<li><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #0000ff;">bool</span> passed <span style="color: #ff0000;">=</span> timer<span style="color: #ff0000;">.</span>has_passed<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">10500</span><span style="color: #ff0000;">);</span></span></span></span></li>
</ul>
<h3><span style="text-decoration: underline;">Wait for</span></h3>
<p>You can also use the <strong>&#8220;wait_for<span style="color: #ff0000;">(</span><span style="color: #0000ff;">double</span> milliseconds<span style="color: #ff0000;">)<span style="color: #000000;">&#8220;</span></span></strong><span style="color: #ff0000;"> </span>function which makes the program wait for the passed in number of milliseconds.<br />
Example:</p>
<ul>
<li>wait_for<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">10000</span><span style="color: #ff0000;">);</span> <span style="color: #808080;">//The program will wait here for 10 seconds.</span></li>
<li>wait_for<span style="color: #ff0000;">(</span>delay_time<span style="color: #ff0000;">);</span> <span style="color: #808080;">//The program will wait here for delay_time milliseconds.</span></li>
</ul>
<p>Remember, there are <span style="color: #ff00ff;">1000</span> milliseconds in <span style="color: #ff00ff;">1</span> second.</p>
<h2><span style="text-decoration: underline;">Animation</span></h2>
<p>To better understand animation, here is a general definition:<strong> Seeing a series of rapid pictures that gives the illusion of movement.</strong></p>
<h3><strong><span style="text-decoration: underline;">Frames</span><br />
</strong></h3>
<p>We are going to call these individual pictures that create this illusion of movement<em><strong> frames. </strong></em>So for example here are a series of four frames:</p>
<p style="text-align: center;"><a rel="attachment wp-att-489" href="http://www.predatorinteractive.com/instinct-graphics-package/7-basic-animation-and-timers/attachment/movingballframe_1"><img class="alignnone size-full wp-image-489" title="movingballframe_1" src="http://www.predatorinteractive.com/wp-content/uploads/2009/06/movingballframe_1.gif" alt="movingballframe_1" width="132" height="132" /></a> <a rel="attachment wp-att-490" href="http://www.predatorinteractive.com/instinct-graphics-package/7-basic-animation-and-timers/attachment/movingballframe_2"><img class="alignnone size-full wp-image-490" title="movingballframe_2" src="http://www.predatorinteractive.com/wp-content/uploads/2009/06/movingballframe_2.gif" alt="movingballframe_2" width="132" height="132" /></a> <a rel="attachment wp-att-491" href="http://www.predatorinteractive.com/instinct-graphics-package/7-basic-animation-and-timers/attachment/movingballframe_3"><img class="alignnone size-full wp-image-491" title="movingballframe_3" src="http://www.predatorinteractive.com/wp-content/uploads/2009/06/movingballframe_3.gif" alt="movingballframe_3" width="132" height="132" /></a> <a rel="attachment wp-att-492" href="http://www.predatorinteractive.com/instinct-graphics-package/7-basic-animation-and-timers/attachment/movingballframe_4"><img class="alignnone size-full wp-image-492" title="movingballframe_4" src="http://www.predatorinteractive.com/wp-content/uploads/2009/06/movingballframe_4.gif" alt="movingballframe_4" width="132" height="132" /></a></p>
<p>Now if we show each of these frames one after another with a small pause in between, we will see what <em>looks</em> like a ball moving. This illusion is the basis behind animation!</p>
<p style="text-align: center;"><a rel="attachment wp-att-498" href="http://www.predatorinteractive.com/instinct-graphics-package/7-basic-animation-and-timers/attachment/movingball"><img class="size-full wp-image-498 aligncenter" title="movingball" src="http://www.predatorinteractive.com/wp-content/uploads/2009/06/movingball.gif" alt="movingball" width="180" height="180" /></a></p>
<p style="text-align: left;">Now that we hopefully have a better understanding of how animation works, we can put it to use with the Instinct Graphics Package.</p>
<h3 style="text-align: left;"><span style="text-decoration: underline;">Coding Animation</span></h3>
<p>Well we could code the above example by simply drawing a ball, moving it and redrawing it.  If we did that four times in our code with a <strong>wait_for<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">100</span><span style="color: #ff0000;">);</span></strong> in between each of those to cause a slight pause, we could reproduce the moving blue ball easily.<br />
Example:</p>
<pre style="padding-left: 30px;">Circle circ <span style="color: #ff0000;">=</span> Circle<span style="color: #ff0000;">(</span>Point<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">1</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">5</span><span style="color: #ff0000;">),</span> <span style="color: #ff00ff;">1</span><span style="color: #ff0000;">,</span> BLUE<span style="color: #ff0000;">,</span> <span style="color: #0000ff;">true</span><span style="color: #ff0000;">);</span>

<span style="color: #808080;">//Frame 1</span>
win <span style="color: #ff0000;">&lt;&lt;</span> circ<span style="color: #ff0000;">;</span>
win<span style="color: #ff0000;">.</span>output_buffer<span style="color: #ff0000;">();</span>

<span style="color: #808080;">//Frame 2</span>
wait_for<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">100</span><span style="color: #ff0000;">);</span>
circ<span style="color: #ff0000;">.</span>move<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">1</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">0</span><span style="color: #ff0000;">);</span>
win.clear_buffer<span style="color: #ff0000;">();</span>
win <span style="color: #ff0000;">&lt;&lt;</span> circ<span style="color: #ff0000;">;</span>
win<span style="color: #ff0000;">.</span>output_buffer<span style="color: #ff0000;">();</span>

<span style="color: #808080;">//Frame 3</span>
wait_for<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">100</span><span style="color: #ff0000;">);</span>
circ<span style="color: #ff0000;">.</span>move<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">1</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">0</span><span style="color: #ff0000;">);</span>
win.clear_buffer<span style="color: #ff0000;">();</span>
win <span style="color: #ff0000;">&lt;&lt;</span> circ<span style="color: #ff0000;">;</span>
win<span style="color: #ff0000;">.</span>output_buffer<span style="color: #ff0000;">();</span>

<span style="color: #808080;">//Frame 4</span>
wait_for<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">100</span><span style="color: #ff0000;">);</span>
circ<span style="color: #ff0000;">.</span>move<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">1</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">0</span><span style="color: #ff0000;">);</span>
win.clear_buffer<span style="color: #ff0000;">();</span>
win <span style="color: #ff0000;">&lt;&lt;</span> circ<span style="color: #ff0000;">;</span>
win<span style="color: #ff0000;">.</span>output_buffer<span style="color: #ff0000;">();
</span></pre>
<p>As you can see above, the frames 2-4 become very much the same. If we wanted more frames we would have to continue copying and pasting the same code for each frame.</p>
<h3><span style="text-decoration: underline;">Using loops</span></h3>
<p>However, if we use a loop that moves everything and redraws it each time, we could have as many frames as we want without having to continuously add code for each frame.<br />
Example:</p>
<pre style="padding-left: 30px;">win <span style="color: #ff0000;">&lt;&lt;</span> circ<span style="color: #ff0000;">;</span>
win<span style="color: #ff0000;">.</span>output_buffer<span style="color: #ff0000;">();</span>

<span style="color: #808080;"><span style="color: #0000ff;">while</span><span style="color: #ff0000;">(</span><span style="color: #0000ff;">true</span><span style="color: #ff0000;">)</span>
<span style="color: #ff0000;">{</span></span>
    wait_for<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">100</span><span style="color: #ff0000;">);</span>
    circ<span style="color: #ff0000;">.</span>move<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">1</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">0</span><span style="color: #ff0000;">);</span>
    win.clear_buffer<span style="color: #ff0000;">();</span>
    win <span style="color: #ff0000;">&lt;&lt;</span> circ<span style="color: #ff0000;">;</span>
    win<span style="color: #ff0000;">.</span>output_buffer<span style="color: #ff0000;">();
}</span></pre>
<p>With the <strong><span style="color: #0000ff;">while</span><span style="color: #ff0000;">(</span><span style="color: #0000ff;">true</span><span style="color: #ff0000;">)</span></strong>, the program will continuously run that loop until we close the program.  So now the loop will continously do frame after frame of moving the ball and redrawing it.</p>
<h3><span style="text-decoration: underline;">Frame Rate<br />
</span></h3>
<p>As you can see above, we were using a value of <span style="color: #ff00ff;">100</span> as the number of milliseconds to wait in between each frame.  This in practice is not a nice number to use since that only allows us to have around <span style="color: #ff00ff;">10</span> frames per second (FPS), which is not a good number.  Generally speaking, a good frame rate for animated programs is usually in between <span style="color: #ff00ff;">60</span> and <span style="color: #ff00ff;">30</span> frames per second.  Because of that, I would suggest using a wait_for amount of <strong><span style="color: #ff00ff;">20</span></strong> milliseconds, which in turn creates a frame rate of around <span style="color: #ff00ff;">50</span> FPS.</p>
<ul>
<li>wait_for<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">20</span><span style="color: #ff0000;">);</span></li>
</ul>
<p>Just keep in mind that this wait_for<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">20</span><span style="color: #ff0000;">);</span> by itself is not the best way to do timing for animation, but it is the simplest.  Later we will go over better and more advanced forms of doing timing for animation loops.</p>
<h3><span style="text-decoration: underline;">Sectioning the Animation Loop</span></h3>
<p>The last bit of advice I would suggest is to always split up the animation loop into two sections to make sure it is done right:</p>
<pre style="padding-left: 30px;"><span style="color: #808080;"><span style="color: #0000ff;">while</span><span style="color: #ff0000;">(</span><span style="color: #0000ff;">true</span><span style="color: #ff0000;">)</span>
<span style="color: #ff0000;">{</span></span>
    wait_for<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">20</span><span style="color: #ff0000;">);</span>

    <span style="color: #808080;">///////////////////
    // Handle Logic
    /////////////////</span><span style="color: #808080;">//</span>
    circ<span style="color: #ff0000;">.</span>move<span style="color: #ff0000;">(</span><span style="color: #ff00ff;">1</span><span style="color: #ff0000;">,</span> <span style="color: #ff00ff;">0</span><span style="color: #ff0000;">);

    <span style="color: #808080;">///////////////////
    // Draw Everything
    ///////////////////</span>
</span>    win.clear_buffer<span style="color: #ff0000;">();</span>
    win <span style="color: #ff0000;">&lt;&lt;</span> circ<span style="color: #ff0000;">;</span>
    win<span style="color: #ff0000;">.</span>output_buffer<span style="color: #ff0000;">();
}
</span></pre>
<p>There should be two distinct sections, the section that handles all the logic of the animation (moving objects, doing collision detection, changing colors of objects, etc), and a section that simply draws everything that needs to be drawn.  So what does this mean?  There should be NO drawing of objects in the <em><strong>Handle Logic</strong></em> section, and only code that deals with the drawing of objects in the <em><strong>Draw Everything</strong></em> section.  If you code is sectioned properly and done correctly, your animation should come out nice and smooth and work perfectly with no flickering.</p>
<h3><span style="text-decoration: underline;">What Now?</span></h3>
<p>Now the rest is up to you in terms of what you want to do in this animation loop.  You don&#8217;t have to have a ball that moves around solely in the X direction.  This was merely an example. You can use Rects, Circles, Images, etc. to make anything you can think of.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.predatorinteractive.com/instinct-graphics-package/7-basic-animation-and-timers/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://www.predatorinteractive.com/wp-content/uploads/2009/06/instinct_animation.mp4" length="40893731" type="video/mp4" />
		</item>
		<item>
		<title>8. Real Time User Input</title>
		<link>http://www.predatorinteractive.com/instinct-graphics-package/8-real-time-user-input</link>
		<comments>http://www.predatorinteractive.com/instinct-graphics-package/8-real-time-user-input#comments</comments>
		<pubDate>Tue, 23 Jun 2009 05:09:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Instinct Graphics Package]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[key]]></category>
		<category><![CDATA[mouse]]></category>
		<category><![CDATA[real time]]></category>
		<category><![CDATA[user]]></category>

		<guid isPermaLink="false">http://www.predatorinteractive.com/?p=237</guid>
		<description><![CDATA[Coming Soon!]]></description>
			<content:encoded><![CDATA[<p>Be able to now get real time feedback from the user without halting your program.  You should know the basics of animations prior to trying this one out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.predatorinteractive.com/instinct-graphics-package/8-real-time-user-input/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>9. Playing Audio</title>
		<link>http://www.predatorinteractive.com/instinct-graphics-package/9-playing-audio</link>
		<comments>http://www.predatorinteractive.com/instinct-graphics-package/9-playing-audio#comments</comments>
		<pubDate>Tue, 23 Jun 2009 05:14:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Instinct Graphics Package]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[ogg]]></category>
		<category><![CDATA[sound]]></category>
		<category><![CDATA[wav]]></category>

		<guid isPermaLink="false">http://www.predatorinteractive.com/?p=242</guid>
		<description><![CDATA[Coming Soon!]]></description>
			<content:encoded><![CDATA[<p>Learn how to play different types of music and sounds as well as converting different types of audio to more suitable file types.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.predatorinteractive.com/instinct-graphics-package/9-playing-audio/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
