processing:compass_example
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
processing:compass_example [2013/08/03 04:05] – [Perlin noise] mithat | processing:compass_example [2015/08/01 21:11] (current) – [Refining randomness] mithat | ||
---|---|---|---|
Line 122: | Line 122: | ||
| | ||
// draw the compass at " | // draw the compass at " | ||
- | drawCompass(ang+random(-4.0, | + | drawCompass(ang + random(-4.0, |
}</ | }</ | ||
Line 131: | Line 131: | ||
The offsets in the " | The offsets in the " | ||
- | A random offset process can be smoothed out by // | + | A random offset process can be smoothed out by // |
+ | <code java> | ||
+ | /** | ||
+ | * Compass example: | ||
+ | * Show due north with accumulated random offsets. | ||
+ | | ||
+ | * Copyright (C) 2013 Mithat Konar | ||
+ | */ | ||
+ | |||
+ | float ang; | ||
+ | |||
+ | void setup() { | ||
+ | frameRate(30); | ||
+ | smooth(); | ||
+ | size(400, 300); | ||
+ | ang = 0; | ||
+ | } | ||
+ | |||
+ | void draw() { | ||
+ | background(# | ||
+ | |||
+ | // draw the compass | ||
+ | drawCompass(ang, | ||
+ | |||
+ | // and then add some random offset to the angle for next time | ||
+ | ang += random(-4.0, | ||
+ | |||
+ | // and wrap around to 360 degrees | ||
+ | ang %= 360; | ||
+ | }</ | ||
===== Perlin noise ===== | ===== Perlin noise ===== | ||
- | [[https:// | + | [[http:// |
+ | |||
+ | [[https:// | ||
- | Processing has a function called '' | + | Processing has a function called '' |
<code java> | <code java> | ||
Line 149: | Line 180: | ||
float ang; | float ang; | ||
float noiseOffset; | float noiseOffset; | ||
- | final float NOISESCALE = 0.01; // amount to move along noise function' | + | final float NOISESCALE = 0.03; // amount to move along noise function' |
// " | // " | ||
final float MAXOFFSET = 45; // the maximum possible generated angle offset | final float MAXOFFSET = 45; // the maximum possible generated angle offset | ||
Line 175: | Line 206: | ||
| | ||
// draw the compass | // draw the compass | ||
- | drawCompass(ang + angleOffset, | + | drawCompass(ang+angleOffset, |
}</ | }</ |
processing/compass_example.1375502725.txt.gz · Last modified: 2013/08/03 04:05 by mithat