need scripting help

Write here what nice effects or shows you have done with MADRIX or ask other users.

Moderator: MADRIX Team

Locked
User avatar
dieter
Posts: 84
Joined: Tue Aug 19, 2008 3:47 pm

need scripting help

Post by dieter »

Hi,

I will build a effect script with an min and max slider for build a range. What I must do? Value for min are never higher then max value and max value never lower then min value automatic.
How program that?

Here my not perfect script test.

Code: Select all

@scriptname="SliderMinMaxRange";
@author="Dieter";
@version="1.0";
@description="11/14/2011";

int	maxX=GetMatrixWidth();
int maxY=GetMatrixHeight();

ctrlslider sliderMin={"Min",1,maxX*1/4,maxX};
ctrlslider sliderMax={"Max",1,maxX*3/4,maxX};


void InitEffect(){
	// get size
	maxX=GetMatrixWidth();
	maxY=GetMatrixHeight();
}

void RenderEffect(){
	Clear(); // clear screen
    // get value of slider
	int maxValue=sliderMax.value;
	int minValue=sliderMin.value;
    // check range
	if(maxValue<minValue)maxValue=minValue;
	if(minValue>maxValue)minValue=maxValue;
    // set value of slider
	sliderMax.value=maxValue;
	sliderMin.value=minValue;
    // draw rectangle
	FillPixelRect(WHITE,0,minValue-1,maxX,maxValue-minValue+1);
	DrawPixelRect(RED,  0,minValue-1,maxX,maxValue-minValue+1);
}

void MatrixSizeChanged(){
	InitEffect();
}
Can anyone help me?
User avatar
Wissmann
Developer
Developer
Posts: 774
Joined: Fri Feb 23, 2007 3:36 pm
Location: Germany
Contact:

Re: need scripting help

Post by Wissmann »

try this

Code: Select all

@scriptname="SliderMinMaxRange";
@author="Dieter";
@version="1.0";
@description="11/14/2011";

int maxX,maxY;
ctrlslider sliderMin={"Min",1,100,100,"Min"};
ctrlslider sliderMax={"Max",1,100,100,"Max"};

void InitEffect()
{
	// get size
	maxX=GetMatrixWidth();
	maxY=GetMatrixHeight();

	//Init Slider ranges
	int sMin = (int)((float)maxY*0.25);
	sliderMin.rangeMax = sMin;
	sliderMin.value = sMin;      		
	
	int sMax = (int)((float)maxY*0.75);
	sliderMax.rangeMax = sMax;
	sliderMax.value = sMax;    	
}

void RenderEffect()
{
	Clear(); // clear screen
    
	//check range
	if(sliderMax.value < sliderMin.value) sliderMax.value = sliderMin.value;   	
	if(sliderMin.value > sliderMax.value) sliderMin.value = sliderMax.value;

	// draw rectangle
	FillPixelRect(WHITE,0,sliderMin.value-1,maxX,sliderMax.value-sliderMin.value+1);
	DrawPixelRect(RED,  0,sliderMin.value-1,maxX,sliderMax.value-sliderMin.value+1);   	
}

void MatrixSizeChanged()
{
   InitEffect();
}



LEDs are nothing without control ;-)
User avatar
dieter
Posts: 84
Joined: Tue Aug 19, 2008 3:47 pm

Re: need scripting help

Post by dieter »

Hi wissmann,
sorry but you don't understand my problem.
I don't will limit the range of slider or output.

I want:
If I slide the max slider lower the min slider then also move the min slider lower.
If I slider the min slider higher the max slider then also move the max slider higher.

If you test my script you see one direction running fine but the inverse way running not really good.
User avatar
Pinzer
Developer
Developer
Posts: 31
Joined: Thu Feb 15, 2007 2:47 pm
Location: Dresden, Germany
Contact:

Re: need scripting help

Post by Pinzer »

Hi dieter,

maybe this is what you are looking for.

Code: Select all

@scriptname="SliderMinMaxRange";
@author="Dieter";
@version="1.0";
@description="11/14/2011";

int maxX=GetMatrixWidth();
int maxY=GetMatrixHeight();

ctrlslider sliderMin={"Min",1,maxX*1/4,maxX};
ctrlslider sliderMax={"Max",1,maxX*3/4,maxX};


void InitEffect(){
   // get size
   maxX=GetMatrixWidth();
   maxY=GetMatrixHeight();
}

void RenderEffect(){
   Clear(); // clear screen
    // get value of slider
   int maxValue=sliderMax.value;
   int minValue=sliderMin.value;
   int newmaxValue=maxValue;
   int newminValue=minValue;
    // check range
   if(minValue>maxValue)newmaxValue=minValue;
   if(maxValue<minValue)newminValue=maxValue;
    // set value of slider
   sliderMax.value=newmaxValue;
   sliderMin.value=newminValue;
    // draw rectangle
   FillPixelRect(WHITE,0,minValue-1,maxX,newmaxValue-newminValue+1);
   DrawPixelRect(RED,  0,minValue-1,maxX,newmaxValue-newminValue+1);
}

void MatrixSizeChanged(){
   InitEffect();
}
Locked