changes for makerfaire ruhr 2019

This commit is contained in:
interfisch 2019-04-07 14:24:16 +02:00
parent 62a5b3bc07
commit 6c39c1560e
5 changed files with 155 additions and 50 deletions

View File

@ -22,7 +22,7 @@ long lastRoutineUpdate=0;
#define ROUTINEUPDATETIME 20 #define ROUTINEUPDATETIME 20
long lastCheckspawn=0; long lastCheckspawn=0;
#define CHECKSPAWNDELAY 4000 //delay in ms to check random spawn #define CHECKSPAWNDELAY 4000 //delay in ms to check random spawn
#define SPAWNCHANCE 20 //1 out of x times wagon will spawn #define SPAWNCHANCE 7 //1 out of x times wagon will spawn
#define SPAWNCHANCEDOUBLE 5 //change of spawning a two trains simultaneously #define SPAWNCHANCEDOUBLE 5 //change of spawning a two trains simultaneously
long lastCheckspawnEffect=0; long lastCheckspawnEffect=0;
#define CHECKSPAWNDELAY_EFFECT 10000 //delay in ms to check random effect #define CHECKSPAWNDELAY_EFFECT 10000 //delay in ms to check random effect
@ -65,39 +65,34 @@ void setup() {
resetHeightmap(); resetHeightmap();
//fixed heightmap //fixed heightmap
heightraw[0]=200; heightraw[0]=182;
heightraw[15]=200; heightraw[51]=100;
heightraw[28]=185; heightraw[91]=57;
heightraw[52]=170; heightraw[121]=100;
heightraw[88]=198; heightraw[147]=100;
heightraw[104]=176; heightraw[170]=75;
heightraw[118]=156; heightraw[184]=71;
heightraw[125]=154; heightraw[216]=100;
heightraw[130]=156; heightraw[228]=103;
heightraw[156]=184; heightraw[257]=101;
heightraw[164]=199; heightraw[305]=107;
heightraw[185]=191; heightraw[316]=100;
heightraw[190]=190; heightraw[349]=78;
heightraw[197]=191; heightraw[386]=100;
heightraw[219]=199; heightraw[420]=83;
heightraw[228]=189; heightraw[438]=78;
heightraw[252]=163; heightraw[460]=83;
heightraw[274]=150; heightraw[489]=95;
heightraw[282]=149; heightraw[515]=92;
heightraw[297]=151; heightraw[566]=100;
heightraw[329]=165; heightraw[580]=103;
heightraw[366]=198; heightraw[599]=89;
heightraw[404]=191;
heightraw[428]=197;
heightraw[459]=191;
heightraw[489]=197;
heightraw[502]=183;
heightraw[521]=162;
heightraw[546]=151;
heightraw[558]=160;
heightraw[585]=198;
heightraw[592]=194;
heightraw[599]=194;

View File

@ -0,0 +1,84 @@
#include "fx_scanner.h"
FX_Scanner::FX_Scanner(int numpixels,Adafruit_NeoPixel *strip,uint8_t *height,int startpos,float scannervel,uint32_t scannercolor)
{
_numpixels=numpixels;
_pos = startpos;
_strip=strip;
_height=height;
_vel=scannervel;
_scannercolor=scannercolor;
}
FX_Scanner::FX_Scanner()
{
_numpixels=0;
_pos = -1; //for active false
_strip=0;
_height=0;
_vel=0;
_scannercolor=0;
}
void FX_Scanner::updateRoutine(float updatedelayms)
{
_pos+=_vel*updatedelayms/1000.0;
}
void FX_Scanner::updateGraphics()
{
#define FEATHERDISTANCE 3 //in both directions
for(int i=0;i<_numpixels;i++){
float heightdistfromlaser=abs(_height[i]-_pos);
if (heightdistfromlaser<=FEATHERDISTANCE) {
uint8_t _r = _scannercolor >> 16;
uint8_t _g = _scannercolor >> 8;
uint8_t _b = _scannercolor;
float distmult=1.0-(heightdistfromlaser/FEATHERDISTANCE);
_r*=distmult;
_g*=distmult;
_b*=distmult;
uint32_t _pxcolor=_strip->getPixelColor(i); //get current color of that pixel
uint8_t _pxr = _pxcolor >> 16;
uint8_t _pxg = _pxcolor >> 8;
uint8_t _pxb = _pxcolor;
uint16_t _tmpr=_pxr+_r; //add colors
uint16_t _tmpg=_pxg+_g;
uint16_t _tmpb=_pxb+_b;
if (_tmpr>255){ //clamp
_tmpr=255;
}
if (_tmpg>255){
_tmpg=255;
}
if (_tmpb>255){
_tmpb=255;
}
_strip->setPixelColor(i,_tmpr,_tmpg,_tmpb); //draw pixel
}
}
}
bool FX_Scanner::active()
{
if (_pos>256 || _pos<0){
return false;
}
return true;
}
uint32_t FX_Scanner::Wheel(byte WheelPos,float brightness) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return _strip->Color(255 - WheelPos * 3*brightness, 0, WheelPos * 3*brightness);
}
if(WheelPos < 170) {
WheelPos -= 85;
return _strip->Color(0, WheelPos * 3*brightness, 255 - WheelPos * 3*brightness);
}
WheelPos -= 170;
return _strip->Color(WheelPos * 3*brightness, 255 - WheelPos * 3*brightness, 0);
}

View File

@ -0,0 +1,26 @@
#ifndef FX_SCANNER_H
#define FX_SCANNER_H
#include <Adafruit_NeoPixel.h>
#include <math.h>
class FX_Scanner
{
public:
FX_Scanner(int numpixels,Adafruit_NeoPixel *strip,uint8_t *height,int startpos,float scannervel,uint32_t scannercolor);
FX_Scanner();
void updateRoutine(float updatedelayms);
void updateGraphics();
uint32_t Wheel(byte WheelPos,float brightness);
bool active();
private:
int _numpixels;
Adafruit_NeoPixel *_strip;
float _pos;
float _vel;
uint8_t *_height;
uint32_t _scannercolor;
};
#endif

View File

@ -24,5 +24,3 @@ class FX_Flash : public Effect
}; };
#endif #endif

View File

@ -2,12 +2,14 @@
#define WAGONLENGTH 3 #define WAGONLENGTH 3
#define EDGE_KILL //#define EDGE_KILL
//#define EDGE_WALL #define EDGE_WALL
//#define EDGE_BOUNCE //#define EDGE_BOUNCE
//#define EDGE_WRAP //#define EDGE_WRAP
#define WRAPLEDPOS _numpixels //standard #define WRAPLEDENDPOS _numpixels //default
//#define WRAPLEDPOS (_numpixels-5) //led index which is also led 0 //#define WRAPLEDENDPOS (_numpixels-5) //led index which is last led
#define WRAPLEDSTARTPOS 0 //default
//#define WRAPLEDSTARTPOS 23 //led index which is the same as WRAPLEDENDPOS (from start)
#define TYPE_RAINBOW 1 #define TYPE_RAINBOW 1
@ -167,9 +169,9 @@ void Wagon::updatePhysics(float updatedelayms)
if (_pos>=WRAPLEDPOS){ if (_pos>=WRAPLEDENDPOS){
#ifdef EDGE_WRAP #ifdef EDGE_WRAP
_pos-=WRAPLEDPOS; //Wrap around edges _pos-=WRAPLEDENDPOS; //Wrap around edges
#endif #endif
#ifdef EDGE_BOUNCE #ifdef EDGE_BOUNCE
_vel*=-1; //bounce at edges _vel*=-1; //bounce at edges
@ -178,14 +180,14 @@ void Wagon::updatePhysics(float updatedelayms)
//nothing //nothing
#endif #endif
#ifdef EDGE_KILL #ifdef EDGE_KILL
if (_pos>=WRAPLEDPOS+(_trainlength*WAGONLENGTH)){ if (_pos>=WRAPLEDENDPOS+(_trainlength*WAGONLENGTH)){
_health=0; _health=0;
} }
#endif #endif
} }
if (_pos<0){ if (_pos<WRAPLEDSTARTPOS){
#ifdef EDGE_WRAP #ifdef EDGE_WRAP
_pos=WRAPLEDPOS+_pos; //warp around edges _pos=WRAPLEDENDPOS+_pos; //warp around edges
#endif #endif
#ifdef EDGE_BOUNCE #ifdef EDGE_BOUNCE
_vel*=-1;; //bounce at edges _vel*=-1;; //bounce at edges
@ -218,15 +220,15 @@ float Wagon::getHeight(int p){
#ifdef EDGE_KILL #ifdef EDGE_KILL
return _height[0]+p*-100.0; //same like edges as wall return _height[0]+p*-100.0; //same like edges as wall
#endif #endif
}else if(p>=_numpixels){ }else if(p>=WRAPLEDENDPOS){
#ifdef EDGE_WRAP #ifdef EDGE_WRAP
p=p-_numpixels; //wrap edge p=p-WRAPLEDENDPOS; //wrap edge
#endif #endif
#ifdef EDGE_WALL #ifdef EDGE_WALL
return _height[_numpixels-1]+(p-_numpixels)*100.0; //edges as wall return _height[WRAPLEDENDPOS-1]+(p-WRAPLEDENDPOS)*100.0; //edges as wall
#endif #endif
#ifdef EDGE_KILL #ifdef EDGE_KILL
return _height[_numpixels-1]+(p-_numpixels)*100.0; //samel like edges as wall return _height[WRAPLEDENDPOS-1]+(p-WRAPLEDENDPOS)*100.0; //samel like edges as wall
#endif #endif
} }
return _height[p]; return _height[p];
@ -282,7 +284,7 @@ void Wagon::updateGraphics()
int iCorrected=i; int iCorrected=i;
#ifdef EDGE_WRAP #ifdef EDGE_WRAP
if (i<0){ if (i<0){
iCorrected=WRAPLEDPOS+i+1; //Wrap around edges iCorrected=WRAPLEDENDPOS+i+1; //Wrap around edges
} }
#endif #endif