Shaking figures
in
Share your Work
•
3 years ago
Hello!
Sorry for my poor English, it's the first time I post here.
The first "real project" based on figures refreshed with a small random position and a little mouse interaction. As a result, the fish seems to be in boiling water or jelly or something like that.
In my 2nd project I tried to explore this differently... But this time I have a problem to export the applet : it works with processing but not when exported.
First project:
- poisson bubulle;
- //nombre de carrés
- int nbcar = 120;
- //coef de parkinson
- int trmblte = 2;
- //rayon de répulsion
- int limite = 100;
- int taillepoisson =20;
- float[][] points = new float[4][nbcar+100];
- float angle = 0;
- void resetsettings() {
- nbcar = 120;
- trmblte = 2;
- limite = 100;
- taillepoisson =20;
- }
- void setup(){
- size (400,500);
- smooth();
- frameRate(30);
- // rectMode(CENTER);
- background(0);
- for (int i = 0 ; i < nbcar ; i++) {
- float a = random(width);
- float b = random(height*0.8);
- float c = random(min(min(width-a,a),min(height*0.8-b,b)));
- float col = random(255);
- points[0][i]=a;
- points[1][i]=b;
- points[2][i]=c;
- points[3][i]=col;
- }
- bubulle = new poisson(taillepoisson,35,100,100,0);
- }
- void draw() {
- background(0);
- if(bubulle.xpos!=mouseX | bubulle.ypos!=mouseY){
- angle=atan((mouseY-bubulle.ypos)/(mouseX-bubulle.xpos));
- if (mouseX-bubulle.xpos < 0) {
- angle = PI + angle;
- }
- }
- bubulle.xpos=mouseX;
- bubulle.ypos=mouseY;
- bubulle.angle=angle;
- bubulle.display();
- stroke(255);
- afficheformes();
- infobox();
- }
- void infobox() {
- stroke(255);
- fill(0);
- rect(0,height*0.8,width-1,height*0.2-1);
- fill(255);
- text("Reset settings : x" ,width*0.025,height*25/30);
- text("Parkinson - : t" ,width*0.025,height*26/30);
- text("Parkinson + : y" ,width*0.025,height*27/30);
- text("Evade - : g" ,width*0.025,height*28/30);
- text("Evade + : h" ,width*0.025,height*29/30);
- text("Redraw : r",width*0.35,height*25/30);
- text("Fish - : b" ,width*0.35,height*26/30);
- text("Fish + : n" ,width*0.35,height*27/30);
- text("Bubbles - : f" ,width*0.35,height*28/30);
- text("Bubbles + : v" ,width*0.35,height*29/30);
- fill(125);
- text("x = "+mouseX,width*0.7,height*25/30);
- text("y = "+mouseY,width*0.85,height*25/30);
- text("Bubbles = "+nbcar,width*0.7,height*26/30);
- text("Parkinson = "+trmblte,width*0.7,height*27/30);
- text("Evade = "+limite,width*0.7,height*28/30);
- text("Fish = "+taillepoisson,width*0.7,height*29/30);
- }
- void keyPressed() {
- if (key == 'r') setup();
- if (key == 't') {
- if (trmblte > 0) trmblte--;
- }
- if (key == 'y') trmblte++;
- if (key == 'g') {
- if (limite > 0) limite--;
- }
- if (key == 'h') limite++;
- if (key == 'b') {
- if (taillepoisson > 10) taillepoisson--;
- }
- if (key == 'n') taillepoisson++;
- if (key == 'f') {
- if (nbcar > 0) nbcar--;
- }
- if (key == 'v') {
- if (nbcar < 200) nbcar++;
- }
- if (key == 'x') resetsettings();
- }
- void afficheformes(){
- for (int i = 0 ; i < nbcar ; i++) {
- float d = 0;
- float dx = 0;
- float dy = 0;
- float x = 0;
- float y = 0;
- // distance sur x de 0 a 50. 0 lorsqu'on est à 50
- if ((sqrt(sq(points[0][i]-mouseX)+sq(points[1][i]-mouseY))) < limite) {
- dx = mouseX-points[0][i] ;
- dy = mouseY-points[1][i];
- d = (sqrt(sq(dx)+sq(dy)));
- x = (limite - d)/d*dx;
- y = (limite - d)/d*dy;
- }
- // text ("mouseX="+mouseX+" mouseY="+mouseY,20,20);
- // text ("a="+points[0][i]+" b="+points[1][i],20,35);
- // text ("d="+d+" dx="+dx+" dy="+dy,20,50);
- ellipse(points[0][i]+random(-trmblte,trmblte)-x,points[1][i]+random(-trmblte,trmblte)-y,points[2][i],points[2][i]);
- fill((points[3][i]));
- // rect(points[0][i]+random(-trmblte,trmblte)-x,points[1][i]+random(-trmblte,trmblte)-y,points[2][i],points[2][i]);
- // fill((points[3][i]));
- }
- }
- class poisson {
- int taille;
- int ligne;
- float xpos;
- float ypos;
- float angle = 0;
- poisson(int tmpTaille, int tmpLigne, float tmpXpos, float tmpYpos, float tmpAngle){
- taille = tmpTaille;
- ligne = tmpLigne;
- xpos = tmpXpos;
- ypos = tmpYpos;
- angle = tmpAngle;
- }
- void display(){
- pushMatrix();
- translate(xpos,ypos);
- rotate(angle);
- stroke(255,125,0);
- fill(255,125,0);
- triangle(-3*taille,-taille,-taille,0,-3*taille,taille);
- ellipse(-1.2*taille,0,2.3*taille,2*taille);
- // fill(255,255,255);
- stroke(255,255,255);
- fill(255,255,255);
- ellipse(-.5*taille,-.4*taille,.6*taille,.6*taille);
- stroke(0,0,0);
- fill(0,0,0);
- ellipse(-.5*taille,-.4*taille,.24*taille,.24*taille);
- popMatrix();
- // fill(0,0,0);
- // stroke(0,0,0);
- }
- }
2nd project
- PImage A;
- //coef parkinson
- int trbl = 2;
- //
- int c = 10;
- //int limite
- int limite = 30;
- int lecran = 640;
- int hecran = 520;
- boolean start = false;
- boolean v = false;
- boolean s = true;
- boolean m = false;
- void setup() {
- A = loadImage("01.jpg");
- size(lecran, hecran);
- smooth();
- background(0);
- stroke(0);
- // image(A, 0, 0);
- }
- void keyPressed(){
- if (key == 'v') v =!v;
- if (key == 's') s=!s;
- if (key == 'm') m=!m;
- if (key == 't') {
- if (trbl > 0) trbl--;
- }
- if (key == 'y') trbl++;
- if (key == 'g') {
- if (c > 5) c--;
- }
- if (key == 'h') {
- if (c < 50) c++;
- }
- if (key == 'b') {
- if (limite > 0) limite--;
- }
- if (key == 'n') {
- if (limite < 200) limite++;
- }
- if (key == ' ') image(A,0,0);
- }
- void draw() {
- // nombre de carrés
- // nombre de lignes et colonnes
- int ncols = floor(A.width/c);
- int nrows = floor(A.height/c);
- if (s == true) {
- stroke(0);
- } else {
- noStroke();
- }
- image(A, 0, 0);
- for (int i = 0; i < ncols+1 ; i++) {
- for (int j = 0; j < nrows ; j++) {
- fill(A.pixels[j*c*A.width+i*c]);
- int x = 1;
- if (m == true) {
- if ((sqrt(sq(c*i-mouseX)+sq(c*j-mouseY))) > limite) {
- rect(i*c+random(-trbl,trbl),j*c+random(-trbl,trbl),c,c);
- }
- } else {
- rect(i*c+random(-trbl,trbl),j*c+random(-trbl,trbl),c,c);
- }
- }
- }
- if (v == true) vignette();
- infobox(c,nrows);
- }
- void vignette() {
- int ratio = 8;
- image(A,0,0,A.width/ratio,A.height/ratio);
- }
- void infobox(int c, int nrows) {
- stroke(255);
- fill(0);
- rect(0,480,639,519);
- fill(255);
- text("toggle stroke 's'",lecran*0.1,hecran*0.96);
- text("toggle thumb 'v'",lecran*0.1,hecran*0.98);
- text("rayon +/- : b/n ("+limite+")",lecran*0.35,hecran*0.96);
- text("toggle mouse : 'm'",lecran*0.35,hecran*0.98);
- text("square +/- : g/h ("+c+")",lecran*0.6,hecran*0.96);
- text("parkinson +/- : t/y ("+trbl+")",lecran*0.6,hecran*0.98);
- }
And the jpg file I use: