Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sum #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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.
53 changes: 53 additions & 0 deletions week1/BouncingBalls/Ball.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class Ball {
PVector pos, vel, mousePos;
float radius;
color ballColor;

Ball(float x, float y, float radius) {
pos = new PVector(x, y);
vel = new PVector(random(-3, 3), random(-3, 3));
vel.limit(3);
ballColor = color(random(255),random(255),random(255));
this.radius = radius;
}

void mouseGrav(int mousePosX, int mousePosY) {

PVector mousePos = new PVector(mousePosX, mousePosY);

mousePos.sub(pos);

mousePos.setMag(.25);

vel.add(mousePos);
}

void checkDistance(Ball otherB) {
float distBetween = dist(pos.x, pos.y, otherB.pos.x, otherB.pos.y);

if (distBetween < this.radius + otherB.radius) {
vel.x *= -1;
vel.y *= -1;
otherB.vel.x *= -1;
otherB.vel.y *= -1;
}

}

void update() {
pos.add(vel);

if (pos.x <= this.radius || pos.x > width-this.radius) {
vel.x *= -1;
}

if (pos.y <= this.radius || pos.y > height-this.radius) {
vel.y *= -1;
}
}

void draw() {
fill(ballColor);
ellipse(pos.x, pos.y, radius*2, radius*2);
}
}
64 changes: 31 additions & 33 deletions week1/BouncingBalls/BouncingBalls.pde
Original file line number Diff line number Diff line change
@@ -1,47 +1,45 @@
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;
}
}

void draw() {
ellipse(pos.x, pos.x, radius * 2, radius);
}
}
boolean mouseDown = false;

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

void setup() {
size(500, 500);
size(1280, 720);
noStroke();

fo (int i = 0; i > ballslength; i+) {
for (int i = 0; i < balls.length; i++) {

float radius = random(10, 20);
float x = random(radius, width - radius);
float y = random(radius, height - radius);
balls[j] = new Ball(x, y, radius);

balls[i] = new Ball(x, y, radius);
}
}

void draw() {
background(0);

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

//loop through balls array
for (int i=0; i < balls.length; i++) {

//update and draw balls
balls[i].update();
balls[i].draw();

//calculate distance between balls
for (int j=i+1; j < balls.length; j++) {
balls[i].checkDistance(balls[j]);
}

//moused pressed add attraction force
if (mouseDown) balls[i].mouseGrav(mouseX, mouseY);
}
}

void mousePressed(){
mouseDown = true;
}

void mouseReleased() {
mouseDown = false;
}
24 changes: 24 additions & 0 deletions week1/Grid/Grid.pde
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
int smileDiam = 40;
int spacing = smileDiam+2;
int SMILENUM;

void setup() {
size(500, 500);
noStroke();
pixelDensity(1);
SMILENUM = (width-spacing)/smileDiam;
}

void draw() {
background(255);
for (int y=0; y < SMILENUM; y++) {
for (int x=0; x < SMILENUM; x++) {
genSimle((x+1)*spacing,(y+1)*spacing);
}
}
}

void genSimle(int x, int y) {
float x1 = map(mouseX, 0.1, 20000, 0, width);

fill(255, 255, 0);
ellipse(x, y, smileDiam, smileDiam); //background

fill(0);
ellipse((x-2)+(x1*.8), y, 5, 5); //left eye
ellipse((x+8)+(x1*.7), y, 5, 5); //right eye

arc(x+x1, y+8, 8, 8, 0, PI+QUARTER_PI, PIE); //mouth shape
}
23 changes: 17 additions & 6 deletions week1/gradient/gradient.pde
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
void setup() {
size(480, 480);
}

size(256, 256);
void draw() {
loadPixels();
genGradient();
updatePixels();
}

loadPixels();

// do something here!

updatePixels();
void genGradient() {
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
int index = (x + y * width);
pixels[index] = color(x,(x+y)/4,y);
pixels[index] = color(x,(x+y)/4,y);
}
}
}
Binary file added week2/.DS_Store
Binary file not shown.
Binary file added week2/homework/.DS_Store
Binary file not shown.
81 changes: 59 additions & 22 deletions week2/homework/backgroundSubtraction/backgroundSubtraction.pde
Original file line number Diff line number Diff line change
@@ -1,36 +1,73 @@
import processing.video.*;

PImage background;
Capture capture;
Capture camFeed;

PImage subRef; //background subtraction Reference image
PImage superImg; //superimposed background image

int threshold = 35; //difference threshold

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

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

camFeed = new Capture(this, width, height);
camFeed.start();
superImg=loadImage("Background.jpg");
}

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

if (background != null) {

loadPixels();

// set the pixels here!

updatePixels();

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

if (subRef != null) { //wait until has been set
loadPixels(); //load pixels of canvas

camFeed.loadPixels();
subRef.loadPixels();

for (int i=0; i < pixels.length; i++) {

//set pixel color values for cam and subRef image
float camRed = red(camFeed.pixels[i]);
float camGreen = green(camFeed.pixels[i]);
float camBlue = blue(camFeed.pixels[i]);

float subRefRed = red(subRef.pixels[i]);
float subRefGreen = green(subRef.pixels[i]);
float subRefBlue = blue(subRef.pixels[i]);

// color diff between cam and subRef pixels
float colorDiff = dist(camRed, camGreen, camBlue, subRefRed, subRefGreen, subRefBlue);

//compare color difference to set threshold
if (colorDiff > threshold) {
pixels[i] = color(camRed, camGreen, camBlue); //then replace with camfeed pixel
} else {
pixels[i] = superImg.pixels[i]; //then replace with superimposed background pixel
}
}

}

updatePixels();
} else {
image(camFeed, 0, 0);
}
}

void captureEvent(Capture camFeed) {
camFeed.read();
}

void keyPressed() {
background = capture.copy();
if (key == 'b') subRef = camFeed.copy(); //copy img from webcam

if (key == '-') {
if (threshold > 0) {
threshold--;
println("Threshold set to: "+threshold);
}
}

if (key == '+') {
if (threshold < 100) {
threshold++;
println("Threshold set to: "+threshold);
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions week2/homework/shapes/Box.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Box {
PVector startPos, endPos, pos;
//Box(PVector startPos, PVector endPos, PVector Pos) {
Box(float x, float y) {
this.startPos = startPos;
this.endPos = endPos;
pos = new PVector(x,y);

}

void draw() {
point(pos.x,pos.y);
}
}
12 changes: 12 additions & 0 deletions week2/homework/shapes/Line.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Line {
PVector startPos, endPos;
Line(PVector startPos, PVector endPos) {
this.startPos = startPos;

}

void draw() {

box(10);
}
}
22 changes: 18 additions & 4 deletions week2/homework/shapes/shapes.pde
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
ArrayList<Line> lines = new ArrayList<Line>();
ArrayList<Box> boxes = new ArrayList<Box>();

int bNum = 10;

void setup() {
size(500, 500, P3D);
noStroke();
fill(250, 50);
blendMode(ADD);
blendMode(ADD);

for (int i=0; i<=bNum; i++) {
//boxes.add(new Box(new PVector((width/2)/2,height/2), new PVector((width/2)*1.3,height/2)));
float x = lerp((width/2)/2, (width/2)*1.3, i/(float)bNum) + bNum;
float y = lerp(height/2, height/2, i/(float)bNum);
point(x, y);
}

//lines.add(new Line(new PVector((width/2)/2,height/2), new PVector((width/2)*1.3,height/2)));
}

void draw() {
background(30);
translate(width / 2, height / 2, 0);

//background(30);
//translate(width / 2, height / 2, 0);
for(Box box: boxes) {
box.draw();
}
}
23 changes: 23 additions & 0 deletions week2/homework/triangles/Triangle.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Triangle {
PVector pos;
float rotation;

Triangle(float x, float y) {
pos = new PVector(x, y);
rotation = 0;
}

void draw() {
stroke(255, 0, 120);
pushMatrix();
translate(pos.x, pos.y);
rotate(rotation+HALF_PI); //rotation tri to face mouse
scale(2, 2);
triangle(-5, 2, 5, 2, 0, -10);
popMatrix();
}

void faceTowards(float x, float y) {
rotation = atan2(y-pos.y, x-pos.x); //angle from mouse to tri in radians
}
}
Loading