HW6_DYNAMIC MOVEMENT_ZHANG

Code:

#include “Charliplexing.h”

const float stretch = 0.9;

const float phaseIncrement = 0.1;

const float driftIncrement = 0.019;
const float driftForce = 0.4;

const float barPhaseIncrement = 0.09;

const byte lightSineBrightness = 3;
const byte darkSineBrightness = 0;
const byte barBrightness = 1;

float phase = 5.0;
float driftPhase = 5.0;
float barPhase = 5.0;

void setup() {
LedSign::Init(DOUBLE_BUFFER | GRAYSCALE);
}
void loop() {
phase += phaseIncrement;

driftPhase += driftIncrement;

barPhase += barPhaseIncrement;
if( barPhase > 1.0 ) barPhase -= 1.0;

boolean drawEvenBars = (barPhase < 0.5);

byte row, col;

for( col=0; col<14; col++ ) {

float lightSineThisColumn = sin( phase + float(col)*stretch );

int lightSine = int( round( lightSineThisColumn*4.0 ) ) + 4.5;

float drift = 5 + (driftForce * sin( driftPhase ));

int darkSine = int( round( sin(phase+drift+float(col)*stretch)*8.0 ) ) + 4;

for( row=0; row<9; row++ ) {

if( row==lightSine ) {
LedSign::Set( col, row, lightSineBrightness );

} else if( row==darkSine ) {
LedSign::Set( col, row, darkSineBrightness );

} else {

int color = 0;

if( (col & 0x1) ^ (drawEvenBars) ) {

if( lightSine < darkSine ) {
if( lightSine<row && row<darkSine ) {
color = barBrightness;
}

} else if( darkSine < lightSine ) {
if( darkSine<row && row<lightSine ) {
color = barBrightness;
}
}
}

LedSign::Set( col, row, color );
}
}
}

LedSign::Flip(true);
}

Leave a Reply

Your email address will not be published.