Dibuja con código
Vas a hacer tu primer dibujo en pantalla sin instalar absolutamente nada. Solo este navegador.
Draw with code
You are going to make your first drawing on screen without installing anything at all. Just this browser.
Todo dibujo necesita una superficie. En la web se llama canvas, y es literalmente
un rectángulo en blanco donde tú mandas.
Abajo hay código de verdad, funcionando. Cámbialo. Prueba poner otro color
en la línea del fillStyle — sirven nombres como "tomato",
"gold" o "hotpink".
Every drawing needs a surface. On the web it is called a canvas, and it is
literally a blank rectangle where you are in charge.
Below is real, running code. Change it. Try another colour on the
fillStyle line — names like "tomato", "gold" or
"hotpink" all work.
Los círculos necesitan una línea más, porque hay que decirle al pincel dónde empieza y
dónde termina. La palabra arc significa arco: un círculo completo es un arco
que da la vuelta entera.
Fíjate en el bucle for: esa es la parte poderosa. En vez de escribir cinco
círculos, escribes uno y le dices "hazlo cinco veces".
Circles need one extra line, because you have to tell the brush where the shape starts and
ends. The word arc means just that: a full circle is an arc that goes all the
way around.
Look at the for loop — that is the powerful part. Instead of writing five
circles, you write one and say "do it five times".
Acá está lo que separa un dibujo de un programa: reaccionar. La línea
addEventListener significa "cuando pase esto, haz esto otro".
Pasa el dedo o el mouse por encima del recuadro negro.
Here is what separates a drawing from a program: reacting. The
addEventListener line means "when this happens, do that".
Drag your finger or mouse across the dark box.
Sin darte cuenta usaste cuatro cosas que están en todos los programas del mundo: variables (guardar un valor), funciones (un bloque con nombre que hace algo), bucles (repetir) y eventos (reaccionar).
Eso es la base. Nuestros juegos usan exactamente lo mismo, solo que con más líneas.
Without noticing, you used four things that appear in every program ever written: variables (storing a value), functions (a named block that does something), loops (repeating) and events (reacting).
That is the foundation. Our games use exactly the same things, just with more lines.