Aula 10: Funções e Recursão

1. Projeto Final 

Acesse o texto em pdf

2. Processing - Funções 

- Como utilizar as funções void(), return();

- Como definir funções de desenvolvimento:

  • Operadores: void setup (), void draw (), return() e outras funções definidas pelo desenvolvimento

3. Processing - Recursão 

3a. Exercícios

  • A partir da sintaxe abaixo definir uma recursão que produz a imagem do desenho:

3b. Exemplo

  • int x = 50; // X-coordinate of the center
    int y = 100; // Y-coordinate of the bottom
    int a = 35; // Half the width of the top bar
    int n = 3; // Number of recursions
    void setup() {
    size(100, 100);
    noLoop();
    }
    void draw() {
    drawT(x, y, a, n);
    }
    void drawT(int x, int y, int apex, int num) {
    line(x, y, x, y-apex);
    line(x-apex, y-apex, x+apex, y-apex);
    // This relational expression must eventually be
    // false to stop the recursion and draw the lines
    if (num > 0) {
    drawT(x-apex, y-apex, apex/2, num-1);
    drawT(x+apex, y-apex, apex/2, num-1);
    }
    }
<<< Volta Menu Principal
<<< Volta ao Conteúdo Programático