Hi all, first post here.
A little background info: One week ago I started to learn how to code in Processing. I’m not familiar with creating code, only with altering work of others. I’ve worked in python, java, javascript etc but never wrote my own code. I have been designing and building pen plotters this summer and decided I want to generate my own artworks to print on these machines. So: incentive to finally learn to work in Processing. Hurray! I’m 35, poorly schooled and everything I do is autodidact.
To teach myself in ‘generative thinking’ I first followed some tutorials and guides for a week and then set off to start and create my own code. What I did was look at the output generated by others (only visual, no code) and tried to generate a similar work to try and think how one could have solved it.
This is the work I’m trying to re-create (by Diana Lange):
Sadly I am limited to only one image per post (come on…) so I’ll try to explain.
When you run the code, the circles shouldn’t be falling over each other in a 90º angle. However, in my script this sometimes happens.
So far I’ve managed to make mostly everything work but I’m running into a barrier here. This question has two parts:
-
How can I make this code smaller/more compatible?
The code consists of a lot of lines that I think are not necessary. I have been working in functions before and plan to convert the code to functions after I solved question number 2: -
How can I prevent this issue with the 90º overlap from happening?
Below you can find the entire code that I’ve written, I know it’s quite bulky but please with me, I’m pretty new to this!
If my question could’ve been written more efficiently, let me know. I am autistic and this sometimes causes me to lose the big picture and focus too much on details.
Have a nice day,
Marinus
void setup() {
pixelDensity(displayDensity()); // set resolution for retina screen on a macbook
size(500, 500);
background(255);
noLoop();
}
float sS = 120; // squareSize, used in the for loop
float offS = 20; // offset (white lines in between boxes), both directions
float xLoc = 0; // x Location
float yLoc = 0; // y Location
float rSx = 100; //rectangle Size x
float rSy = 100; //rectangle Size y
void draw () {
noStroke();
for (float r=0; r<480; r+=sS) { // create four fows
for (float c=0; c<480; c+=sS) { // create four columns of the four rows
fill(#3E83A2); // blue squares
rect(xLoc+offS+r, yLoc+offS+c, rSx, rSy); // draw the rectangles
fill(240); // fill color for the off-white half circles
float dice1 = random(6); // generate a random number to decide the orientation of the white half circle
if (dice1<1) {
float startdeg = 0;
float enddeg = 180;
float startrad = radians(startdeg);
float endrad = radians(enddeg);
fill(240);
arc(xLoc+offS+r+(rSx/2), yLoc+offS+c+(rSy/2), rSx-30, rSy-30, startrad, endrad, PIE);
} else if (dice1<2) {
float startdeg = 90;
float enddeg = 270;
float startrad = radians(startdeg);
float endrad = radians(enddeg);
fill(240);
arc(xLoc+offS+r+(rSx/2), yLoc+offS+c+(rSy/2), rSx-30, rSy-30, startrad, endrad, PIE);
} else if (dice1<3) {
float startdeg = 180;
float enddeg = 360;
float startrad = radians(startdeg);
float endrad = radians(enddeg);
fill(240);
arc(xLoc+offS+r+(rSx/2), yLoc+offS+c+(rSy/2), rSx-30, rSy-30, startrad, endrad, PIE);
} else if (dice1<4) {
float startdeg = 270;
float enddeg = 90;
float startrad = radians(startdeg);
float endrad = radians(enddeg);
fill(240);
arc(xLoc+offS+r+(rSx/2), yLoc+offS+c+(rSy/2), rSx-30, rSy-30, startrad, endrad, PIE);
}
float dice2 = random(6); // generate a random number to decide the orientation of the blue half circle
if (dice2<1) {
float startdeg = 0;
float enddeg = 180;
float startrad = radians(startdeg);
float endrad = radians(enddeg);
fill(#264D5F);
arc(xLoc+offS+r+(rSx/2), yLoc+offS+c+(rSy/2), rSx-30, rSy-30, startrad-PI, endrad-PI, PIE);
} else if (dice2<2) {
float startdeg = 90;
float enddeg = 270;
float startrad = radians(startdeg);
float endrad = radians(enddeg);
fill(#264D5F);
arc(xLoc+offS+r+(rSx/2), yLoc+offS+c+(rSy/2), rSx-30, rSy-30, startrad-PI, endrad-PI, PIE);
} else if (dice2<3) {
float startdeg = 180;
float enddeg = 360;
float startrad = radians(startdeg);
float endrad = radians(enddeg);
fill(#264D5F);
arc(xLoc+offS+r+(rSx/2), yLoc+offS+c+(rSy/2), rSx-30, rSy-30, startrad-PI, endrad-PI, PIE);
} else if (dice2<4) {
float startdeg = 270;
float enddeg = 90;
float startrad = radians(startdeg);
float endrad = radians(enddeg);
fill(#264D5F);
arc(xLoc+offS+r+(rSx/2), yLoc+offS+c+(rSy/2), rSx-30, rSy-30, startrad-PI, endrad-PI, PIE);
}
}
}
}
ps added comments in the code so you don’t have to sift through to understand it