fixed selection sort
This commit is contained in:
@@ -57,7 +57,7 @@ node_grp.links.new(arrayCounter.outputs[0], joinStrings.inputs[1])
|
|||||||
node_grp.links.new(arrayString.outputs[0], joinStrings.inputs[1])
|
node_grp.links.new(arrayString.outputs[0], joinStrings.inputs[1])
|
||||||
|
|
||||||
#fill arrays with numbers between 1 & count
|
#fill arrays with numbers between 1 & count
|
||||||
ran = list(range(1,count+1))
|
ran = list(range(0,count))
|
||||||
|
|
||||||
#randomize array order
|
#randomize array order
|
||||||
random.shuffle(ran)
|
random.shuffle(ran)
|
||||||
@@ -85,22 +85,36 @@ i = 0
|
|||||||
for ob in bpy.data.objects:
|
for ob in bpy.data.objects:
|
||||||
if ob.type == 'MESH' and ob.name != "Counter":
|
if ob.type == 'MESH' and ob.name != "Counter":
|
||||||
origin_to_bottom(ob)
|
origin_to_bottom(ob)
|
||||||
ob.scale.z = ran[i]
|
ob.scale.z = ran[i]+1
|
||||||
cubes.append(ob)
|
cubes.append(ob)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
#sort array based on location.x
|
#sort array based on location.x
|
||||||
cubes.sort(key = lambda obj: obj.location.x)
|
cubes.sort(key = lambda obj: obj.location.x)
|
||||||
|
iframe = 0
|
||||||
|
|
||||||
#Selection Sort ALgorithm
|
#Selection Sort ALgorithm
|
||||||
def selection_sort(cubes):
|
def selection_sort(cubes):
|
||||||
|
|
||||||
|
global iframe
|
||||||
|
|
||||||
for i in range(0, len(cubes)):
|
for i in range(0, len(cubes)):
|
||||||
min_idx = i
|
min_idx = i
|
||||||
|
|
||||||
|
for cube in cubes:
|
||||||
|
cube.keyframe_insert(data_path="location", frame= iframe)
|
||||||
|
|
||||||
for j in range(i , len(cubes)):
|
for j in range(i , len(cubes)):
|
||||||
if cubes[min_idx].scale.z > cubes[j].scale.z:
|
if cubes[min_idx].scale.z > cubes[j].scale.z:
|
||||||
min_idx = j
|
min_idx = j
|
||||||
|
|
||||||
cubes[i].location.x = min_idx
|
cubes[i].location.x = min_idx
|
||||||
cubes[min_idx].location.x = i
|
cubes[min_idx].location.x = i
|
||||||
|
|
||||||
|
cubes[i].keyframe_insert(data_path="location", frame= iframe)
|
||||||
|
cubes[min_idx].keyframe_insert(data_path="location", frame= iframe)
|
||||||
|
iframe +=1
|
||||||
|
|
||||||
cubes[i], cubes[min_idx] = cubes[min_idx], cubes[i]
|
cubes[i], cubes[min_idx] = cubes[min_idx], cubes[i]
|
||||||
|
|
||||||
#Call Function
|
#Call Function
|
||||||
|
|||||||
Reference in New Issue
Block a user