void setup() {
size(600,600) ;
background (#69C2FC) ;
}
void draw() {
fill(#FF7164);
circle(300,500,700);
stroke(0);
fill(#FFA064);
circle(300,500,650);
stroke(0);
fill(#FCFF64);
circle(300,500,600);
stroke(0);
fill(#80FF64);
circle(300,500,550);
stroke(0);
fill(#64FBFF);
circle(300,500,500);
stroke(0);
fill(#6468FF);
circle(300,500,450);
stroke(0);
fill(#B664FF);
circle(300,500,400);
stroke(0);
fill(#FC64FF);
circle(300,500,350);
stroke(0);
fill(#FF64C9);
circle(300,500,300);
stroke(0);
fill(#69C2FC);
circle(300,500,250);
stroke(0);
fill (#69FC8C) ;
stroke(#0F0501);
rect(0,500,700,500) ;
fill(#AA7C65);
rect(150, 350, 100, 150);
fill(#C67272);
triangle(150, 350, 250, 350, 200, 300);
fill (#E3C3A5);
stroke(#0F0501);
rect(170,450,20,50);
fill (#F1FF5D);
stroke(#0F0501);
rect(210,400,20,20);
fill (#F1FF5D);
stroke(#0F0501);
rect(160,400,20,20);
fill(#FFB87E);
ellipse(350,490,20,40);
stroke (#FFB87E);
fill(#FFB87E);
ellipse(350,490,20,40);
stroke (#FFB87E);
fill(#FFB87E);
ellipse(350,460,20,20);
stroke (#FFB87E);
fill(#FFB87E);
ellipse(340,450,10,10);
stroke (#FFB87E);
fill(#FFB87E);
ellipse(360,450,10,10);
stroke (#FFB87E);
fill(#FFF8A7);
ellipse(500,50,50,50);
fill(#FFB87E);
ellipse(335,500,10,10);
stroke (#FFB87E);
fill (#6A4C3E);
stroke(#0F0501);
rect(400,400,20,100);
fill(#3DDB00);
circle(360,400,50);
stroke(#3DDB00);
fill(#3DDB00);
circle(390,430,50);
stroke(#3DDB00);
fill(#3DDB00);
circle(405,410,50);
stroke(#3DDB00);
fill(#3DDB00);
circle(390,370,50);
stroke(#3DDB00);
fill(#3DDB00);
circle(430,370,50);
stroke(#3DDB00);
fill(#3DDB00);
circle(430,400,50);
stroke(#3DDB00);
fill(#3DDB00);
circle(440,425,50);
stroke(#3DDB00);
fill(#3DDB00);
circle(360,400,50);
stroke(#3DDB00);
fill(#3DDB00);
circle(460,395,50);
stroke(0);
stroke(#3DDB00);
fill(#FF2C15);
circle(360,400,15);
fill(#FF2C15);
circle(440,500,15);
stroke(#3DDB00);
fill(#FF2C15);
circle(440,370,15);
stroke(#3DDB00);
fill(#FF2C15);
circle(440,410,15);
stroke(#3DDB00);
fill(#FF2C15);
circle(400,400,15);
stroke(#030000);
fill(#FFFFFF);
circle(120,55,50);
stroke(#FFFFFF);
fill(#FFFFFF);
circle(140,90,50);
stroke(#FFFFFF);
fill(#FFFFFF);
circle(100,100,50);
stroke(#FFFFFF);
fill(#FFFFFF);
circle(120,55,50);
stroke(#FFFFFF);
fill(#FFFFFF);
circle(80,85,50);
stroke(#FFFFFF);
stroke(0);
float x = random(width);
float y = random(height / 2);
line(x, y, x + 10, y - 5);
line(x + 10, y - 5, x + 20, y);
}
Hello @averges, welcome! Your post has been edited to format the code for better readability. Please review our FAQ for guidance on posting code. Thank you!
Your code that creates a nice graphic image but it is not clear what your question is
Nice image !!!
I am not sure what your question is.
Using functions
First, it’s useful to split the long draw() function into different functions that we call from draw().
So you can see where is tree() and dog() in your code and so on.
Some even say, that one function should not be longer than one screen page. So you can see it at once without scrolling.
Tipp: In draw() you can right-click on dog() and jump to its definition (to the dog() function below). Nice.
Stroke command
please understand that here
fill(#FF7164);
circle(300, 500, 700);
stroke(0);
The order is a bit off.
The stroke command would not effect the circle command, because the stroke command is after the circle command.
Before drawing the circle we need to set how we draw it, so we use fill and stroke before circle command:
fill(#FF7164);
stroke(0);
circle(300, 500, 700);
That looks better.
That occurs a lot in your code; please be aware that the stroke command affects the next circle/rect not the previous one.
Stroke and fill
Once stroke and fill are set for a circle and the next circle has the same stroke and fill again, you don’t have to repeat this.
So here
fill(#FC64FF);
circle(300,500,350);
stroke(0);
fill(#FC64FF); // same color again
circle(300,500,300);
stroke(0);
just say
fill(#FC64FF); // define color once
stroke(0);
circle(300,500,350); // use the same color twice or more times
circle(300,500,300);
The birds
draw() runs on and on in a loop automatically.
That’s why you get so many birds.
I stopped draw() from doing loops by saing noLoop().
Instead, I made a for-loop for the birds only.
(draw() stops now, so it’s not interactive, you can’t do animations now. There are other solutions for that).
Use comments
Comments // can be useful.
Warm regards,
Chrisir
Code
void setup() {
size(600, 600);
background(#69C2FC);
noLoop(); // !!!!!!!!!!!!!!!!!!!!!!!
}
void draw() {
background (#69C2FC); // !!!!!!!!!!!!!!!!!!!!!!!
rainbow();
house();
sun();
grassArea();
dog();
tree();
apples();
cloud();
birds();
}
//----------------------------------------------------------------------
void rainbow() {
fill(#FF7164);
stroke(0);
circle(300, 500, 700);
fill(#FFA064);
circle(300, 500, 650);
fill(#FCFF64);
circle(300, 500, 600);
fill(#80FF64);
circle(300, 500, 550);
fill(#64FBFF);
circle(300, 500, 500);
fill(#6468FF);
circle(300, 500, 450);
fill(#B664FF);
circle(300, 500, 400);
fill(#FC64FF);
circle(300, 500, 350);
fill(#FF64C9);
circle(300, 500, 300);
fill(#69C2FC);
circle(300, 500, 250);
}
void house() {
//
fill(#AA7C65);
rect(150, 350, 100, 150);
fill(#C67272);
triangle(150, 350, 250, 350, 200, 300);
fill (#E3C3A5);
stroke(#0F0501);
rect(170, 450, 20, 50);
fill (#F1FF5D);
stroke(#0F0501);
rect(210, 400, 20, 20);
fill (#F1FF5D);
stroke(#0F0501);
rect(160, 400, 20, 20);
}
void dog() {
// Dog
fill(#FFB87E);
stroke (#FFB87E);
ellipse(350, 490, 20, 40);
ellipse(350, 490, 20, 40);
ellipse(350, 460, 20, 20);
ellipse(340, 450, 10, 10);
ellipse(360, 450, 10, 10);
ellipse(335, 500, 10, 10);
}
void tree() {
// stem tree
fill (#6A4C3E);
stroke(#0F0501);
rect(400, 400, 20, 100); // stem tree
// green tree parts
fill(#3DDB00);
stroke(#3DDB00);
circle(360, 400, 50);
circle(390, 430, 50);
circle(405, 410, 50);
circle(390, 370, 50);
circle(430, 370, 50);
circle(430, 400, 50);
circle(440, 425, 50);
circle(360, 400, 50);
circle(460, 395, 50);
}
void apples() {
stroke(#3DDB00);
fill(#FF2C15);
circle(360, 400, 15);
circle(440, 500, 15);
circle(440, 370, 15);
circle(440, 410, 15);
circle(400, 400, 15);
}
void cloud() {
fill(#FFFFFF);
stroke(#FFFFFF);
circle(120, 55, 50);
circle(140, 90, 50);
circle(100, 100, 50);
circle(120, 55, 50);
circle(80, 85, 50);
}
void sun() {
stroke (#FFB87E);
fill(#FFF8A7);
ellipse(500, 50, 50, 50);
}
void grassArea() {
fill (#69FC8C);
stroke(#0F0501);
rect(0, 500, 700, 500);
}
void birds() {
// birds
int max=int(random(22, 100));
for (int i=0; i<max; i++) {
stroke(0);
float x = random(width);
float y = random(height / 2);
line(x, y, x + 10, y - 5);
line(x + 10, y - 5, x + 20, y);
}
}
//