Changing BPM using if>then statement
Posted: Tue Sep 13, 2022 8:40 am
I'm trying to create an effect where a line moves across the matrix but varies its speed based on position. I have tried using the if>then statements examining the xpos of the line but I am getting something wrong in the syntax or use of the SetBPM command when nested in an if>then statement.
Can anyone look at this and point me in the right direction.
// Global Vars
float mw;
float mh;
int xdir;
int ydir;
float xpos;
float ypos;
// Global Colors
color col = {255,255,255,0}; //White
color col2 = {127,127,127,0}; //Gray
color col3 = {255,0,0,0}; //Red
void InitEffect()
{
SetBpm(600.0);
SetAsync(true);
xdir = 1;
xpos = 0.0;
mw = (float)GetMatrixWidth();
mh = (float)GetMatrixHeight();
}
void RenderEffect()
{
//Calc Position and Direction for X
if(xdir == 1)
{
xpos += 1.0;
if(xpos == mw-1.0)
// xdir = -1;
xpos=0;
}
if (xpos == 30)
(SetBPM(900.0);)
else
if (xpos == 60)
(SetBPM(1200.0);)
else
if (xpos == 90)
(SetBPM(600.0);)
//Draw Matrix Black
ClearAlpha(255);
//First Vertical Line
DrawVectorLine(col2,(xpos-1.0)/mw,0.0,(xpos-1.0)/mw,1.0);
DrawVectorLine(col,(xpos+4.0)/mw,0.0,(xpos+5.0)/mw,4.0);
DrawVectorLine(col3,(xpos+8.0)/mw,0.0,(xpos+5.0)/mw,4.0);
}
void MatrixSizeChanged()
{
InitEffect();
}
Can anyone look at this and point me in the right direction.
// Global Vars
float mw;
float mh;
int xdir;
int ydir;
float xpos;
float ypos;
// Global Colors
color col = {255,255,255,0}; //White
color col2 = {127,127,127,0}; //Gray
color col3 = {255,0,0,0}; //Red
void InitEffect()
{
SetBpm(600.0);
SetAsync(true);
xdir = 1;
xpos = 0.0;
mw = (float)GetMatrixWidth();
mh = (float)GetMatrixHeight();
}
void RenderEffect()
{
//Calc Position and Direction for X
if(xdir == 1)
{
xpos += 1.0;
if(xpos == mw-1.0)
// xdir = -1;
xpos=0;
}
if (xpos == 30)
(SetBPM(900.0);)
else
if (xpos == 60)
(SetBPM(1200.0);)
else
if (xpos == 90)
(SetBPM(600.0);)
//Draw Matrix Black
ClearAlpha(255);
//First Vertical Line
DrawVectorLine(col2,(xpos-1.0)/mw,0.0,(xpos-1.0)/mw,1.0);
DrawVectorLine(col,(xpos+4.0)/mw,0.0,(xpos+5.0)/mw,4.0);
DrawVectorLine(col3,(xpos+8.0)/mw,0.0,(xpos+5.0)/mw,4.0);
}
void MatrixSizeChanged()
{
InitEffect();
}