@@ -535,22 +535,22 @@ del capítulo.
535535
536536{{index "vector graphics", "bitmap graphics"}}
537537
538- In computer ((graphics )), a distinction is often made between _ vector _
539- graphics and _ bitmap _ graphics. The first is what we have been doing
540- so far in this chapter—specifying a picture by giving a logical
541- description of ((shape ))s. Bitmap graphics, on the other hand, don't
542- specify actual shapes but rather work with ((pixel)) data (rasters of
543- colored dots ).
538+ En computación ((gráfica )), a menudo se distingue entre gráficos de _ vectores _
539+ y gráficos de _ mapa de bits _ . Los primeros son los que hemos estado
540+ trabajando en este capítulo, especificando una imagen mediante la
541+ descripción lógica de sus ((figura ))s. Los gráficos de mapa de bits,
542+ por otro lado, especifican figuras, pero funcionan con datos de pixeles
543+ (rejillas de puntos coloreados ).
544544
545545{{index "load event", "event handling", "img (HTML tag)", "drawImage method"}}
546546
547- The ` drawImage ` method allows us to draw ((pixel)) data onto a
548- ((canvas)). This pixel data can originate from an ` <img> ` element or
549- from another canvas. The following example creates a detached ` <img> `
550- element and loads an image file into it. But it cannot immediately
551- start drawing from this picture because the browser may not have
552- loaded it yet. To deal with this, we register a ` "load" ` event handler
553- and do the drawing after the image has loaded .
547+ El método ` drawImage ` nos permite dibujar datos de ((pixel))es en
548+ un ((canvas)). Estos datos pueden originarse desde un elemento ` <img> ` o
549+ desde otro canvas. El siguiente ejemplo crea un elemento ` <img> `
550+ y carga un archivo de imagen en él. Pero no podemos empezar a
551+ de esta imagen porquen el navegador podría no haberla cargadao aún.
552+ Para lidiar con esto, registramos un ` "load" ` _ event handler _
553+ y dibujamos después de que la imagen se ha cargado .
554554
555555``` {lang: "text/html"}
556556<canvas></canvas>
@@ -568,42 +568,42 @@ and do the drawing after the image has loaded.
568568
569569{{index "drawImage method", scaling}}
570570
571- By default , ` drawImage ` will draw the image at its original size. You
572- can also give it two additional arguments to set a different width
573- and height .
571+ Por defecto , ` drawImage ` dibujará la imagen en su tamaño original.
572+ También puedes darle dos argumentos adicionales para definir
573+ ancho y alto distintos .
574574
575- When ` drawImage ` is given _ nine _ arguments, it can be used to draw
576- only a fragment of an image. The second through fifth arguments
577- indicate the rectangle (x, y, width, and height) in the source image
578- that should be copied, and the sixth to ninth arguments give the
579- rectangle (on the canvas) into which it should be copied .
575+ Cuando ` drawImage ` recibe _ nueve _ argumentos, puede usarse para
576+ dibujar solo un fragmento de la imagen. Del segundo al quinto argumentos
577+ indican el rectángulo (x, y, ancho y alto) en la imagen de origen
578+ que debe copiarse, y de los argumentos cinco a nueve indicen el
579+ otro (en el canvas) en donde serán copiados .
580580
581581{{index "player", "pixel art"}}
582582
583- This can be used to pack multiple _ ((sprite))s_ (image elements) into
584- a single image file and then draw only the part you need. For example ,
585- we have this picture containing a game character in multiple
583+ Esto puede ser usado para empaquetar múltiples _ ((sprite))s_ (elementos de imagen)
584+ en una sola imagen y dibujar solo la parte que necesitas. Por ejemplo ,
585+ tenemos una imagen con un personaje de un juego en múltiples
586586((pose))s:
587587
588- {{figure {url: "img/player_big.png", alt: "Various poses of a game character ",width: "6cm"}}}
588+ {{figure {url: "img/player_big.png", alt: "Varias poses de un personaje ",width: "6cm"}}}
589589
590590{{index [ animation, "platform game"] }}
591591
592- By alternating which pose we draw, we can show an animation that
593- looks like a walking character .
592+ Alternando las poses que dibujamos, podemos mostrar una animación
593+ en la que se vea nuestro personaje caminando .
594594
595595{{index "fillRect method", "clearRect method", clearing}}
596596
597- To animate a ((picture )) on a ((canvas)), the ` clearRect ` method is
598- useful. It resembles ` fillRect ` , but instead of coloring the
599- rectangle, it makes it ((transparent )), removing the previously drawn
600- pixels .
597+ Para animar una ((imagen )) en un ((canvas)), el método ` clearRect ` es
598+ muy útil. Reutiliza ` fillRect ` , pero en vez de colorear el
599+ rectángulo, lo vuelve ((transparente )), quitando los pixeles
600+ previamente dibujados .
601601
602602{{index "setInterval function", "img (HTML tag)"}}
603603
604- We know that each _ ((sprite))_ , each subpicture, is 24 ((pixel ))s wide
605- and 30 pixels high. The following code loads the image and then sets
606- up an interval (repeated timer) to draw the next ((frame)):
604+ Sabemos que cada _ ((sprite))_ , cada subimagen, es de 24 ((pixele ))s de ancho
605+ y 30 pixeles de alto. El siguiente código carga la imagen y establece
606+ un intervalo de tiempo para dibujar el siguiente ((frame)):
607607
608608``` {lang: "text/html"}
609609<canvas></canvas>
@@ -613,27 +613,27 @@ up an interval (repeated timer) to draw the next ((frame)):
613613 img.src = "img/player.png";
614614 let spriteW = 24, spriteH = 30;
615615 img.addEventListener("load", () => {
616- let cycle = 0;
616+ let ciclo = 0;
617617 setInterval(() => {
618618 cx.clearRect(0, 0, spriteW, spriteH);
619619 cx.drawImage(img,
620620 // source rectangle
621- cycle * spriteW, 0, spriteW, spriteH,
621+ ciclo * spriteW, 0, spriteW, spriteH,
622622 // destination rectangle
623623 0, 0, spriteW, spriteH);
624- cycle = (cycle + 1) % 8;
624+ ciclo = (ciclo + 1) % 8;
625625 }, 120);
626626 });
627627</script>
628628```
629629
630630{{index "remainder operator", "% operator", [ animation, "platform game"] }}
631631
632- The ` cycle ` binding tracks our position in the animation. For each
633- ((frame)), it is incremented and then clipped back to the 0 to 7 range
634- by using the remainder operator. This binding is then used to compute
635- the x-coordinate that the sprite for the current pose has in the
636- picture .
632+ El valor ` ciclo ` rastrea la posición en la animación. Para cada
633+ ((frame)), se incrementa y regresa al rango del 0 al 7 usando
634+ el operador del remanente. Entonces este valor es usado para
635+ calcular la coordenada en x que tiene el _ sprite _ para la pose que
636+ tiene actualmente la imagen .
637637
638638## Transformation
639639
0 commit comments