Accessing Color Elements
4 posts • Page 1 of 1
Accessing Color Elements
Is it possible to access and modify the elements of an object's color array individually, without modifying the others?
-

Blazemann - Posts: 151
- Joined: Tue Sep 01, 2009 1:19 am
Re: Accessing Color Elements
- Code: Select all
color = [color(0),color(1),newval,color(3)]
Unfortunately Thyme has really sucky arrays.
Somebody also wrote an array-modification function that looks like
- Code: Select all
scene.my.arrayChange(color,2,newval)
- daniels220
- Posts: 95
- Joined: Mon Aug 31, 2009 11:30 pm
Re: Accessing Color Elements
Thanks, I never needed to modify arrays in thyme after they were built. assumed it e.this.color(3)=1.
-

Blazemann - Posts: 151
- Joined: Tue Sep 01, 2009 1:19 am
Re: Accessing Color Elements
There's three ways to do it. They are Grady's, Kilinich's, and KarateBrot's.
These are my functions, using these three methods. All use Grady's method of counting how many values are in an array.
Hmm, I suppose one could infix this.
Thus, scene.my.color(2)=0.5 really would do the trick.
These are my functions, using these three methods. All use Grady's method of counting how many values are in an array.
- Code: Select all
scene.my.arrayLength = (array)=>{
a := array ++ ["enD"];
length := 0;
sizeKnown := false;
for(65, (i)=>{
{!sizeKnown} ? {
length = length + 1;
{a(i) == "enD"} ? {sizeKnown = true} : {}
} : {}
});
length
}; //All credit to Grady, I think, it was KarateBrot who showed this to me,
//and I later saw him repeat it and give credit to Grady.
//NOTE: This will only work with arrays with 64 values or less.
//The built-in FOR loop is strange that way.
/*
Hmm, I can't figure out how to replicate Grady's method from memory without it being overly inefficient.
KarateBrot's is similar, but simpler and more efficient anyway.
It followed this form:
scene.my.array = scene.my.array([0, 1, 2, 3, 4, 5, 6]) ++ [NewVal] ++ scene.my.array([8, 9, 10, 11, 12, 13, 14])
*/
scene.my.arrayChangeKarateBrot = (array, pos, val)=>{
a := [];
for(scene.my.arrayLength(array), (i)=>{
{i - 1 == pos} ? {a = a ++ val} : {a = a ++ a(i - 1)}
});
a
}; //Very simple and efficient. Will accept any value, even another array, to edit into the array.
//There's really no good way to turn this into a bit of more efficient, specialized syntax
//as there are for Grady's and Kilinich's methods.
//Other than editing the function itself, so you must include the length as an argument.
//Hmm, I could build a function to delete or insert a value
//instead of just substituting via this method...
scene.my.arrayChangeKilinich = (array, pos, val)=>{
a := [];
length := scene.my.arrayLength(array);
for(length, (i)=>{
a = a ++ {i - 1 == pos} ? {[0]} : {[1]}
});
out := array * a;
a = [];
for(length, (i)=>{
a = a ++ {i - 1 == pos} ? {[val]} : {[0]}
});
out + a
}//As this is, as a function, this is fairly inefficient.
//The following syntax in much more so and allows you to change multiple values at once:
//scene.my.color = scene.my.color * [1, 1, 0, 1] + [0, 0, newVal, 0]
//Or, to change multiple values,
//scene.my.array = scene.my.array * [1, 1, 0, 1, 0, 1, 1, 1, 0] + [0, 0, 5, 0, 8, 0, 0, 0, 3]
//Note that either form of Kilinich's method requires all values to be numbers,
//those already in the array and the new one.
Hmm, I suppose one could infix this.
- Code: Select all
infix 3 left: _(_)=_ => scene.my.arrayChangeKarateBrot
Thus, scene.my.color(2)=0.5 really would do the trick.
Matthias Wandel is epic, in my humble opinion.
I love my brain...
ARE YA HAPPY NOW?????
Thymechanic/Phundamentalist
Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.
ARE YA HAPPY NOW?????
Thymechanic/Phundamentalist
Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
-

Someone Else - Posts: 1147
- Joined: Sun Nov 21, 2010 10:53 pm
- Location: The Milky Way Galaxy
4 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 8 guests



