Randomly Select a Function?

I’m trying to randomly select between BladeAngle<>, SwingSpeed<>, TwistAngle<>, etc

I think I need a function that selects / returns a Class/Function, similar to ColorSelect or TrSelect/TrRandom.

Is there currently a way to do something like this?

IntSelect<
	Scale<
		RandomF,
		Int<0>,
		Int<3> // Increment me if you add!
	>,

	EffectRandomF<EFFECT_BLAST>,
	BladeAngle<>,
	SwingSpeed<SWING_SPEED_DEFAULT>,
	TwistAngle<>
>

If not, can it be added? it could make a large impact on style memory use reduction For example: Blast Effect could use it to randomly, or sequentially, choose what method it uses for position/size.

First of all, there already is an IntSelect, but it takes a list of numbers, not functions. I could make an IntSelectX that does exactly this, but I still don’t think that will really help you, because random will select a new function every “frame”, so the result will be a bunch of flickering, which is probably not what you want.

Hmm.

I’m trying to make a using function for Blast Effects that takes in a template argument for which function it passes into it’s Scale<> functions. Atm I have basically copies of the same functions for BladeAngle<>, EffectRandomF<>, and TwistAngle<>, so 5x of each is 15 blast effects in a TrRandom<>.

On a related note:

Whoot, new personal record. Do I win anything?

You win… (click to reveal)

… a desire to get a V3 board

Ok, so you’re not using RandomF for the selection?
Why not just pass in BladeAngle<>, EffectRandomF<>, etc. to the template?

The idea was to make a function that randomly chooses which one to use. I was trying RandomF with IntSelect but it can only choose between functiosn that return “number”.

Let’s say I have this function:

using BLASTFADE_SIZE = Scale<
	EffectRandomF<EFFECT_BLAST>,
	Int<28000>,
	Int<8000>
>;

This is where I’d want to put in a random selection in place of “EffectRandomF<EFFECT_BLAST>,”, where it could also choose BladeAngle<> or TwistAngle<> instead, for instance.

Which is used as a Size (or position) value for a Blast effect:

template<class POS = EffectPosition<EFFECT_BLAST>, class SIZE = BLASTFADE_SIZE<>>
using Blast_Fade = TrConcat<
	TrInstant,
	AlphaMixL<
		Bump<
			POS,
			SIZE
		>,
		RgbArg<BLAST_COLOR_ARG, Rgb<127, 127, 127>>,
		Mix<Int<16384>, Black, RgbArg<BLAST_COLOR_ARG, Rgb<127, 127, 127>>>
	>,
	TrFade<300>
>;

So, I still end up having in my style code 20 blast effects, which are all copies of 3 sections of code:

	// Random Positions based on EffectPosition
		// Blast Fade Random
		Blast_Fade<BLASTPOS_SCALE<>, BLASTFADE_SIZE<>>,
		// Blast Fade Sound
		Blast_Fade<BLASTPOS_SCALE<>, BLASTFADE_SIZE<WavLen<EFFECT_BLAST>>>,

		// Blast Wave Random
		Blast_Wave<BLASTWAVE_SCALE<>, BLASTWAVE_SCALE<SlowNoise<Int<3000>>>, BLASTWAVE_SCALE<>, BLASTPOS_SCALE<>>,
		// Blast Wave Sound
		Blast_Wave<BLASTWAVE_SCALE<WavLen<EFFECT_BLAST>>, BLASTWAVE_SCALE<SlowNoise<Int<3000>>>, BLASTWAVE_SCALE<WavLen<EFFECT_BLAST>>, BLASTPOS_SCALE<>>,

		// Blast Ripple Fade
		Blast_Ripple_Fade<BLASTRIPPLE_POS<>, Int<6000>, Int<320000>>,
	// Responsive Blast Fade Random
		Blast_Fade<BLASTPOS_SCALE<BladeAngle<>>, BLASTFADE_SIZE<>>,
		// Responsive Blast Fade Sound
		Blast_Fade<BLASTPOS_SCALE<BladeAngle<>>, WavLen<EFFECT_BLAST>>,

		// Responsive Blast Wave Random
		Blast_Wave<BLASTWAVE_SCALE<>, BLASTWAVE_SCALE<SlowNoise<Int<3000>>>, BLASTWAVE_SCALE<>, BLASTPOS_SCALE<BladeAngle<>>>,
		// Responsive Blast Wave Sound
		Blast_Wave<BLASTWAVE_SCALE<WavLen<EFFECT_BLAST>>, BLASTWAVE_SCALE<SlowNoise<Int<3000>>>, BLASTWAVE_SCALE<WavLen<EFFECT_BLAST>>, BLASTPOS_SCALE<BladeAngle<>>>,

		// Responsive Blast Ripple Fade
		Blast_Ripple_Fade<BLASTRIPPLE_POS<BladeAngle<>>, Int<6000>, Int<320000>>,

	// Responsive based on SwingSpeed<>
		// Responsive Blast Fade Random
		Blast_Fade<BLASTPOS_SCALE<SwingSpeed<200>>, BLASTFADE_SIZE<>>,
		// Responsive Blast Fade Sound
		Blast_Fade<BLASTPOS_SCALE<SwingSpeed<200>>, WavLen<EFFECT_BLAST>>,

		// Responsive Blast Wave Random
		Blast_Wave<BLASTWAVE_SCALE<>, BLASTWAVE_SCALE<SlowNoise<Int<3000>>>, BLASTWAVE_SCALE<>, BLASTPOS_SCALE<SwingSpeed<200>>>,
		// Responsive Blast Wave Sound
		Blast_Wave<BLASTWAVE_SCALE<WavLen<EFFECT_BLAST>>, BLASTWAVE_SCALE<SlowNoise<Int<3000>>>, BLASTWAVE_SCALE<WavLen<EFFECT_BLAST>>, BLASTPOS_SCALE<SwingSpeed<200>>>,

		// Responsive Blast Ripple Fade
		Blast_Ripple_Fade<BLASTRIPPLE_POS<SwingSpeed<200>>, Int<6000>, Int<320000>>,

	// Responsive based on TwistAngle<>
		// Responsive Blast Fade Random
		Blast_Fade<BLASTPOS_SCALE<TwistAngle<>>, BLASTFADE_SIZE<>>,
		// Responsive Blast Fade Sound
		Blast_Fade<BLASTPOS_SCALE<TwistAngle<>>, WavLen<EFFECT_BLAST>>,

		// Responsive Blast Wave Random
		Blast_Wave<BLASTWAVE_SCALE<>, BLASTWAVE_SCALE<SlowNoise<Int<3000>>>, BLASTWAVE_SCALE<>, BLASTPOS_SCALE<TwistAngle<>>>,
		// Responsive Blast Wave Sound
		Blast_Wave<BLASTWAVE_SCALE<WavLen<EFFECT_BLAST>>, BLASTWAVE_SCALE<SlowNoise<Int<3000>>>, BLASTWAVE_SCALE<WavLen<EFFECT_BLAST>>, BLASTPOS_SCALE<TwistAngle<>>>,

		// Responsive Blast Ripple Fade
		Blast_Ripple_Fade<BLASTRIPPLE_POS<TwistAngle<>>, Int<6000>, Int<320000>>[/code]

Aaaand that’s what i’ve been up to today, taking all the Blast effects from the StyleBuilder, studying them, realizing they’re all variations of the same 3 functions, except for what method is used in Scale<>, and making 3 template functions to use for them all.

Now if only I could get it to randomly select which item to use in said Scale functions each time EFFECT_BLAST triggers, I could make those 20 functions only 3 functions, and greatly reduce the amount of code on memory.

I’m going to add IntSelectX to ProffieOS 8.x. It’s checked in on github master, but it is untested.

Ok, random Q: Is Github master compilable on audrino? Like I can just take the ProffieOS folder, drop my config in and boom?

Most of the time yes.
Two caveats:

  1. when you unzip the source from github master you usually get a directory called “Proffieos-master”, which will need to be renamed to “Proffieos” or arduino won’t be happy.
  2. Github master has new stuff, untested stuff, and sometimes bugs. It might not compile, it may compile, but crash or do something weird. Please adjust your expectations accordingly. If you do try it out, please me know when something doesn’t work so I can fix it.

I like to use an app called GitHub Desktop.
It makes syncing a breeze, easily shows the diffs for updates, and keeps a local copy so you can play all you want.

I use SourceTree

Ok, testing your IntSelectX, trying to figure out how to use it in my Blast effect…

TrConcat<
	TrInstant,
	AlphaMixL<
		Bump<
			Scale<
				IntSelectX<
					Scale<
						RandomF,
						Int<0>,
						Int<3> // Increment me if you add!
					>,
					// Choose randomly from the following:
					EffectRandomF<EFFECT_BLAST>,
					BladeAngle<>,
					SwingSpeed<SWING_SPEED_DEFAULT>,
					TwistAngle<>
				>,
				Int<28000>,
				Int<8000>
			>,
			Scale<
				BladeAngle<>,
				Int<9000>,
				Int<15000>
			>
		>,
		RgbArg<BLAST_COLOR_ARG, Rgb<127, 127, 127>>,
		Mix<
			Int<16384>, 
			Black, 
			RgbArg<BLAST_COLOR_ARG, Rgb<127, 127, 127>>>
	>,
	TrFade<300>
>

Generates the following error:

Compilation error: 'int IntSelectX<F, N>::getInteger(int) [with F = SingleValueAdapter<ScaleSVF<RandomFSVF, SingleValueAdapter<IntSVF<0> >, SingleValueAdapter<IntSVF<3> > > >; N = {EffectRandomF<EffectType::EFFECT_BLAST>, SingleValueAdapter<BladeAngleXSVF<SingleValueAdapter<IntSVF<0> >, SingleValueAdapter<IntSVF<32768> > > >, SingleValueAdapter<SwingSpeedSVF<SingleValueAdapter<IntSVF<500> > > >, SingleValueAdapter<TwistAngleSVF<2, 0> >}]' is private within this context

though, I also want to trigger the selection on EFFECT_BLAST triggers, like EffectPulseF, but random selection.

also, Is there a function like EffectSequence<> that is random? I know we have TrRandom<>, but that only works for transitions?

This should (hopefully) be fixed now.

Use EffectRandomF<EFFECT_BLAST> as the select function.

Just use EffectRandomF as the input to ColorSelect, right?

Ah, right. So,

				IntSelectX<
					Scale<
						EffectRandomF<EFFECT_BLAST>,
						Int<0>,
						Int<3> // Increment me if you add!
					>,
					// Choose randomly from the following:
					EffectRandomF<EFFECT_BLAST>,
					BladeAngle<>,
					SwingSpeed<SWING_SPEED_DEFAULT>,
					TwistAngle<>
				>

still errors generating Compilation error: 'TypeList<EffectRandomF<EffectType::EFFECT_BLAST>, SingleValueAdapter<BladeAngleXSVF<SingleValueAdapter<IntSVF<0> >, SingleValueAdapter<IntSVF<32768> > > > >::size' cannot be used as a function

I’m not sure what that means.

You don’t need Scale<>, it will work as intended without it.

Means I still need to fix it. :slight_smile:

Try it now.

Compiles :slight_smile: Going to go test it

So, it seems to only ever pick the first option.

Here’s my current test Blast style if you’d like to try it.

TrConcat<
	TrInstant,
	AlphaMixL<
		Bump<
			Scale<
				IntSelectX<
					EffectRandomF<EFFECT_BLAST>,

					BladeAngle<>,
					EffectRandomF<EFFECT_BLAST>,
					SwingSpeed<500>,
					TwistAngle<>
				>,
				Int<28000>,
				Int<8000>
			>,
			Scale<
				IntSelectX<
					EffectRandomF<EFFECT_BLAST>,

					BladeAngle<>,
					EffectRandomF<EFFECT_BLAST>,
					SwingSpeed<500>,
					TwistAngle<>
				>,
				Int<1000>,
				Int<20000>
			>
		>,
		RgbArg<BLAST_COLOR_ARG, Rgb<127, 127, 127>>,
		Mix<
			Int<16384>, 
			Black, 
			RgbArg<BLAST_COLOR_ARG, Rgb<127, 127, 127>>>
	>,
	TrFade<300>
>

using this, it only ever changes with BladeAngle<>.

How about now?

Yay, it works! <3

Last Q: Can this be added to ProffieOS v7.x? (assuming you’re doing another update to v7)