Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick B committed Aug 19, 2024
2 parents 7883ba3 + b64c15f commit 9094957
Show file tree
Hide file tree
Showing 513 changed files with 1,094 additions and 70 deletions.
32 changes: 28 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@

# Created by https://www.toptal.com/developers/gitignore/api/processing,visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=processing,visualstudiocode
# Created by https://www.gitignore.io/api/java,processing,visualstudiocode
# Edit at https://www.gitignore.io/?templates=java,processing,visualstudiocode

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

### Processing ###
.DS_Store
Expand All @@ -20,10 +45,9 @@ out
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

### VisualStudioCode Patch ###
# Ignore all local history of files
.history

# End of https://www.toptal.com/developers/gitignore/api/processing,visualstudiocode
# End of https://www.gitignore.io/api/java,processing,visualstudiocode
35 changes: 35 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run Sketch",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"command": "${config:processing.path}",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "dedicated"
},
"args": [
"--force",
"--sketch=${workspaceFolder}/${relativeFileDirname}",
"--output=${workspaceFolder}/out",
"--run"
],
"windows": {
"args": [
"--force",
"--sketch=${workspaceFolder}\\${relativeFileDirname}",
"--output=${workspaceFolder}\\out",
"--run"
]
}
}
]
}

23 changes: 23 additions & 0 deletions _notes/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Classe avec forces
## Code de base
```java
//... autre code ...

// Code de base pour update
// adapter pour la classe
void update() {
velocity.add(acceleration);
velocity.limit(maxSpeed); // Si limite de vitesse
location.add(velocity);

acceleration.mult(0); // On remet l'accélération à 0
}

// Fonction pour ajouter une force à l'accélération
void applyForce(PVector force) {
var f = PVector.div(force, mass);
acceleration.add(f);
}

//... autre code ...
```
5 changes: 3 additions & 2 deletions arkanoid/Ball.pde
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Ball extends GraphicObject{
class Ball extends GraphicObject {

int radius = 10;

Expand All @@ -9,7 +9,8 @@ class Ball extends GraphicObject{
}


void update(float delta) {
void update(int delta) {

}

void display()
Expand Down
31 changes: 4 additions & 27 deletions arkanoid/Block.pde
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Block extends GraphicObject {
class Block extends Rectangle {
int w = 50;
int h = 10;
ICollidable collidable;
Expand All @@ -15,10 +15,8 @@ class Block extends GraphicObject {



void update (float delta) {
if (hasCollision(collidable)) {
print ("boom");
}
void update (int deltaTime) {

}


Expand All @@ -29,27 +27,6 @@ class Block extends GraphicObject {
rect(0, 0, w, h);
popMatrix();
}


float top() {
return location.y;
}

float bottom() {
return location.y + h;
}

float left() {
return location.x;
}

float right() {
return location.x + w;
}

boolean hasCollision(ICollidable other) {
if (other == null) return false;

return other.bottom() > top() && other.top() < bottom()
&& other.left() < right() && other.right() > left();
}
}
Empty file added arkanoid/BrickWall.pde
Empty file.
File renamed without changes.
8 changes: 4 additions & 4 deletions arkanoid/GraphicObject.pde
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
abstract class GraphicObject {
PVector location;
PVector velocity;
PVector acceleration;
public PVector location;
public PVector velocity;
public PVector acceleration;

color fillColor = color (255);
color strokeColor = color (255);
float strokeWeight = 1;

abstract void update(float deltaTime);
abstract void update(int deltaTime);

abstract void display();

Expand Down
Empty file added arkanoid/Paddle.pde
Empty file.
96 changes: 96 additions & 0 deletions arkanoid/Rectangle.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
class Rectangle extends GraphicObject {
int w, h;

Rectangle () {
instanciate();
}

Rectangle (float x, float y, int _w, int _h) {
instanciate();

location.x = x;
location.y = y;
w = _w;
h = _h;
}

void instanciate() {
location = new PVector();
velocity = new PVector();
acceleration = new PVector();

w = 100;
h = 50;
}

void update(int deltaTime) {
checkEdges();

velocity.add (acceleration);
location.add (velocity);

acceleration.mult(0);
}

void display() {
pushMatrix();
translate (location.x, location.y);
rect (0, 0, w, h);
popMatrix();
}

// Fonction facilitant la compréhension des conditions
public int top() { return (int)location.y; }
public int bottom() { return (int)location.y + h; }
public int left() { return (int)location.x; }
public int right() { return (int)location.x + w; }

void checkEdges() {
if (left() < 0 || right() > width) {
velocity.x *= -1;
}

if (top() < 0 || bottom() > height) {
velocity.y *= -1;
}
}

public void checkCollisions(Rectangle other) {
if (isBouncingX(other)) {
velocity.x *= -1;
}

if (isBouncingY(other)) {
velocity.y *= -1;
}
}

// Retourne vrai s'il y a un contact en X
public boolean isBouncingX(Rectangle other) {
// Si je continue en X est-ce que je vais
// avoir une collision avec l'autre
boolean passLeft = right() + velocity.x > other.left();
boolean passRight = left() + velocity.x < other.right();

boolean checkTop = bottom() > other.top();
boolean checkBottom = top() < other.bottom();

return passLeft && passRight && checkBottom && checkTop;
}

// Retourne vrai s'il y a un contact en Y
public boolean isBouncingY(Rectangle other) {

boolean checkRight = right() > other.left();
boolean checkLeft = left() < other.right();

// Si je continue en Y est-ce que je vais
// avoir une collision avec l'autre
boolean passBottom = bottom() + velocity.y > other.top();
boolean passTop = top() + velocity.y < other.bottom();

return checkRight && checkLeft && passBottom && passTop;
}


}
2 changes: 1 addition & 1 deletion arkanoid/shapeTemplate.pde
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ShapeTemplate extends GraphicObject {



void update(float deltaTime) {
void update(int deltaTime) {
velocity.add(acceleration);
location.add (velocity);

Expand Down
Binary file added bin/s02_forces_01.pdez
Binary file not shown.
Binary file added bin/s02_forces_exemple.pdez
Binary file not shown.
Binary file added bin/s03_collision_cercles.pdez
Binary file not shown.
Binary file added bin/s04_collision_cercles_impact.pdez
Binary file not shown.
Binary file added bin/s04_demo_boids_al.pdez
Binary file not shown.
Binary file added bin/s04_demo_boids_base.pdez
Binary file not shown.
Binary file added bin/s04_demo_boids_cohe.pdez
Binary file not shown.
Binary file added bin/s04_demo_boids_sep.pdez
Binary file not shown.
Binary file added bin/s04_push_pop.pdez
Binary file not shown.
Binary file added bin/s04_syst_solaire.pdez
Binary file not shown.
66 changes: 66 additions & 0 deletions s02_forces_exemple/Fluid.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
Classe simulant un fluide. Elle est représentée par un rectangle.
*/
class Fluid {
Rectangle r;
float density;
float coefficientFriction;

private color c;

Fluid () {
float quarterHeight = height / 4;
r = new Rectangle(0, height - quarterHeight, width, quarterHeight);
density = 0.8;
coefficientFriction = 0.1;

this.c = color (127, 127);
}

Fluid (Rectangle _r, float _density, float _coefficientFriction) {
r = _r;
density = _density;
coefficientFriction = _coefficientFriction;

this.c = color (127, 127);
}

void setRectangle (Rectangle _r) {
r = _r;
}

Rectangle getRectangle () {
return r;
}

void display () {

fill (c);
r.display();
}

/**
Formule F = -0.5 * rho * ||v||^2 * area * friction * speed.normalise
*/
PVector draggingForce(PVector speed, float area) {
float speedMag = speed.mag();
float coeffRhoMag = density * coefficientFriction * speedMag * speedMag * 0.5;

PVector result = speed.get();
result.mult(-1);
result.normalize();
result.mult(area);
result.mult(coeffRhoMag);

return result;
}

void setColor (color c) {
this.c = c;
}

void setLocation (int x, int y) {
this.r.x = x;
this.r.y = y;
}
}
20 changes: 20 additions & 0 deletions s02_forces_exemple/Forces.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Forces {

Forces () {
}

// Faux calcul qui prend une valeur scalaire pour la normale
PVector friction (PVector vitesse, float coeffFriction, float normale) {
PVector resultat = new PVector();

resultat = vitesse.get();

resultat.mult(-1);
resultat.normalize(); // Réduire la direction en valeur unitaire


resultat.mult(normale * coeffFriction);

return resultat;
}
}
Loading

0 comments on commit 9094957

Please sign in to comment.