Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float rinc = 0.5;
- float rmax = 17;
- float rmin = 2;
- float periodoPG = 1.5;
- float periodoF = 2;
- float r = 0;
- boolean runonce = true;
- PVector v;
- float caja1x = 0;
- float caja1y = 450;
- float caja2x = 0;
- float caja2y = 50;
- PVector vector1[] = new PVector[144];
- PVector vector2[] = new PVector[144];
- PVector vector3[] = new PVector[144];
- int indexgen = 0;
- void setup(){
- size(600,600);
- frameRate(60);
- }
- void draw(){
- background(255);
- fill(0);
- circle(caja1x,caja1y,20);
- circle(caja2x,caja2y,20);
- for(int i = 20; i < 620; i += 50){
- for(int j = 20; j < 620; j+= 50){
- stroke(0);
- vector3[indexgen] = new PVector(0,0);
- if(key == '1' || key == '3' || key == '4') separado(i,j,PI, map(sqrt(pow(i-caja1x,2)+pow(j-caja1y,2)),0,300,0,1),map(sqrt(pow(i-caja1x,2)+pow(j-caja1y,2)),0,300,rmax+rmin,rmax+rmin-4),indexgen,0);
- stroke(0,0,255);
- if(key == '2' || key == '3' || key == '4') separado(i,j,PI, map(sqrt(pow(i-caja2x,2)+pow(j-caja2y,2)),0,300,0,1),map(sqrt(pow(i-caja2x,2)+pow(j-caja2y,2)),0,300,rmax+rmin,rmax+rmin-4),indexgen,1);
- stroke(255,0,0);
- if(key == '3' || key == '4') dibujavector(i,j,vector3[indexgen]);
- indexgen++;
- }
- }
- indexgen = 0;
- /*separado(300,300, PI, map(sqrt(pow(300-300,2)+pow(300-300,2)),0,300,0,4));
- separado(200,200, PI, map(sqrt(pow(200-300,2)+pow(200-300,2)),0,300,0,4));*/
- }
- void separado(float x, float y, float aini, float tiempoini, float radiomax, int indexgen, int indexpart){
- if(millis() > tiempoini*1000){
- float velang = (2*PI)/(60*periodoF);
- float t = ((millis() - tiempoini*1000)/1000)*60; //El tiempo (en frames)
- float ang = aini + velang * t;
- float rad = rmin + abs(radiomax*sin((1/periodoPG)*ang));
- //println(ang);
- v = PVector.fromAngle(ang);
- v.mult(rad);
- if(indexpart == 0){
- vector1[indexgen] = v.copy();
- vector3[indexgen].add(vector1[indexgen]);
- }
- if(indexpart == 1){
- vector2[indexgen] = v.copy();
- vector3[indexgen].add(vector2[indexgen]);
- }
- if(key != '4')dibujavector(x,y,v);
- }
- }
- void dibujavector(float x, float y, PVector vector){
- //stroke(0);
- noFill();
- circle(x,y,2*vector.mag());
- arrow(x, y, x+vector.x, y+vector.y);
- }
- void arrow(float x1, float y1, float x2, float y2) {
- line(x1, y1, x2, y2);
- pushMatrix();
- translate(x2, y2);
- float a = atan2(x1-x2, y2-y1);
- rotate(a);
- line(0, 0, -3, -3);
- line(0, 0, 3, -3);
- popMatrix();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement