Advertisement
A-Sin

Datchiki

Feb 28th, 2020
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1. final int n = 3;
  2. final int scale = 200; // кол-во значений на экране
  3. final int b_mult = 2; // bias
  4.  
  5. ArrayList<Sensor> sensors;
  6. int t;
  7. boolean doStep;
  8.  
  9. void setup() {
  10.   //size(700, 600);  
  11.   //surface.setResizable(true);
  12.  
  13.   fullScreen();
  14.   background(0);
  15.   strokeWeight(1);
  16.  
  17.   fill(255, 128);
  18.   //frameRate(5);
  19.   smooth(16);
  20.   reset();
  21. }
  22.  
  23. void draw() {
  24.   background(0);
  25.   boolean alert = true;
  26.   if (doStep) step(1);
  27.   for (Sensor s : sensors) {
  28.     s.display();
  29.     if (!s.alert) alert = false;
  30.   }
  31.  
  32.   if (alert) reset();
  33.   stroke(#00ff00);
  34.   line(0, height/5, width, height/5);
  35.   line(0, height*4/5, width, height*4/5);
  36. }
  37.  
  38. void mousePressed() {
  39.   if (mouseButton == LEFT) {
  40.     doStep = true;
  41.   }
  42. }
  43. void mouseReleased() {
  44.   doStep = false;
  45. }
  46.  
  47. void mouseClicked() {
  48.   if (mouseButton == RIGHT) {
  49.     reset();
  50.   }
  51. }
  52. void step(int steps) {
  53.   for (int i=0; i<steps; i++) {
  54.     for (Sensor s : sensors)
  55.       s.step();
  56.     t++;
  57.   }
  58. }
  59.  
  60. void reset() {
  61.   sensors = new ArrayList();
  62.   t=0;
  63.   for (int i=0; i<n; i++)  
  64.     sensors.add(new Sensor());
  65.   step(10);
  66. }
  67.  
  68. class Sensor {
  69.   int n;
  70.   float b, p;
  71.   FloatList op = new FloatList();
  72.   FloatList opt = new FloatList();
  73.   int r=0;  
  74.   boolean alert;
  75.  
  76.   Sensor() {
  77.     n = sensors.size();
  78.     p = height/2+random(-height/5, height/5);
  79.     b = height/100+random(height/50)*b_mult;
  80.     op.push(p);
  81.     opt.push(0);
  82.   }
  83.  
  84.   void step() {
  85.     p+=random(-b, b);
  86.     op.push(p);
  87.     opt.push(t);
  88.  
  89.     if (op.size()>scale) {
  90.       op.remove(0);
  91.       opt.remove(0);
  92.       r++;
  93.     }
  94.   }
  95.  
  96.   void display() {
  97.     stroke(#00ffff);
  98.     beginShape();    
  99.     for (int i=0; i<op.size(); i++) {  
  100.       fill(255, 40);
  101.       float x = map(opt.get(i), r, t, 10, width-10);  
  102.       float y = op.get(i);
  103.       if (y>height*4/5 || y<height/5) {
  104.         fill(255, 0, 0, 128);
  105.         alert = true;
  106.       }
  107.       vertex(x, y);
  108.     }
  109.     endShape();
  110.   }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement