noise function - does it accelerate?
in
Programming Questions
•
1 year ago
i dont know why this code seems to get fast over time?
the "worm" starts off wiggling nice and smooth, but by a few seconds in gets more and more until the ellipses form a tight spiral. but i cant work out whats accerlerating in my code.
- import processing.opengl.*;
- int ay;
- float zvalue;
- ArrayList blobscollection;
- int arraynumber = 1;
- PVector m2, m3, finalPOS;
- PVector m1 = new PVector(0,0,0);
- PVector shaderoffset = new PVector(2,2);
- PGraphics textureSampler0;
- //////////////////////////////////////////////
- //////////////////////////////////////////////
- //////////////////////////////////////////////
- void setup() {
- size (500, 500, OPENGL);
- textureSampler0 = createGraphics(500, 500, OPENGL);
- float fov = PI/3;
- float cameraZ = (height/2.0) / tan(fov/2.0);
- perspective(fov, float(width)/float(height),
- cameraZ/10.0, cameraZ*10.0);
- blobscollection = new ArrayList();
- frameRate(70);
- }
- //////////////////////////////////////////////
- //////////////////////////////////////////////
- //////////////////////////////////////////////
- void draw() {
- background(0);
- //println("framerate" + frameRate);
- /*
- pushMatrix();
- translate(650,250,-2000);
- scale(50);
- beginShape();
- colorMode(RGB,255,255,255);
- fill(150, 15, 0);
- vertex(-50, -50,0);
- fill(150, 0, 0);
- vertex(-50, 50,0);
- vertex(50, 50,0);
- fill(150, 15, 0);
- vertex(50, -50,0);
- endShape(CLOSE);
- scale(500);
- popMatrix();
- */
- for (int i = blobscollection.size()-1; i > 0; i--) {
- blobs myblobs = (blobs) blobscollection.get(i);
- myblobs.display();
- if (myblobs.zvalue < -2000) {
- // Items can be deleted with remove().
- blobscollection.remove(i);
- }
- }
- ay = (blobscollection.size());
- }
- void mouseMoved() {
- // A new ball object is added to the ArrayList, by default to the end.
- float circle = map ((mouseX+mouseY),0,(width+height),0,PI*2);
- //blobscollection.add(new blobs ((sin(circle)*250+250), (cos(circle)*250+250),arraynumber));
- blobscollection.add(new blobs (mouseX,mouseY,arraynumber));
- arraynumber++;
- if (arraynumber > 500){
- arraynumber = 0;
- }
- }
- class blobs {
- float randomnumber = random(1,3);
- int arraynumber = 0;
- float locx = 0;
- float locy = 0;
- float zvalue = 100;
- blobs(float _locx, float _locy, int _arraynumber) {
- locx = _locx;
- locy = _locy;
- arraynumber = _arraynumber;
- }
- void display() {
- float scaleoffset = ((noise(arraynumber*0.1)*3));
- float translatescale = (noise(arraynumber*0.01));
- float translatescalemap = map(translatescale,0,1,0.15,0.2);
- float randomhue = (noise(arraynumber*0.1)*40)+20;
- float life = map(zvalue,-2000,-50, 0,1);
- float inverselife = map(zvalue,-1000,50, 1,0);
- float translatelife = map(zvalue,-50,0, 1,0);
- float timer = 1.0; //sin(0.05*millis()*PI/90*noise(arraynumber))+1;
- float timer2 = (sin((0.5*millis()*PI/90)*translatescalemap))*(30);
- float timer3 = (cos((0.5*millis()*PI/90)*translatescalemap))*(30);
- zvalue-= 3;
- colorMode(HSB,360,100,100,255);
- pushMatrix();
- noStroke();
- translate(locx+timer2, locy+timer3, zvalue);
- scale(scaleoffset+(timer*0.5));
- fill(randomhue,100,(100*life),255);
- ellipseMode(CENTER);
- ellipse(0,0,(20+scaleoffset),(20+scaleoffset));
- //locx = (locx-250)*0.9999+250;
- //locy = (locy-250)*0.9999+250;
- //println("translatescale" + translatescale);
- popMatrix();
- }
- }
1