Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Control control;
- void setup() {
- size(600, 600);
- Model model = new Model();
- View view = new View(model);
- view.drawPattern();
- control = new Control(model, view);
- }
- void draw() {}
- void mousePressed() {
- control.press();
- }
- class Model {
- color[][] myData;
- color[][] myData2;
- boolean seq;
- color drawColor;
- Model() {
- myData = new color[5][5];
- myData2 = new color[5][5];
- seq = false;
- drawColor = color(0);
- for(int x = 0; x < 5; x++) {
- for(int y = 0; y < 5; y++) {
- myData[x][y] = color(255);
- myData2[x][y] = color(255);
- }
- }
- }
- }
- class View {
- Model model;
- View(Model model) {
- this.model = model;
- }
- void drawGrid(int offsetX, int offsetY) {
- for(int x = 0; x < 5; x++) {
- for(int y = 0; y < 5; y++) {
- fill(model.myData[x][y]);
- rect(offsetX + (x * 10), offsetY + (y * 10), 10, 10);
- }
- }
- }
- void drawGrid2(int offsetX, int offsetY) {
- for(int x = 0; x < 5; x++) {
- for(int y = 0; y < 5; y++) {
- fill(model.myData2[x][y]);
- rect(offsetX + (x * 10), offsetY + (y * 10), 10, 10);
- }
- }
- }
- void drawPattern() {
- fill(model.drawColor);
- rect(0, 100, 50, 50);
- drawGrid(0, 0);
- drawGrid2(0, 50);
- for(int x = 0; x < 11; x++) {
- for(int y = 0; y < 13; y++) {
- if(model.seq) {
- if(x % 2 == 0)
- drawGrid(x * 50 + 50, y * 50);
- else
- drawGrid2(x * 50 + 50, y * 50);
- }else {
- drawGrid(x * 50 + 50, y * 50);
- }
- }
- }
- }
- }
- class Control {
- Model model;
- View view;
- Control(Model model, View view) {
- this.model = model;
- this.view = view;
- }
- void press() {
- if(mouseButton == RIGHT) {
- model.seq = !model.seq;
- view.drawPattern();
- return;
- }
- int x = mouseX / 10;
- int y = mouseY / 10;
- if(x < 5 && y < 5) {
- model.myData[x][y] = model.drawColor;
- view.drawPattern();
- }else if(x < 5 && y < 10) {
- model.myData2[x][y - 5] = model.drawColor;
- view.drawPattern();
- }
- x = mouseX / 50;
- y = mouseY / 50;
- if(x == 0 & y == 2) {
- model.drawColor = color(random(255), random(255), random(255));
- view.drawPattern();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement