added sunset color gradient
This commit is contained in:
@@ -3,6 +3,7 @@ import random
|
|||||||
import math
|
import math
|
||||||
from array import *
|
from array import *
|
||||||
from math import pi
|
from math import pi
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# Insertion Sort Algorithm
|
# Insertion Sort Algorithm
|
||||||
@@ -26,7 +27,19 @@ def insertion_sort(arr, count):
|
|||||||
mat1 = arr[j].active_material.diffuse_color
|
mat1 = arr[j].active_material.diffuse_color
|
||||||
mat2 = key_item.active_material.diffuse_color
|
mat2 = key_item.active_material.diffuse_color
|
||||||
|
|
||||||
while j >= 0 and mat1[0] > mat2[0]:
|
#get R value of both materials
|
||||||
|
r1 = mat1[0]
|
||||||
|
r2 = mat2[0]
|
||||||
|
|
||||||
|
#get G value of both materials
|
||||||
|
g1 = mat1[1]
|
||||||
|
g2 = mat2[1]
|
||||||
|
|
||||||
|
# R + G = value for comparison
|
||||||
|
rg1 = r1 + g1
|
||||||
|
rg2 = r2 + g2
|
||||||
|
|
||||||
|
while j >= 0 and rg1 > rg2:
|
||||||
|
|
||||||
#sets position of item in array
|
#sets position of item in array
|
||||||
arr[j + 1] = arr[j]
|
arr[j + 1] = arr[j]
|
||||||
@@ -41,6 +54,18 @@ def insertion_sort(arr, count):
|
|||||||
mat1 = arr[j].active_material.diffuse_color
|
mat1 = arr[j].active_material.diffuse_color
|
||||||
mat2 = key_item.active_material.diffuse_color
|
mat2 = key_item.active_material.diffuse_color
|
||||||
|
|
||||||
|
#get R value of both materials
|
||||||
|
r1 = mat1[0]
|
||||||
|
r2 = mat2[0]
|
||||||
|
|
||||||
|
#get G value of both materials
|
||||||
|
g1 = mat1[1]
|
||||||
|
g2 = mat2[1]
|
||||||
|
|
||||||
|
# R + G = value for comparison
|
||||||
|
rg1 = r1 + g1
|
||||||
|
rg2 = r2 + g2
|
||||||
|
|
||||||
#adding keyframes to all planes whenever one position/location is shifted
|
#adding keyframes to all planes whenever one position/location is shifted
|
||||||
for plane in arr:
|
for plane in arr:
|
||||||
plane.keyframe_insert(data_path="location", frame=iframe)
|
plane.keyframe_insert(data_path="location", frame=iframe)
|
||||||
@@ -78,10 +103,44 @@ def setup_array(count):
|
|||||||
#initialize 2d array
|
#initialize 2d array
|
||||||
Matrix = [[0 for x in range(count)] for y in range(count)]
|
Matrix = [[0 for x in range(count)] for y in range(count)]
|
||||||
|
|
||||||
#initialize object and material array
|
#initialize plane array
|
||||||
planes = [0 for i in range(count*count)]
|
planes = [0 for i in range(count*count)]
|
||||||
|
|
||||||
|
#initialize material array
|
||||||
materials = [0 for i in range(count)]
|
materials = [0 for i in range(count)]
|
||||||
|
|
||||||
|
#create arrays for each color value (RGB) to generate the sunset gradient
|
||||||
|
|
||||||
|
#first half 0 --> 255, second half 255 --> 255
|
||||||
|
colors_r = [0 for i in range(count)]
|
||||||
|
colors_r1 = np.linspace(0, 255, count//2)
|
||||||
|
colors_r2 = np.linspace(255, 255, count//2)
|
||||||
|
for i in range(count):
|
||||||
|
if(i < count//2):
|
||||||
|
colors_r[i]=colors_r1[i]
|
||||||
|
else:
|
||||||
|
colors_r[i]=colors_r2[i-count//2]
|
||||||
|
|
||||||
|
#first half 0 --> 0, second half 0 --> 200
|
||||||
|
colors_g = [0 for i in range(count)]
|
||||||
|
colors_g1 = np.linspace(0, 0, count//2)
|
||||||
|
colors_g2 = np.linspace(0, 200, count//2)
|
||||||
|
for i in range(count):
|
||||||
|
if(i < count//2):
|
||||||
|
colors_g[i]=colors_g1[i]
|
||||||
|
else:
|
||||||
|
colors_g[i]=colors_g2[i-count//2]
|
||||||
|
|
||||||
|
#first half 200 --> 0, secondhalf 0 --> 100
|
||||||
|
colors_b = [0 for i in range(count)]
|
||||||
|
colors_b1 = np.linspace(200, 0, count//2)
|
||||||
|
colors_b2 = np.linspace(0, 100, count//2)
|
||||||
|
for i in range(count):
|
||||||
|
if(i < count//2):
|
||||||
|
colors_b[i]=colors_b1[i]
|
||||||
|
else:
|
||||||
|
colors_b[i]=colors_b2[i-count//2]
|
||||||
|
|
||||||
#delete every existing object
|
#delete every existing object
|
||||||
for ob in bpy.data.objects:
|
for ob in bpy.data.objects:
|
||||||
bpy.data.objects.remove(ob)
|
bpy.data.objects.remove(ob)
|
||||||
@@ -89,25 +148,31 @@ def setup_array(count):
|
|||||||
#delete all existing materials
|
#delete all existing materials
|
||||||
for material in bpy.data.materials:
|
for material in bpy.data.materials:
|
||||||
bpy.data.materials.remove(material, do_unlink=True)
|
bpy.data.materials.remove(material, do_unlink=True)
|
||||||
|
|
||||||
|
#creating count * count planes with location.x = j * 2 and location.z = i * 2
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
for j in range(count):
|
for j in range(count):
|
||||||
bpy.ops.mesh.primitive_plane_add(location=(j*2, 0, i*2), rotation=(pi / 2, 0, 0), scale=(0.1, 0.1, 0.1))
|
bpy.ops.mesh.primitive_plane_add(location=(j*2, 0, i*2), rotation=(pi / 2, 0, 0), scale=(0.1, 0.1, 0.1))
|
||||||
|
|
||||||
|
#adding all planes to an array
|
||||||
i=0
|
i=0
|
||||||
for ob in bpy.data.objects:
|
for ob in bpy.data.objects:
|
||||||
planes[i]= ob
|
planes[i]= ob
|
||||||
i+=1
|
i+=1
|
||||||
|
|
||||||
#sorts list of all objects based primary on their location.z and secondary on their location.x
|
#sorts list of all objects based primary on their location.x and secondary on their location.z
|
||||||
planes.sort(key = lambda obj: obj.location.z + obj.location.x/(count*count))
|
planes.sort(key = lambda obj: obj.location.z + obj.location.x/(count*count))
|
||||||
|
|
||||||
|
#adding materials to array and set colorgradient
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
material = bpy.data.materials.new(name="")
|
for j in range(count):
|
||||||
material.diffuse_color = (index[i]/3, 255, 255, 255)
|
material = bpy.data.materials.new(name="")
|
||||||
materials[i] = material
|
material.diffuse_color = (colors_r[i], colors_g[i], colors_b[i], 255)
|
||||||
|
materials[i] = material
|
||||||
|
|
||||||
|
#add materials to planes and planes to 2d array
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
|
#randomize distribution of colors for every row
|
||||||
random.shuffle(materials)
|
random.shuffle(materials)
|
||||||
for j in range(count):
|
for j in range(count):
|
||||||
planes[j+i*count].data.materials.append(materials[j]) #add the material to the object
|
planes[j+i*count].data.materials.append(materials[j]) #add the material to the object
|
||||||
@@ -119,7 +184,7 @@ def setup_array(count):
|
|||||||
# Call Functions
|
# Call Functions
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
Matrix, count = setup_array(31)
|
Matrix, count = setup_array(30)#only even numbers are valid
|
||||||
|
|
||||||
#insertion_sort every array
|
#insertion_sort every array
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import random
|
|||||||
import math
|
import math
|
||||||
from array import *
|
from array import *
|
||||||
from math import pi
|
from math import pi
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# Selection Sort Algorithm
|
# Selection Sort Algorithm
|
||||||
@@ -24,7 +25,19 @@ def selection_sort(arr, count):
|
|||||||
mat1 = arr[min_idx].active_material.diffuse_color
|
mat1 = arr[min_idx].active_material.diffuse_color
|
||||||
mat2 = arr[j].active_material.diffuse_color
|
mat2 = arr[j].active_material.diffuse_color
|
||||||
|
|
||||||
if mat1[0] > mat2[0]:
|
#get R value of both materials
|
||||||
|
r1 = mat1[0]
|
||||||
|
r2 = mat2[0]
|
||||||
|
|
||||||
|
#get G value of both materials
|
||||||
|
g1 = mat1[1]
|
||||||
|
g2 = mat2[1]
|
||||||
|
|
||||||
|
# R + G = value for comparison
|
||||||
|
rg1 = r1 + g1
|
||||||
|
rg2 = r2 + g2
|
||||||
|
|
||||||
|
if rg1 > rg2:
|
||||||
min_idx = j
|
min_idx = j
|
||||||
|
|
||||||
arr[i].location.x = min_idx * 2
|
arr[i].location.x = min_idx * 2
|
||||||
@@ -48,10 +61,44 @@ def setup_array(count):
|
|||||||
#initialize 2d array
|
#initialize 2d array
|
||||||
Matrix = [[0 for x in range(count)] for y in range(count)]
|
Matrix = [[0 for x in range(count)] for y in range(count)]
|
||||||
|
|
||||||
#initialize object and material array
|
#initialize plane array
|
||||||
planes = [0 for i in range(count*count)]
|
planes = [0 for i in range(count*count)]
|
||||||
|
|
||||||
|
#initialize material array
|
||||||
materials = [0 for i in range(count)]
|
materials = [0 for i in range(count)]
|
||||||
|
|
||||||
|
#create arrays for each color value (RGB) to generate the sunset gradient
|
||||||
|
|
||||||
|
#first half 0 --> 255, second half 255 --> 255
|
||||||
|
colors_r = [0 for i in range(count)]
|
||||||
|
colors_r1 = np.linspace(0, 255, count//2)
|
||||||
|
colors_r2 = np.linspace(255, 255, count//2)
|
||||||
|
for i in range(count):
|
||||||
|
if(i < count//2):
|
||||||
|
colors_r[i]=colors_r1[i]
|
||||||
|
else:
|
||||||
|
colors_r[i]=colors_r2[i-count//2]
|
||||||
|
|
||||||
|
#first half 0 --> 0, second half 0 --> 200
|
||||||
|
colors_g = [0 for i in range(count)]
|
||||||
|
colors_g1 = np.linspace(0, 0, count//2)
|
||||||
|
colors_g2 = np.linspace(0, 200, count//2)
|
||||||
|
for i in range(count):
|
||||||
|
if(i < count//2):
|
||||||
|
colors_g[i]=colors_g1[i]
|
||||||
|
else:
|
||||||
|
colors_g[i]=colors_g2[i-count//2]
|
||||||
|
|
||||||
|
#first half 200 --> 0, secondhalf 0 --> 100
|
||||||
|
colors_b = [0 for i in range(count)]
|
||||||
|
colors_b1 = np.linspace(200, 0, count//2)
|
||||||
|
colors_b2 = np.linspace(0, 100, count//2)
|
||||||
|
for i in range(count):
|
||||||
|
if(i < count//2):
|
||||||
|
colors_b[i]=colors_b1[i]
|
||||||
|
else:
|
||||||
|
colors_b[i]=colors_b2[i-count//2]
|
||||||
|
|
||||||
#delete every existing object
|
#delete every existing object
|
||||||
for ob in bpy.data.objects:
|
for ob in bpy.data.objects:
|
||||||
bpy.data.objects.remove(ob)
|
bpy.data.objects.remove(ob)
|
||||||
@@ -59,25 +106,31 @@ def setup_array(count):
|
|||||||
#delete all existing materials
|
#delete all existing materials
|
||||||
for material in bpy.data.materials:
|
for material in bpy.data.materials:
|
||||||
bpy.data.materials.remove(material, do_unlink=True)
|
bpy.data.materials.remove(material, do_unlink=True)
|
||||||
|
|
||||||
|
#creating count * count planes with location.x = j * 2 and location.z = i * 2
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
for j in range(count):
|
for j in range(count):
|
||||||
bpy.ops.mesh.primitive_plane_add(location=(j*2, 0, i*2), rotation=(pi / 2, 0, 0), scale=(0.1, 0.1, 0.1))
|
bpy.ops.mesh.primitive_plane_add(location=(j*2, 0, i*2), rotation=(pi / 2, 0, 0), scale=(0.1, 0.1, 0.1))
|
||||||
|
|
||||||
|
#adding all planes to an array
|
||||||
i=0
|
i=0
|
||||||
for ob in bpy.data.objects:
|
for ob in bpy.data.objects:
|
||||||
planes[i]= ob
|
planes[i]= ob
|
||||||
i+=1
|
i+=1
|
||||||
|
|
||||||
#sorts list of all objects based primary on their location.z and secondary on their location.x
|
#sorts list of all objects based primary on their location.x and secondary on their location.z
|
||||||
planes.sort(key = lambda obj: obj.location.z + obj.location.x/(count*count))
|
planes.sort(key = lambda obj: obj.location.z + obj.location.x/(count*count))
|
||||||
|
|
||||||
|
#adding materials to array and set colorgradient
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
material = bpy.data.materials.new(name="")
|
for j in range(count):
|
||||||
material.diffuse_color = (index[i]/3, 255, 255, 255)
|
material = bpy.data.materials.new(name="")
|
||||||
materials[i] = material
|
material.diffuse_color = (colors_r[i], colors_g[i], colors_b[i], 255)
|
||||||
|
materials[i] = material
|
||||||
|
|
||||||
|
#add materials to planes and planes to 2d array
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
|
#randomize distribution of colors for every row
|
||||||
random.shuffle(materials)
|
random.shuffle(materials)
|
||||||
for j in range(count):
|
for j in range(count):
|
||||||
planes[j+i*count].data.materials.append(materials[j]) #add the material to the object
|
planes[j+i*count].data.materials.append(materials[j]) #add the material to the object
|
||||||
@@ -89,8 +142,9 @@ def setup_array(count):
|
|||||||
# Call Functions
|
# Call Functions
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
Matrix, count = setup_array(31)
|
Matrix, count = setup_array(24)
|
||||||
|
|
||||||
#selection_sort every array
|
#selection_sort every array
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
selection_sort(Matrix[i], count)
|
selection_sort(Matrix[i], count)
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import random
|
|||||||
import math
|
import math
|
||||||
from array import *
|
from array import *
|
||||||
from math import pi
|
from math import pi
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# Shell Sort Algorithm
|
# Shell Sort Algorithm
|
||||||
@@ -34,7 +35,19 @@ def shell_sort(arr, count):
|
|||||||
mat1 = arr[i+gap].active_material.diffuse_color
|
mat1 = arr[i+gap].active_material.diffuse_color
|
||||||
mat2 = arr[i].active_material.diffuse_color
|
mat2 = arr[i].active_material.diffuse_color
|
||||||
|
|
||||||
if mat1[0] > mat2[0]:
|
#get R value of both materials
|
||||||
|
r1 = mat1[0]
|
||||||
|
r2 = mat2[0]
|
||||||
|
|
||||||
|
#get G value of both materials
|
||||||
|
g1 = mat1[1]
|
||||||
|
g2 = mat2[1]
|
||||||
|
|
||||||
|
# R + G = value for comparison
|
||||||
|
rg1 = r1 + g1
|
||||||
|
rg2 = r2 + g2
|
||||||
|
|
||||||
|
if rg1 > rg2:
|
||||||
break
|
break
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -64,10 +77,44 @@ def setup_array(count):
|
|||||||
#initialize 2d array
|
#initialize 2d array
|
||||||
Matrix = [[0 for x in range(count)] for y in range(count)]
|
Matrix = [[0 for x in range(count)] for y in range(count)]
|
||||||
|
|
||||||
#initialize object and material array
|
#initialize plane array
|
||||||
planes = [0 for i in range(count*count)]
|
planes = [0 for i in range(count*count)]
|
||||||
|
|
||||||
|
#initialize material array
|
||||||
materials = [0 for i in range(count)]
|
materials = [0 for i in range(count)]
|
||||||
|
|
||||||
|
#create arrays for each color value (RGB) to generate the sunset gradient
|
||||||
|
|
||||||
|
#first half 0 --> 255, second half 255 --> 255
|
||||||
|
colors_r = [0 for i in range(count)]
|
||||||
|
colors_r1 = np.linspace(0, 255, count//2)
|
||||||
|
colors_r2 = np.linspace(255, 255, count//2)
|
||||||
|
for i in range(count):
|
||||||
|
if(i < count//2):
|
||||||
|
colors_r[i]=colors_r1[i]
|
||||||
|
else:
|
||||||
|
colors_r[i]=colors_r2[i-count//2]
|
||||||
|
|
||||||
|
#first half 0 --> 0, second half 0 --> 200
|
||||||
|
colors_g = [0 for i in range(count)]
|
||||||
|
colors_g1 = np.linspace(0, 0, count//2)
|
||||||
|
colors_g2 = np.linspace(0, 200, count//2)
|
||||||
|
for i in range(count):
|
||||||
|
if(i < count//2):
|
||||||
|
colors_g[i]=colors_g1[i]
|
||||||
|
else:
|
||||||
|
colors_g[i]=colors_g2[i-count//2]
|
||||||
|
|
||||||
|
#first half 200 --> 0, secondhalf 0 --> 100
|
||||||
|
colors_b = [0 for i in range(count)]
|
||||||
|
colors_b1 = np.linspace(200, 0, count//2)
|
||||||
|
colors_b2 = np.linspace(0, 100, count//2)
|
||||||
|
for i in range(count):
|
||||||
|
if(i < count//2):
|
||||||
|
colors_b[i]=colors_b1[i]
|
||||||
|
else:
|
||||||
|
colors_b[i]=colors_b2[i-count//2]
|
||||||
|
|
||||||
#delete every existing object
|
#delete every existing object
|
||||||
for ob in bpy.data.objects:
|
for ob in bpy.data.objects:
|
||||||
bpy.data.objects.remove(ob)
|
bpy.data.objects.remove(ob)
|
||||||
@@ -75,25 +122,31 @@ def setup_array(count):
|
|||||||
#delete all existing materials
|
#delete all existing materials
|
||||||
for material in bpy.data.materials:
|
for material in bpy.data.materials:
|
||||||
bpy.data.materials.remove(material, do_unlink=True)
|
bpy.data.materials.remove(material, do_unlink=True)
|
||||||
|
|
||||||
|
#creating count * count planes with location.x = j * 2 and location.z = i * 2
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
for j in range(count):
|
for j in range(count):
|
||||||
bpy.ops.mesh.primitive_plane_add(location=(j*2, 0, i*2), rotation=(pi / 2, 0, 0), scale=(0.1, 0.1, 0.1))
|
bpy.ops.mesh.primitive_plane_add(location=(j*2, 0, i*2), rotation=(pi / 2, 0, 0), scale=(0.1, 0.1, 0.1))
|
||||||
|
|
||||||
|
#adding all planes to an array
|
||||||
i=0
|
i=0
|
||||||
for ob in bpy.data.objects:
|
for ob in bpy.data.objects:
|
||||||
planes[i]= ob
|
planes[i]= ob
|
||||||
i+=1
|
i+=1
|
||||||
|
|
||||||
#sorts list of all objects based primary on their location.z and secondary on their location.x
|
#sorts list of all objects based primary on their location.x and secondary on their location.z
|
||||||
planes.sort(key = lambda obj: obj.location.z + obj.location.x/(count*count))
|
planes.sort(key = lambda obj: obj.location.z + obj.location.x/(count*count))
|
||||||
|
|
||||||
|
#adding materials to array and set colorgradient
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
material = bpy.data.materials.new(name="")
|
for j in range(count):
|
||||||
material.diffuse_color = (index[i]/3, 255, 255, 255)
|
material = bpy.data.materials.new(name="")
|
||||||
materials[i] = material
|
material.diffuse_color = (colors_r[i], colors_g[i], colors_b[i], 255)
|
||||||
|
materials[i] = material
|
||||||
|
|
||||||
|
#add materials to planes and planes to 2d array
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
|
#randomize distribution of colors for every row
|
||||||
random.shuffle(materials)
|
random.shuffle(materials)
|
||||||
for j in range(count):
|
for j in range(count):
|
||||||
planes[j+i*count].data.materials.append(materials[j]) #add the material to the object
|
planes[j+i*count].data.materials.append(materials[j]) #add the material to the object
|
||||||
@@ -105,8 +158,9 @@ def setup_array(count):
|
|||||||
# Call Functions
|
# Call Functions
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
Matrix, count = setup_array(32)
|
Matrix, count = setup_array(24)
|
||||||
|
|
||||||
#shell_sort every array
|
#shell_sort every array
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
shell_sort(Matrix[i], count)
|
shell_sort(Matrix[i], count)
|
||||||
|
|
||||||
Reference in New Issue
Block a user