added sunset color gradient
This commit is contained in:
parent
149ca26c67
commit
1f017692af
@ -85,7 +85,7 @@ def setup_array(count):
|
||||
#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)
|
||||
colors_g2 = np.linspace(1, 200, count//2)
|
||||
for i in range(count):
|
||||
if(i < count//2):
|
||||
colors_g[i]=colors_g1[i]
|
||||
|
@ -92,7 +92,7 @@ def insertion_sort(arr, count):
|
||||
originFrame = iframe
|
||||
|
||||
############################################################
|
||||
# Setup Random Cubes + Array to be sorted
|
||||
# Setup Random Colors + Array to be sorted
|
||||
############################################################
|
||||
|
||||
def setup_array(count):
|
||||
@ -124,7 +124,7 @@ def setup_array(count):
|
||||
#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)
|
||||
colors_g2 = np.linspace(1, 200, count//2)
|
||||
for i in range(count):
|
||||
if(i < count//2):
|
||||
colors_g[i]=colors_g1[i]
|
||||
|
@ -125,6 +125,7 @@ def merge_sort(seed, iframe,arr, l, r):
|
||||
############################################################
|
||||
# Setup Random Colors + Array to be sorted
|
||||
############################################################
|
||||
|
||||
def setup_array(count):
|
||||
|
||||
#fill array with numbers between 0 & count - 1
|
||||
@ -154,7 +155,7 @@ def setup_array(count):
|
||||
#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)
|
||||
colors_g2 = np.linspace(1, 200, count//2)
|
||||
for i in range(count):
|
||||
if(i < count//2):
|
||||
colors_g[i]=colors_g1[i]
|
||||
|
@ -3,6 +3,7 @@ import random
|
||||
import math
|
||||
from array import *
|
||||
from math import pi
|
||||
import numpy as np
|
||||
|
||||
############################################################
|
||||
# Quick Sort Algorithm
|
||||
@ -24,18 +25,66 @@ def partition(seed, array, low, high):
|
||||
mat1 = array[i].active_material.diffuse_color
|
||||
mat2 = pivot.active_material.diffuse_color
|
||||
|
||||
while 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 rg1 < rg2:
|
||||
i += 1
|
||||
mat1 = array[i].active_material.diffuse_color
|
||||
mat2 = pivot.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
|
||||
|
||||
mat3 = array[j].active_material.diffuse_color
|
||||
mat4 = pivot.active_material.diffuse_color
|
||||
|
||||
while mat3[0] > mat4[0]:
|
||||
#get R value of both materials
|
||||
r3 = mat3[0]
|
||||
r4 = mat4[0]
|
||||
|
||||
#get G value of both materials
|
||||
g3 = mat3[1]
|
||||
g4 = mat4[1]
|
||||
|
||||
# R + G = value for comparison
|
||||
rg3 = r3 + g3
|
||||
rg4 = r4 + g4
|
||||
|
||||
while rg3 > rg4:
|
||||
j -= 1
|
||||
mat3 = array[j].active_material.diffuse_color
|
||||
mat4 = pivot.active_material.diffuse_color
|
||||
|
||||
#get R value of both materials
|
||||
r3 = mat3[0]
|
||||
r4 = mat4[0]
|
||||
|
||||
#get G value of both materials
|
||||
g3 = mat3[1]
|
||||
g4 = mat4[1]
|
||||
|
||||
# R + G = value for comparison
|
||||
rg3 = r3 + g3
|
||||
rg4 = r4 + g4
|
||||
|
||||
if i >= j:
|
||||
return j
|
||||
@ -74,19 +123,51 @@ def quick_sort(seed, array, low, high):
|
||||
############################################################
|
||||
|
||||
def setup_array(count):
|
||||
|
||||
global Matrix
|
||||
|
||||
|
||||
#fill array with numbers between 0 & count - 1
|
||||
index = list(range(count))
|
||||
|
||||
#initialize 2d array
|
||||
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)]
|
||||
|
||||
#initialize material array
|
||||
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(1, 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
|
||||
for ob in bpy.data.objects:
|
||||
bpy.data.objects.remove(ob)
|
||||
@ -94,25 +175,31 @@ def setup_array(count):
|
||||
#delete all existing materials
|
||||
for material in bpy.data.materials:
|
||||
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 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))
|
||||
|
||||
#adding all planes to an array
|
||||
i=0
|
||||
for ob in bpy.data.objects:
|
||||
planes[i]= ob
|
||||
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))
|
||||
|
||||
#adding materials to array and set colorgradient
|
||||
for i in range(count):
|
||||
material = bpy.data.materials.new(name="")
|
||||
material.diffuse_color = (index[i]/3, 255, 255, 255)
|
||||
materials[i] = material
|
||||
|
||||
for j in range(count):
|
||||
material = bpy.data.materials.new(name="")
|
||||
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):
|
||||
#randomize distribution of colors for every row
|
||||
random.shuffle(materials)
|
||||
for j in range(count):
|
||||
planes[j+i*count].data.materials.append(materials[j]) #add the material to the object
|
||||
@ -120,13 +207,14 @@ def setup_array(count):
|
||||
|
||||
return(Matrix, count)
|
||||
|
||||
|
||||
############################################################
|
||||
# Call Functions
|
||||
############################################################
|
||||
|
||||
Matrix, count = setup_array(30)
|
||||
Matrix, count = setup_array(12)
|
||||
|
||||
#quick_sort every array
|
||||
for i in range(count):
|
||||
iframe= 0
|
||||
quick_sort(i, Matrix[i], 0, count - 1)
|
||||
quick_sort(i, Matrix[i], 0, count - 1)
|
@ -82,7 +82,7 @@ def setup_array(count):
|
||||
#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)
|
||||
colors_g2 = np.linspace(1, 200, count//2)
|
||||
for i in range(count):
|
||||
if(i < count//2):
|
||||
colors_g[i]=colors_g1[i]
|
||||
|
@ -98,7 +98,7 @@ def setup_array(count):
|
||||
#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)
|
||||
colors_g2 = np.linspace(1, 200, count//2)
|
||||
for i in range(count):
|
||||
if(i < count//2):
|
||||
colors_g[i]=colors_g1[i]
|
||||
|
Loading…
x
Reference in New Issue
Block a user