Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.thomasdiewald.pixelflow.java.DwPixelFlow;
- import com.thomasdiewald.pixelflow.java.imageprocessing.filter.DwFilter;
- import toxi.geom.*;
- import toxi.physics2d.*;
- import toxi.physics2d.behaviors.*;
- import toxi.util.*;
- VerletPhysics2D physics;
- Vec2D mouse;
- AttractionBehavior2D mouseAttractor;
- PGraphics2D pg_render;
- PGraphics2D pg_luminance;
- PGraphics2D pg_bloom;
- DwPixelFlow context;
- DwFilter filter;
- void setup() {
- size(1000, 400, P2D);
- frameRate(1000);
- colorMode(HSB, 100);
- //fullScreen();
- physics = new VerletPhysics2D();
- int divPoints = 50;
- for (int i = 0; i < 30; i++) {
- VerletParticle2D a = new VerletParticle2D(15, random(50, height - 50));
- VerletParticle2D b = new VerletParticle2D(width - 15, random(50, height - 50));
- a.lock();
- b.lock();
- ArrayList<VerletParticle2D> particles = new ArrayList<VerletParticle2D>();
- particles.add(a);
- for (int j = 1; j < divPoints; j++) {
- Vec2D diff = b.sub(a);
- float distance = diff.magnitude() / divPoints * j;
- diff.normalizeTo(distance);
- diff.addSelf(a);
- VerletParticle2D vp = new VerletParticle2D(diff);
- particles.add(vp);
- }
- particles.add(b);
- ParticleString2D string = new ParticleString2D(physics, particles, 1);
- }
- for (VerletParticle2D vp1 : physics.particles) {
- for (VerletParticle2D vp2 : physics.particles) {
- float distance = vp1.distanceTo(vp2);
- if (distance > 0 && distance < 10) {
- VerletSpring2D spring = new VerletSpring2D(vp1, vp2, 2, 0.1);
- physics.addSpring(spring);
- }
- }
- }
- pg_render = (PGraphics2D) createGraphics(width, height, P2D);
- pg_render.smooth(8);
- pg_luminance = (PGraphics2D) createGraphics(width, height, P2D);
- pg_luminance.smooth(8);
- pg_bloom = (PGraphics2D) createGraphics(width, height, P2D);
- pg_bloom.smooth(0);
- context = new DwPixelFlow(this);
- filter = new DwFilter(context);
- }
- void draw() {
- background(50);
- pg_render.beginDraw();
- pg_render.colorMode(HSB, 100);
- pg_render.background(0);
- pg_render.stroke(100);
- for (VerletSpring2D spring : physics.springs) {
- pg_render.line(spring.a.x, spring.a.y, spring.b.x, spring.b.y);
- }
- pg_render.noStroke();
- //pg_render.fill(255);
- for (VerletParticle2D p : physics.particles) {
- pg_render.fill(map(p.x, 0, width, 0, 100), 100, 100);
- pg_render.ellipse(p.x, p.y, 5, 5);
- }
- pg_render.endDraw();
- physics.update();
- filter.luminance_threshold.param.threshold = 0f; // when 0, all colors are used
- filter.luminance_threshold.param.exponent = 100;
- filter.luminance_threshold.apply(pg_render, pg_luminance);
- filter.bloom.param.mult = 2.7;
- filter.bloom.param.radius = 0.04;
- filter.bloom.apply(pg_luminance, pg_bloom, pg_render);
- filter.copy.apply(pg_bloom, pg_render);
- image(pg_render, 0, 0);
- surface.setTitle(DateUtils.timeStampGMT() + " " + frameRate + " fps");
- }
- void mousePressed() {
- mouse = new Vec2D(mouseX, mouseY);
- mouseAttractor = new AttractionBehavior2D(mouse, 250, 0.9);
- physics.addBehavior(mouseAttractor);
- }
- void mouseReleased() {
- physics.removeBehavior(mouseAttractor);
- }
- void mouseDragged() {
- mouse.set(mouseX, mouseY);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement