commit dfedc3f9b698e87eb1f51a396004fb66a2d41a7b Author: Yannick Francois Date: Sun Sep 3 15:49:14 2017 +0200 Random walk and random distribution visualisation diff --git a/random_visualisation/randpm_visualisation.pde b/random_visualisation/randpm_visualisation.pde new file mode 100644 index 0000000..dd0df9e --- /dev/null +++ b/random_visualisation/randpm_visualisation.pde @@ -0,0 +1,19 @@ +int[] randomCounts; + +void setup() { + size(640, 240); + randomCounts = new int[20]; +} + +void draw() { + background(255); + int index = int(random(randomCounts.length)); + randomCounts[index]++; + stroke(0); + fill(175); + int w = width/randomCounts.length; + + for(int x = 0; x < randomCounts.length; x++) { + rect(x * w, height - randomCounts[x], w - 1, randomCounts[x]); + } +} \ No newline at end of file diff --git a/random_walk/random_walk.pde b/random_walk/random_walk.pde new file mode 100644 index 0000000..1584579 --- /dev/null +++ b/random_walk/random_walk.pde @@ -0,0 +1,39 @@ + +int EQUILIBRE = 3; +int SUD_EST = 4; +int BALADE = SUD_EST; + +class Walker { + int x; + int y; + + Walker() { + x = width / 2; + y = height / 2; + } + + void display() { + stroke(0); + point(x, y); + } + + void step() { + int stepx = int(random(BALADE)) - 1; + int stepy = int(random(BALADE)) - 1; + x += stepx; + y += stepy; + } +} + +Walker w; + +void setup(){ + size(640, 360); + w = new Walker(); + background(255); +} + +void draw() { + w.step(); + w.display(); +} \ No newline at end of file