From 2e52ee90db274e239459f323a1da13fca865bda3 Mon Sep 17 00:00:00 2001 From: ForeignGods Date: Thu, 5 May 2022 22:18:26 +0200 Subject: [PATCH] Added unique location and scale for cubes --- BubbleSort.py | 26 ++++++++++++++++++-------- InsertionSort.py | 23 ++++++++++++++++------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/BubbleSort.py b/BubbleSort.py index 86538ee..2178d63 100644 --- a/BubbleSort.py +++ b/BubbleSort.py @@ -1,17 +1,27 @@ import bpy -from random import randint -count = 100 +import random + +count = 50 cubes=[] +locationList=[] +scaleList=[] +i = 1 +while i < count+1: + locationList.append(i) + scaleList.append(i) + i += 1 +random.shuffle(locationList) +random.shuffle(scaleList) i = 0 while i < count: - x = randint(1,10) - cube = bpy.ops.mesh.primitive_cube_add(location=(x, 0, 0), scale=(0.25, 0.25, 0.25)) - i += 1 + cube = bpy.ops.mesh.primitive_cube_add(location=(locationList[i], 0, 0), scale=(0.25, 0.25, 0.25)) + i+=1 +i = 0 for ob in bpy.data.objects: - z = randint(1,10) - if ob.type == 'MESH': - ob.scale.z = z + if ob.type == 'MESH': + ob.scale.z = scaleList[i] cubes.append(ob) + i += 1 n = len(cubes) for i in range(n): already_sorted = True diff --git a/InsertionSort.py b/InsertionSort.py index 9a15c61..2b0ad19 100644 --- a/InsertionSort.py +++ b/InsertionSort.py @@ -1,17 +1,26 @@ import bpy -from random import randint +import random count = 50 cubes=[] +locationList=[] +scaleList=[] +i = 1 +while i < count+1: + locationList.append(i) + scaleList.append(i) + i += 1 +random.shuffle(locationList) +random.shuffle(scaleList) i = 0 while i < count: - x = randint(1,10) - cube = bpy.ops.mesh.primitive_cube_add(location=(x, 0, 0), scale=(0.25, 0.25, 0.25)) - i += 1 + cube = bpy.ops.mesh.primitive_cube_add(location=(locationList[i], 0, 0), scale=(0.25, 0.25, 0.25)) + i+=1 +i = 0 for ob in bpy.data.objects: - z = randint(1,10) - if ob.type == 'MESH': - ob.scale.z = z + if ob.type == 'MESH': + ob.scale.z = scaleList[i] cubes.append(ob) + i += 1 n = len(cubes) for i in range(1, n): key_item = cubes[i]