Tech Schtuff
Sort function
BubbleSort works by repeatedly stepping through the list to be sorted, comparing two items at a time and swapping them if they are in the wrong order. The algorithm sort from smaller to bigger element.
maya version(mel)
global proc float[] bubbleSort(float $numbers[])
{
int $i, $j;
float $temp;
$array_size = size($numbers);
for ($i = ($array_size - 1); $i >= 0; $i--)
{
for ($j = 1; $j <= $i; $j++)
{
if ($numbers[$j-1] > $numbers[$j])
{
$temp = $numbers[$j-1];
$numbers[$j-1] = $numbers[$j];
$numbers[$j] = $temp;
}
}
}
return $numbers;
}
float $nums[] = {10,4,2};
bubbleSort($nums);
// Result:2 4 10//
python version(which you dont really need since you can use array.sort())
def bubblesort(list):
max = len(list)-1
for i in range(max,0,-1):
for k in range(i):
if list[k] > list[k+1]:
temp = list[k]
list[k] = list[k+1]
list[k+1] = temp
return list
num = [12,9,3,5,10,1]
string = ['t','test','te']
heres the result for string and number
['t', 'te', 'test']
[1, 3, 5, 9, 10, 12]
Quicksort:
A sorting technique that sequences a list by continuously dividing the list into two parts and moving the lower items to one side and the higher items to the other. It starts by picking one item in the entire list to serve as a pivot point. The pivot could be the first item or a randomly chosen one. All items that compare lower than the pivot are moved to the left of the pivot; all equal or higher items are moved to the right. It then picks a pivot for the left side and moves those items to left and right of the pivot and continues the pivot picking and dividing until there is only one item left in the group. It then proceeds to the right side and performs the same operation again.
Quicksort is a lot faster and should be used instead of bubblesort
def quicksort(lst):
if len(lst) < = 1:
return lst
pivot = lst.pop(0)
greater = quicksort([i for i in lst if i >= pivot])
lesser = quicksort([i for i in lst if i < pivot])
return lesser + [pivot] + greater
Recursive ?
In simple terms, the recursive definition is one that grows an awareness and clarity upon itself toward a conclusive end, with each recurrence contributing something new toward the end definition. The recurring theme or influence will strengthen the definition as it is repeatedly applied to itself, and will eventually arrive at a point where no more recurrence is required. Exemple of recursive script:
import os
def findDirectories(root):
subdir = []
for f in os.listdir(root):
if os.path.isdir(os.path.join(root,f)):
subdir.append(os.path.join(root,f))
for sub in subdir:
subdir.extend(findDirectories(sub))
return subdir
You can achieve the same result with python without a recursive script.
I`m using os.walk which replace the looping function.
import os
def walkToDir(root):
directories = []
for dirp,dirn,file in os.walk(root):
if os.path.isdir(dirp):
directories.append(dirp)
return directories
the cartoon Animation Filter
Here`s the ”Cartoon Animation Filter”, a simple filter that takes
an arbitrary input motion signal and modulates it in such a way that
the output motion is more ”alive” or ”animated”. The filter adds a
smoothed, inverted, and (sometimes) time shifted version.
You can see on these 2 images a fcurve before and after the animation filtered applied.
[nggallery id=1]
you can read more aobut the animation filter :
http://www.cs.washington.edu/homes/juewang/juew/JueAniFilter.pdf
- No comments yet.
Recent Comments