====== EFFETS SUR WEBCAM ======
* Porteur(s) du projet : Thomas Leloup
* Date : Mars 2017
* Contexte : Cours de programmation
* Lien : {{:wiki:projets:projets-processing-dsaa1:webcam_effet.zip| Dossier du programme}}
----
Ce programme réalisé sur Processing propose différents filtres à appliquer sur sa webcam pour ensuite prendre en photo.Pour ce programme la bibliothèque vidéo de processing sera nécessaire.La bibliothèque controlP5 utilisé pour la création de boutons n'est pas nécessaire ici car les boutons sont réalisés dans une classe nommée bouton. Pour se prendre en photo, il faut appuyer sur la touche ENTRÉE. Les 8 filtres ont chacun leur particularités :
* Saturation
* Déformation
* Pong
* Pluie
* Trame
* Neige
* Noir & blanc
* Négatif
{{:wiki:projets:projets-processing-dsaa1:webcamprocessing.jpg|}}
----
===== Code principale du programme =====
/*
Thomas Leloup
Programme webcam/boutons/applications de filtres
À améliorer = l'ergonomie des boutons et les filtres
*/
//importation librairie vidéo
import processing.video.*;
//attribut balle pong
ArrayList collectionBalle;
int Nballes = 100; // nombre de balles pour l'effet balle
//tableau des boutons
button[] ton;
//attribut boolean pour bouton
boolean overBox = false;
boolean locked = false;
boolean singlePress = false;
//boîte de particules de pluie
Drop[] drops = new Drop[500];
//attribut pour trame de points
ArrayList circles;
int space;
//attribut pour la création de neige
PVector xx, yy, fcx, fcy, sx, sy;
int seed = 0, cell = 15;
Boolean randomized = true;
//attribut typographie
PFont font;
//déclaration de la caméra
Capture cam;
///////////////////////////////////////////////////////////////////////////////////
void setup() {
//taille zone de travail
size(1280, 760);
//on attribue la webcam à la caméra puis démarrage
cam = new Capture(this, width, height-40);
cam.start();
//initialisation de l'effet neige
Boolean randomized = true;
initialize();
//mode de couleur RVB
colorMode(RGB);
// initialisation du tableau de boutton
ton = new button[8];
//initialisation des boutons
for (int i=0;i<8;i++){
ton[i] = new button();
}
//les balles ont une nouvelle boîte
collectionBalle = new ArrayList();
//pour i compris entre 0 et nombre de balles
for(int i = 0; i i
x = randomized ? random(width) : i;
//fonction aléatoire sur la hauteur de travail pour y => j
y = randomized ? random(height-40) : j;
//hauteur de vague (cycle ondulatoire) maximale sur x et y
//max x = coordonnées de X x X x coefficient de rotation en fontion de X + largeur
maxx = xx.x * (1 + sin(y/sx.x + fc/fcx.x)) + width;
//min x = coordonnées de -X x Y x coefficient de rotation en fonction de y
minx = -xx.y * (1 + sin(y/sx.y + fc/fcx.y));
x = map(x, 0, width, minx, maxx); //remappage de x 0=> minx et de width => maxx
if (x > 0 && x < width) { //pour x compris entre 0 et largeur
maxy = yy.x * (1 + sin(x/sy.x + fc/fcy.x)) + height;
miny = -yy.y * (1 + sin(x/sy.y + fc/fcy.y));
y = map(y, 0, height, miny, maxy); //remappage de y 0=> miny et de width => maxy
if (y > 0 && y < height-40){ //pour x compris entre 0 et largeur
point(x,y);
}
}
}}
popStyle();
fill(255,50); //bouton neige
rect(5*width/8,height-40,width/8,40);
}
///////////////////////////////////////////////////////////////////////////////////
//BOUTON 7 NOIR & BLANC
else if(ton[6].clicked()){
pushStyle();
image(cam, 0,0);
filter(GRAY); //filtre noir et blanc
popStyle();
fill(255,50); //bouton N&B
rect(6*width/8,height-40,width/8,40);
}
///////////////////////////////////////////////////////////////////////////////////
//BOUTON 8 NÉGATIF
else if(ton[7].clicked()){
pushStyle();
image(cam, 0,0);
filter(INVERT); //filtre inversion
popStyle();
fill(255,50); //bouton négatif
rect(7*width/8,height-40,width/8,40);
}
///////////////////////////////////////////////////////////////////////////////////
else {
image(cam, 0,0); //si il n'y a plus d'effet on reprend la caméra
}
}
///////////////////////////////////////////////////////////////////////////////////
void keyPressed() {
randomized = !randomized;
if (key == ENTER) { //prendre une photo avec le bouton ENTRÉE
saveFrame("image-"+hour()+minute()+second()+".png");
//img.save("image-"+hour()+minute()+second()+".png");
}
}
void mousePressed() {
initialize();
}
// FIN DU PROGRAMME PRINCIPAL //
----
===== Classe bouton =====
class button{
//couleurs
int Red;
int Gre;
int Blu;
//coordonnées des boutons
int x;
int y;
int si1;
int si2;
button(){
Red =40;
Gre =39;
Blu = 45;
}
//méthode pour remplir les boutons
void setFill(int R, int G, int B){
Red = R;
Gre = G;
Blu = B;
}
//méthode pour dessiner les boutons
void draw(int x1, int y1, int s1, int s2){
x = x1;
y = y1;
si1 = s1;
si2 = s2;
stroke(0);
fill(Red,Gre,Blu);
rect(x1, y1, s1, s2);
}
//États fonction du bouton
boolean clicked(){
if(mouseX > x && mouseX < (x+si1) && mouseY > y && mouseY < (y+si2) ){
overBox = true;
if(!locked) {
return true;
}
}
overBox = false;
return false;
}
}
----
===== Classe balle (pour PONG) =====
class balle{
// attributs (paramètre) de la balle
PVector pos; // vecteur position de du centre de la balle
color c ; // couleur
int r; // rayon de la balle
PVector dep; // vecteur deplacement
// constructeur
balle(PVector _pos, color _c, int _r, PVector _dep){
pos = _pos;
c = _c;
r = _r;
dep = _dep;
}
// méthodes
// méthode pour afficher la balle
void affiche(){
// dessin de la balle
fill(c);
ellipse(pos.x,pos.y,2*r,2*r);
}
//méthode pour déplacer la balle
void deplacement(){
//déplacement
pos.x = pos.x+dep.x;
pos.y = pos.y+dep.y;
}
// méthode de collision
void collision(){
// test de collision suivant x
if ((pos.x+r>=width) || (pos.x-r<=0)) {
dep.x = dep.x * (-1);
c = color(random(255),random(255),random(255));
}
// test de collision suivant y
if ((pos.y+r >= height-40) || ((pos.y-r<=0) )){
dep.y = dep.y * (-1);
c = color(random(360),100,100);
}
}
}
----
===== Classe circle (pour TRAME) =====
class Circle {
//variables ellipse
float cx, cy;
float rx, ry;
//variable temps
float rT;
//variable position des ellipses
float offset;
//variable taille des ellipses
float size;
// constructeur ellipse
Circle(float x, float y) {
this.cx = x;
this.cy = y;
this.rT = 400;
this.offset = random(-PI/4, PI/8);
this.size = 50;
}
//méthode pour remettre à jour les ellipses
void update() {
//t => temps en millisecondes
float t = millis()/rT;
//t += (cx/400)*PI;
//t += (cy/400)*PI;
t += cos(abs(1-(cx/(width/2))))*TWO_PI;
t += cos(abs(1-(cy/(height/2))))*TWO_PI;
t += offset;
//rx = abs((cos(t))*(((cx)/25)+10))-4;
rx = sin(t)*size;
ry = rx;
}
//méthode pour dessiner les points
void draw() {
if (rx > 0 && ry > 0 && cy < height-40) {
noStroke();
fill(255,200);
ellipse(cx, cy, rx/2, ry/2);
}
}
}
----
===== Classe drop (pour PLUIE) =====
class Drop {
//variables chute
float x;
float y;
float z;
float len;
float yspeed;
//constructeur
Drop() {
x = random(width);
y = random(-500, -50);
z = random(0, 20);
len = map(z, 0, 20, 10, 20);
yspeed = map(z, 0, 20, 1, 40);
}
//méthode chute
void fall() {
y = y + yspeed;
float grav = map(z, 0, 20, 0, 0.2);
yspeed = yspeed + grav;
if (y > height-60) {
y = random(-500, -100);
yspeed = map(z, 0, 20, 4, 5.8);
}
}
//méthode afficher
void show() {
float thick = map(z, 0, 20, 1, 3);
strokeWeight(thick*2);
stroke(255,random(100,200));
line(x, y, x, y+len);
}
}
===== Références =====
Pour l'effet pluie voici le tutoriel : {{youtube>KkyIDI6rQJI?}}
Pour l'effet trame : [[https://www.openprocessing.org/sketch/155107]]