Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Exercice 5 - La fourmi de langton, v5 : 11000 étapes, grille de 75 x 75 (centrée en 37,37), cases de 10 pixels de côtés, une étape dure 0.0025s, fourmi initialement tête à droite
Tout est dans le titre, pour réaliser cette animation : https://youtu.be/qZRYGxF6D3w?t=247 (Télécharger)
Avec pour résultat final au bout des 11000 déplacements de la fourmi, la mise en évidence de "l'autoroute" :
Exercice 5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdlib.h>
#include "paper.h"
#define up 1
#define right 2
#define down 3
#define left 4
int ant_looks = right; // (up is 1 / right is 2 / down is 3 / left is 4)
void ant_turns_left_then_move();
void ant_turns_right_then_move();
int main()
{
init_paper(75,75,10,0.0025,0);
move_to(37,37);
repeat(11000) {
if (!is_colored()) {
colorize();
ant_turns_right_then_move();
} else {
erase();
ant_turns_left_then_move();
}
} loop;
display_paper();
return 0;
}
void ant_turns_right_then_move() {
switch (ant_looks) {
case up : // ant looks up
ant_looks = right;
move_right();
break;
case right : // ant looks right
ant_looks = down;
move_down();
break;
case down : // ant looks down
ant_looks = left;
move_left();
break;
case left : // ant looks left
ant_looks = up;
move_up();
break;
}
}
Enter to Rename, Shift+Enter to Preview
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content