diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:41:45 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:41:45 -0500 |
| commit | 1109132f09d75da9a28b649c7677bb6ce07c40c0 (patch) | |
| tree | 0dd8b084480983cf9f9680e8aedb92782a921b13 /files/es/web/api/canvasrenderingcontext2d/clearrect | |
| parent | 4b1a9203c547c019fc5398082ae19a3f3d4c3efe (diff) | |
| download | translated-content-1109132f09d75da9a28b649c7677bb6ce07c40c0.tar.gz translated-content-1109132f09d75da9a28b649c7677bb6ce07c40c0.tar.bz2 translated-content-1109132f09d75da9a28b649c7677bb6ce07c40c0.zip | |
initial commit
Diffstat (limited to 'files/es/web/api/canvasrenderingcontext2d/clearrect')
| -rw-r--r-- | files/es/web/api/canvasrenderingcontext2d/clearrect/index.html | 203 |
1 files changed, 203 insertions, 0 deletions
diff --git a/files/es/web/api/canvasrenderingcontext2d/clearrect/index.html b/files/es/web/api/canvasrenderingcontext2d/clearrect/index.html new file mode 100644 index 0000000000..64aa1a3908 --- /dev/null +++ b/files/es/web/api/canvasrenderingcontext2d/clearrect/index.html @@ -0,0 +1,203 @@ +--- +title: CanvasRenderingContext2D.clearRect() +slug: Web/API/CanvasRenderingContext2D/clearRect +translation_of: Web/API/CanvasRenderingContext2D/clearRect +--- +<div>{{APIRef}}</div> + +<div>El método <code><strong>CanvasRenderingContext2D</strong></code><strong><code>.clearRect() </code></strong><code>del API Canvas 2D convierte todos los pixeles en el rectangulo definido por el punto de inicio<em> (x, y) </em>y tamaño </code><em>(width, height)</em> a negro transparente, borrando cualquier contenido dibujado anteriormente.</div> + +<div> </div> + +<h2 id="Syntaxis">Syntaxis</h2> + +<div> +<h3 id="HTML_Content">HTML Content</h3> + +<pre class="brush: html">void <var><em>ctx</em>.clearRect(x, y, width, height);</var></pre> + +<h3 id="Parametros">Parametros</h3> + +<dl> + <dt><strong>x</strong></dt> + <dd>El eje <strong>x </strong> de la coordenada para el punto de inicio del rectangulo.</dd> + <dt>y</dt> + <dd>El eje <strong>y </strong> de la coordenada para el punto de inicio del rectangulo.</dd> + <dt>width</dt> + <dd>El ancho del rectangulo.</dd> + <dt>heigth</dt> + <dd>el alto del rectangulo.</dd> +</dl> + +<h2 id="Notas_de_uso">Notas de uso</h2> + +<p>Un problema común con <strong><code>clearRect </code></strong>es que puede parecer que no funciona cuando no se usan las <a href="/en-US/docs/Web/API/Canvas_API/Tutorial/Drawing_shapes#Drawing_paths">trayectorias de dibujo</a> (<a href="/en-US/docs/Web/API/Canvas_API/Tutorial/Drawing_shapes#Drawing_paths">paths</a>) de forma adecuada. No olvide llamar {{domxref("CanvasRenderingContext2D.beginPath", "beginPath()")}} antes de comenzar a dibujar el nuevo cuadro después de llamar <strong><code>clearRect</code></strong><code>.</code></p> + +<h2 id="Ejemplos">Ejemplos</h2> + +<dl> + <dt> + <h3 id="Usando_el_método_clearRect">Usando el método <code>clearRect</code></h3> + </dt> +</dl> + +<p><span style="display: none;"> </span> Este es un simple fragmento (snippet) de código que usa el método <strong><code>clearRect</code></strong>.</p> + +<h4 id="HTML">HTML</h4> + +<pre class="brush: html"><canvas id="canvas"></canvas></pre> +</div> + +<h4 id="JavaScript">JavaScript</h4> + +<pre class="brush: js">var canvas = document.getElementById('canvas'); +var ctx = canvas.getContext('2d'); c + +tx.beginPath(); ctx.moveTo(20, 20); +ctx.lineTo(200, 20); +ctx.lineTo(120, 120); +ctx.closePath(); // draws last line of the triangle +ctx.stroke(); + +ctx.clearRect(10, 10, 100, 100); + +// clear the whole canvas +// ctx.clearRect(0, 0, canvas.width, canvas.height);</pre> + +<h2 id="sect1"><span style="display: none;"> </span> </h2> + +<p>Edite el código de abajo y vea sus cambios actualizados en vivo en el canvas:</p> + +<p>{{ EmbedLiveSample('Playable_code', 700, 400) }}</p> + +<h2 id="Especificaciones">Especificaciones</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificación</th> + <th scope="col">Estado</th> + <th scope="col">Comentario</th> + </tr> + <tr> + <td>{{SpecName('HTML WHATWG', "scripting.html#dom-context-2d-clearrect", "CanvasRenderingContext2D.clearRect")}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<div style="display: none;"> +<h6 id="Playable_code">Playable code</h6> + +<pre class="brush: html"><canvas id="canvas" width="400" height="200" class="playable-canvas"></canvas> +<div class="playable-buttons"> + <input id="edit" type="button" value="Edit" /> + <input id="reset" type="button" value="Reset" /> +</div> +<textarea id="code" class="playable-code" style="height:140px;"> +ctx.beginPath(); +ctx.moveTo(20,20); +ctx.lineTo(200,20); +ctx.lineTo(120,120); +ctx.closePath(); // draws last line of the triangle +ctx.stroke(); + +ctx.clearRect(10, 10, 100, 100);</textarea> +</pre> + +<pre class="brush: js">var canvas = document.getElementById("canvas"); +var ctx = canvas.getContext("2d"); +var textarea = document.getElementById("code"); +var reset = document.getElementById("reset"); +var edit = document.getElementById("edit"); +var code = textarea.value; + +function drawCanvas() { + ctx.clearRect(0, 0, canvas.width, canvas.height); + eval(textarea.value); +} + +reset.addEventListener("click", function() { + textarea.value = code; + drawCanvas(); +}); + +edit.addEventListener("click", function() { + textarea.focus(); +}) + +textarea.addEventListener("input", drawCanvas); +window.addEventListener("load", drawCanvas); + +</pre> +</div> + +<table class="standard-table"> + <tbody> + </tbody> +</table> + +<h2 id="Compatibilidad_con_exploradores">Compatibilidad con exploradores</h2> + +<p>{{CompatibilityTable}}</p> + +<div> +<table class="compat-table"> + <tbody> + <tr> + <th>Caracteristica</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Soporte Básico</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div> +<table class="compat-table"> + <tbody> + <tr> + <th>Caracteristica</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Soporte Basico</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Vea_También">Vea También</h2> + +<ul> + <li>The interface defining it, {{domxref("CanvasRenderingContext2D")}}</li> + <li>{{domxref("CanvasRenderingContext2D.fillRect()")}}</li> + <li>{{domxref("CanvasRenderingContext2D.strokeRect()")}}</li> +</ul> |
