DiyLightAnimation

Software => Vixen => Topic started by: jwilliams31 on November 29, 2011,

Title: Need some scripting help
Post by: jwilliams31 on November 29, 2011,
I have 2 trees that I have set up kind of like a mega tree. A bunch of strings running down, each on a separate channel. I was thinking of possibly having them do a slow chase during the background sequence, but need some help with how to script it.

Also, during the background, I currently have the lights on some bushes do a fade between white and multi-colored strings every 5 minutes.

Here is my current script:

Code: You are not allowed to view links. Register or Login
while (now.CompareTo(start0) >= 0 && now.CompareTo(end0) <= 0)
{
On(Channels(allOther), At (60));
On(Channels(whiteLights), At (60), For (300).Seconds, Wait);

Ramp(Channels(whiteLights), 60, 0, Over (10).Seconds);
Ramp(Channels(multiLights), 0, 60, Over (10).Seconds, Wait);

On(Channels(multiLights), At (60), For (300).Seconds, Wait);

Ramp(Channels(multiLights), 60, 0, Over (10).Seconds);
Ramp(Channels(whiteLights), 0, 60, Over (10).Seconds, Wait);

now = DateTime.Now; //update the current time
}

The problem is that, with the Waits for the fades, the Chase function doesn't work right because it completes and then stops and waits.

Does anyone have any thoughts on how I can make the chase work with the above script?

I already tried posting on DIYC, but so far I havent found a solution.

Thanks.

Jason
Title: Re: Need some scripting help
Post by: inzeos on November 29, 2011,
Interesting... Did not know you could script like that in Vixen...  Is that in all current versions?
Title: Re: Need some scripting help
Post by: rrowan on November 29, 2011,
see if this post provides any useful info

http://diylightanimation.com/index.php?topic=776.0

Rick R.
Title: Re: Need some scripting help
Post by: DanHouston on November 30, 2011,
I'm not totally sure what you are trying to do, so this may not help, but I'll take a stab at it....

I think you want to switch between your white lights and multi-color lights every 5 minutes. And you want them to ramp on/off as the transition to do that. If that's what you want to do here's what I would do (I'll send you my code that does this every minute when I get home):
1. Create a variable that stores the state of your white lights (Integer whiteOn;) (You could also use boolean, but I prefer integer). Let's say 0 is off and 1 is on.
2. Use the Mod function (I think it is %) with 5 and check for 0 (so this will evaluate to true every 5 minutes).
    a. If whiteOn = 0 (ramp on white and ramp off multi....no need for the wait parameter)
    b. if whiteOn = 1 (ramp on multi and ramp off white....no need for the wait parameter)

Here is some uncompiled code so there are probably errors in it, but should get you going (again, I'll post the real code when I get home):

Integer whiteOn;
.
.
.
whiteOn = 0;
.
.
.
while (now.CompareTo(start0) >= 0 && now.CompareTo(end0) <= 0)
    {
        On(Channels(allOther), At (60));
        if (now.minutes % 5 == 0) then
            {
                if (whiteOn == 0) then
                    {
                        Ramp(Channels(multiLights), 60, 0, Over (10).Seconds);
                        Ramp(Channels(whiteLights), 0, 60, Over (10).Seconds);
                        whiteOn = 1;
                    }
                else
                    {
                        Ramp(Channels(whiteLights), 60, 0, Over (10).Seconds);
                        Ramp(Channels(multiLights), 0, 60, Over (10).Seconds);
                        whiteOn = 0;
                    }
            }                               
        //update the current time
        now = DateTime.Now;
    }


Title: Re: Need some scripting help
Post by: inzeos on November 30, 2011,
You are not allowed to view links. Register or Login
I'm not totally sure what you are trying to do, so this may not help, but I'll take a stab at it....

I think you want to switch between your white lights and multi-color lights every 5 minutes. And you want them to ramp on/off as the transition to do that. If that's what you want to do here's what I would do (I'll send you my code that does this every minute when I get home):
1. Create a variable that stores the state of your white lights (Integer whiteOn;) (You could also use boolean, but I prefer integer). Let's say 0 is off and 1 is on.
2. Use the Mod function (I think it is %) with 5 and check for 0 (so this will evaluate to true every 5 minutes).
    a. If whiteOn = 0 (ramp on white and ramp off multi....no need for the wait parameter)
    b. if whiteOn = 1 (ramp on multi and ramp off white....no need for the wait parameter)

Here is some uncompiled code so there are probably errors in it, but should get you going (again, I'll post the real code when I get home):

Integer whiteOn;
.
.
.
whiteOn = 0;
.
.
.
while (now.CompareTo(start0) >= 0 && now.CompareTo(end0) <= 0)
    {
        On(Channels(allOther), At (60));
        if (now.minutes % 5 == 0) then
            {
                if (whiteOn == 0) then
                    {
                        Ramp(Channels(multiLights), 60, 0, Over (10).Seconds);
                        Ramp(Channels(whiteLights), 0, 60, Over (10).Seconds);
                        whiteOn = 1;
                    }
                else
                    {
                        Ramp(Channels(whiteLights), 60, 0, Over (10).Seconds);
                        Ramp(Channels(multiLights), 0, 60, Over (10).Seconds);
                        whiteOn = 0;
                    }
            }                               
        //update the current time
        now = DateTime.Now;
    }

You could probably simplify it a lot... by setting the channels to a known state to start with an assuming that the state will stay the same.

Then you can ramp on for a ramp period for one and off for another and pause or sleep for the amount of time that one color should be on for.
Title: Re: Need some scripting help
Post by: DanHouston on November 30, 2011,
It looked like he was trying to do that with the wait commands and it was not working for him. In mine I am doing other things so I want to run the loop every 10 seconds or so (I think that is the default), and I wanted it to be odd/even minutes so I had to check the time (of course if you are not concerned with that then what you had mines the wait on the RAMP commands should work). A couple of updates to the previous bit I posted....should work, although I did not have a chance to test with my lights.

int whiteOn = 0;
.
.
.
while (now.CompareTo(start0) >= 0 && now.CompareTo(end0) <= 0)
    {
        On(Channels(allOther), At (60));
        if (now.minutes % 5 == 0) then
            {
                if (whiteOn == 0)
                    {
                        Ramp(Channels(multiLights), 60, 0, Over (10).Seconds);
                        Ramp(Channels(whiteLights), 0, 60, Over (10).Seconds);
                        whiteOn = 1;
                    }
                else
                    {
                        Ramp(Channels(whiteLights), 60, 0, Over (10).Seconds);
                        Ramp(Channels(multiLights), 0, 60, Over (10).Seconds);
                        whiteOn = 0;
                    }
            }                               
        //update the current time
        now = DateTime.Now;
    }

Title: Re: Need some scripting help
Post by: jwilliams31 on December 01, 2011,
Actually I'm trying to do 2 things.

1) I want to switch between my white and multicolored lights with an overlapping fade for the transition.  This IS working with the code that I posted.

2) I have 2 trees that I draped light strings down, similar to a mega tree (just with fewer lights).  I would like to have the lights on these trees chase.

The problem I'm having is getting these to work together. 

If I use the "chase" function, it will run through once, but then will not run again until the Waits complete.

I'm looking for some advice on how to get these to play nice together.  A constant chase as well as the light transition every 5 minutes.

Thanks.

Jason
Title: Re: Need some scripting help
Post by: jwilliams31 on December 01, 2011,
I added Dan's example.  Here's what I have now:

Code: You are not allowed to view links. Register or Login
while (now.CompareTo(start0) >= 0 && now.CompareTo(end0) <= 0)
  {
    On(Channels(allOther, palmLights1,
palmLights2, palmLights3, palmLights4,
palmLights5, palmLights6, Signs), At (60));
    Chase(ChannelRange(palmLights1, palmLights6), Over (3700).Milliseconds);
    if (now.minutes % 5 == 0)
    {
      if (whiteOn == 0)
      {
        Ramp(Channels(multiLights), 60, 0, Over (10).Seconds);
        Ramp(Channels(whiteLights), 0, 60, Over (10).Seconds);
        whiteOn = 1;
      }
      else
      {
        Ramp(Channels(multiLights), 60, 0, Over (10).Seconds);
        Ramp(Channels(whiteLights), 0, 60, Over (10).Seconds);
        whiteOn = 0;
      }
    }
    now = DateTime.Now; //update the current time
  }

But it won't compile.  I get an error:

"System.DateTime does not contain a definition for minutes"

for this line,  if (now.minutes % 5 == 0).

Thanks.

Title: Re: Need some scripting help
Post by: DanHouston on December 01, 2011,
Mispelled it....now.Minute
Title: Re: Need some scripting help
Post by: jwilliams31 on December 02, 2011,
Vixen doesn't like something.  It keeps crashing when I run the script.



Title: Re: Need some scripting help
Post by: DanHouston on December 02, 2011,
I'll adjust it to match my light profile and run it when I get home.
Title: Re: Need some scripting help
Post by: DanHouston on December 02, 2011,
It does not seem to like using Milliseconds....I've never done anything that granular with a script in Vixen so I don't have experience with it (I've always done it over seconds). I changed it to 3 seconds for testing purposes and it ran without crashing.

Start by commenting out the chase command and see if it runs for you. If it does you know that you need to work on the chase command. Next you might try my test of using seconds rather than milliseconds.

The other thing I did not get to test here (I just had the chase on a single light) was if it is really working correctly since nothing is slowing it down from being called over and over again....You may need to enclose it in an if/then check to make sure it is not called again until the previous run completed (you could use wait here, but since you are doing 3.7 seconds that will hurt your 5 minute check).
Title: Re: Need some scripting help
Post by: jwilliams31 on December 03, 2011,
So I disabled everything except the transition.  Vixen doesn't seem to be crashing now, but it's also not doing the transition correctly.  The just kind of flicker and then eventually both the white and multicolor stay on.

Here is my code as it is right now.  I'm going to try to take a screen recording to show you the behavior that I'm seeing when I run/preview it.

Code: You are not allowed to view links. Register or Login
int whiteOn;

whiteOn = 0;

  while (now.CompareTo(start0) >= 0 && now.CompareTo(end0) <= 0)
  {
//    On(Channels(allOther, palmLights1,
// palmLights2, palmLights3, palmLights4,
// palmLights5, palmLights6, Signs), At (60));

    if (now.Second % 20 == 0)
    {
      if (whiteOn == 0)
      {
        Ramp(Channels(multiLights), 60, 0, Over (10).Seconds);
        Ramp(Channels(whiteLights), 0, 60, Over (10).Seconds);
        whiteOn = 1;
      }
      else
      {
        Ramp(Channels(whiteLights), 60, 0, Over (10).Seconds);
        Ramp(Channels(multiLights), 0, 60, Over (10).Seconds);
        whiteOn = 0;
      }
    }
    now = DateTime.Now; //update the current time
  }
Title: Re: Need some scripting help
Post by: DanHouston on December 03, 2011,
It's not doing the ramp correctly? Do you have anywhere in your code where those are just set to ON? Is your last post your complete script?

I saw that flickering in mine when I accidentally had one of the channels in the original "ON" command with my other lights.
Title: Re: Need some scripting help
Post by: jwilliams31 on December 03, 2011,
No.  In fact I just completely simplified the script and removed everything except the lights I want to transition.

This is my entire script.

Code: You are not allowed to view links. Register or Login
void Start() {

//***********************************************************************************************

DateTime now = DateTime.Now; //Gets the current time

ChannelCollection whiteLights;
ChannelCollection multiLights;

//*********************************************************************************************

whiteLights = Channels(Center_Oak_White, Bush_1_White, Bush_2_White, Bush_3_White, Bush_4_White,
Bush_5_White, Bush_6_White, Split_Palm_White, Left_Oak_White);

multiLights = Channels(Center_Oak_Multi, Bush_1_Multi, Bush_2_Multi, Bush_3_Multi, Bush_4_Multi,
Bush_5_Multi, Bush_6_Multi, Split_Palm_Multi, Left_Oak_Multi);

//*********************************************************************************************

int whiteOn;
whiteOn = 0;

//*********************************************************************************************

  while (true)
  {
    if (now.Second % 20 == 0)
    {
      if (whiteOn == 0)
      {
        Ramp(Channels(multiLights), 60, 0, Over (10).Seconds);
        Ramp(Channels(whiteLights), 0, 60, Over (10).Seconds);
        whiteOn = 1;
      }
      else
      {
        Ramp(Channels(whiteLights), 60, 0, Over (10).Seconds);
        Ramp(Channels(multiLights), 0, 60, Over (10).Seconds);
        whiteOn = 0;
      }
    }
 
    now = DateTime.Now; //update the current time
  }
}

Also, the script with run for about a minute or so, the lights will flicker and then stay on and then Vixen will crash.

In case I hadn't mentioned it yet, I'm running this on 2.1.4.0
Title: Re: Need some scripting help
Post by: DanHouston on December 03, 2011,
Can you put 2.1.1 back in place? I was running 2.1.4 and had other issues so I've gone back to 2.1.1.

I don't see anything wrong with that script....If I get a chance I'll change it to my lights and run it.


Title: Re: Need some scripting help
Post by: jwilliams31 on December 04, 2011,
Before I do that, do you know if going back to 2.1.1 will have any negative effect on any of my profiles or sequences?
Title: Re: Need some scripting help
Post by: jwilliams31 on December 04, 2011,
Ok, I downloaded a clean copy of 2.1.1 and copied everything over to it.  I tried to run the script and it did the flashy thing with the lights and then Vixen crashed.
Title: Re: Need some scripting help
Post by: DanHouston on December 05, 2011,
Tricky one...It was coming back over the script so fast that the mod 20 was running repeatedly. Since I do things on odd/even minutes mine does not run into that issue. I put in a check to make sure we are not still on the same second as the last transition and it ran fine with my lights for over an hour before I stopped it.


Code: You are not allowed to view links. Register or Login
void Start() {

Off(All);
//***********************************************************************************************

DateTime now = DateTime.Now; //Gets the current time

ChannelCollection whiteLights;
ChannelCollection multiLights;

//*********************************************************************************************

whiteLights = Channels(Left_Magnolia___White,Right_Bradford___White);
multiLights = Channels(Left_Magnolias___Red___Multi,Right_Bradford_Pear___Red___Multi);

//*********************************************************************************************

int whiteOn;
int transitionSecond;
whiteOn = 0;
transitionSecond = 0;

//*********************************************************************************************

while (true) <= 0)
{
    if (now.Second % 20 == 0 && now.Second != transitionSecond)
{
transitionSecond = now.Second;
if (whiteOn == 0)
{
Ramp(Channels(multiLights), 60, 0, Over (10).Seconds);
Ramp(Channels(whiteLights), 0, 60, Over (10).Seconds);
whiteOn = 1;
}
else
{
Ramp(Channels(whiteLights), 60, 0, Over (10).Seconds);
Ramp(Channels(multiLights), 0, 60, Over (10).Seconds);
whiteOn = 0;
}
}
    now = DateTime.Now; //update the current time
  }
}