Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final int n = 3;
- final int scale = 200; // кол-во значений на экране
- final int b_mult = 2; // bias
- ArrayList<Sensor> sensors;
- int t;
- boolean doStep;
- void setup() {
- //size(700, 600);
- //surface.setResizable(true);
- fullScreen();
- background(0);
- strokeWeight(1);
- fill(255, 128);
- //frameRate(5);
- smooth(16);
- reset();
- }
- void draw() {
- background(0);
- boolean alert = true;
- if (doStep) step(1);
- for (Sensor s : sensors) {
- s.display();
- if (!s.alert) alert = false;
- }
- if (alert) reset();
- stroke(#00ff00);
- line(0, height/5, width, height/5);
- line(0, height*4/5, width, height*4/5);
- }
- void mousePressed() {
- if (mouseButton == LEFT) {
- doStep = true;
- }
- }
- void mouseReleased() {
- doStep = false;
- }
- void mouseClicked() {
- if (mouseButton == RIGHT) {
- reset();
- }
- }
- void step(int steps) {
- for (int i=0; i<steps; i++) {
- for (Sensor s : sensors)
- s.step();
- t++;
- }
- }
- void reset() {
- sensors = new ArrayList();
- t=0;
- for (int i=0; i<n; i++)
- sensors.add(new Sensor());
- step(10);
- }
- class Sensor {
- int n;
- float b, p;
- FloatList op = new FloatList();
- FloatList opt = new FloatList();
- int r=0;
- boolean alert;
- Sensor() {
- n = sensors.size();
- p = height/2+random(-height/5, height/5);
- b = height/100+random(height/50)*b_mult;
- op.push(p);
- opt.push(0);
- }
- void step() {
- p+=random(-b, b);
- op.push(p);
- opt.push(t);
- if (op.size()>scale) {
- op.remove(0);
- opt.remove(0);
- r++;
- }
- }
- void display() {
- stroke(#00ffff);
- beginShape();
- for (int i=0; i<op.size(); i++) {
- fill(255, 40);
- float x = map(opt.get(i), r, t, 10, width-10);
- float y = op.get(i);
- if (y>height*4/5 || y<height/5) {
- fill(255, 0, 0, 128);
- alert = true;
- }
- vertex(x, y);
- }
- endShape();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement