Problems with translate

Hi everyone, i’m really new to processing, and I have a project that consists on doing something in 3d, so I was trying to draw the Starry Night and add the stars and houses with spheres that rotate and boxes, but when I use translate just one object moves and all the other ones dissapear apparently? I don’t really know what I’m doing wrong and I was hoping someone could help me please. This is what I currenty have:(

float  x=0.0;
int y=0;

void setup(){
  size(800,600,P3D);
  background(33,55,130);
}
  void draw(){
    
    //sky
  strokeWeight(20);
  strokeCap(ROUND);
  stroke(129,186,205);
    line(0,100,150,80);
line(150,80,x*2,85);
x=x+0.5;
line(190,85,300,90);
line(300,90,400,120);
line(400,120,500,130);
line(500,130,600,140);
line(600,140,700,160);
line(600,140,x*2,160);
line(700,160,800,130);
stroke(29,31,44);
strokeWeight(5);
line(800,50,x*2,160);
stroke(221,218,201);
strokeWeight(5);
line(800,40,x*.5,130);
     stroke(29,31,44);
   line(800,300,x*2,200);
   stroke(56,100,103);
   line(x*2,350,400,200);
   stroke(55,105,200);
   line(x,300,x*2, 200);
   stroke(129,186,205);
   line(x*2,300,500,200);

//mountains
fill(120,148,170);
noStroke();
ellipse(100,550,200,100);
fill(50,70,77);
ellipse(0,600,300,150);
fill(18,18,30);
ellipse(300,600,400,120);
fill(33,60,127);
ellipse(800,600,800,120);

  //tree
    fill(10);
strokeWeight(2);
stroke(5);
beginShape();
vertex(250,750);
vertex(225,700);
vertex(250,650);
vertex(235,600);
vertex(260,400);
vertex(257,350);
vertex(265,370);
vertex(270,350);
vertex(267,270);
vertex(259,250);
vertex(265,200);
vertex(272,250);
vertex(278,260);
vertex(280,275);
vertex(284,350);
vertex(290,400);
vertex(310,500);
vertex(315,470);
vertex(320,500);
vertex(330,550);
vertex(325,480);
vertex(335,460);
vertex(345,490);
vertex(356,500);
vertex(360,525);
vertex(375,550);
vertex(375,580);
vertex(393,650);
vertex(387,750);
vertex(250,750);
endShape(CLOSE);
 
  //stars
 
  fill(75,142,169);
translate(700,100,0);
sphere(30);
    
    translate(500,200,0);
    sphere(20);
    
    }
1 Like

Hello,

Please format your code:
https://discourse.processing.org/faq#format-your-code

Resources < Click here to expand !

I encourage you to review the resources available here:

:)

1 Like
float  x=0.0;
int y=0;

void setup(){
  size(800,600,P3D);
  background(33,55,130);
}
  void draw(){
    
    //sky
  strokeWeight(20);
  strokeCap(ROUND);
  stroke(129,186,205);
    line(0,100,150,80);
line(150,80,x*2,85);
x=x+0.5;
line(190,85,300,90);
line(300,90,400,120);
line(400,120,500,130);
line(500,130,600,140);
line(600,140,700,160);
line(600,140,x*2,160);
line(700,160,800,130);
stroke(29,31,44);
strokeWeight(5);
line(800,50,x*2,160);
stroke(221,218,201);
strokeWeight(5);
line(800,40,x*.5,130);
     stroke(29,31,44);
   line(800,300,x*2,200);
   stroke(56,100,103);
   line(x*2,350,400,200);
   stroke(55,105,200);
   line(x,300,x*2, 200);
   stroke(129,186,205);
   line(x*2,300,500,200);

   

//mountains
fill(120,148,170);
noStroke();
ellipse(100,550,200,100);
fill(50,70,77);
ellipse(0,600,300,150);
fill(18,18,30);
ellipse(300,600,400,120);
fill(33,60,127);
ellipse(800,600,800,120);


    
    //tree
    fill(10);
strokeWeight(2);
stroke(5);
beginShape();
vertex(250,750);
vertex(225,700);
vertex(250,650);
vertex(235,600);
vertex(260,400);
vertex(257,350);
vertex(265,370);
vertex(270,350);
vertex(267,270);
vertex(259,250);
vertex(265,200);
vertex(272,250);
vertex(278,260);
vertex(280,275);
vertex(284,350);
vertex(290,400);
vertex(310,500);
vertex(315,470);
vertex(320,500);
vertex(330,550);
vertex(325,480);
vertex(335,460);
vertex(345,490);
vertex(356,500);
vertex(360,525);
vertex(375,550);
vertex(375,580);
vertex(393,650);
vertex(387,750);
vertex(250,750);
endShape(CLOSE);
 
 
 //stars
 
  fill(75,142,169);

translate(700,100,0);
sphere(30);
    
    translate(500,200,0);
    sphere(20);
     
}
1 Like

Please use the pencil below the code of your two posts. Then select everything and delete it.
Paste your code again and select exactly and only the code. Then press the </> button.
There is no x2 declared in your code. Also you can’t use x.5.

Hello,

I posted some resources for you before to explore in my previous post.

The rest is you and your imagination.

And some work on your part learning how to use the tools.

I only tweaked your code a bit and made some comments.

Code
float x=0.0;
int y=0;

void setup() 
  {
  size(800, 600, P3D);
  background(33, 55, 130);
  }

void draw() 
  {
  background(33, 55, 130);
  lights();               // :) 
  //sky
  strokeWeight(20);
  strokeCap(ROUND);       // Does NOT work in P3D
  stroke(129, 186, 205);
  line(0, 100, 150, 80);
  line(150, 80, x*2, 85);
  x=x+0.5;
  line(190, 85, 300, 90);
  line(300, 90, 400, 120);
  line(400, 120, 500, 130);
  line(500, 130, 600, 140);
  line(600, 140, 700, 160);
  line(600, 140, x*2, 160);
  line(700, 160, 800, 130);
  stroke(29, 31, 44);
  strokeWeight(5);
  line(800, 50, x*2, 160);
  stroke(221, 218, 201);
  strokeWeight(5);
  line(800, 40, x*.5, 130);
  stroke(29, 31, 44);
  line(800, 300, x*2, 200);
  stroke(56, 100, 103);
  line(x*2, 350, 400, 200);
  stroke(55, 105, 200);
  line(x, 300, x*2, 200);
  stroke(129, 186, 205);
  line(x*2, 300, 500, 200);

  //mountains
  fill(120, 148, 170);
  noStroke();
  ellipse(100, 550, 200, 100);
  fill(50, 70, 77);
  ellipse(0, 600, 300, 150);
  fill(18, 18, 30);
  ellipse(300, 600, 400, 120);
  fill(33, 60, 127);
  ellipse(800, 600, 800, 120);

  //tree
  fill(0, 255, 0);
  strokeWeight(2);
  stroke(5);
  beginShape();
  vertex(250, 750);
  vertex(225, 700);
  vertex(250, 650);
  vertex(235, 600);
  vertex(260, 400);
  vertex(257, 350);
  vertex(265, 370);
  vertex(270, 350);
  vertex(267, 270);
  vertex(259, 250);
  vertex(265, 200);
  vertex(272, 250);
  vertex(278, 260);
  vertex(280, 275);
  vertex(284, 350);
  vertex(290, 400);
  vertex(310, 500);
  vertex(315, 470);
  vertex(320, 500);
  vertex(330, 550);
  vertex(325, 480);
  vertex(335, 460);
  vertex(345, 490);
  vertex(356, 500);
  vertex(360, 525);
  vertex(375, 550);
  vertex(375, 580);
  vertex(393, 650);
  vertex(387, 750);
  vertex(250, 750);
  endShape(CLOSE);

  //stars 
  push(); 
  fill(75, 142, 169);      //Look up push() and pop()
  translate(700, 100, 0);
  noStroke();
  sphere(30);
  pop();
  
  // Work on this...
  translate(500, 200, 0);
  sphere(20);
  }

:)

1 Like