daily pastebin goal
18%
SHARE
TWEET

Untitled

a guest Dec 9th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Control control;
  2. void setup() {
  3.   size(600, 600);
  4.   Model model = new Model();
  5.   View view = new View(model);
  6.   view.drawPattern();
  7.   control = new Control(model, view);
  8. }
  9.  
  10. void draw() {}
  11. void mousePressed() {
  12.   control.press();
  13. }
  14.  
  15. class Model {
  16.   color[][] myData;
  17.   color[][] myData2;
  18.   boolean seq;
  19.   color drawColor;
  20.  
  21.   Model() {
  22.     myData = new color[5][5];
  23.     myData2 = new color[5][5];
  24.     seq = false;
  25.     drawColor = color(0);
  26.     for(int x = 0; x < 5; x++) {
  27.       for(int y = 0; y < 5; y++) {
  28.         myData[x][y] = color(255);
  29.         myData2[x][y] = color(255);
  30.       }
  31.     }
  32.   }
  33. }
  34.  
  35. class View {
  36.   Model model;
  37.   View(Model model) {
  38.      this.model = model;
  39.   }
  40.  
  41.   void drawGrid(int offsetX, int offsetY) {
  42.     for(int x = 0; x < 5; x++) {
  43.       for(int y = 0; y < 5; y++) {
  44.          fill(model.myData[x][y]);
  45.          rect(offsetX + (x * 10), offsetY + (y * 10), 10, 10);
  46.       }
  47.     }
  48.   }
  49.  
  50.   void drawGrid2(int offsetX, int offsetY) {
  51.     for(int x = 0; x < 5; x++) {
  52.       for(int y = 0; y < 5; y++) {
  53.          fill(model.myData2[x][y]);
  54.          rect(offsetX + (x * 10), offsetY + (y * 10), 10, 10);
  55.       }
  56.     }
  57.   }
  58.  
  59.   void drawPattern() {
  60.     fill(model.drawColor);
  61.     rect(0, 100, 50, 50);
  62.    
  63.     drawGrid(0, 0);
  64.     drawGrid2(0, 50);
  65.     for(int x = 0; x < 11; x++) {
  66.       for(int y = 0; y < 13; y++) {
  67.        
  68.         if(model.seq) {
  69.           if(x % 2 == 0)
  70.             drawGrid(x * 50 + 50, y * 50);
  71.           else
  72.             drawGrid2(x * 50 + 50, y * 50);
  73.         }else {
  74.           drawGrid(x * 50 + 50, y * 50);
  75.         }
  76.       }
  77.     }
  78.   }
  79. }
  80.  
  81. class Control {
  82.   Model model;
  83.   View view;
  84.   Control(Model model, View view) {
  85.     this.model = model;
  86.     this.view = view;
  87.   }
  88.  
  89.   void press() {
  90.     if(mouseButton == RIGHT) {
  91.       model.seq = !model.seq;
  92.       view.drawPattern();
  93.       return;
  94.     }
  95.    
  96.     int x = mouseX / 10;
  97.     int y = mouseY / 10;
  98.     if(x < 5 && y < 5) {
  99.       model.myData[x][y] = model.drawColor;
  100.       view.drawPattern();
  101.     }else if(x < 5 && y < 10) {
  102.       model.myData2[x][y - 5] = model.drawColor;
  103.       view.drawPattern();
  104.     }
  105.    
  106.     x = mouseX / 50;
  107.     y = mouseY / 50;
  108.     if(x == 0 & y == 2) {
  109.       model.drawColor = color(random(255), random(255), random(255));
  110.       view.drawPattern();
  111.     }
  112.   }
  113. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top