Created
July 25, 2019 13:03
-
-
Save KrabCode/39a5e8707b9b5ffa783597ddadd7723f 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
| ArrayList<V> vs = new ArrayList<V>(); | |
| ArrayList<V> vsBin = new ArrayList<V>(); | |
| float minD = 10; | |
| float maxD = 1920/2; | |
| float t; | |
| float hue; | |
| void setup() { | |
| fullScreen(P2D); | |
| background(0); | |
| noSmooth(); | |
| colorMode(HSB, 1, 1, 1, 1); | |
| } | |
| void mouseReleased() { | |
| vs.add(new V(mouseX, mouseY)); | |
| if(isPointInRect(mouseX, mouseY, 0,0,60,60)){ | |
| reset(); | |
| } | |
| } | |
| void mouseDragged() { | |
| vs.add(new V(mouseX, mouseY)); | |
| } | |
| void draw() { | |
| t = radians(frameCount*.05); | |
| hue = t%1; | |
| /* | |
| if (frameCount % 4 == 0) { | |
| rectMode(CORNER); | |
| blendMode(SUBTRACT); | |
| noStroke(); | |
| fill(0.004); | |
| rect(0, 0, width, height); | |
| blendMode(REPLACE); | |
| } | |
| for(V v : vs){ | |
| if(v.birth + v.lifespan < frameCount){ | |
| vsBin.add(v); | |
| } | |
| } | |
| vs.removeAll(vsBin); | |
| vsBin.clear(); | |
| while(vs.size()>500){ | |
| vs.remove(0); | |
| } | |
| */ | |
| noStroke(); | |
| fill(hue,1,1,1); | |
| rect(10,10,50,50); | |
| beginShape(LINES); | |
| noFill(); | |
| for (V v : vs) { | |
| if (v.neighboursUnknown) { | |
| v.findNeighbours(); | |
| v.neighboursUnknown = false; | |
| } | |
| } | |
| endShape(); | |
| } | |
| void reset(){ | |
| vs.clear(); | |
| background(0); | |
| } | |
| class V { | |
| boolean neighboursUnknown = true; | |
| PVector pos; | |
| ArrayList<V> ns = new ArrayList<V>(); | |
| int birth = frameCount; | |
| int lifespan = 600; | |
| V(float x, float y) { | |
| pos = new PVector(x, y); | |
| } | |
| void findNeighbours() { | |
| strokeWeight(3); | |
| stroke(hue,1,1,1); | |
| vertex(pmouseX, pmouseY); | |
| vertex(pos.x, pos.y); | |
| strokeWeight(1); | |
| for (V v : vs) { | |
| if (v.equals(this)) { | |
| continue; | |
| } | |
| float d = dist(pos.x, pos.y, v.pos.x, v.pos.y); | |
| if (d > minD && d < maxD) { | |
| float dN = map(d, minD, maxD, 0, 1); | |
| if(abs(randomGaussian()) < dN*15){ | |
| continue; | |
| } | |
| stroke(hue, 1, 1, 1-dN); | |
| vertex(v.pos.x, v.pos.y); | |
| vertex(pos.x, pos.y); | |
| } | |
| } | |
| } | |
| } | |
| boolean isPointInRect(float px, float py, float rx, float ry, float rw, float rh) { | |
| return px >= rx && px <= rx + rw && py >= ry && py <= ry + rh; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment