2019-02-08 22:56:19 +01:00
|
|
|
Navigation
|
|
|
|
----------
|
2019-02-24 15:56:54 +01:00
|
|
|
|
2020-05-18 22:18:39 +02:00
|
|
|
The back end can both move the origin and the current point from
|
2019-02-24 15:56:54 +01:00
|
|
|
which the next line is going to start. Boxes.py hides this by using
|
|
|
|
Turtle Graphics commands that also move the origin to the end of the
|
|
|
|
last line. Other drawing commands restore the current position after
|
|
|
|
they are finished.
|
|
|
|
|
|
|
|
Moving the origin like this allows ignoring the absolute coordinates
|
|
|
|
and do all movement and drawing to be relative to the current
|
|
|
|
position. The current positions does not only consist of a point on
|
|
|
|
the drawing canvas but also a direction.
|
|
|
|
|
|
|
|
To move the origin to a different location there are these to methods:
|
|
|
|
|
2019-02-08 22:56:19 +01:00
|
|
|
.. automethod:: boxes.Boxes.moveTo
|
|
|
|
.. automethod:: boxes.Boxes.moveArc
|
|
|
|
|
2019-02-24 15:56:54 +01:00
|
|
|
Often it is necessary to return to a position e.g. after placing a
|
|
|
|
row of parts. This can be done with the following context manager:
|
2019-02-08 22:56:19 +01:00
|
|
|
|
|
|
|
.. automethod:: boxes.Boxes.saved_context()
|
2019-02-24 15:56:54 +01:00
|
|
|
|
|
|
|
It can be used with the following code pattern:
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
2021-05-09 18:41:22 +02:00
|
|
|
with self.saved_context():
|
2019-02-24 15:56:54 +01:00
|
|
|
self.rectangularWall(x, h, move="right")
|
|
|
|
self.rectangularWall(y, h, move="right")
|
|
|
|
self.rectangularWall(y, h, move="right")
|
|
|
|
self.rectangularWall(x, h, move="right")
|
|
|
|
self.rectangularWall(x, h, move="up only")
|
|
|
|
|
|
|
|
# continue above the row
|
|
|
|
|
2020-05-18 22:18:39 +02:00
|
|
|
Parts of the code still directly use the back end primitives **Boxes.ctx.save()**
|
2019-02-24 15:56:54 +01:00
|
|
|
and **Boxes.ctx.restore()**. But this has several disadvantages and is
|
2022-12-28 17:03:26 +01:00
|
|
|
discouraged. For one it requires matching calls. It also does not
|
2019-02-24 15:56:54 +01:00
|
|
|
reset the starting point of the next line. This is "healed" by a
|
|
|
|
follow up **.moveTo()**. Use **.moveTo(0, 0)** if in doubt.
|