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 03:49] – 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://en.wikipedia.org/wiki/Perlin_noise|Perlin noise]] | + | [[http://mithatkonar.com/processing/ |
+ | [[https:// | ||
+ | Processing has a function called '' | ||
+ | |||
+ | <code java> | ||
+ | /** | ||
+ | * Compass example: | ||
+ | * Show due north with Perlin noise offset. | ||
+ | * | ||
+ | * Copyright (C) 2013 Mithat Konar | ||
+ | */ | ||
+ | |||
+ | float ang; | ||
+ | float noiseOffset; | ||
+ | final float NOISESCALE = 0.03; // amount to move along noise function' | ||
+ | // " | ||
+ | final float MAXOFFSET = 45; // the maximum possible generated angle offset | ||
+ | |||
+ | void setup() { | ||
+ | frameRate(30); | ||
+ | smooth(); | ||
+ | size(400, 300); | ||
+ | ang = 0; | ||
+ | | ||
+ | // start the noise' | ||
+ | noiseOffset = random(0, 1000); | ||
+ | } | ||
+ | |||
+ | void draw() { | ||
+ | float angleOffset; | ||
+ | |||
+ | background(# | ||
+ | | ||
+ | // increment the noise' | ||
+ | noiseOffset += NOISESCALE; | ||
+ | |||
+ | // calculate a noisy angle offset based on noise' | ||
+ | angleOffset = (2*MAXOFFSET) * (noise(noiseOffset)-0.5); | ||
+ | | ||
+ | // draw the compass | ||
+ | drawCompass(ang+angleOffset, | ||
+ | }</ |
processing/compass_example.1375501793.txt.gz · Last modified: 2013/08/03 03:49 by mithat