CodingTrain / Suggestion-Box

A repo to track ideas for topics
572 stars 86 forks source link

Mondrian #456

Open josefuks opened 7 years ago

josefuks commented 7 years ago

Hey Daniel , I was thinking about a code that could generate a neoplastic artwork(specifically from piet mondrian), I made a quick sketch on processing:


Mondrian a;
void setup(){
  background(255);
  size(600,440);
  a = new Mondrian();}
  void draw(){
    noLoop();

    a.display();
  }
class Mondrian{

void display(){

  for (float i=0;i<40;i=i+1){
float larg=random(width);
float altura=random(height);
float x=random(width);
float y=random(height);
color red=color(255,0,0);
color yellow=color(255,255,0);
color b=color(0,0,255);
color branco=color(255,255,255);
color[] cores={red,yellow,b,branco};
int index=int(random(4));
fill(cores[index]);

rect(x,y,larg,altura);

strokeWeight(4);
println(i);}}}

An issue that I couldn't fix yet is that I couldnt make the rectangles stop overlapping each others, and I dont know how to use p5 yet.... :( I started learning code 6 days ago, so I am still a padwan.... I love your videos!Thank you and sorry for this bad code here!

Davidramsey03 commented 6 years ago

Hey there, I'm not an admin here, but saw your post, and thought I'd give my two cents. I think you're off to a decent start, but the approach needs to be a bit different to achieve a "non-overlapping" setup, as the rect function is merely drawing shapes to the screen, not objects that have any "awareness" in this context.

I've found a sketch you can demo/look through on OpenProcessing here, where the author has taken a 'grids and row dividers' approach.

Hope that points you in the right direction.