Color code according to collision group

Suggest changes and improvements to Algodoo.

Color code according to collision group

Postby kilebantick » Fri Sep 04, 2009 7:04 am

Not much to say here, i just think there should be a button somewhere in the overcowded menu that makes all of the colors of every object change according to their collision group. EG: Cololision group A = red B= blue A and B = Purple so on.
Image
User avatar
kilebantick
 
Posts: 1267
Joined: Tue Sep 01, 2009 9:50 am

Re: Color code according to collision group

Postby gradyfitz » Fri Sep 04, 2009 2:03 pm

Code: Select all
// Colour Modification Script
//      By Grady Fitzpatrick
//Project 04: Colour Modification via collideSet
// Colours
// Reccommended minimum of 7 different colours,
// as this will allow for each different collision group to have its own colour
Scene.my.Pro04Red = [1.0,0.0,0.0]; // Red
Scene.my.Pro04Blue = [0.0,0.0,1.0]; // Blue
Scene.my.Pro04Green = [0.0,1.0,0.0]; // Green
Scene.my.Pro04Yellow = [1.0,1.0,0.0]; // Yellow
Scene.my.Pro04Black = [0.0,0.0,0.0]; // Black
Scene.my.Pro04White = [1.0,1.0,1.0]; // White
Scene.my.Pro04Cyan = [0.0,1.0,1.0]; // Cyan

// collideSet's Colours
// Requires previous definition of colour (as above).
Scene.my.Pro04CollideA = "Red"; // Collide A's colour
Scene.my.Pro04CollideB = "Blue"; // Collide B's colour
Scene.my.Pro04CollideC = "Green"; // Collide C's colour
Scene.my.Pro04CollideD = "Yellow"; // Collide D's colour
Scene.my.Pro04CollideE = "Black"; // Collide E's colour
Scene.my.Pro04CollideF = "White"; // Collide F's colour
Scene.my.Pro04CollideG = "Cyan"; // Collide G's colour

// Options
Scene.my.Pro04BlendAmount = 1.0; // How much to blend (1.0 = 100%, 0.5 = 50%), a blend of less than 100% may lead to odd colourings.

// Functions
Scene.my.Pro04ConvertToNumber = (array)=>{
NumberOfTrues := 0;
NumberOfTrues = (array(0) ? (NumberOfTrues + 1) : (NumberOfTrues));
NumberOfTrues = (array(1) ? (NumberOfTrues + 1) : (NumberOfTrues));
NumberOfTrues = (array(2) ? (NumberOfTrues + 1) : (NumberOfTrues));
NumberOfTrues = (array(3) ? (NumberOfTrues + 1) : (NumberOfTrues));
NumberOfTrues = (array(4) ? (NumberOfTrues + 1) : (NumberOfTrues));
NumberOfTrues = (array(5) ? (NumberOfTrues + 1) : (NumberOfTrues));
NumberOfTrues = (array(6) ? (NumberOfTrues + 1) : (NumberOfTrues));
NumberOfTrues }; // Number of trues

Scene.my.Pro04ConvertToBinary = (combinedBinary)=>{
OutputA := [(combinedBinary % 2)];
OutputB := OutputA(0);
Output  := [(OutputA(0) == 1)];
OutputA = OutputA ++ [((combinedBinary % 4) - OutputB)];
OutputB = OutputA(1) + OutputB;
Output  = Output  ++ [(OutputA(1) == 2)];
OutputA = OutputA ++ [((combinedBinary % 8) - OutputB)];
OutputB = OutputA(2) + OutputB;
Output  = Output  ++ [(OutputA(2) == 4)];
OutputA = OutputA ++ [((combinedBinary % 16) - OutputB)];
OutputB = OutputA(3) + OutputB;
Output  = Output  ++ [(OutputA(3) == 8)];
OutputA = OutputA ++ [((combinedBinary % 32) - OutputB)];
OutputB = OutputA(4) + OutputB;
Output  = Output  ++ [(OutputA(4) == 16)];
OutputA = OutputA ++ [((combinedBinary % 64) - OutputB)];
OutputB = OutputA(5) + OutputB;
Output  = Output  ++ [(OutputA(5) == 32)];
OutputA = OutputA ++ [((combinedBinary % 128) - OutputB)];
Output  = Output  ++ [(OutputA(6) == 64)];
Output;
}; // Convert binaries to T/F array

Scene.my.Pro04CollideSetColour = (collideSet)=>{
Binary := Scene.my.Pro04ConvertToBinary(collideSet);
NumberOfCollides := Scene.my.Pro04ConvertToNumber(Binary);
Colour := [0.0,0.0,0.0];
NumberOfCollides == 0 ? {Colour = [0.0,0.0,0.0]} : {
(Binary(0) ? {Colour = ((eval("Scene.my.Pro04" + Scene.my.Pro04CollideA)) / (NumberOfCollides * Scene.my.Pro04BlendAmount))} : {});
(Binary(1) ? {Colour = (((eval("Scene.my.Pro04" + Scene.my.Pro04CollideB)) / (NumberOfCollides * Scene.my.Pro04BlendAmount)) + Colour)} : {});
(Binary(2) ? {Colour = (((eval("Scene.my.Pro04" + Scene.my.Pro04CollideC)) / (NumberOfCollides * Scene.my.Pro04BlendAmount)) + Colour)} : {});
(Binary(3) ? {Colour = (((eval("Scene.my.Pro04" + Scene.my.Pro04CollideD)) / (NumberOfCollides * Scene.my.Pro04BlendAmount)) + Colour)} : {});
(Binary(4) ? {Colour = (((eval("Scene.my.Pro04" + Scene.my.Pro04CollideE)) / (NumberOfCollides * Scene.my.Pro04BlendAmount)) + Colour)} : {});
(Binary(5) ? {Colour = (((eval("Scene.my.Pro04" + Scene.my.Pro04CollideF)) / (NumberOfCollides * Scene.my.Pro04BlendAmount)) + Colour)} : {});
(Binary(6) ? {Colour = (((eval("Scene.my.Pro04" + Scene.my.Pro04CollideG)) / (NumberOfCollides * Scene.my.Pro04BlendAmount)) + Colour)} : {});
};
Colour = (NumberOfCollides == 0 ? (Colour ++ [0.1]) : (Colour ++ [1.0]));
Colour;};


It works, but, I think it could be implemented better if it were by Emil :) (because you can link it quicker).
Mechanisms: 18 Mechanisms.
Thyme: Tutorial - Variables/Commands List.
Thymechanic
gradyfitz
 
Posts: 174
Joined: Tue Sep 01, 2009 8:33 am
Location: Victoria, Australia


Return to Suggestions

Who is online

Users browsing this forum: No registered users and 1 guest