Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
36 views

RingGenerator Py

The document contains code to generate a multi-segment ring blueprint by taking user input for parameters like part type, position, dimensions, textures, etc. and calculating segment positions. It either prints the output or writes it to a blueprint file in JSON format with an array of parts.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

RingGenerator Py

The document contains code to generate a multi-segment ring blueprint by taking user input for parameters like part type, position, dimensions, textures, etc. and calculating segment positions. It either prints the output or writes it to a blueprint file in JSON format with an array of parts.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

import math

def print_part(x, y, w, z, h):


if not reverse_texture:
if 45 >= z or z > 225:
n = "-"
f_w = 3.4
else:
n = ""
f_w = 2.6
else:
if 45 < z <= 225:
n = "-"
f_w = 3.4
else:
n = ""
f_w = 2.6
w = w / 3
if part_type == 'fuel tank':
print(
""" {
"n": "Fuel Tank",
"p": {
"x": %s,
"y": %s
},
"o": {
"x": %s%s,
"y": 1.0,
"z": %s
},
"t": "-Infinity",
"N": {
"width_original": %s3.0,
"width_a": %s3.0,
"width_b": %s3.0,
"height": %s,
"fuel_percent": 1.0
},
"T": {
"color_tex": "%s",
"shape_tex": "%s"
}
},
""" % (x, y, n, w, z, n, n, n, h, color_tex, shape_tex), end="")
else:
print(
""" {
"n": "Fairing",
"p": {
"x": %s,
"y": %s
},
"o": {
"x": %s%s,
"y": 1.0,
"z": %s
},
"t": "-Infinity",
"N": {
"width_original": %s%s,
"width_a": %s%s,
"width_b": %s%s,
"height": %s,
"force_percent": 0.5
},
"B": {
"occupied_a": false
},
"T": {
"fragment": "1",
"color_tex": "%s",
"shape_tex": "%s"
}
},
""" % (x, y, n, w, z, n, f_w, n, f_w, n, f_w, h, color_tex, shape_tex), end="")

def write_part(x, y, w, z, h, file_name):


if not reverse_texture:
if 45 >= z or z > 225:
n = "-"
f_w = 3.4
else:
n = ""
f_w = 2.6
else:
if 45 < z <= 225:
n = "-"
f_w = 3.4
else:
n = ""
f_w = 2.6
w = w / 3
if part_type == 'fuel tank':
file_name.write(
""" {
"n": "Fuel Tank",
"p": {
"x": %s,
"y": %s
},
"o": {
"x": %s%s,
"y": 1.0,
"z": %s
},
"t": "-Infinity",
"N": {
"width_original": %s3.0,
"width_a": %s3.0,
"width_b": %s3.0,
"height": %s,
"fuel_percent": 1.0
},
"T": {
"color_tex": "%s",
"shape_tex": "%s"
}
},
""" % (x, y, n, w, z, n, n, n, h, color_tex, shape_tex))
else:
file_name.write(
""" {
"n": "Fairing",
"p": {
"x": %s,
"y": %s
},
"o": {
"x": %s%s,
"y": 1.0,
"z": %s
},
"t": "-Infinity",
"N": {
"width_original": %s%s,
"width_a": %s%s,
"width_b": %s%s,
"height": %s,
"force_percent": 0.5
},
"B": {
"occupied_a": false
},
"T": {
"fragment": "1",
"color_tex": "%s",
"shape_tex": "%s"
}
},
""" % (x, y, n, w, z, n, f_w, n, f_w, n, f_w, h, color_tex, shape_tex))

color_tex_shown = False
shape_tex_shown = False
segment_list = []
state = 0

color_textures = {"✓£¢€¥": "Possible textures:", "none": "None", "array": "Array",


"color_orange": "Color_Orange", "gold_foil": "Gold_Foil",
"color_gray": "Color_Gray",
"color_black": "Color_Black", "metal_1": "Metal_1", "metal_2":
"Metal_2", "metal_3": "Metal_3",
"metal_4": "Metal_4", "strut_gray": "Strut_Gray",
"pattern_squares": "Pattern_Squares", "pattern_cone": "Pattern_Cone",
"pattern_bars": "Pattern_Bars", "pattern_bars_band":
"Pattern_Bars_Band", "pattern_bars_half": "Pattern_Bars_Half",
"nozzle_2": "Nozzle_2", "nozzle_3": "Nozzle_3", "sv_s1_usa":
"SV_S1_USA", "sv_s1_flag": "SV_S1_Flag", "sv_s2": "SV_S2", "sv_s3": "SV_S3",
"usa_logo": "USA_Logo"}

shape_textures = {"✓£¢€¥": "Possible textures:", "none": "None", "flat": "Flat",


"flat smooth": "Flat Smooth",
"rivets": "Rivets", "half rivets": "Half Rivets", "edges":
"Edges", "flat faces": "Flat Faces",
"interstage": "Interstage", "interstage_full": "Interstage_Full",
"edges faces top": "Edges Faces Top", "edges faces bottom":
"Edges Faces Bottom",
"edges smooth": "Edges Smooth", "nozzle_4": "Nozzle_4", "strut":
"Strut"}

while True:
if state == 0:
part_type = input("Part_type (fuel tank/fairing): ").lower()
if part_type == "fuel tank":
state = 1
elif part_type == "fairing":
state = 1
else:
print("Input must be 'fuel tank' or 'fairing'!")
state = 0
elif state == 1:
try:
ring_x = float(input("Ring X: "))
state = 2
except ValueError:
print("Input must be a number!")
elif state == 2:
try:
ring_y = float(input("Ring Y: "))
state = 3
except ValueError:
print("Input must be a number!")
elif state == 3:
try:
inner_diameter = float(input("Diameter: "))
inner_radius = inner_diameter / 2
state = 4
except ValueError:
print("Input must be a number!")
elif state == 4:
try:
segment_w = float(input("Ring width: "))
state = 5
except ValueError:
print("Input must be a number!")
elif state == 5:
try:
color_tex = color_textures[input("Color texture: ").lower()]
state = 6
except KeyError:
if not color_tex_shown:
for i in color_textures:
print(" ", color_textures[i])
color_tex_shown = True
else:
print("Input must be valid texture")
elif state == 6:
try:
shape_tex = shape_textures[input("Shape texture: ").lower()]
state = 7
except KeyError:
if not shape_tex_shown:
for i in shape_textures:
print(" ", shape_textures[i])
shape_tex_shown = True
else:
print("Input must be a valid texture")
elif state == 7:
try:
segment_angle_increment = float(input("Segment angle increments
(degrees): "))
if 360 % segment_angle_increment == 0:
state = 8
else:
print("Number must be a divisor of 360!")
state = 7
except ValueError:
print("Input must be a number!")
elif state == 8:
reverse_texture = input("Reverse ring shading (yes/no)? ")
if reverse_texture == "yes":
reverse_texture = True
state = 9
elif reverse_texture == "no":
reverse_texture = False
state = 9
else:
print("Input must be 'yes' or 'no'!")
state = 8
elif state == 9:
write_blueprint = input("Write blueprint file (yes/no)? ")
if write_blueprint == "yes":
write_blueprint = True
break
elif write_blueprint == "no":
write_blueprint = False
break
else:
print("Input must be 'yes' or 'no'!")
state = 9

radius = inner_radius / math.cos(math.radians(segment_angle_increment / 2))


diameter = radius * 2
segment_n = int(360 / segment_angle_increment)
segment_h = math.sin(math.radians(segment_angle_increment / 2)) * radius * 2
radius_middle = math.cos(math.radians(segment_angle_increment / 2)) * radius
root_segment_x = ring_x + inner_radius - segment_w / 2
root_segment_y = ring_y - 1.5 * segment_h
segment_angle_1 = -segment_angle_increment
segment = 0

for segment in range(segment_n):

segment_angle_2 = segment_angle_1 + segment_angle_increment

if segment == 0:
segment += 1
segment_angle_1 = 0

w_b = math.sin(math.radians(segment_angle_1)) * (segment_w / 2)


w_a = math.cos(math.radians(segment_angle_1)) * (segment_w / 2)
h_b = math.sin(math.radians(segment_angle_1)) * segment_h
h_a = math.cos(math.radians(segment_angle_1)) * segment_h

root_x = root_segment_x - h_b + w_a


root_y = root_segment_y + h_a + w_b

w_b = math.sin(math.radians(segment_angle_2)) * (segment_w / 2)


w_a = math.cos(math.radians(segment_angle_2)) * (segment_w / 2)

part_x = root_x - w_a


part_y = root_y - w_b

segment_list.append([part_x, part_y, segment_w, segment_angle_2, segment_h])

segment_angle_1 = segment_angle_2
root_segment_x = part_x
root_segment_y = part_y

if not write_blueprint:
for i in segment_list:
print_part(i[0], i[1], i[2], i[3], i[4])

elif write_blueprint:
blueprint_file = open("Blueprint.txt", "w+")
blueprint_file.write("""{
"center": 9.0,
"offset": {
"x": 0.0,
"y": 0.0
},
"parts": [
""")
for i in segment_list:
write_part(i[0], i[1], i[2], i[3], i[4], blueprint_file)
blueprint_file.write(""" ],
"stages": []
}""")
blueprint_file.close()

while not write_blueprint:


if input(
"""
Press any button to exit...
"""):
break

You might also like