User Tools

Site Tools


processing:compass_example

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
processing:compass_example [2013/08/03 04:08] – [Refining randomness] mithatprocessing:compass_example [2015/08/01 21:11] (current) – [Refining randomness] mithat
Line 122: Line 122:
      
   // draw the compass at "ang" degrees plus or minus 0-4 random degrees   // draw the compass at "ang" degrees plus or minus 0-4 random degrees
-  drawCompass(ang+random(-4.0,4.0), 20, 200, width/2, height/2);+  drawCompass(ang + random(-4.0,4.0), 20, 200, width/2, height/2);
 }</code> }</code>
  
Line 131: Line 131:
 The offsets in the "Adding randomness" example above appear noticeably more jittery than a true natural process. This is because the random offsets are allowed to jump directly over the entire range that the indicator bounces within. The offsets in the "Adding randomness" example above appear noticeably more jittery than a true natural process. This is because the random offsets are allowed to jump directly over the entire range that the indicator bounces within.
  
-A random offset process can be smoothed out by //accumulating small random offsets// rather than jumping completely randomly over some range. The small random offsets will average out to zero in the long run, but they will prevent the indicator from jumping too far between any two frames. On the other hand, it's possible for the total offset to temporarily exceed the desired bounds.+A random offset process can be smoothed out by //accumulating small random offsets// rather than jumping completely randomly over some range. The small random offsets will average out to zero in the long run, but they will prevent the indicator from jumping too far between any two frames. The downsides are that it's possible for the total offset to temporarily exceed the desired bounds and that sometimes the accumulated offset can become so large that it never seems to return to zero.
  
 <code java> <code java>
Line 164: Line 164:
 ===== Perlin noise ===== ===== Perlin noise =====
  
-[[https://en.wikipedia.org/wiki/Perlin_noise|Perlin noise]] is a mapping function that simulates natural random variations very well. We call it a mapping function because unlike Processing's ''[[http://processing.org/reference/random_.html|random]]'' function, which returns a new random value over a specified range each time you call it, Perlin noise has an input and an output. The input is some point in N-dimensional space, and the output is some value. Every time you invoke a Perlin noise function with the same input, you'll get the same output. If you shift the input slightly, the output value changes, and these changes are very similar to the kinds of changes found in nature.+[[http://mithatkonar.com/processing/compass/compass_noise/|{{:processing:processing_compass_noise.png?300}}]]
  
-Processing has a function called ''[[http://processing.org/reference/noise_.html|noise]]'' that implements Perlin noise. We use the one-dimensional version of ''noise'' here to determine the offset of the indicator.+[[https://en.wikipedia.org/wiki/Perlin_noise|Perlin noise]] is a **mapping function** that was designed to simulate natural random variations. It's called a mapping function because unlike Processing's ''[[http://processing.org/reference/random_.html|random]]'' function, which returns a new random value over a specified range each time you call it, Perlin noise has an input and an output. The input is some point in N-dimensional space, and the output is some value. Every time you invoke a Perlin noise function with the same input, you'll get the same output. If you shift the input slightly, the output value changes, and these changes are very similar to the kinds of changes found in nature. 
 + 
 +Processing has a function called ''[[http://processing.org/reference/noise_.html|noise]]'' that implements Perlin noise. We use the one-dimensional version of the ''noise'' function here to determine the offset of the indicator.
  
 <code java> <code java>
Line 178: Line 180:
 float ang; float ang;
 float noiseOffset;              // noise function's "x-value" float noiseOffset;              // noise function's "x-value"
-final float NOISESCALE = 0.01;  // amount to move along noise function's+final float NOISESCALE = 0.03;  // amount to move along noise function's
                                 // "x-axis" each frame                                 // "x-axis" each frame
 final float MAXOFFSET = 45;     // the maximum possible generated angle offset final float MAXOFFSET = 45;     // the maximum possible generated angle offset
Line 204: Line 206:
      
   // draw the compass   // draw the compass
-  drawCompass(ang + angleOffset, 20, 200, width/2, height/2);+  drawCompass(ang+angleOffset, 20, 200, width/2, height/2);
 }</code> }</code>
processing/compass_example.1375502917.txt.gz · Last modified: 2013/08/03 04:08 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki