Skip to content

Instantly share code, notes, and snippets.

@sampottinger
Created September 15, 2019 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sampottinger/85a76161f959ed407d8f2b87508556dd to your computer and use it in GitHub Desktop.
Save sampottinger/85a76161f959ed407d8f2b87508556dd to your computer and use it in GitHub Desktop.
ArrayList<Female> females = new ArrayList<Female>();
boolean diagp=false; //true;
int many = 5000;
void setup() {
size(800,800,FX2D);
frameRate(120);
for (int i = 0; i < many; i++) {
PVector location = new PVector(height/2, width/2);
int[] colours = {floor(random(255)), floor(random(255)), floor(random(255))};
Female newFem = new Female(location, "female", 1, colours, 16, 10, 10, 10, 10, 50);
for (int x = 0; x < newFem.moves.length; x++) {
newFem.moves[x] = new PVector(random(-0.5, 0.5), random(-0.5, 0.5));
}
females.add(newFem);
}
noStroke();
}
void draw() {
background(255);
// This only cuts about 1 millis
females.stream().parallel().forEach((female) -> {
female.move();
female.wallWrap();
});
for (Female female : females) {
female.display();
}
if ( frameCount%100 == 0 ) println("fps: "+ frameRate );
}
//Breeder entity object
class Ent {
////Abstract properties
int id;
int age;
//'male' or 'female'
String gender;
//PVectors
PVector location;
PVector velocity = new PVector();
//n pixels per frame
float speed;
////Physical properties
//0-255
int[] colour;
//4, 8, 16
int size;
////Combat properties
float hp;
float damage;
float b_velocity;
float f_rate;
////Hunger
boolean hungry = false;
int hunger = 0;
int hungermax;
Ent(PVector location_, String gender_, float speed_, int[] colour_, int size_, float hp_, float damage_, float b_velocity_, float f_rate_) {
id = floor(random(10000000, 99999999));
location = location_;
gender = gender_;
speed = speed_;
colour = colour_;
size = size_;
hp = hp_;
damage = damage_;
b_velocity = b_velocity_;
f_rate = f_rate_;
}
Ent() {
}
//void move(){
// location.add(velocity.x * speed, velocity.y * speed);
//}
//Draw Ent on step
void display() {
fill(colour[0], colour[1], colour[2]);
rect(location.x, location.y, size, size, 5.00);
}
void wallWrap() {
//Wall wrap
if (location.y > height) {
location.y = 0.00;
if (diagp) println("more than height");
}
if (location.y < 0) {
location.y = height;
if (diagp) println("less than height");
}
if (location.x > width) {
location.x = 0.00;
}
if (location.x < 0) {
location.x = width;
}
}
}
class Female extends Ent {
boolean pregnant = false;
int gestation = 0;
int gestperiod;
PVector[] moves = new PVector[90];
int food;
////Movement
//increment
int stepcount = 0;
//change direction when stepcount is a modulus of stepchange
int stepchange;
//which move is it up to
int movenumber = 0;
Female(PVector location_, String gender_, float speed_, int[] colour_, int size_, float hp_, float damage_, float b_velocity_, float f_rate_, int gestperiod_) {
super(location_, gender_, speed_, colour_, size_, hp_, damage_, b_velocity_, f_rate_);
gestperiod = gestperiod_;
stepchange = floor(random(50, 100));
}
void move() {
if (stepcount % stepchange == 0) {
velocity.set(moves[movenumber]);
if (diagp) println(moves[movenumber].x);
if (diagp) println(velocity);
if (diagp) println(stepchange);
movenumber++;
if (movenumber == 90) {
movenumber = 0;
}
}
location.add(velocity);
stepcount++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment