Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # rman_particles.py
- import sys
- import math
- import random
- import gen_points
- def writePointInfo(rib_path, num, p_data, p_color, p_size, bbox_size):
- f = open(rib_path, 'w')
- f.write('#bbox: '+', '.join(map(str,bbox_size))+'\n')
- # Write point position information
- f.write('Points "P" [\n')
- for x,y,z in p_data:
- f.write('%f %f %f\n' % (x,y,z))
- f.write(']\n')
- # Write point size information
- f.write('"width" [\n')
- for n in range (num):
- f.write('%f\n' % random.uniform(p_size[0], p_size[1]))
- f.write(']\n')
- # Write point color information
- f.write('"varying color tint" [\n')
- for r,g,b in p_color:
- f.write('%f %f %f\n' % (r,g,b))
- f.write(']\n')
- f.close()
- def writeSphere(rib_path, num, radius, p_size=[0.1, 0.1], hsv_range=[0, 360, 100, 100, 100, 100]):
- # Call gen_point.py
- p_data = gen_points.sphere (num, radius)
- p_color = gen_points.rand_rgb(num, hsv_range)
- # Set bbox information
- bbox_size = [-radius, -radius, -radius, radius, radius, radius]
- # Write into file
- writePointInfo(rib_path, num, p_data, p_color, p_size, bbox_size)
- print ('Sphere generated successfully.\n')
- def writeCylinder(rib_path, num, radius, height, p_size=[0.1, 0.1], hsv_range=[0, 360, 100, 100, 100, 100]):
- # Call gen_point.py
- p_data = gen_points.cylinder (num, radius, height)
- p_color = gen_points.rand_rgb(num, hsv_range)
- # Set bbox information
- bbox_size = [-radius, -height/2, -radius, radius, height/2, radius]
- # Write into file
- writePointInfo(rib_path, num, p_data, p_color, p_size, bbox_size)
- print ('Cylinder generated successfully.\n')
- def writeCone(rib_path, num, radius, height, p_size=[0.1, 0.1], hsv_range=[0, 360, 100, 100, 100, 100]):
- # Call gen_point.py
- p_data = gen_points.cone (num, radius, height)
- p_color = gen_points.rand_rgb(num, hsv_range)
- # Set bbox information
- bbox_size = [-radius, -height/2, -radius, radius, height/2, radius]
- # Write into file
- writePointInfo(rib_path, num, p_data, p_color, p_size, bbox_size)
- print ('Cone generated successfully.\n')
- def writeCubic(rib_path, num, side, p_size=[0.1, 0.1], hsv_range=[0, 360, 100, 100, 100, 100]):
- # Call gen_point.py
- p_data = gen_points.cubic (num, side)
- p_color = gen_points.rand_rgb(num, hsv_range)
- # Set bbox information
- bbox_size = [-side/2, -side/2, -side/2, side/2, side/2, side/2]
- # Write into file
- writePointInfo(rib_path, num, p_data, p_color, p_size, bbox_size)
- print ('Cubic generated successfully.\n')
- if __name__=='__main__':
- # File Attribute
- shape = 'cubic'
- rib_path = shape + 'Particle.rib'
- # Particle number/Size: [Size_Min, Size_Max]
- num = 10000
- p_size = [0.1, 0.7]
- # 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]
- if shape.lower() == 'cubic':
- writeCubic(rib_path, num, side, p_size, hsv_range)
- elif shape.lower() == 'sphere':
- writeSphere(rib_path, num, radius, p_size, hsv_range)
- elif shape.lower() == 'cylinder':
- writeCylinder(rib_path, num, radius, height, p_size, hsv_range)
- elif shape.lower() == 'cone':
- writeCone(rib_path, num, radius, height, p_size, hsv_range)
- else:
- print ('No such shape.\n')
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement