Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- How to use :
- Create the object, then init it in setup()
- Call its render() method at the end of draw()
- Call its method build() to get a new pattern
- */
- final int F_CIRCLE = 0;
- final int F_PAUSE = 1;
- final int F_RING = 2;
- final int F_PATTERN_DIAL = 3;
- final int F_STRIPES = 4;
- class Filter {
- PShape shape;
- int mode = floor(random(0, 5));
- Filter() {
- this.build();
- }
- void build() {
- shape = createShape();
- shape.beginShape();
- shape.fill(0);
- shape.noStroke();
- this.vertScreen();
- // Style for the contours
- shape.fill(0);
- shape.stroke(255);
- shape.strokeWeight(3.0);
- if ( mode == F_CIRCLE ) {
- shape.fill(255);
- shape.stroke(0);
- shape.strokeWeight(3.0);
- this.vertCircle(new PVector(width/2, height/2), 430);
- }
- if ( mode == F_PAUSE ) {
- this.makePause();
- }
- if ( mode == F_RING ) {
- this.makeRing();
- }
- if ( mode == F_PATTERN_DIAL ) {
- this.makeDial();
- }
- if ( mode == F_STRIPES ) {
- this.makeStripes();
- }
- shape.endShape(CLOSE);
- }
- void render() {
- shape(shape);
- }
- void vertScreen() {
- shape.vertex(0, 0);
- shape.vertex(width, 0);
- shape.vertex(width, height);
- shape.vertex(0, height);
- }
- void vertCircle(PVector pos, float radius) {
- shape.beginContour();
- float step = TWO_PI / 150;
- for ( float a = TWO_PI; a > 0.0; a -= step ) {
- shape.vertex(
- pos.x + cos(a) * radius,
- pos.y + sin(a) * radius);
- }
- shape.endContour();
- }
- void vertRect(PVector pos, PVector dim) {
- shape.beginContour();
- dim.mult(0.5);
- shape.vertex(pos.x - dim.x, pos.y - dim.y);
- shape.vertex(pos.x - dim.x, pos.y + dim.y);
- shape.vertex(pos.x + dim.x, pos.y + dim.y);
- shape.vertex(pos.x + dim.x, pos.y - dim.y);
- shape.endContour();
- }
- void makeDial() {
- float size = 210 + random(-100, 100);
- float spacing = 250 + random(-100, 100);
- PVector origin = new PVector(width/2, height/2);
- int[][] placer = {
- {-1, -1},
- {0, -1},
- {1, -1},
- {-1, 0},
- {1, 0},
- {-1, 1},
- {0, 1},
- {1, 1},
- };
- for ( int i = 0; i < 8; ++i ) {
- PVector pos = new PVector(placer[i][0]*spacing, placer[i][1]*spacing);
- pos.add(origin);
- if ( random(1) > 0.3 ) {
- if ( random(1) > 0.5 ) {
- this.vertRect(pos, new PVector(size, size));
- } else {
- this.vertCircle(pos, size/2);
- }
- }
- }
- }
- void makePause() {
- float spacing = random(width * 0.1, width * 0.3);
- float w = random(100, 300);
- float h = random(400, 700);
- this.vertRect(new PVector(width*0.5-spacing, height/2), new PVector(w, h));
- this.vertRect(new PVector(width*0.5+spacing, height/2), new PVector(w, h));
- }
- void makeRing() {
- float outerRadius = random(300, 450);
- float innerRadius = outerRadius - random(50, 290);
- this.vertCircle(new PVector(width/2, height/2), outerRadius);
- this.vertCircle(new PVector(width/2, height/2), innerRadius);
- }
- void makeStripes() {
- int count = floor(random(1, 6));
- float w = width * 0.7;
- float h = random(20, 100);
- float spacing = h + random(10, 50);
- PVector pos = new PVector(width/2, height/2);
- pos.y -= (spacing*count)/2;
- for ( int i = 0; i < count; ++i ) {
- this.vertRect(pos, new PVector(w, h));
- pos.y += spacing;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement