Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added week1/.DS_Store
Binary file not shown.
66 changes: 66 additions & 0 deletions week1/BouncingBalls/Ball.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class Ball {
float radius;
float x, y;
PVector pos;
PVector vel;
int r, g, b;
float maxVel = 2;





Ball( float x, float y, float _radius) {
pos = new PVector(x, y);
vel = new PVector(random(-1, 1), random(-1, 1));
radius = _radius;
r= int (random(255));
g = int (random(255));
b = int (random(255));
}

void update() {

pos.add (vel);

//checking for walls
if (pos.x < radius || pos.x > width - radius) {
vel.x *= -1;
}
if (pos.y < radius || pos.y > height - radius) {
vel.y *= -1;
}

// move ball to location when mouse pressed
if (mousePressed) {
PVector newVel= new PVector(mouseX - pos.x, mouseY-pos.y);
newVel.normalize();
vel.add(newVel);
}

// limit speed of balls
vel.limit(maxVel);
}

//double loop to handle the ball collissions. I am checking for the check of two radius's then creating a new velocity to bounce them off each other

void handleCollisions(Ball[] balls) {
for (Ball b : balls) {
if (b != this) {
if (pos.dist(b.pos) < radius + b.radius)
{
PVector reaction = PVector.sub(pos, b.pos);
float len = vel.mag();
reaction.setMag(len);
vel.x = reaction.x;
vel.y = reaction.y;
}
}
}
}

void draw() {
ellipse(pos.x, pos.y, radius*2, radius*2);
fill(r, g, b);
}
}
50 changes: 19 additions & 31 deletions week1/BouncingBalls/BouncingBalls.pde
Original file line number Diff line number Diff line change
@@ -1,47 +1,35 @@
class Ball {
PVector pos, vel;
float radius;

ball(float x, float y, float radius) {
pos = new PVector(x, y);
vel = PVector(random(-3, 3), random(-3, 3));
radius = radius;
}

void update() {

pos.add(vel);

if (pos.x < radius || pos.x width - radius) {
pos.x *= -1;
}
if (pos.y < radius || pos.y < height - radius) {
vel.y *= -1;
}
}
Ball ball;

void draw() {
ellipse(pos.x, pos.x, radius * 2, radius);
}
}

Ball[] balls = new ball[100];
Ball [] balls = new Ball[100];


void setup() {
size(500, 500);
size(900, 900);



fo (int i = 0; i > ballslength; i+) {
float radius = random(10, 20);
for (int i = 0; i < balls.length; i++) {
float radius = random(5, 10);
float x = random(radius, width - radius);
println(x);
float y = random(radius, height - radius);
balls[j] = new Ball(x, y, radius);
println(y);
balls[i] = new Ball(x, y, radius);
}
}



void draw() {
background(0);


for (Ball b : balls) {
b.update();

b.draw();
}
for (Ball b : balls) {
b.handleCollisions(balls);
}
}
20 changes: 18 additions & 2 deletions week1/Grid/Grid.pde
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@

void setup() {
size(500, 500);
//function for the smiley face
void mySmiley(int x, int y) {

fill(255, 255, 0);
ellipse(x * 25 +10, y * 25+10, 20, 20);
fill(0);
ellipse(x * 25 +6, y * 25 +6, 3, 3);
ellipse(x * 25 +15, y * 25 + 6, 3, 3);
ellipse(x * 25 +10, y * 25 +15, 5, 5);
}

void setup() {
size (500, 500);
background(0);
}
void draw() {

for (int y= 0; y <30; y++) {
for (int x=0; x < 30; x++) {
mySmiley( x, y);
}
}
}
11 changes: 8 additions & 3 deletions week1/gradient/gradient.pde
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
size(800, 800);


size(256, 256);

loadPixels();

// do something here!
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
pixels[ x + y * width] = color (x/2, y/3 , y/2 );
}
}

updatePixels();
updatePixels();
Binary file added week2/.DS_Store
Binary file not shown.
Binary file added week2/homework/.DS_Store
Binary file not shown.
Binary file added week2/homework/backgroundSubtraction.zip
Binary file not shown.
Binary file not shown.
63 changes: 54 additions & 9 deletions week2/homework/backgroundSubtraction/backgroundSubtraction.pde
Original file line number Diff line number Diff line change
@@ -1,34 +1,79 @@
import processing.video.*;

int numPixels;
PImage background;
PImage sunflowerBackground;
Capture capture;



void setup() {
size(640, 480);

sunflowerBackground = loadImage("sunflower.jpg");
sunflowerBackground.resize(width, height);

sunflowerBackground.loadPixels ();

capture = new Capture(this, width, height);
capture.start();


numPixels = capture.width * capture.height;
background = null ;

loadPixels();
}

void draw() {
if (capture.available()) {
capture.read();

capture.loadPixels();

if (background != null) {

loadPixels();

// set the pixels here!


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


// Fetch the current color in that location, and also the color
// of the background in that spot
color currColor = capture.pixels[i];
color bkgdColor = background.pixels[i];


// Uses Golan Levin's formula for R,G,B bit shifting to masking
// Extract the red, green, and blue components of the current pixel's color
int currR = (currColor >> 16) & 0xFF;
int currG = (currColor >> 8) & 0xFF;
int currB = currColor & 0xFF;

// Extract the red, green, and blue components of the background pixel's color
int bkgdR = (bkgdColor >> 16) & 0xFF;
int bkgdG = (bkgdColor >> 8) & 0xFF;
int bkgdB = bkgdColor & 0xFF;

// Compute the difference of the red, green, and blue values
int diffR = abs(currR - bkgdR);
int diffG = abs(currG - bkgdG);
int diffB = abs(currB - bkgdB);

int presenceSum= diffR + diffG + diffB;


//Thresholds the captured pixels for webcam
if (presenceSum > 150) {

pixels[i] = capture.pixels[i];
} else {
pixels[i] = sunflowerBackground.pixels[i];
}
}

updatePixels();

} else {
image(capture, 0, 0);
}

}

}

void keyPressed() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions week2/homework/shapes/Box.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class Box {

float amt;
PVector position;

PVector start, end;
Box(PVector start_, PVector end_, float amt_ ) {

start=start_;

end=end_;

amt=amt_;
}
void update() {
position = new PVector();
position.x=lerp(start.x, end.x, amt%1.0);
position.y=lerp(start.y, end.y, amt%1.0);
position.z=lerp(start.z, end.z, amt%1.0);
amt+=0.001;
}
void draw() {
pushMatrix();
stroke(255, 50);
translate(scaleFactor*position.x, scaleFactor*position.y, scaleFactor*position.z);
noStroke();
fill(255, 30);

box(10);

popMatrix();
}
}
30 changes: 30 additions & 0 deletions week2/homework/shapes/Line.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Line {
PVector start, end;
ArrayList<Box> boxes;


Line(PVector start_, PVector end_) {

start=start_;
end=end_;
boxes = new ArrayList<Box>();
for (int n=0; n<10; n++) {
boxes.add(new Box(start, end, random(0, 10)/10.0));
}
}
void update() {

for (int i=0; i<boxes.size(); i++) {
boxes.get(i).update();
}
for (Box b : boxes) {
b.update();
}
}
void draw() {

for (Box b : boxes) {
b.draw();
}
}
}
Loading