Created
September 13, 2016 11:42
-
-
Save takawo/b9f354f22b72f5d7b45488e452f99eb7 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
| Mover m; | |
| ArrayList<Mover> movers = new ArrayList<Mover>(); | |
| void setup() { | |
| size(500, 500); | |
| colorMode(HSB, 360, 100, 100); | |
| noStroke(); | |
| for (int i = 0; i < 20; i++) { | |
| m = new Mover(random(width), random(height), 10); | |
| movers.add(m); | |
| } | |
| } | |
| void draw() { | |
| background(0, 0, 100); | |
| for (Mover m : movers) { | |
| m.update(); | |
| m.draw(); | |
| for(Mover m2 : movers){ | |
| if(m.equals(m2) != true){ | |
| float dist = m.calDist(m2); | |
| if(dist < 10*2){ | |
| m.vel.mult(-1); | |
| m2.vel.mult(-1); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| class Mover { | |
| float r = 50; | |
| PVector loc; | |
| PVector vel; | |
| float angle; | |
| float amp1, amp2; | |
| PVector p1, p2, p3, p4; | |
| color c; | |
| Mover(float x, float y, float r) { | |
| loc = new PVector(x, y); | |
| vel = new PVector(random(-.5, .5), random(-.5, .5)); | |
| this.r = r; | |
| amp1 = random(0.01, 0.1); | |
| amp2 = random(0.01, 0.1); | |
| c = color(random(100,180),random(40,80),80); | |
| } | |
| void update() { | |
| loc.add(vel); | |
| println(angle); | |
| if(loc.x < 0 || loc.x > width){ | |
| vel.x *= -1; | |
| } | |
| if(loc.y < 0 || loc.y > height){ | |
| vel.y *= -1; | |
| } | |
| } | |
| boolean equals(Mover m){ | |
| return loc.equals(m.loc); | |
| } | |
| float calDist(Mover m){ | |
| return dist(loc.x,loc.y,m.loc.x,m.loc.y); | |
| } | |
| void draw() { | |
| fill(c); | |
| pushMatrix(); | |
| translate(loc.x, loc.y); | |
| angle = atan2(vel.y, vel.x)+PI/2; | |
| rotate(angle); | |
| p1 = new PVector( | |
| cos(radians(0))*map(noise(vel.x,frameCount*amp1), 0, 1, r/2, r), | |
| sin(radians(0))*r | |
| ); | |
| p2 = new PVector( | |
| cos(radians(90))*(r*2), | |
| sin(radians(90))*(map(noise(vel.y,frameCount*amp2), 0, 1, r/2, r)*2) | |
| ); | |
| p3 = new PVector( | |
| cos(radians(180))*map(noise(vel.x,frameCount*amp1), 0, 1, r/2, r), | |
| sin(radians(180))*r | |
| ); | |
| p4 = new PVector( | |
| cos(radians(270))*r, | |
| sin(radians(270))*r | |
| ); | |
| // fill(0, 0, 100); | |
| // ellipse(p1.x, p1.y, 3, 3); | |
| // ellipse(p2.x, p2.y, 3, 3); | |
| // ellipse(p3.x, p3.y, 3, 3); | |
| // ellipse(p4.x, p4.y, 3, 3); | |
| // fill(0, 0, 0); | |
| // ellipse(p1.x, p1.y-r/2, 3, 3); | |
| // ellipse(p1.x, p1.y+r/2, 3, 3); | |
| // ellipse(p2.x-r/2, p2.y, 3, 3); | |
| // ellipse(p2.x+r/2, p2.y, 3, 3); | |
| // ellipse(p3.x, p3.y-r/2, 3, 3); | |
| // ellipse(p3.x, p3.y+r/2, 3, 3); | |
| // ellipse(p4.x-r/2, p4.y, 3, 3); | |
| // ellipse(p4.x+r/2, p4.y, 3, 3); | |
| // noFill(); | |
| beginShape(); | |
| vertex(p1.x, p1.y); | |
| bezierVertex( | |
| p1.x, p1.y+r/2, | |
| p2.x+r/2, p2.y, | |
| p2.x, p2.y | |
| ); | |
| bezierVertex( | |
| p2.x-r/2, p2.y, | |
| p3.x, p3.y+r/2, | |
| p3.x, p3.y | |
| ); | |
| bezierVertex( | |
| p3.x, p3.y-r/2, | |
| p4.x-r/2, p4.y, | |
| p4.x, p4.y | |
| ); | |
| bezierVertex( | |
| p4.x+r/2, p4.y, | |
| p1.x, p1.y-r/2, | |
| p1.x, p1.y | |
| ); | |
| endShape(CLOSE); | |
| popMatrix(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment