-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
35 lines (28 loc) · 837 Bytes
/
sketch.js
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
// Daniel Shiffman
// https://www.kadenze.com/courses/the-nature-of-code
// http://natureofcode.com/
// Session 5: Evolutionary Computing
// A World of creatures that eat food
// The more they eat, the longer they survive
// The longer they survive, the more likely they are to reproduce
// The bigger they are, the easier it is to land on food
// The bigger they are, the slower they are to find food
// When the creatures die, food is left behind
var world;
function setup() {
createCanvas(windowWidth, windowHeight);
// World starts with 20 creatures
// and 20 pieces of food
world = new World(20);
}
function draw() {
background(175);
world.run();
}
// We can add a creature manually if we so desire
function mousePressed() {
world.born(mouseX,mouseY);
}
function mouseDragged() {
world.born(mouseX,mouseY);
}