Advertisement
joch1175

gen_points.py

Sep 29th, 2020 (edited)
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.02 KB | None | 0 0
  1. # gen_points.py
  2. import sys
  3. import math
  4. import random
  5. import colorsys
  6.  
  7. #--------------------- Cubic ---------------------------
  8. def cubic(num, side):
  9.     data = []
  10.     count = 0
  11.     for n in range(num):
  12.         x = random.uniform(-side/2, side/2)
  13.         y = random.uniform(-side/2, side/2)
  14.         z = random.uniform(-side/2, side/2)
  15.         pnt = [x,y,z]
  16.         data.append(pnt)
  17.     return data
  18.  
  19. #--------------------- Sphere ---------------------------
  20. def sphere (num, radius):
  21.     data = []
  22.     count = 0
  23.     while count < num:
  24.         x = random.uniform(-radius, radius)
  25.         y = random.uniform(-radius, radius)
  26.         z = random.uniform(-radius, radius)
  27.         dist = math.sqrt(x*x + y*y + z*z)
  28.         if dist <= radius:
  29.             pnt = [x,y,z]
  30.             data.append(pnt)
  31.             count += 1
  32.     return data
  33.  
  34. #--------------------- Disk ---------------------------
  35. def disk(num, radius):
  36.     data = []
  37.     count = 0
  38.     while count < num:
  39.         x = random.uniform(-radius, radius)
  40.         y = 0
  41.         z = random.uniform(-radius, radius)
  42.         dist = math.sqrt(x * x + z * z)
  43.         if dist <= radius:
  44.             pnt = [x,y,z]
  45.             data.append(pnt)
  46.             count += 1
  47.     return data      
  48.  
  49. #--------------------- Cylinder ---------------------------
  50. def cylinder(num, radius, height):
  51.     data = []
  52.     count = 0
  53.     while count < num:
  54.         x = random.uniform(-radius, radius)
  55.         y = random.uniform(-height/2, height/2)
  56.         z = random.uniform(-radius, radius)
  57.         dist = math.sqrt(x * x + z * z)
  58.         if dist <= radius:
  59.             pnt = [x,y,z]
  60.             data.append(pnt)
  61.             count += 1
  62.     return data      
  63.  
  64. #--------------------- Cone ---------------------------
  65. def cone(num, radius, height):
  66.     data = []
  67.     count = 0
  68.     while count < num:
  69.         x = random.uniform(-radius, radius)
  70.         y = random.uniform(-height/2, height/2)
  71.         z = random.uniform(-radius, radius)
  72.         dist = math.sqrt(x*x + z*z)
  73.         if dist/(y+height/2) <= radius/height:
  74.             pnt = [x,-y,z]
  75.             data.append(pnt)
  76.             count += 1
  77.     return data
  78.  
  79. #--------------------- Wave -------------------------- 
  80. def wave(num, width, length, wave_n, wave_h):
  81.     data = []
  82.     count = 0
  83.     for n in range(num):
  84.         x = random.uniform(-length/2,length/2)
  85.         z = random.uniform(-width/2,width/2)
  86.         y = wave_h*math.sin(wave_n*x*math.pi*2/length)
  87.         pnt = [x,y,z]
  88.         data.append(pnt)
  89.     return data
  90.  
  91. #--------------------- Oval Wave --------------------------
  92. def ovalwave(num, width, length, wave_n, wave_h):
  93.     data = []
  94.     count = 0
  95.     a = length/2
  96.     b = width/2
  97.     while count < num:
  98.         x = random.uniform(-a,a)
  99.         z = random.uniform(-b,b)
  100.         y = wave_h*math.sin(wave_n*x*math.pi*2/length)
  101.         if (x*x)/(a*a)+ (z*z)/(b*b) <= 1:
  102.             pnt = [x,y,z]
  103.             data.append(pnt)
  104.             count += 1
  105.     return data
  106.  
  107. #--------------------- Pringles -------------------------- 
  108. def pringles(num, width, length, wave_h):
  109.     data = []
  110.     count = 0
  111.     a = length/2
  112.     b = width/2
  113.     while count < num:
  114.         x = random.uniform(-a,a)
  115.         z = random.uniform(-b,b)
  116.         y = (wave_h/2)*(-math.cos(x*math.pi/length)+math.cos(z*math.pi/width))
  117.         if (x*x)/(a*a)+ (z*z)/(b*b) <= 1:
  118.             pnt = [x,y,z]
  119.             data.append(pnt)
  120.             count += 1
  121.     return data
  122.  
  123. #--------------------- Ripple--------------------------
  124. def ripple(num, width, length, wave_n, wave_h):
  125.     data = []
  126.     count = 0
  127.     for n in range(num):
  128.         x = random.uniform(-length/2,length/2)
  129.         z = random.uniform(-width/2,width/2)
  130.         y = wave_h*math.cos(wave_n*2*math.sqrt(x*x+z*z)*math.pi*2/max(width,length))
  131.         pnt = [x,y,z]
  132.         data.append(pnt)
  133.     return data
  134.  
  135. def rand_rgb(num, hsv_range):
  136.     data = []
  137.     for n in range(num):
  138.         h = random.uniform(hsv_range[0], hsv_range[1])
  139.         s = random.uniform(hsv_range[2], hsv_range[3])
  140.         v = random.uniform(hsv_range[4], hsv_range[5])
  141.         rgb = colorsys.hsv_to_rgb(h/360, s/100, v/100)
  142.         data.append(rgb)
  143.     return data
  144.  
  145. if __name__=='__main__':
  146.     # Particle number
  147.     num = 10000
  148.  
  149.     # Cubic/Sphere/Cylinder/Cone variables
  150.     side = 5       
  151.     radius = 15
  152.     height = 25
  153.  
  154.     # Wave/Ripple variables
  155.     length = 10    
  156.     width = 10
  157.     wave_n = 5
  158.     wave_h = 1
  159.  
  160.     # HSV Color Range: [H_Min, H_Max, S_Min, S_Max, V_Min, V_Max]
  161.     hsv_range = [0, 360, 60, 80, 80, 100]
  162.    
  163.     print(cubic(num, side))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement