Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # gen_points.py
- import sys
- import math
- import random
- import colorsys
- #--------------------- Cubic ---------------------------
- def cubic(num, side):
- data = []
- count = 0
- for n in range(num):
- x = random.uniform(-side/2, side/2)
- y = random.uniform(-side/2, side/2)
- z = random.uniform(-side/2, side/2)
- pnt = [x,y,z]
- data.append(pnt)
- return data
- #--------------------- Sphere ---------------------------
- def sphere (num, radius):
- data = []
- count = 0
- while count < num:
- x = random.uniform(-radius, radius)
- y = random.uniform(-radius, radius)
- z = random.uniform(-radius, radius)
- dist = math.sqrt(x*x + y*y + z*z)
- if dist <= radius:
- pnt = [x,y,z]
- data.append(pnt)
- count += 1
- return data
- #--------------------- Disk ---------------------------
- def disk(num, radius):
- data = []
- count = 0
- while count < num:
- x = random.uniform(-radius, radius)
- y = 0
- z = random.uniform(-radius, radius)
- dist = math.sqrt(x * x + z * z)
- if dist <= radius:
- pnt = [x,y,z]
- data.append(pnt)
- count += 1
- return data
- #--------------------- Cylinder ---------------------------
- def cylinder(num, radius, height):
- data = []
- count = 0
- while count < num:
- x = random.uniform(-radius, radius)
- y = random.uniform(-height/2, height/2)
- z = random.uniform(-radius, radius)
- dist = math.sqrt(x * x + z * z)
- if dist <= radius:
- pnt = [x,y,z]
- data.append(pnt)
- count += 1
- return data
- #--------------------- Cone ---------------------------
- def cone(num, radius, height):
- data = []
- count = 0
- while count < num:
- x = random.uniform(-radius, radius)
- y = random.uniform(-height/2, height/2)
- z = random.uniform(-radius, radius)
- dist = math.sqrt(x*x + z*z)
- if dist/(y+height/2) <= radius/height:
- pnt = [x,-y,z]
- data.append(pnt)
- count += 1
- return data
- #--------------------- Wave --------------------------
- def wave(num, width, length, wave_n, wave_h):
- data = []
- count = 0
- for n in range(num):
- x = random.uniform(-length/2,length/2)
- z = random.uniform(-width/2,width/2)
- y = wave_h*math.sin(wave_n*x*math.pi*2/length)
- pnt = [x,y,z]
- data.append(pnt)
- return data
- #--------------------- Oval Wave --------------------------
- def ovalwave(num, width, length, wave_n, wave_h):
- data = []
- count = 0
- a = length/2
- b = width/2
- while count < num:
- x = random.uniform(-a,a)
- z = random.uniform(-b,b)
- y = wave_h*math.sin(wave_n*x*math.pi*2/length)
- if (x*x)/(a*a)+ (z*z)/(b*b) <= 1:
- pnt = [x,y,z]
- data.append(pnt)
- count += 1
- return data
- #--------------------- Pringles --------------------------
- def pringles(num, width, length, wave_h):
- data = []
- count = 0
- a = length/2
- b = width/2
- while count < num:
- x = random.uniform(-a,a)
- z = random.uniform(-b,b)
- y = (wave_h/2)*(-math.cos(x*math.pi/length)+math.cos(z*math.pi/width))
- if (x*x)/(a*a)+ (z*z)/(b*b) <= 1:
- pnt = [x,y,z]
- data.append(pnt)
- count += 1
- return data
- #--------------------- Ripple--------------------------
- def ripple(num, width, length, wave_n, wave_h):
- data = []
- count = 0
- for n in range(num):
- x = random.uniform(-length/2,length/2)
- z = random.uniform(-width/2,width/2)
- y = wave_h*math.cos(wave_n*2*math.sqrt(x*x+z*z)*math.pi*2/max(width,length))
- pnt = [x,y,z]
- data.append(pnt)
- return data
- def rand_rgb(num, hsv_range):
- data = []
- for n in range(num):
- h = random.uniform(hsv_range[0], hsv_range[1])
- s = random.uniform(hsv_range[2], hsv_range[3])
- v = random.uniform(hsv_range[4], hsv_range[5])
- rgb = colorsys.hsv_to_rgb(h/360, s/100, v/100)
- data.append(rgb)
- return data
- if __name__=='__main__':
- # Particle number
- num = 10000
- # Cubic/Sphere/Cylinder/Cone variables
- side = 5
- radius = 15
- height = 25
- # Wave/Ripple variables
- length = 10
- width = 10
- wave_n = 5
- wave_h = 1
- # HSV Color Range: [H_Min, H_Max, S_Min, S_Max, V_Min, V_Max]
- hsv_range = [0, 360, 60, 80, 80, 100]
- print(cubic(num, side))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement