pollen:Merging codes
in
Programming Questions
•
1 year ago
Hey I'm really new to processing and I'm trying to merge 2 bits of code, they both run separately but I can't figure out what I am doing wrong when I put them together? Any help would be much appreciated.
here's each code:
//import processing.opengl.*;
PFont displayFont; //font
//PImage bg;
int fullScreenX = 825;//screen dimensions
int fullScreenY = 617;
int padding = 150;
int numBugs = 200;//number of bugs, people on social group
int bugSize = 1;
bug[] bugs;//declare array
String bugCounter = "bug";
float milliTick = 1500; //stand in for heart rate info
void setup() {
frameRate(30);
size (600, 600);
//displayFont = loadFont("LucidaGrande-48.vlw"); //font
//textFont(displayFont, 11); //font
//bg = loadImage("bg.png");
smooth();
bugs = new bug[numBugs];
for (int i = 0; i < numBugs; i++){//assisgns values to each bug
bugs[i] = new bug(round(random(width)), round(random(padding, height - padding)), random(2), random(2), bugSize);
if (i%100 == 0){
bugSize++;
padding = padding - 20;
}
}
}
void draw() {
background(11,82,103);
//image(bg, 0, 0);
for (int i = 0; i < numBugs; i++){
bugs[i].move();
bugs[i].display();
bugs[i].glow(round(random(600, milliTick)));
}
counter(10, 12);
}
void counter(int x, int y){
fill(200);
rect (x, y, 100, 15);
fill(0);
if (numBugs == 1){
bugCounter = numBugs + " pollen grains"; //pollen counter
}
else {
bugCounter = numBugs + " pollen grains";
}
text(bugCounter, x + 3, y + 11);
}
BUG CLASS:
class bug {
int diameter;
int brightAdjust = 10;//getting brighter or darker
int bright = 0;//how bright at the moment
boolean glowing = true;//is it glowing
float x, y, xmove, ymove;
//for movement
float angle = 0.0;
float speed = 0.03;
float displacement = 0.2;
//constructor
bug(float xpos, float ypos, float sx, float sy, int dia){
x = xpos;//assigned higher in code^
y = ypos;//assigned higher in code^
diameter = dia;
xmove = sx;
ymove = sy;
}
void move() {
angle += speed;//moves the item forward
float sinval = sin(angle);
float cosval = cos(angle);
float _x = x + (cosval * displacement);// x here shifts the bugs into position
float _y = y + (sinval * displacement);// y here shifts the bugs into position
float x2 = _x + cos(angle * xmove) * displacement/2;
float y2 = _y + sin(angle * ymove) * displacement/2;
ellipse(x2, y2, 10, 10);
x = x2;
y = y2;
}
void display(){
noStroke();
/*bug * * * * */
fill((bright/2) + 20);
ellipse(x, y, diameter, diameter);
}
void glow(int speed){
// (( (halo) )) \\
//speed/(1000/frameRate) formula to find out how many frames are needed to match miliseconds
//44 is how long it takes the light to strobe
if ((frameCount%(round(speed/(1000/frameRate))+ 44) ) == 0){
glowing = true;
}
if(glowing){//glow sequence
bright = bright + brightAdjust;//get brighter
if(bright >= 255){
brightAdjust = -10;//get darker
}
else if (bright <= 0){
bright=0;//nothing, darkest, 0
glowing=false;//stop glowing sequance
brightAdjust = 10;//return brightness adjustment to former state
}
}
fill(200, 200, 0, bright/3);//brightness of halo
ellipse(x, y, diameter * 10, diameter * 10); //halo itself
}
}
SWAYING PLANTS
//VAR
float inc=0.0; //for tail
void setup ()
{
size (500,500);
stroke(255,204);
smooth();
}
void draw (){
background(0);
inc +=0.01;
float angle2=sin(inc)/10.0+sin(inc*1.2)/20.0;
tail(18,9,angle2/1.3);
tail(33,12,angle2);
}
void tail(int x,int units2, float angle2) {
pushMatrix();
translate(x,500);
for (int j=units2; j>0; j--) {
strokeWeight(j);
line (0,0,0,-3);
translate(0,-8);
rotate(angle2);
}
popMatrix();
}
ideally i wanted to try and move the pollen with the grass plants at the bottom of the screen
1