2. Draw a flower

_images/scratch-p02-cuatro-flores.png

In this practice we are going to program a series of functions that draw various types of flowers on the screen.


  1. We start the Scratch editor.


  2. We create a new function called Start.

    First click on the button more blocks

    mas-bloques

    Then click on create a block crear-bloque

    Then we change the name of the new block to Home

    _images/scratch-bloque-inicio.png

    Finally we press the button OK


  3. We program the Start function with the following blocks.

    _images/scratch-p02-programa-inicio.png

    This program places the cat in the center of the screen, prepares the pen, and erases any previous drawing.


  4. We will create a new function called Point.

    First click on the button more blocks

    mas-bloques

    Then click on create a block crear-bloque

    Then we change the name of the new block to Point

    Now we will add the variable Radius.

    Within options, we add a numeric input

    entrada-numerica

    We will call the new entry Radio

    _images/scratch-p02-punto-radio.png

    Finally we press the button OK


  5. Now we will program the function that draws a point on the screen (pen down and pen up).

    _images/scratch-p02-programa-punto.png

    This program will draw a point of a size that depends on the variable radius. If the radius is very large, the point will be very large, and if the radius value is small, the point drawn will be small.


  6. Next we will create a small test program to check that the dot is drawn on the screen.

    _images/scratch-p02-programa-prueba1.png

    When executing the program, pressing the green flag bandera-verde, the following drawing will appear on the screen.

    _images/scratch-p02-punto-rojo.png

    The cat has drawn a point of size 50 at a distance of 100 steps

    Once everything works fine, we will delete the test program.


  7. Now that we can draw points, we are going to program the drawing of a flower.

    First we will create a new function called Flower.

    First click on the button more blocks

    mas-bloques

    Then click on create a block crear-bloque

    Then we change the name of the new block to Flower

    Now we will add the variable Size.

    Within options, we add a numeric input

    entrada-numerica

    We will call the new entry Size

    _images/scratch-p02-nuevo-bloque-flor.png

    Finally we press the button OK


  8. Next we will program the function that will draw a flower on the screen.

    _images/scratch-p02-programa-flor.png


  9. To test that the function is well written, let's create a small test program that draws the flower on the screen.

    _images/scratch-p02-programa-prueba2.png

    After pressing the green flag bandera-verde, a flower made of colored dots will appear on the screen around the cat as shown in the following image.

    _images/scratch-p02-circulo-puntos.png

    Once everything works fine, we will delete the test program.


  10. Finally we are going to play with the flower function so that drawings made up of flowers of different sizes appear on the screen.

    _images/scratch-p02-programa-cuatro-anillos.png

    The previous program draws on the screen an image made up of several colored rings around the cat.

    Click on the green flag bandera-verde to see the result.

    _images/scratch-p02-cuatro-anillos.png

    Once everything works fine, we will delete the test program.


  11. With the following program, various flowers will be drawn at different points on the screen. In the end the cat will be in the middle of all.

    _images/scratch-p02-programa-cuatro-flores.png

    Click on the green flag bandera-verde to see the result.

    _images/scratch-p02-cuatro-flores.png

Exercises

  1. Modify the program so that all the points of the flower function have the same color. Draw a flower made up of large red rings on the outside and small green rings on the inside.
  2. Make a program that draws five rings positioned as the logo of the olympic games.