Created
January 13, 2020 13:23
-
-
Save avinayak/d2c99b4be6334a57098b78e889abc6d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AccelerometerManager accel; | |
float ax, ay, az; | |
void setup() { | |
accel = new AccelerometerManager(this); | |
orientation(PORTRAIT); | |
background (0); | |
fill(255); | |
flakes = new flake [N]; | |
for(int i=0;i<N;i++) | |
flakes[i]=new flake(random(1)*width, | |
random(1)*height, | |
random(2), | |
random(2), | |
random(3000), | |
random(2)); | |
} | |
int N = 50; | |
class flake { | |
public float x; | |
public float y; | |
public float yv; | |
public float xv; | |
public float s; | |
public float r; | |
flake(float _x,float _y, float _yv,float _xv,float _s,float _r){ | |
this.x = _x; | |
this.y = _y; | |
this.yv = _yv; | |
this.xv = _xv; | |
this.s = _s; | |
this.r = _r; | |
} | |
} | |
flake[] flakes; | |
float i=0; | |
void draw() { | |
fill(0,0,0,170); | |
rect(-10,-10,width+10, height+10); | |
fill(255); | |
stroke(255); | |
if(mousePressed){ | |
} | |
for(int j=0;j<N;j++){ | |
float rad = flakes[j].r*4;//noise(i*0.01)*200 | |
flakes[j].y += flakes[j].yv; | |
flakes[j].x -= 2*(0.5-noise(flakes[j].s)); | |
flakes[j].y += 2*(0.5-noise(flakes[j].s)); | |
flakes[j].x -= flakes[j].xv; | |
flakes[j].s += 0.01*flakes[j].r; | |
flakes[j].yv = ay*0.314; | |
flakes[j].xv = ax*0.314; | |
ellipse(flakes[j].x ,flakes[j].y ,rad,rad); | |
if(flakes[j].y > height) | |
flakes[j].y = 0; | |
if(flakes[j].y<0) | |
flakes[j].y = height; | |
if(flakes[j].x > width) | |
flakes[j].x =0; | |
if(flakes[j].x < 0) | |
flakes[j].x = width; | |
} | |
} | |
public void resume() { | |
if (accel != null) { | |
accel.resume(); | |
} | |
} | |
public void pause() { | |
if (accel != null) { | |
accel.pause(); | |
} | |
} | |
public void shakeEvent(float force) { | |
println("shake : " + force); | |
} | |
public void accelerationEvent(float x, float y, float z) { | |
// println("acceleration: " + x + ", " + y + ", " + z); | |
ax = x; | |
ay = y; | |
az = z; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment