Transformation Calculator

So I am a Freshmen in high school that is learning Python and taking Geometry right now. We are learning about transformations (translations, reflections, rotations, and dilations) and I thought that I might as well make a calculator to do some of the work for me. Here is the calculator (took me about 2 hours to make) hope you like it and please give me some feedback on how I can make it better!!:

``````def transformations(movement_type, movement_spec, points):
if movement_type == "Translation" or movement_type == "translation" or movement_type == "Trans" or movement_type == "tran" or movement_type == "trans" or movement_type == "Tran":
X_movement = movement_spec[0] #This is the movement on the X
Y_movement = movement_spec[1] #This is the movement on the Y
First_movement = X_movement + points[0]
Second_movement = Y_movement + points[1]
print ("The new set of points for the translation of " + "(" + str(points[0]) + "," + str(points[1]) + ") " + "is: " + "(" + str(First_movement) + "," + str(Second_movement) + ")")
elif movement_type == "Rotation" and movement_spec == 90: #This is for a rotation of 90 degrees
First_movement = points[1] - (points[1] * 2) #This is making the Y point negative
print ("The new set of points for the rotation of " + "(" + str(points[0]) + "," + str(points[1]) + ") " + "is: " + "(" + str(points[1]) + "," + str(First_movement) + ")")
elif movement_type == "Rotation" and movement_spec == 180: #This is for a rotation of 180 degrees
First_movement = points[0] - (points[0] * 2) #This is making the X point negative
Second_movement = points[1] - (points[1] * 2) #This is making the Y point negative
print ("The new set of points for the rotation of " + "(" + str(points[0]) + "," + str(points[1]) + ") " + "is: " + "(" + str(First_movement) + "," + str(Second_movement) + ")")
elif movement_type == "Rotation" and movement_spec == 270: #This is for a rotation of 270 degrees
First_movement = points[1] #This is swaping X with Y
Second_movement = points[0] - (points[0] * 2) #This is making the X point negative
print ("The new set of points for the rotation of "  + "(" + str(points[0]) + "," + str(points[1]) + ") " + "is: " + "(" + str(First_movement) + "," + str(Second_movement) + ")")
elif movement_type == "Reflection" and movement_spec == "y_axis":
First_movement = points[1] - (points[1] * 2) #This is making the Y point negative
print ("The new set of points for the reflection of "  + "(" + str(points[0]) + "," + str(points[1]) + ") " + "is: " + "("  + str(points[1]) + "," + str(First_movement) + ")")
elif movement_type == "Reflection" and movement_spec == "x_axis":
First_movement = points[0] - (points[0] * 1) #This is making the X point negative
print ("The new set of points for the reflection of "  + "(" + str(points[0]) + "," + str(points[1]) + ") " + "is: " + "("  + str(points[1]) + "," + str(First_movement) + ")")
elif movement_type == "Reflection" and movement_spec[0] == "X": #If it is intending to be reflected in the X-axis
First_movement = movement_spec[1] + points[1] #When it being reflected in the X-axis it is really being reflected in the Y-axis
print ("The new set of points for the rotation of "  + "(" + str(points[0]) + "," + str(points[1]) + ") " + "is: " + "("  + str(points[1]) + "," + str(First_movement) + ")")
elif movement_type == "Reflection" and movement_spec[0] == "Y": #If it is intending to be reflected in the Y-axis
First_movement = movement_spec[1] + points[0] #When it being reflected in the Y-axis it is really being reflected in the X-axis
print ("The new set of points ofr the reflection of "  + "(" + str(points[0]) + "," + str(points[1]) + ") " + "is: " + "("  "(" + str(First_movement) + "," + str(points[1]) + ")")
elif movement_type == "Dilation":
First_movement = points[0] * movement_spec #This is taking the X point and multiplying it with the scale factor
Second_movement = points[1] * movement_spec #This is taking the Y point and multiplying it with the scale factor
print ("The new set of points for the dilation of "  + "(" + str(points[0]) + "," + str(points[1]) + ") " + "is: " + "("  + str(First_movement) + "," + str(Second_movement) + ")")
else:
print ("Something went wrong. Check if everything is put in the right way!")

#Examples for Translation:
transformations("translation",[1,2],[2,3]) #Translation can be called with "translation"
transformations("Translation",[1,2],[2,0]) #Translation can be called with "Translation"
transformations("Trans",[1,2],[2,7]) #Translation can be called with "Trans"
transformations("tran",[1,2],[5,8]) #Translation can be called with "tran"
transformations("Tran",[1,2],[1,4]) #Translation can be called with "Tran"
transformations("trans",[1,2],[0,2]) #Translation can be called with "Trans"

#Examples for Rotation:
transformations("Rotation",90,[2,3]) #Rotation with a 90 degree turn
transformations("Rotation",180,[2,0]) #Rotation with a 180 degree turn
transformations("Rotation",270,[2,7]) #Rotation with a 270 degree turn

#Examples for Refletion:
transformations("Reflection","x_axis",[2,3]) #Reflection in the x-axis
transformations("Reflection", "y_axis",[2,7]) #Reflection in the y-axis
transformations("Reflection",["X",3],[5,8]) #Reflection in the x-axis
transformations("Reflection",["Y",2],[1,4]) #Reflection in the y-axis

#Examples for Dilation:
transformations("Dilation",0.5,[2,3]) #Dilation with an reduction
transformations("Dilation",-3,[2,7]) #Dilation wih an enlargement
``````
2 Likes

First, nice job! I like this style used in this. Creativeness a definitely a thing here! I really donâ€™t have many suggestions exempt for keep up the good work!

2 Likes

This whole thing can be simplified to single expression:

``````if 'tran' in movement_type.lower():
``````
2 Likes

Awesome! Thanks for the help!

3 Likes

Thank you so much for the kind words!

2 Likes

Your welcome Matthew! Thank you for showing me this

1 Like

Nice job on this! Iâ€™ve also turned some of homework into codes to help me. Mostly as a calculator.

2 Likes