• Rob George

Week 11: Dynamic Mask + Noise + Random Bezier

In Class Task 1: Dynamic Mask

We reviewed masks and this time animated them to create a more dynamic mask over our Paris image.


//Task 1 Dynamic Mask in Shape of Ellipse


PImage img;

PGraphics mask;

float diam;


void setup() {

size(800, 800);

img=loadImage("paris.jpg");

frameRate(10);

}


void draw() {

background(255, 0, 0);

image(img, 0, 0);


//mask

mask=createGraphics(img.width, img.height);

mask.beginDraw();

mask.background(0);

mask.noStroke();


for (int i=0; i<50; i++) {

//mask.fill(255); //the mask is opaque

mask.fill(255, 100); //mask is transparent

diam = random(50, 150);

mask.ellipse(random(mask.width/4, mask.width-120), random(mask.height/10, mask.height-100), diam, diam);

}


mask.endDraw();


//apply mask to the img

img.mask(mask);

}


In Class Lesson 1: Noise

I then learned about noise which is a technique in code that allows you to randomly generate art.

//random lines across the screen


float x, y;


void setup(){

size(600, 400);

background(255);

}


void draw(){

//vertical lines

//x=random(width);

stroke(0, 20);

x=map(noise(0.01*frameCount), 0, 1, 0, width);

line(x, 0, x, height);

//horizontal lines

stroke(0, 20);

y=map(noise(0.01*frameCount+5), 0, 1, 0, height);

line(0, y, width, y);

}



I really enjoyed this use of Noise. The squiggly tube of circles reminds me of either a slinky with a mind of it's own or intestines...strange right?

//noise vs random circles


float x, y;

float t;


void setup(){

size(800,800);

background(0);

}


void draw(){

fill(255);

//ellipse(random(width), random(height), 80,80);

x = map(noise(0.01*t), 0, 1, 0, width);

y = map(noise(0.013*t), 0, 1, 0, height);

ellipse(x, y, 80, 80);

t=t+1;

}


I then played around with color and opacity for this one by learning how to apply noise to rgba (red, green, blue, opacity).

//noise rgba


float x, y, diam;

float t;

float r, g, b, a;


void setup(){

size(800,800);

background(255);

}


void draw(){

fill(r, g, b, a);

//ellipse(random(width), random(height), 80,80);

x = map(noise(0.01*t), 0, 1, 0, width);

y = map(noise(0.013*t), 0, 1, 0, height);

diam = map(noise(0.01*t+10), 0, 1, 20, 100);

//color

r = map(noise(0.01*t+15), 0, 1, 0, 255);

g = map(noise(0.01*t+20), 0, 1, 0, 255);

b = map(noise(0.01*t+25), 0, 1, 0, 255);

a = map(noise(0.01*t+30), 0, 1, 0, 100);

ellipse(x, y, diam, diam);

t=t+1;

}


Using noise, I applied this new code to the dynamic mask mentioned earlier.

//Task 1 Dynamic Mask with Noise


PImage img;

PGraphics mask;

float diam;


void setup() {

size(800, 800);

img=loadImage("paris.jpg");

//frameRate(10);

}


void draw() {

background(255, 0, 0);

image(img, 0, 0);


//mask

mask=createGraphics(img.width, img.height);

mask.beginDraw();

mask.background(0);

mask.noStroke();


for (int i=0; i<150; i++) {

//mask.fill(255); //the mask is opaque

mask.fill(255, 100); //mask is transparent

float x=map(noise(0.01*frameCount, i+5), 0, 1, 0, mask.width);

float y=map(noise(0.01*frameCount+5, i+10), 0, 1, 0, mask.height);

float w=map(noise(0.01*frameCount+10, i+15), 0, 1, 20, 200);

float h=map(noise(0.01*frameCount+15, i+20), 0, 1, 20, 200);

mask.rect(x, y, w, h);

}


mask.endDraw();


//apply mask to the img

img.mask(mask);

}


In Class Lesson 2: Random Bezier

Next I learned about Bezier, a simple way to randomly generate art.

I felt this first Bezier practice looked like loose hair clumped together.

// bezier randomizer


float x1, y1, x2, y2, x3, y3, x4, y4;


void setup(){

size(800,800);

background(255);

}


void draw(){

noFill();

x1=random(width);

x2=random(width);

x3=random(width);

x4=random(width);

y1=random(height);

y2=random(height);

y3=random(height);

y4=random(height);

bezier(x1, y1, x2, y2, x3, y3, x4, y4);


}


We then took it a step further and added noise to the Bezier.

// bezier randomizer


float x1, y1, x2, y2, x3, y3, x4, y4;


void setup() {

size(800, 800);

background(255);

frameRate(100);

}


void draw() {


stroke(#A920E5, 20);

noFill();

x1=map(noise(0.001*frameCount), 0, 1, 0, width);

x2=map(noise(0.001*frameCount+5), 0, 1, 0, width);

x3=map(noise(0.001*frameCount+10), 0, 1, 0, width);

x4=map(noise(0.001*frameCount+15), 0, 1, 0, width);


y1=map(noise(0.001*frameCount+20), 0, 1, 0, height);

y2=map(noise(0.001*frameCount+25), 0, 1, 0, height);

y3=map(noise(0.001*frameCount+30), 0, 1, 0, height);

y4=map(noise(0.001*frameCount+35), 0, 1, 0, height);


bezier(x1, y1, x2, y2, x3, y3, x4, y4);


stroke(#2032E5, 20);

x1=map(noise(0.001*frameCount+50), 0, 1, 0, width);

x2=map(noise(0.001*frameCount+55), 0, 1, 0, width);

x3=map(noise(0.001*frameCount+60), 0, 1, 0, width);

x4=map(noise(0.001*frameCount+65), 0, 1, 0, width);


y1=map(noise(0.001*frameCount+70), 0, 1, 0, height);

y2=map(noise(0.001*frameCount+75), 0, 1, 0, height);

y3=map(noise(0.001*frameCount+80), 0, 1, 0, height);

y4=map(noise(0.001*frameCount+85), 0, 1, 0, height);


bezier(x1, y1, x2, y2, x3, y3, x4, y4);

}


void keyPressed() {

if (key=='s') {

int random_number=int(random(100));

save(random_number+"bezier"+"rob"+".png");

}

}



< Return to Coding Page

2 views0 comments