At My Fingertips
Implement a rhombus
function to recreate the following graphic.
A rhombus is composed of two isosceles triangles placed one above the other.
Let's start by implementing the upright_isosceles_triangle
function,
that generates an isosceles triangle rotated upright
(with a horizontal base, and the tip at the top center).
An approach could be to import your isosceles_triangle
function from your toolbox
(or to call the triangle function with the same value for the two sides),
and then to rotate the resulting triangle accordingly.
The following sketches might help you with the reasoning on the rotation angle.
Note that the rotate function requires a negative angle to rotate clock-wise.
result of triangle(160, 160, 40, black)
with horizontal and vertical axis to help find the angle of rotation
wanted result
Now you only have to combine two isosceles triangles,
one above the other,
to generate a rhombus.
Implement the rhombus
function using the pytamaro above and
rotate functions,
together with the upright_isosceles_triangle
function that you just implemented.
Now save your rhombus
function in your toolbox.
It may come in handy as a component for more complex graphics in the future.
This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.
Rhombus
PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI
Privacy Policy • Platform Version c3a8286 (Mon, 14 Oct 2024 13:30:28 GMT)