Skip to content
Open

hi #6

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
45 changes: 30 additions & 15 deletions week1/BouncingBalls/BouncingBalls.pde
Original file line number Diff line number Diff line change
@@ -1,47 +1,62 @@
Ball[] balls = new Ball[20];

class Ball {
PVector pos, vel;
float radius;



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

}


void update() {

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

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

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

Ball[] balls = new ball[100];



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

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) {

fill(random(0,224),random(67,212),random(34,176),random(43,189));
b.draw();
b.update();

}

}

}
62 changes: 62 additions & 0 deletions week1/BouncingBalls/W_Tang_WK01BouncingBalls.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Ball[] balls = new Ball[20];

class Ball {
PVector pos, vel;
float radius;



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

}


void update() {

pos.add(vel);

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

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




void setup() {
size(800, 800);

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[i] = new Ball(x, y, radius);

}


}

void draw() {
background(0);

for (Ball b : balls) {

fill(random(0,224),random(67,212),random(34,176),random(43,189));
b.draw();
b.update();

}

}
Empty file modified week1/BouncingBalls/readme.md
100644 → 100755
Empty file.
Binary file added week1/Grid/.DS_Store
Binary file not shown.
31 changes: 29 additions & 2 deletions week1/Grid/Grid.pde
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@

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

void draw() {
for (int y = 0; y<10; y++) {
for (int x = 0; x<10; x++) {
smile(x*60, y*60);

}
}
}

void smile(int _x, int _y) {
int x =_x+30;
int y=_y+30;

//face
noStroke();
fill(255, 235, 15);
ellipse(x, y, 60, 60);

//eye
fill(0);
ellipse( x-10, y-10, 10, 10);
ellipse( x+10, y-10, 10, 10);


//mouse
fill(0);
arc(x, y+6, 20, 20, radians(0), radians(180));


}
35 changes: 35 additions & 0 deletions week1/Grid/W_Tang_WK01_Grid.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
void setup() {
size(600, 600);
background(0);
}

void draw() {
for (int y = 0; y<10; y++) {
for (int x = 0; x<10; x++) {
smile(x*60, y*60);

}
}
}

void smile(int _x, int _y) {
int x =_x+30;
int y=_y+30;

//face
noStroke();
fill(255, 235, 15);
ellipse(x, y, 60, 60);

//eye
fill(0);
ellipse( x-10, y-10, 10, 10);
ellipse( x+10, y-10, 10, 10);


//mouse
fill(0);
arc(x, y+6, 20, 20, radians(0), radians(180));


}
Empty file modified week1/Grid/readme.md
100644 → 100755
Empty file.
Binary file added week1/gradient/.DS_Store
Binary file not shown.
13 changes: 13 additions & 0 deletions week1/gradient/W_Tang_WK01_gradient.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
void setup() {
size(300,300);
background(0);
colorMode(RGB);
//set up pixel for loop
loadPixels();
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
pixels[i+j*height] = color(i,j,255);
}
}
updatePixels();
}
20 changes: 12 additions & 8 deletions week1/gradient/gradient.pde
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@

size(256, 256);

loadPixels();

// do something here!

updatePixels();
void setup() {
size(300,300);
background(0);
colorMode(RGB);
loadPixels();
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
pixels[i+j*height] = color(i,j,255);
}
}
updatePixels();
}
Empty file modified week1/gradient/gradient.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified week1/gradient/readme.md
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion week1/readme.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void go(Thing t) {
void setup() {
Thing thing = new Thing();
thing.a = 2;

go(thing);

println(thing.a);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

import processing.video.*;

// Variable for capture device
Capture video;

// Saved background
PImage backgroundImage;
PImage img;

float threshold = 20;

void setup() {
size(320, 240);
video = new Capture(this, width, height, 30);
video.start();
//setup imgbackground
img = loadImage("1.jpg");
backgroundImage = createImage(video.width, video.height, RGB);
}



void draw() {

if (video.available()) {
video.read();
}
loadPixels();
video.loadPixels();
backgroundImage.loadPixels();
// add img
img.loadPixels();
image(video, 0, 0);


for (int x = 0; x < video.width; x ++ ) {
for (int y = 0; y < video.height; y ++ ) {
int loc = x + y*video.width;
color fgColor = video.pixels[loc];
color bgColor = backgroundImage.pixels[loc];

// add img pixel
color bgImg=img.pixels[loc];

// Step 4, compare the foreground and background color
float r1 = red(fgColor);
float g1 = green(fgColor);
float b1 = blue(fgColor);
float r2 = red(bgColor);
float g2 = green(bgColor);
float b2 = blue(bgColor);
float diff = dist(r1, g1, b1, r2, g2, b2);


if (diff > threshold) {

pixels[loc] = fgColor;
} else {

pixels[loc] = bgImg;
}
}
}
updatePixels();
}

void keyPressed() {
if (key == ' ') {
backgroundImage.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
backgroundImage.updatePixels();
}
}
Loading