Issue With Making a House

Hi Guys, Im trying to make a house and my code isn’t running. Can someone please tell me why?

This is the code:

void setup()
{
  size(200, 200);
  background(255);
  smooth();
}

void draw ()
{
 fill(#1E4609);
 rect (0, 500, 800, 600);
 fill (#E6F2E8);
 ellipse (240, 80, 100, 50);
 ellipse (200, 100, 100, 50);
 ellipse (220, 150, 100, 50);
 fill(#EBF233);
 ellipse(700, 75, 75, 75);
 }
 
 {
  fill(#714B11);
  rect (98, 388, 250, 125);
  fill (#837C71);
  rect (131, 420, 50, 50);
}

Thanks!

little cleanup, resize …
and posted with </> code formatter

void setup() {
  size(800, 800);
}

void draw () {
  background(255);
  fill(#1E4609);
  rect (0, 500, 800, 600);
  fill (#E6F2E8);
  ellipse (240, 80, 100, 50);
  ellipse (200, 100, 100, 50);
  ellipse (220, 150, 100, 50);
  fill(#EBF233);
  ellipse(700, 75, 75, 75);
  fill(#714B11);
  rect (98, 388, 250, 125);
  fill (#837C71);
  rect (131, 420, 50, 50);
}

you have clouds over the house, and still no roof, hurry up! rain is coming!

Thank you so much! Appreciate it a lot :grin:

I want to make a triangular roof, where would i add that in the code?

use the
https://processing.org/reference/triangle_.html

and use it ?after the rectangle of the house?

please document your code like

// house:
fill()
rect()
fill()
stroke()
strokeWeight()
triangle()

but next step in coding would be
-a- make the house a function
-b- make it so that you can position it

void myHouse(int posx, int posy) {
  push();
  // graphic elements using relative to position 
  pop();
}

and call it like

  myHouse(100,400);

from draw()

Ive done this so far and can’t seem to get it. I don’t know where to place the points of the triangle

void setup() {
  size(800, 800);
}

void draw () {
  background(255);
  fill(#1E4609);
  rect (0, 500, 800, 600);
  fill (#E6F2E8);
  triangle (100,115, 58, 20, 86, 75);
  ellipse (100, 100, 100, 50);
  ellipse (300, 100, 100, 50);
  ellipse (500, 100, 100, 50);
  fill(#EBF233);
  ellipse(700, 75, 75, 75);
  fill(#714B11);
  rect (98, 388, 250, 125);
  fill (#837C71);
  rect (131, 420, 50, 50);
} ```

33%20pm

Here the triangle is in the cloud, and I get really confused about where to place them in relation to the rectangle.

Hello!

In draw() write println (mouseX,mouseY);

(or if (mousePressed) println (mouseX,mouseY); )

  • Start program
  • Move mouse to where you want to have the corners of the triangle
  • Make notes where they are on a sheet of paper
  • Use them for your triangle

The coordinate system:

  • The upper left corner of the screen is your 0,0.
  • x goes right, y goes down.

see also https://www.processing.org/tutorials/drawing/

Chrisir

1 Like

first step:

  myHouse();
}
void myHouse() {
  push();
  fill(#714B11);
  rect (100, 400, 250, 125);
  fill (#837C71);
  rect (131, 420, 50, 50);
  fill(0,200,100);
  stroke(0,0,100);
  strokeWeight(15);
  triangle (100, 400, 225, 320, 350, 400);
  pop();
}

next step: relative positioning

  myHouse(100,400);
}
void myHouse(int posx,int posy) {
  push();
  fill(#714B11);
  rect (posx, posy, 250, 125);
  fill (#837C71);
  rect (posx+31, posy+20, 50, 50);
  fill(0,200,100);
  stroke(0,0,100);
  strokeWeight(15);
  triangle (posx, posy, posx+125, posy-80, posx+250,posy);
  pop();
}

if you now try

  myHouse(mouseX,mouseY);

you see how good that function and position thing can be.

The initial problem from your first post were these brackets { }

You can’t have a block of brackets outside of a function.

Instead, have these lines inside the function draw().

(inside draw() you can even use a block of brackets {...} )

Awesome! I tried running those codes but it kept coming up with error ‘it looks like you’re mixing active and static modes’, so I kept the code like this:

void setup() {
  size(800, 800);
}

void draw () {
  background(255);
  fill(#1E4609);
  rect (0, 500, 800, 600);
  fill (#6F4C19);
  triangle (100,400, 225, 320, 350, 400);
  fill (#E6F2E8);
  ellipse (100, 100, 100, 50);
  ellipse (100,150, 100, 60);
  ellipse (300, 150, 100, 60);
  ellipse (300, 100, 100, 50);
  ellipse (500, 150, 100, 60);
  ellipse (500, 100, 100, 50);
  fill(#EBF233);
  ellipse(700, 75, 75, 75);
  fill(#B77512);
  rect (98, 388, 250, 125);
  fill (#DBBB8B);
  rect (260, 420, 50, 50);
  rect (131, 420, 50, 50);
  fill (#76592D);
  rect (205, 452, 30,60);
}

Now i want to animate the clouds to move up and down, how exactly do i do this? I’ve tried following the processing website instructions, but i keep coming up with error.

how can it be awesome, if you can not test it?

sorry, i give example of making the house a own function.

and you learn that first and get that running.
https://processing.org/reference/void.html
fixing problems is number one for coders…

then you make same for the clouds
-a- a own function
-b- with relative positioning

and THEN we talk about a animation loop over that.

Why does it need to be a function?

because you again not document anything in your code…
and this way it reads very clear,
and as i said, it will come handy for a animation.
actually the play example with the usage of

 myHouse(mouseX,mouseY);

was to introduce you to moving element groups…

( but right: IT NOT NEED TO )

void setup() {
  size(800, 800);
  noStroke();
}

int x =200;

void draw () {
  background(175);
  myGround();
  myClouds(x,100);
  mySun(700, 75);
  myHouse(100,400);
}

and imagine you want a street with houses?