@@ -635,7 +635,7 @@ el operador del remanente. Entonces este valor es usado para
635635calcular la coordenada en x que tiene el _ sprite_ para la pose que
636636tiene actualmente la imagen.
637637
638- ## Transformation
638+ ## Transformaciones
639639
640640{{index transformation, mirroring}}
641641
@@ -771,82 +771,81 @@ universo alrededor del centro vertical de los personajes.
771771</script>
772772```
773773
774- ## Storing and clearing transformations
774+ ## Almacenando y limpiando transformaciones
775775
776776{{index "side effect", canvas, transformation}}
777777
778- Transformations stick around. Everything else we draw after
779- ((drawing )) that mirrored character would also be mirrored. That might
780- be inconvenient .
778+ La transformaciones se mantienen. Todo lo que dibujemos después de
779+ ((dibujar )) de nuestro personaje espejeado también puede ser
780+ espejeado. Eso puede ser un inconveniente .
781781
782- It is possible to save the current transformation, do some drawing and
783- transforming, and then restore the old transformation. This is usually
784- the proper thing to do for a function that needs to temporarily
785- transform the coordinate system. First, we save whatever
786- transformation the code that called the function was using. Then the
787- function does its thing, adding more transformations on top of the
788- current transformation. Finally, we revert to the
789- transformation we started with .
782+ Es posible guardar el estado actual de la transformación, dibujar
783+ de nuevo y restaurar la transformación anterior. Usualmente esto
784+ es lo que debemos hacer para una función que necesite transformar
785+ de forma temporal el sistema de coordenadas. Primero, guardamos el
786+ código de la transformación que haya llamado a la función que estamos
787+ usando. La función hace lo suyo, agregando más transformaiones
788+ sobre la transformación actual. Finalmente, revertimos a la
789+ transformación con la que empezamos .
790790
791791{{index "save method", "restore method", [ state, "of canvas"] }}
792792
793- The ` save ` and ` restore ` methods on the 2D ((canvas)) context do this
794- ((transformation)) management. They conceptually keep a stack of
795- transformation states. When you call ` save ` , the current state is
796- pushed onto the stack, and when you call ` restore ` , the state on top
797- of the stack is taken off and used as the context's current
798- transformation. You can also call ` resetTransform ` to fully reset the
799- transformation .
793+ Los métodos ` save ` y ` restore ` en el contexto del ((canvas)) 2D
794+ realizan el manejo de las ((transformaciones)). Conceptualmente
795+ mantienen una pila de los estados de la transformación. Cuando
796+ se llama ` save ` , el estado actual se agrega a la pila, y cuando se
797+ llama ` restore ` , el estado en la cima de la pila se usa en el
798+ contexto actual de la transformación. También puedes llamar
799+ ` resetTransform ` para resetear por completo la transformación .
800800
801801{{index "branching recursion", "fractal example", recursion}}
802802
803- The ` branch ` function in the following example illustrates what you
804- can do with a function that changes the transformation and then calls
805- a function (in this case itself ), which continues drawing with
806- the given transformation .
803+ La función ` ramificar ` en el siguiente ejemplo ilustra lo que puedes
804+ hacer con una función que cambia la transformación y llama una
805+ función (en este caso a sí misma ), que continúa dibujando con una
806+ transformación dada .
807807
808- This function draws a treelike shape by drawing a line, moving the
809- center of the coordinate system to the end of the line, and calling
810- itself twice—first rotated to the left and then rotated to the right .
811- Every call reduces the length of the branch drawn, and the recursion
812- stops when the length drops below 8.
808+ La función dibuja un árbol dibujando una línea, moviendo el centro
809+ del sistema de coordenadas hacia el final de la línea, y llamándose
810+ a sí misma rotándose a la izquierda y luego a la derecha .
811+ Cada cada llamada reduce el ancho de la rama dibujada, y la
812+ recursión se detiene cuando el ancho es menor a 8.
813813
814814``` {lang: "text/html"}
815815<canvas width="600" height="300"></canvas>
816816<script>
817817 let cx = document.querySelector("canvas").getContext("2d");
818- function branch (length, angle, scale) {
818+ function ramificar (length, angle, scale) {
819819 cx.fillRect(0, 0, 1, length);
820820 if (length < 8) return;
821821 cx.save();
822822 cx.translate(0, length);
823823 cx.rotate(-angle);
824- branch (length * scale, angle, scale);
824+ ramificar (length * scale, angle, scale);
825825 cx.rotate(2 * angle);
826- branch (length * scale, angle, scale);
826+ ramificar (length * scale, angle, scale);
827827 cx.restore();
828828 }
829829 cx.translate(300, 0);
830- branch (60, 0.5, 0.8);
830+ ramificar (60, 0.5, 0.8);
831831</script>
832832```
833833
834834{{if book
835835
836- The result is a simple fractal.
836+ El resultado es un simple fractal.
837837
838- {{figure {url: "img/canvas_tree.png", alt: "A recursive picture ",width: "5cm"}}}
838+ {{figure {url: "img/canvas_tree.png", alt: "Una imagen recursiva ",width: "5cm"}}}
839839
840840if}}
841841
842842{{index "save method", "restore method", canvas, "rotate method"}}
843843
844- If the calls to ` save ` and ` restore ` were not there, the second
845- recursive call to ` branch ` would end up with the position and rotation
846- created by the first call. It wouldn't be connected to the current
847- branch but rather to the innermost, rightmost branch drawn by the
848- first call. The resulting shape might also be interesting, but it is
849- definitely not a tree.
844+ Sí la llamada a ` save ` y ` restore ` no estuvieran, la segunda llamada
845+ recursiva a ` ramificar ` terminarían con la posición y rotación
846+ creados en la primera llamada. No se conectarían con la rama actual,
847+ excepto por las mas cercanas, la mayoría dibujadas en la primera
848+ llamada. La figura resultante sería interesante, pero no es un árbol definitivamente.
850849
851850{{id canvasdisplay}}
852851
0 commit comments