aboutsummaryrefslogtreecommitdiff
path: root/examples/ChainedPanelsAuroraDemo/PatternFlock.h
diff options
context:
space:
mode:
authorKosso <kosso1@gmail.com>2020-09-13 15:56:29 +0100
committerKosso <kosso1@gmail.com>2020-09-13 15:56:29 +0100
commit0e4e9738b6ecbffa260cc8e5e8e4c4d9f1bf6499 (patch)
treeff2a812bd892cef0ec792b583df3fbab07d67f2b /examples/ChainedPanelsAuroraDemo/PatternFlock.h
parenta3aedaefb1326c5781646a8a51c5d83e61dc0a57 (diff)
Kosso: Updated Aurora demo for chained virtual displays. Added a better Fire demo. Removed some old Aurora demos which just didn't work and saves some memory.
Diffstat (limited to 'examples/ChainedPanelsAuroraDemo/PatternFlock.h')
-rw-r--r--examples/ChainedPanelsAuroraDemo/PatternFlock.h125
1 files changed, 125 insertions, 0 deletions
diff --git a/examples/ChainedPanelsAuroraDemo/PatternFlock.h b/examples/ChainedPanelsAuroraDemo/PatternFlock.h
new file mode 100644
index 0000000..3ae31b1
--- /dev/null
+++ b/examples/ChainedPanelsAuroraDemo/PatternFlock.h
@@ -0,0 +1,125 @@
+/*
+ * Aurora: https://github.com/pixelmatix/aurora
+ * Copyright (c) 2014 Jason Coon
+ *
+ * Portions of this code are adapted from "Flocking" in "The Nature of Code" by Daniel Shiffman: http://natureofcode.com/
+ * Copyright (c) 2014 Daniel Shiffman
+ * http://www.shiffman.net
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+// Flocking
+// Daniel Shiffman <http://www.shiffman.net>
+// The Nature of Code, Spring 2009
+
+// Demonstration of Craig Reynolds' "Flocking" behavior
+// See: http://www.red3d.com/cwr/
+// Rules: Cohesion, Separation, Alignment
+
+#ifndef PatternFlock_H
+#define PatternFlock_H
+
+class PatternFlock : public Drawable {
+ public:
+ PatternFlock() {
+ name = (char *)"Flock";
+ }
+
+ static const int boidCount = 10;
+ Boid predator;
+
+ PVector wind;
+ byte hue = 0;
+ bool predatorPresent = true;
+
+ void start() {
+ for (int i = 0; i < boidCount; i++) {
+ boids[i] = Boid(15, 15);
+ boids[i].maxspeed = 0.380;
+ boids[i].maxforce = 0.015;
+ }
+
+ predatorPresent = random(0, 2) >= 1;
+ if (predatorPresent) {
+ predator = Boid(31, 31);
+ predatorPresent = true;
+ predator.maxspeed = 0.385;
+ predator.maxforce = 0.020;
+ predator.neighbordist = 16.0;
+ predator.desiredseparation = 0.0;
+ }
+ }
+
+ unsigned int drawFrame() {
+ effects.DimAll(230); effects.ShowFrame();
+
+ bool applyWind = random(0, 255) > 250;
+ if (applyWind) {
+ wind.x = Boid::randomf() * .015;
+ wind.y = Boid::randomf() * .015;
+ }
+
+ CRGB color = effects.ColorFromCurrentPalette(hue);
+
+ for (int i = 0; i < boidCount; i++) {
+ Boid * boid = &boids[i];
+
+ if (predatorPresent) {
+ // flee from predator
+ boid->repelForce(predator.location, 10);
+ }
+
+ boid->run(boids, boidCount);
+ boid->wrapAroundBorders();
+ PVector location = boid->location;
+ // PVector velocity = boid->velocity;
+ // backgroundLayer.drawLine(location.x, location.y, location.x - velocity.x, location.y - velocity.y, color);
+ // effects.leds[XY(location.x, location.y)] += color;
+ effects.drawBackgroundFastLEDPixelCRGB(location.x, location.y, color);
+
+ if (applyWind) {
+ boid->applyForce(wind);
+ applyWind = false;
+ }
+ }
+
+ if (predatorPresent) {
+ predator.run(boids, boidCount);
+ predator.wrapAroundBorders();
+ color = effects.ColorFromCurrentPalette(hue + 128);
+ PVector location = predator.location;
+ // PVector velocity = predator.velocity;
+ // backgroundLayer.drawLine(location.x, location.y, location.x - velocity.x, location.y - velocity.y, color);
+ // effects.leds[XY(location.x, location.y)] += color;
+ effects.drawBackgroundFastLEDPixelCRGB(location.x, location.y, color);
+ }
+
+ EVERY_N_MILLIS(200) {
+ hue++;
+ }
+
+ EVERY_N_SECONDS(30) {
+ predatorPresent = !predatorPresent;
+ }
+
+ return 0;
+ }
+};
+
+#endif