123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- package main.java.com.lotkavolterra;
- import processing.core.PApplet;
- import processing.core.PImage;
- public class Structs extends PApplet {
- int n_boxes = 30;
- int FOX = 0;
- int RABBIT = 1;
- int GRASS = 2;
- int DESERT = 3;
- int ROAD = 4;
- int N_AGENTS = 4;
- PImage[] images = new PImage[5];
- int SIZE = -1;
- boolean DIAGONAL = false;
- int nn = n_boxes *n_boxes;
- Box [] boxes = new Box[nn];
- Neighbours [] neighs = new Neighbours[nn] ;
- class Box {
- float x;
- float y;
- float xend;
- float yend;
- float w=SIZE;
- float h=SIZE;
- int type;
- int next;
- // constr
- Box ( float x, float y, int type, int size) {
- this.x=x;
- this.y=y;
- this.w = size;
- this.h = size;
- this.xend=x+size;
- this.yend=y+size;
- this.type =type;
- this.next =type;
- } // constr
- Box ( float x, float y, int type) {
- this.x=x;
- this.y=y;
- this.type =type;
- this.next =type;
- this.xend=x+this.w;
- this.yend=y+this.h;
- } // constr
- void make_borders() {
- int j = type;
- if (j==GRASS) {stroke(77,137,99);}
- else if (j==FOX) {stroke(182,22,63);}
- else if (j==DESERT) {stroke(244,148,0);}
- else if (j==RABBIT) {stroke(4,54,84);}
- strokeWeight(10);
- rect(x, y, w, h);
- }
- void display(int n) {
- image(images[n], x, y);
- }
- } // class
- class Neighbours {
- int x;
- int y;
- int [] surround;
- Neighbours( int x, int y) {
- this.x = x;
- this.y = y;
- if (DIAGONAL) {
- int N = 8;
- int[] xs= new int[N];
- int[] ys= new int[N];
- ys[0] = (n_boxes + y-1)%n_boxes;
- ys[1] = ys[0];
- ys[2] = ys[0];
- ys[3] = y; ys[4] = y;
- ys[5] = (y+1)%n_boxes;
- ys[6] = ys[5];
- ys[7] = ys[5];
- xs[0] = (n_boxes + x-1)%n_boxes;
- xs[1] = x;
- xs[2] = (x+1) %n_boxes;
- xs[3] = xs[0]; xs[4] =xs[2];
- xs[5] = xs[0];
- xs[6] = x;
- xs[7] = xs[2];
- this.surround = new int[N];
- for (int i=0; i<N; i++){
- surround[i] = xs[i]+ys[i]*n_boxes;
- }
- }
- else{
- int N = 4;
- int[] xs= new int[N];
- int[] ys= new int[N];
- this.surround = new int[N];
- ys[0] = (n_boxes + y-1)%n_boxes;
- ys[1] = y;
- ys[2] = y;
- ys[3] = (y+1)%n_boxes;
- xs[0] = x;
- xs[1] = (n_boxes + x-1)%n_boxes;
- xs[2] = (x+1) %n_boxes;
- xs[3] = x;
- for (int i=0; i<N; i++){
- surround[i] = xs[i]+(ys[i]*n_boxes);
- }
- }
- }
- }
- }
|