[Solved]Problem with rotating cells in array
              in 
             Contributed Library Questions 
              •  
              8 months ago    
            
 
           
             Hello everyone, I am new to the forum and have been interested in Processing for quite a while, I am a 3D artist which doesn't help me at all at trying to learn programming language (: but I am trying my best! 
            
            
I want to make a generative pattern program that gives the user an option to the colour scheme and shape of the pattern but still maintain a bit of randomness to the whole thing. The problem is that I cannot make the cells rotate individually when Box mode is on. which will result in whole a lot different patterns. That is in the last if/else statement. Hope you understand. Sorry if my code is messy.
            
Thank you!
            
            
 
            
           I want to make a generative pattern program that gives the user an option to the colour scheme and shape of the pattern but still maintain a bit of randomness to the whole thing. The problem is that I cannot make the cells rotate individually when Box mode is on. which will result in whole a lot different patterns. That is in the last if/else statement. Hope you understand. Sorry if my code is messy.
Thank you!
- import controlP5.*;
 - Cell[] [] grid;
 - int cols = 50;
 - int rows = 25;
 - ControlP5 cp5;
 - int R = 100;
 - int G = 100;
 - int B = 100;
 - int A = 100;
 - int size = 80;
 - int save = 0;
 - int Box = 0;
 - int Smooth = 0;
 - int Angle = 0;
 - Slider abc;
 - void setup() {
 - size(1000, 600);
 - frameRate(8);
 - cp5 = new ControlP5(this);
 - cp5.addSlider("R")
 - .setPosition(50, 20)
 - .setRange(0, 255);
 - cp5.addSlider("G")
 - .setPosition(50, 30)
 - .setRange(0, 255);
 - cp5.addSlider("B")
 - .setPosition(50, 40)
 - .setRange(0, 255);
 - cp5.addSlider("A")
 - .setPosition(50, 50)
 - .setRange(0, 255);
 - cp5.addSlider("size")
 - .setPosition(50, 60)
 - .setRange(0, 150);
 - cp5.addSlider("Smooth")
 - .setPosition(62, 72)
 - .setRange(0, 80)
 - .setSize(88, 9);
 - cp5.addSlider("Angle")
 - .setPosition(62, 83)
 - .setRange(0, 80)
 - .setSize(88, 9);
 - cp5.addButton("save")
 - .setPosition (0, 20)
 - .setSize (49, 49);
 - cp5.addToggle("Box")
 - .setPosition (50, 72)
 - .setSize (9, 9);
 - grid = new Cell [cols][rows];
 - for (int i=0; i<cols; i++) {
 - for (int j=0; j<rows; j++) {
 - grid[i][j] = new Cell (i*50, j*50, size, size, Smooth, Angle);
 - }
 - }
 - }
 - void draw() {
 - smooth();
 - rect(0, 0, width, height);
 - background(255);
 - for (int i=0; i< cols; i++) {
 - for (int j=0; j < rows; j++) {
 - grid[i][j].display();
 - }
 - }
 - if (save == 0) {
 - save =0;
 - }
 - else {
 - saveFrame();
 - save=0;
 - }
 - }
 - class Cell {
 - float x, y;
 - float h, w;
 - float r, a;
 - Cell(float tempX, float tempY, float tempW, float tempH, float tempR, float tempA) {
 - x = tempX;
 - y = tempY;
 - w = tempW;
 - h = tempH;
 - r = tempR;
 - a = tempA;
 - }
 - void display() {
 - if (Box == 0) {
 - noStroke();
 - fill(random(R), random(G), random(B), random(A));
 - ellipse(x, y, size, size);
 - }
 - else {
 - rectMode(CENTER);
 - rotate(PI+Angle);
 - fill(random(R), random(G), random(B), random(A));
 - rect(x, y, size, size, Smooth);
 - }
 - }
 - }
 
 
              
              1  
            
 
            