<?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>AquilaX's development blog &#187; Java</title>
	<atom:link href="http://dev.horemag.net/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://dev.horemag.net</link>
	<description>code and so on...</description>
	<lastBuildDate>Thu, 02 Feb 2012 08:29:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Smooth tile scrolling with Slick</title>
		<link>http://dev.horemag.net/2009/05/05/smooth-tile-scrolling-with-slick/</link>
		<comments>http://dev.horemag.net/2009/05/05/smooth-tile-scrolling-with-slick/#comments</comments>
		<pubDate>Tue, 05 May 2009 05:27:10 +0000</pubDate>
		<dc:creator>AquilaX</dc:creator>
				<category><![CDATA[Slick]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[tile-based]]></category>
		<category><![CDATA[tiles]]></category>

		<guid isPermaLink="false">http://dev.horemag.net/?p=89</guid>
		<description><![CDATA[
This is my first attempt for smooth tile scrolling in Slick. The offx/offy coordinates are not entirely correct for hero, smaller than the tile image but it's a good start the "smooth" part comes from shx/shy variables which offset the rendering position. The code is after the break:
Update: Check the project source code page at [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://dev.horemag.net/wp-content/uploads/game1.png" alt="game1" title="game1" width="299" height="254" class="alignnone size-full wp-image-92" /></p>
<p>This is my first attempt for smooth tile scrolling in Slick. The offx/offy coordinates are not entirely correct for hero, smaller than the tile image but it's a good start the "smooth" part comes from shx/shy variables which offset the rendering position. The code is after the break:</p>
<p><strong>Update:</strong> Check the project source code page at Google Code: <a href="http://code.google.com/p/jmuonline/" onclick="javascript:urchinTracker('/outbound/article/http://code.google.com/p/jmuonline/');">http://code.google.com/p/jmuonline/</a></p>
<p><span id="more-89"></span></p>
<pre class="java">&nbsp;
<span style="color: #000000; font-weight: bold;">package</span> scroller;
&nbsp;
<span style="color: #a1a100;">import org.newdawn.slick.AppGameContainer;</span>
<span style="color: #a1a100;">import org.newdawn.slick.BasicGame;</span>
<span style="color: #a1a100;">import org.newdawn.slick.Color;</span>
<span style="color: #a1a100;">import org.newdawn.slick.GameContainer;</span>
<span style="color: #a1a100;">import org.newdawn.slick.Graphics;</span>
<span style="color: #a1a100;">import org.newdawn.slick.Input;</span>
<span style="color: #a1a100;">import org.newdawn.slick.SlickException;</span>
<span style="color: #a1a100;">import org.newdawn.slick.tiled.TiledMap;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 *
 * @author aquilax
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Scroller2 <span style="color: #000000; font-weight: bold;">extends</span> BasicGame<span style="color: #66cc66;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> TiledMap map = <span style="color: #000000; font-weight: bold;">null</span>;
  <span style="color: #000000; font-weight: bold;">private</span> Hero hero = <span style="color: #000000; font-weight: bold;">null</span>;
&nbsp;
  <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #993333;">int</span> screenw = <span style="color: #cc66cc;">432</span>;
  <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #993333;">int</span> screenh = <span style="color: #cc66cc;">336</span>;
  <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #993333;">int</span> centerx = screenw/<span style="color: #cc66cc;">2</span>;
  <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #993333;">int</span> centery = screenh/<span style="color: #cc66cc;">2</span>;
  <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #993333;">int</span> visx = <span style="color: #cc66cc;">9</span>;
  <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #993333;">int</span> visy = <span style="color: #cc66cc;">7</span>;
  <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #993333;">float</span> halfvisx = visx/<span style="color: #cc66cc;">2</span>;
  <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #993333;">float</span> halfvisy = visy/<span style="color: #cc66cc;">2</span>;
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">int</span> tileW;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">int</span> tileH;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">int</span> mapW;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">int</span> mapH;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">boolean</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> blocked;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">int</span> offx;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">int</span> offy;
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> Scroller2<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Scroller2&quot;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  @Override
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> init<span style="color: #66cc66;">&#40;</span>GameContainer container<span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> SlickException <span style="color: #66cc66;">&#123;</span>
    map = <span style="color: #000000; font-weight: bold;">new</span> TiledMap<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;data/testone.tmx&quot;</span><span style="color: #66cc66;">&#41;</span>;
    tileW = map.<span style="color: #006600;">getTileWidth</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    tileH = map.<span style="color: #006600;">getTileHeight</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    mapW = map.<span style="color: #006600;">getWidth</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    mapH = map.<span style="color: #006600;">getHeight</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    fillBlocked<span style="color: #66cc66;">&#40;</span>map<span style="color: #66cc66;">&#41;</span>;
    hero = <span style="color: #000000; font-weight: bold;">new</span> Hero<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;data/hero.png&quot;</span><span style="color: #66cc66;">&#41;</span>;
    hero.<span style="color: #006600;">speed</span> = <span style="color: #cc66cc;">1</span>;
    hero.<span style="color: #006600;">xtile</span> = <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AInteger+java.sun.com&amp;bntI=I%27m%20Feeling%20Lucky" onclick="javascript:urchinTracker('/outbound/article/http://www.google.com/search?hl=en&amp;q=allinurl%3AInteger+java.sun.com&amp;bntI=I%27m%20Feeling%20Lucky');"><span style="color: #aaaadd; font-weight: bold;">Integer</span></a>.<span style="color: #006600;">parseInt</span><span style="color: #66cc66;">&#40;</span>map.<span style="color: #006600;">getMapProperty</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;herox&quot;</span>, <span style="color: #ff0000;">&quot;16&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
    hero.<span style="color: #006600;">ytile</span> = <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AInteger+java.sun.com&amp;bntI=I%27m%20Feeling%20Lucky" onclick="javascript:urchinTracker('/outbound/article/http://www.google.com/search?hl=en&amp;q=allinurl%3AInteger+java.sun.com&amp;bntI=I%27m%20Feeling%20Lucky');"><span style="color: #aaaadd; font-weight: bold;">Integer</span></a>.<span style="color: #006600;">parseInt</span><span style="color: #66cc66;">&#40;</span>map.<span style="color: #006600;">getMapProperty</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;heroy&quot;</span>, <span style="color: #ff0000;">&quot;8&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    hero.<span style="color: #006600;">xpos</span> = centerx - hero.<span style="color: #006600;">awidth</span>/<span style="color: #cc66cc;">2</span>;
    hero.<span style="color: #006600;">ypos</span> = centery - hero.<span style="color: #006600;">aheight</span>/<span style="color: #cc66cc;">2</span>;
&nbsp;
    offx = hero.<span style="color: #006600;">xtile*tileW</span>;
    offy = hero.<span style="color: #006600;">ytile*tileH</span>;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  @Override
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> update<span style="color: #66cc66;">&#40;</span>GameContainer container, <span style="color: #993333;">int</span> delta<span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> SlickException <span style="color: #66cc66;">&#123;</span>
    Input input = container.<span style="color: #006600;">getInput</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>input.<span style="color: #006600;">isKeyDown</span><span style="color: #66cc66;">&#40;</span>Input.<span style="color: #006600;">KEY_LEFT</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      moveChar<span style="color: #66cc66;">&#40;</span>hero, <span style="color: #cc66cc;">-1</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>input.<span style="color: #006600;">isKeyDown</span><span style="color: #66cc66;">&#40;</span>Input.<span style="color: #006600;">KEY_RIGHT</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      moveChar<span style="color: #66cc66;">&#40;</span>hero, <span style="color: #cc66cc;">+1</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>input.<span style="color: #006600;">isKeyDown</span><span style="color: #66cc66;">&#40;</span>Input.<span style="color: #006600;">KEY_UP</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      moveChar<span style="color: #66cc66;">&#40;</span>hero, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>input.<span style="color: #006600;">isKeyDown</span><span style="color: #66cc66;">&#40;</span>Input.<span style="color: #006600;">KEY_DOWN</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      moveChar<span style="color: #66cc66;">&#40;</span>hero, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">+1</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> render<span style="color: #66cc66;">&#40;</span>GameContainer container, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AGraphics+java.sun.com&amp;bntI=I%27m%20Feeling%20Lucky" onclick="javascript:urchinTracker('/outbound/article/http://www.google.com/search?hl=en&amp;q=allinurl%3AGraphics+java.sun.com&amp;bntI=I%27m%20Feeling%20Lucky');"><span style="color: #aaaadd; font-weight: bold;">Graphics</span></a> g<span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> SlickException <span style="color: #66cc66;">&#123;</span>
    <span style="color: #993333;">int</span> shx = <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>offx/tileW<span style="color: #66cc66;">&#41;</span>*tileW - offx;
    <span style="color: #993333;">int</span> shy = <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>offy/tileH<span style="color: #66cc66;">&#41;</span>*tileH - offy;
    map.<span style="color: #006600;">render</span><span style="color: #66cc66;">&#40;</span>shx, shy, <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>offx/tileW-halfvisx<span style="color: #66cc66;">&#41;</span>, <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>offy/tileH-halfvisy<span style="color: #66cc66;">&#41;</span>, visx<span style="color: #cc66cc;">+1</span>, visy<span style="color: #cc66cc;">+1</span><span style="color: #66cc66;">&#41;</span>;
    hero.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span>hero.<span style="color: #006600;">xpos</span>, hero.<span style="color: #006600;">ypos</span><span style="color: #66cc66;">&#41;</span>;
    g.<span style="color: #006600;">setColor</span><span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AColor+java.sun.com&amp;bntI=I%27m%20Feeling%20Lucky" onclick="javascript:urchinTracker('/outbound/article/http://www.google.com/search?hl=en&amp;q=allinurl%3AColor+java.sun.com&amp;bntI=I%27m%20Feeling%20Lucky');"><span style="color: #aaaadd; font-weight: bold;">Color</span></a>.<span style="color: #006600;">red</span><span style="color: #66cc66;">&#41;</span>;
    g.<span style="color: #006600;">drawString</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;offx &quot;</span>+offx, <span style="color: #cc66cc;">300</span>, <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;
    g.<span style="color: #006600;">drawString</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;offy &quot;</span>+offy, <span style="color: #cc66cc;">300</span>, <span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #993333;">void</span> main<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;bntI=I%27m%20Feeling%20Lucky" onclick="javascript:urchinTracker('/outbound/article/http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;bntI=I%27m%20Feeling%20Lucky');"><span style="color: #aaaadd; font-weight: bold;">String</span></a><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> args<span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> SlickException <span style="color: #66cc66;">&#123;</span>
    AppGameContainer app = <span style="color: #000000; font-weight: bold;">new</span> AppGameContainer<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Scroller2<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
    app.<span style="color: #006600;">setDisplayMode</span><span style="color: #66cc66;">&#40;</span>screenw, screenh, <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;
    app.<span style="color: #006600;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">void</span> fillBlocked<span style="color: #66cc66;">&#40;</span>TiledMap map<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    blocked = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #993333;">boolean</span><span style="color: #66cc66;">&#91;</span>mapW<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span>mapH<span style="color: #66cc66;">&#93;</span>;
    <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> x = <span style="color: #cc66cc;">0</span>; x &lt; mapW; x++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
      <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> y = <span style="color: #cc66cc;">0</span>; y &lt; mapH; y++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
        blocked<span style="color: #66cc66;">&#91;</span>x<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span>y<span style="color: #66cc66;">&#93;</span>  = <span style="color: #ff0000;">&quot;true&quot;</span>.<span style="color: #006600;">equals</span><span style="color: #66cc66;">&#40;</span>map.<span style="color: #006600;">getTileProperty</span><span style="color: #66cc66;">&#40;</span>map.<span style="color: #006600;">getTileId</span><span style="color: #66cc66;">&#40;</span>x, y, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">&quot;blocked&quot;</span>, <span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">void</span> moveChar<span style="color: #66cc66;">&#40;</span>Hero ob, <span style="color: #993333;">int</span> dirx, <span style="color: #993333;">int</span> diry<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    offx += <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>dirx*ob.<span style="color: #006600;">speed</span><span style="color: #66cc66;">&#41;</span>;
    offy += <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>diry*ob.<span style="color: #006600;">speed</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://dev.horemag.net/2009/05/05/smooth-tile-scrolling-with-slick/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chasing balls with faiding tails</title>
		<link>http://dev.horemag.net/2008/03/03/chasing-balls-with-faiding-tails/</link>
		<comments>http://dev.horemag.net/2008/03/03/chasing-balls-with-faiding-tails/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 10:56:51 +0000</pubDate>
		<dc:creator>AquilaX</dc:creator>
				<category><![CDATA[Processing]]></category>
		<category><![CDATA[blur]]></category>
		<category><![CDATA[processing]]></category>

		<guid isPermaLink="false">http://dev.horemag.net/2008/03/03/chasing-balls-with-faiding-tails/</guid>
		<description><![CDATA[
Another very simple Processing script. Nothing fancy just three points with circle orbits and blur on every step to ensure the fading of the "tails" but still looks nice.
&#160;
int R = 20;  //radius
int speed = 2;  // speed
&#160;
int t = 0;
float x;
float y;
int offx = 0;
int offy = 0;
&#160;
void setup&#40;&#41;&#123;
  size&#40;80,80&#41;;
  [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://dev.horemag.net/wp-content/uploads/rotor.png' alt='Rotor' /><br />
Another very simple Processing script. Nothing fancy just three points with circle orbits and blur on every step to ensure the fading of the "tails" but still looks nice.</p>
<pre class="java">&nbsp;
<span style="color: #993333;">int</span> R = <span style="color: #cc66cc;">20</span>;  <span style="color: #808080; font-style: italic;">//radius</span>
<span style="color: #993333;">int</span> speed = <span style="color: #cc66cc;">2</span>;  <span style="color: #808080; font-style: italic;">// speed</span>
&nbsp;
<span style="color: #993333;">int</span> t = <span style="color: #cc66cc;">0</span>;
<span style="color: #993333;">float</span> x;
<span style="color: #993333;">float</span> y;
<span style="color: #993333;">int</span> offx = <span style="color: #cc66cc;">0</span>;
<span style="color: #993333;">int</span> offy = <span style="color: #cc66cc;">0</span>;
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
  size<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">80</span>,<span style="color: #cc66cc;">80</span><span style="color: #66cc66;">&#41;</span>;
  offx = width/<span style="color: #cc66cc;">2</span>;
  offy = height/<span style="color: #cc66cc;">2</span>;
  background<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
  strokeWeight<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">7</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> draw<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
  filter<span style="color: #66cc66;">&#40;</span>BLUR,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
  stroke<span style="color: #66cc66;">&#40;</span>#FF0000<span style="color: #66cc66;">&#41;</span>;
  x = sin<span style="color: #66cc66;">&#40;</span>radians<span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>*R+offx;
  y = cos<span style="color: #66cc66;">&#40;</span>radians<span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>*R+offy;
  point <span style="color: #66cc66;">&#40;</span>x,y<span style="color: #66cc66;">&#41;</span>;
  stroke<span style="color: #66cc66;">&#40;</span>#00FF00<span style="color: #66cc66;">&#41;</span>;
  x = sin<span style="color: #66cc66;">&#40;</span>radians<span style="color: #66cc66;">&#40;</span>t<span style="color: #cc66cc;">+120</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>*R+offx;
  y = cos<span style="color: #66cc66;">&#40;</span>radians<span style="color: #66cc66;">&#40;</span>t<span style="color: #cc66cc;">+120</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>*R+offy;
  point <span style="color: #66cc66;">&#40;</span>x,y<span style="color: #66cc66;">&#41;</span>;
  stroke<span style="color: #66cc66;">&#40;</span>#0000FF<span style="color: #66cc66;">&#41;</span>;
  x = sin<span style="color: #66cc66;">&#40;</span>radians<span style="color: #66cc66;">&#40;</span>t<span style="color: #cc66cc;">+240</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>*R+offx;
  y = cos<span style="color: #66cc66;">&#40;</span>radians<span style="color: #66cc66;">&#40;</span>t<span style="color: #cc66cc;">+240</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>*R+offy;
  point <span style="color: #66cc66;">&#40;</span>x,y<span style="color: #66cc66;">&#41;</span>;
  t += speed;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://dev.horemag.net/2008/03/03/chasing-balls-with-faiding-tails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spirograph with Processing</title>
		<link>http://dev.horemag.net/2008/03/03/spirograph-with-processing/</link>
		<comments>http://dev.horemag.net/2008/03/03/spirograph-with-processing/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 10:07:57 +0000</pubDate>
		<dc:creator>AquilaX</dc:creator>
				<category><![CDATA[Processing]]></category>
		<category><![CDATA[processing]]></category>
		<category><![CDATA[spirograph]]></category>

		<guid isPermaLink="false">http://dev.horemag.net/2008/03/03/spirograph-with-processing/</guid>
		<description><![CDATA[
I continue my tests with Processing. Today's project is simple Spirograph. The formulas are taken from here.
&#160;
int R = 130;         //Outer radius
int r = 15;          //Iner radius
int O = 7;         [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://dev.horemag.net/wp-content/uploads/spiro.png' alt='Spirograph' /><br />
I continue my tests with <a href="http://processing.org/" onclick="javascript:urchinTracker('/outbound/article/http://processing.org/');">Processing</a>. Today's project is simple <a href="http://en.wikipedia.org/wiki/Spirograph" onclick="javascript:urchinTracker('/outbound/article/http://en.wikipedia.org/wiki/Spirograph');">Spirograph</a>. The formulas are taken from <a href="http://wordsmith.org/~anu/java/spirograph.html" onclick="javascript:urchinTracker('/outbound/article/http://wordsmith.org/~anu/java/spirograph.html');">here</a>.</p>
<pre class="java">&nbsp;
<span style="color: #993333;">int</span> R = <span style="color: #cc66cc;">130</span>;         <span style="color: #808080; font-style: italic;">//Outer radius</span>
<span style="color: #993333;">int</span> r = <span style="color: #cc66cc;">15</span>;          <span style="color: #808080; font-style: italic;">//Iner radius</span>
<span style="color: #993333;">int</span> O = <span style="color: #cc66cc;">7</span>;           <span style="color: #808080; font-style: italic;">//Offset</span>
<span style="color: #993333;">float</span> swidth = <span style="color: #cc66cc;">0.2</span>;  <span style="color: #808080; font-style: italic;">// Stroke width</span>
<span style="color: #993333;">int</span> iter = <span style="color: #cc66cc;">500</span>;      <span style="color: #808080; font-style: italic;">// Numer of iterations</span>
&nbsp;
<span style="color: #993333;">float</span> x;
<span style="color: #993333;">float</span> y;
<span style="color: #993333;">float</span> ox = <span style="color: #cc66cc;">0</span>;
<span style="color: #993333;">float</span> oy = <span style="color: #cc66cc;">0</span>;
<span style="color: #993333;">int</span> offx;
<span style="color: #993333;">int</span> offy;
<span style="color: #993333;">int</span> t = <span style="color: #cc66cc;">0</span>;
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
  size<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">400</span>,<span style="color: #cc66cc;">400</span><span style="color: #66cc66;">&#41;</span>;
  offx = width/<span style="color: #cc66cc;">2</span>;
  offy = height/<span style="color: #cc66cc;">2</span>;
  colorMode<span style="color: #66cc66;">&#40;</span>HSB, iter<span style="color: #66cc66;">&#41;</span>;
  strokeWeight<span style="color: #66cc66;">&#40;</span>swidth<span style="color: #66cc66;">&#41;</span>;
  background<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
  smooth<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> draw<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>t &lt;= iter<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    x = <span style="color: #66cc66;">&#40;</span>R+r<span style="color: #66cc66;">&#41;</span>*cos<span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#41;</span> - <span style="color: #66cc66;">&#40;</span>r+O<span style="color: #66cc66;">&#41;</span>*cos<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>R+r<span style="color: #66cc66;">&#41;</span>/r<span style="color: #66cc66;">&#41;</span>*t<span style="color: #66cc66;">&#41;</span>+offx;
    y = <span style="color: #66cc66;">&#40;</span>R+r<span style="color: #66cc66;">&#41;</span>*sin<span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#41;</span> - <span style="color: #66cc66;">&#40;</span>r+O<span style="color: #66cc66;">&#41;</span>*sin<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>R+r<span style="color: #66cc66;">&#41;</span>/r<span style="color: #66cc66;">&#41;</span>*t<span style="color: #66cc66;">&#41;</span>+offy;
    stroke<span style="color: #66cc66;">&#40;</span>t, iter/<span style="color: #cc66cc;">1.5</span>, iter<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #808080; font-style: italic;">//point (x, y);  //&lt;- points</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>ox != <span style="color: #cc66cc;">0</span> &amp;&amp; oy != <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
      line <span style="color: #66cc66;">&#40;</span>ox, oy, x, y<span style="color: #66cc66;">&#41;</span>;  <span style="color: #808080; font-style: italic;">//&lt;-lines</span>
    <span style="color: #66cc66;">&#125;</span>
    ox = x;
    oy = y;
    t++;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://dev.horemag.net/2008/03/03/spirograph-with-processing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple terrain generator in Processing</title>
		<link>http://dev.horemag.net/2008/03/02/simple-terrain-generator-in-processing/</link>
		<comments>http://dev.horemag.net/2008/03/02/simple-terrain-generator-in-processing/#comments</comments>
		<pubDate>Sun, 02 Mar 2008 09:49:39 +0000</pubDate>
		<dc:creator>AquilaX</dc:creator>
				<category><![CDATA[Processing]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[perlin noise]]></category>
		<category><![CDATA[processing]]></category>
		<category><![CDATA[terrain]]></category>
		<category><![CDATA[terrain generartor]]></category>

		<guid isPermaLink="false">http://dev.horemag.net/2008/03/02/simple-terrain-generator-in-processing/</guid>
		<description><![CDATA[Here is simple processing script for generating random terrains using Perlin noise. The good thing is that Processing has integrated noise() function and all you have to do is call it with the coordinates as parameters. Then assign the colors depending on the "height" of the point and add some randomness to the snow to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://dev.horemag.net/wp-content/uploads/terros.png" title="Generated terrain" ><img src="http://dev.horemag.net/wp-content/uploads/terros.thumbnail.png" alt="Generated terrain" style="float:left; margin-right:5px"/></a>Here is simple processing script for generating random terrains using <a href="http://en.wikipedia.org/wiki/Perlin_noise" onclick="javascript:urchinTracker('/outbound/article/http://en.wikipedia.org/wiki/Perlin_noise');">Perlin noise</a>. The good thing is that <a href="http://processing.org/" onclick="javascript:urchinTracker('/outbound/article/http://processing.org/');">Processing</a> has integrated <a href="http://processing.org/reference/noise_.html" onclick="javascript:urchinTracker('/outbound/article/http://processing.org/reference/noise_.html');">noise()</a> function and all you have to do is call it with the coordinates as parameters. Then assign the colors depending on the "height" of the point and add some randomness to the snow to make it look more dispersed.</p>
<pre class="java">&nbsp;
<span style="color: #993333;">float</span> noiseScale=<span style="color: #cc66cc;">0.02</span>;
<span style="color: #993333;">int</span> tsize = <span style="color: #cc66cc;">250</span>;
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  size<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">640</span>, <span style="color: #cc66cc;">480</span>, P3D<span style="color: #66cc66;">&#41;</span>;
  background<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
  rotateX<span style="color: #66cc66;">&#40;</span>radians<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">45</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  beginShape<span style="color: #66cc66;">&#40;</span>POINTS<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> x=<span style="color: #cc66cc;">0</span>; x &lt; tsize; x++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> y=<span style="color: #cc66cc;">0</span>; y &lt; tsize; y++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
      <span style="color: #993333;">float</span> noiseVal = noise<span style="color: #66cc66;">&#40;</span>x*noiseScale, y*noiseScale<span style="color: #66cc66;">&#41;</span>;
      <span style="color: #993333;">int</span> t = <span style="color: #993333;">int</span><span style="color: #66cc66;">&#40;</span>noiseVal*<span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>;
      stroke<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">165</span>, <span style="color: #cc66cc;">80</span>, <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>t &gt;<span style="color: #cc66cc;">180</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
        stroke<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, t<span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>
      <span style="color: #808080; font-style: italic;">// add some randomness to the snow to make it more realistic</span>
      <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>t &lt;<span style="color: #cc66cc;">60</span> +random<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
        stroke<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span>, <span style="color: #cc66cc;">255</span>, <span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>
      vertex<span style="color: #66cc66;">&#40;</span>width/<span style="color: #cc66cc;">2</span>+x-tsize/<span style="color: #cc66cc;">2</span>, height/<span style="color: #cc66cc;">2</span>+y-tsize/<span style="color: #cc66cc;">2</span>, -noiseVal*<span style="color: #cc66cc;">60</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
  endShape<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> draw<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://dev.horemag.net/2008/03/02/simple-terrain-generator-in-processing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

