Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.10 KB | None | 0 0
  1. import java.util.LinkedList;
  2. float[]x, y, a, s;
  3. int n=4;
  4. float vel=0.03, velX=1;
  5. void setup(){
  6.  fullScreen();
  7.  background(0);
  8.  x=new float[n];
  9.  y=new float[n];
  10.  s=new float[n];
  11.  a=new float[n];
  12.  for(int i = 0; i < n; i++){
  13.   s[i]=width/(8*pow(2, i));
  14.  }
  15. }
  16. LinkedList<PVector>points=new LinkedList<PVector>();
  17. LinkedList<PVector>sin1=new LinkedList<PVector>();
  18. LinkedList<PVector>sin2=new LinkedList<PVector>();
  19. LinkedList<PVector>sin3=new LinkedList<PVector>();
  20. LinkedList<PVector>sin4=new LinkedList<PVector>();
  21. void draw(){
  22.   background(0);
  23.   //alsó
  24.   pushMatrix();
  25.   translate(width/4, height*3/4);
  26.   noFill();
  27.   x[0]=s[0]*cos(a[0]);
  28.   y[0]=s[0]*sin(a[0]);
  29.   strokeWeight(2);
  30.       stroke(255);
  31.       ellipse(0, 0, s[0]*2, s[0]*2);
  32.       line(0, 0, x[0], y[0]);
  33.   for(int i = 1; i < n; i++){
  34.     try{
  35.       x[i]=x[i-1]+s[i]*cos(a[i]);
  36.       y[i]=y[i-1]+s[i]*sin(a[i]);
  37.       strokeWeight(2);
  38.       stroke(255);
  39.       ellipse(x[i-1], y[i-1], s[i]*2, s[i]*2);
  40.       line(x[i-1], y[i-1], x[i], y[i]);
  41.     }catch(Exception ex){}
  42.    
  43.    
  44.   }
  45.   for(int i = 0; i < n; i++){
  46.    a[i]+=vel*pow(2, i);
  47.    
  48.   }
  49.   for(int i = 0; i < points.size(); i++){
  50.    try{
  51.      stroke(200, 0, 0);
  52.      strokeWeight(2);
  53.      line(points.get(i).x, points.get(i).y, points.get(i+1).x, points.get(i+1).y);
  54.    }catch(Exception ex){}
  55.      points.get(i).x+=velX;
  56.   }
  57.  
  58.   points.add(new PVector(width/4, y[n-1]));
  59.   popMatrix();
  60.   //felső
  61.   pushMatrix();
  62.   translate(width/4, height/4);
  63.    for(int i = 0; i < n; i++){
  64.      strokeWeight(2);
  65.      stroke(255);
  66.      ellipse(0, 0, s[i]*2, s[i]*2);
  67.      try{
  68.        line(0, 0, cos(a[i])*s[i], sin(a[i])*s[i]);
  69.      }catch(Exception ex){}
  70.  }
  71.  
  72.    for(int i = 0; i < sin1.size(); i++){
  73.    try{
  74.      stroke(0, 200, 0);
  75.      strokeWeight(2);
  76.      line(sin1.get(i).x, sin1.get(i).y, sin1.get(i+1).x, sin1.get(i+1).y);
  77.    }catch(Exception ex){}
  78.      sin1.get(i).x+=velX;
  79.   }
  80.   for(int i = 0; i < sin2.size(); i++){
  81.    try{
  82.      stroke(200, 200, 0);
  83.      strokeWeight(2);
  84.      line(sin2.get(i).x, sin2.get(i).y, sin2.get(i+1).x, sin2.get(i+1).y);
  85.    }catch(Exception ex){}
  86.      sin2.get(i).x+=velX;
  87.   }
  88.   for(int i = 0; i < sin3.size(); i++){
  89.    try{
  90.      stroke(0, 0, 200);
  91.      strokeWeight(2);
  92.      line(sin3.get(i).x, sin3.get(i).y, sin3.get(i+1).x, sin3.get(i+1).y);
  93.    }catch(Exception ex){}
  94.      sin3.get(i).x+=velX;
  95.   }
  96.   for(int i = 0; i < sin4.size(); i++){
  97.    try{
  98.      stroke(200, 0, 200);
  99.      strokeWeight(2);
  100.      line(sin4.get(i).x, sin4.get(i).y, sin4.get(i+1).x, sin4.get(i+1).y);
  101.    }catch(Exception ex){}
  102.      sin4.get(i).x+=velX;
  103.   }
  104.  
  105.      sin1.add(new PVector(width/4, sin(a[0])*s[0]));
  106.      sin2.add(new PVector(width/4, sin(a[1])*s[1]));
  107.      sin3.add(new PVector(width/4, sin(a[2])*s[2]));
  108.      sin4.add(new PVector(width/4, sin(a[3])*s[3]));
  109.    popMatrix();
  110.   //egyéb
  111.  
  112.  
  113.   while(points.size()>500)points.removeFirst();
  114.    while(sin1.size()>500)sin1.removeFirst();
  115.     while(sin2.size()>500)sin2.removeFirst();
  116.      while(sin3.size()>500)sin3.removeFirst();
  117.       while(sin4.size()>500)sin4.removeFirst();
  118.    
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement