How to fill the sphere with the earth image?

Here is my code :

 PImage background;
 PImage globe;

void setup() {
  size (1025,576,P3D);
  background = loadImage("luarangkasa.jpg");
  globe = loadImage("bumi.jpg");
}

void draw()  {
  background(background);
  pushMatrix();
  translate(500,300);
  lights();
  rotateY(radians(HALF_PI* frameCount));
  sphere(150);
  texture(globe);
  popMatrix();
}

Untitled

Answers

  • Answer ✓

    https://forum.processing.org/two/discussion/13500/applying-a-texture-to-a-sphere
    This is the code posted by @TfGuy44:

    PShape globe;
    
    void setup() { 
      size(600, 600, P3D); 
      background(0); 
      String http = "http://";
      earth = loadImage( http + "previewcf.turbosquid.com/Preview/2014/08/01__15_41_30/Earth.JPG5a55ca7f-1d7c-41d7-b161-80501e00d095Larger.jpg");
      globe = createShape(SPHERE, 200); 
      globe.setTexture(earth);
      noStroke();
    }
    
    void draw() { 
      translate(width/2, height/2); 
      shape(globe);
    }
    
  • it works mr.cameyo, i need some help again, How to remove the existing line on the sphere? i'd use noStroke(); and the line still in there

  • Try (un-tested)

    globe.beginShape();
    globe.noStroke();
    globe.endShape();
    

    Kf

  • doesn't work my friend, have another idea? that's make the globe is disappear

  • Try:

      globe = createShape(SPHERE, 200); 
      globe.setStroke(false);
      globe.setTexture(earth);
    
  • PShape globe;
    
    void setup() { 
      size(600, 600, P3D); 
      background(0); 
      String http = "http://";
      PImage earth = loadImage( http + "previewcf.turbosquid.com/Preview/2014/08/01__15_41_30/Earth.JPG5a55ca7f-1d7c-41d7-b161-80501e00d095Larger.jpg");
      globe = createShape(SPHERE, 200); 
      globe.setStroke(false);
      globe.setTexture(earth);
      noStroke();
    }
    
    void draw() {
      background(0);
      translate(width/2, height/2);
      rotateY(map(mouseX,0,width,-PI,PI));
      rotateX(map(mouseY,0,width,-PI,PI));
      shape(globe);
    }
    

    Still works great. What's the problem?

  • edited May 2017

    @mohammadarifien --

    I don't know what bumi.jpg is, but my guess is that the line is an artifact of your image.

    Notice that the image that @TfGuy44 is using is designed to wrap around into a globe -- the left side and the right side match up perfectly. Does bumi.jpg do that? If the two sides don't match then you are going to see a line no matter what -- you need to fix your image.

  • edited May 2017

    thanks a lot guys i appreciated it

Sign In or Register to comment.