// ran tao // 10.16.06 // nature of code // midterm // creating a creature float const_mass = 10; float const_k = 0.6; float const_dist = 100; float const_bounce = 0.25; float const_friction = 0.95; float const_gravityx = 0; float const_gravityy = 0; boingy b; int n = 12; float c = 1; void setup() { size(600, 600); b = new boingy(n); stroke(0, 0, 0, 172); fill(255, 0, 0, 172); ellipseMode(CENTER); smooth(); } void draw() { background(255); b.go(); if (mousePressed) { const_gravityx = (float)(mouseX - width/2)/150.0; const_gravityy = (float)(mouseY - height/2)/150.0; //translate(width/2, height/2); //const_gravityx = (float)(mouseX)/100.0; //const_gravityy = (float)(mouseY)/100.0; //b.mouse(); } else { int tmp = 4; if (tmp >0) { const_gravityx += .0005; const_gravityy += .0005; tmp --; //b.noMouse(); } if (tmp == 0) tmp = -4; if (tmp < 0){ const_gravityx -= .0005; const_gravityy -= .0005; tmp ++; } } } void keyPressed() { if (key == '-' && n > 3) n--; if (key == '+' && n < 25) n++; if (key == '-' || key == '+') b = new boingy(n); if (key == CODED) { if (keyCode == LEFT) b.moveLeft(); if (keyCode == RIGHT) b.moveRight(); if (keyCode == UP) b.moveUp(); if (keyCode == DOWN) b.moveDown(); } }