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.
Binary file added week1/BouncingBalls/.DS_Store
Binary file not shown.
57 changes: 57 additions & 0 deletions week1/BouncingBalls/Ball.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class Ball {

PVector pos;
PVector vel;
PVector velb;
PVector acceleration;
PVector mouse;
float diameter;
color c;

Ball(float x ) {
pos = new PVector(random(width), random(height));
vel = new PVector(0, 0);
velb = new PVector(2, -2);
diameter = x;
c =color(random(255), random(255), random(255));
}


void update() {
pos.add(velb);
if (pos.x<diameter/2||pos.x>width) {
velb.x = -velb.x;
}
if (pos.y<diameter/2||pos.y>height) {
velb.y=-velb.y;
}
}


void clickclick() {
mouse = new PVector (mouseX, mouseY);


mouse.sub(pos);
mouse.setMag(0.5);
acceleration = mouse;

vel.add(acceleration);
vel.limit(5);
pos.add(vel);






//println(i);
println("done");
}
void display() {
stroke(0);
strokeWeight(2);
fill(c);
ellipse(pos.x, pos.y, diameter, diameter);
}
}
52 changes: 14 additions & 38 deletions week1/BouncingBalls/BouncingBalls.pde
Original file line number Diff line number Diff line change
@@ -1,47 +1,23 @@
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);
}
}

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

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

fo (int i = 0; i > ballslength; 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);
size(640, 360);
for (int i=0; i<20; i++) {
ball[i] = new Ball(random(12,48));

}
}


void draw() {
background(0);
for (int i=0; i<20; i++) {

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

ball[i].update();
ball[i].display();
if(mousePressed){
ball[i].clickclick();
}
println(i);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week1/BouncingBalls/data/face0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week1/BouncingBalls/data/face1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week1/BouncingBalls/data/face1.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week1/BouncingBalls/data/face2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week1/gradient/.DS_Store
Binary file not shown.
File renamed without changes
26 changes: 20 additions & 6 deletions week1/gradient/gradient.pde
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
PImage gradient;

size(256, 256);
void setup() {
size(256, 256);
gradient = loadImage("gradient.png");
}

loadPixels();

// do something here!

updatePixels();
void draw() {
loadPixels();
for (int x = 0; x < width; x++) {
for (int y =0;y<height;y++) {
int loc = x + y *width;
float r = red(gradient.pixels[loc]);
float g = green(gradient.pixels[loc]);
float b = blue(gradient.pixels[loc]);
float d = dist(mouseX,mouseY, x, y);
float factor = map(d,0,100,0,2);
pixels[loc] = color(r*factor,g*factor,b*factor);
}
}
updatePixels();
}