# Please Help: How to add texture

**URL:** <https://discourse.processing.org/t/please-help-how-to-add-texture/30311>\
**Category:** Processing.py\
**Tags:** homework\
**Created:** [May 26, 2021, 10:42am UTC](https://discourse.processing.org/t/please-help-how-to-add-texture/30311 "2021-05-26T10:42:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bridgette](https://avatars.discourse-cdn.com/v4/letter/b/b3f665/32.png) [@bridgette](https://discourse.processing.org/u/bridgette)\
**Post date:** [May 26, 2021, 10:42am UTC](https://discourse.processing.org/t/please-help-how-to-add-texture/30311/1 "2021-05-26T10:42:56Z")

</div>

Hello,  
I wanted to create a sphere with texture on it. So I tried to make the image wrap around the sphere, but when I run the code, only the rotating sphere shows. Is there something wrong with the code?

```auto
def setup():
    size(550,700,P3D)
    global img
    img = loadImage('uranus.jpg')

r = 0;
z = 200; 

def draw():
    global r
    global z
    
    background(0)
    stroke('#FFFFFF')
    strokeWeight(2)
    fill('#FF0000')
    translate(width/2, height/2, z)
    rotateY(r)
    beginShape()
    texture(img)
    textureWrap(REPEAT)
    noFill()
    
    
    pushMatrix()
    translate(0,0)
    sphere(100)
    lights()
    popMatrix()
*emphasized text*

```

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [May 26, 2021, 10:51am UTC](https://discourse.processing.org/t/please-help-how-to-add-texture/30311/2 "2021-05-26T10:51:39Z")

</div>

Wheres your endShape() call to close the shape.

---

<div class="post-metadata">

**Author:** ![bridgette](https://avatars.discourse-cdn.com/v4/letter/b/b3f665/32.png) [@bridgette](https://discourse.processing.org/u/bridgette)\
**Post date:** [May 26, 2021, 10:56am UTC](https://discourse.processing.org/t/please-help-how-to-add-texture/30311/3 "2021-05-26T10:56:05Z")

</div>

Hello, I just added it and it still only gives me the rotating sphere without the texture.

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [May 26, 2021, 11:08am UTC](https://discourse.processing.org/t/please-help-how-to-add-texture/30311/4 "2021-05-26T11:08:33Z")

</div>

Are you sure you are translating to the right place?

---

<div class="post-metadata">

**Author:** ![bridgette](https://avatars.discourse-cdn.com/v4/letter/b/b3f665/32.png) [@bridgette](https://discourse.processing.org/u/bridgette)\
**Post date:** [May 26, 2021, 11:12am UTC](https://discourse.processing.org/t/please-help-how-to-add-texture/30311/5 "2021-05-26T11:12:18Z")

</div>

Yes, so when I run the program, everything is according to plan except the texture doesn’t come

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [May 26, 2021, 11:18am UTC](https://discourse.processing.org/t/please-help-how-to-add-texture/30311/6 "2021-05-26T11:18:11Z")

</div>

Just cooking atm and then have some shopping to do, will check in later.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 26, 2021, 1:54pm UTC](https://discourse.processing.org/t/please-help-how-to-add-texture/30311/7 "2021-05-26T13:54:16Z")

</div>

> [@bridgette](#):
>
> everything is according to plan except the texture doesn’t come

Take at look at the Processing JAVA example (see last section) to give you a idea of how this is done in the JAVA version:

[https://processing.org/tutorials/pshape/](https://processing.org/tutorials/pshape/)

There is a reference in the PShape tutorial to the P3D tutorial which is available in JAVA and Python:  
[https://py.processing.org/tutorials/p3d/](https://py.processing.org/tutorials/p3d/)

I did not find a Processing Python tutorial on PShapes.

Now _ **adapt this** _ to the Processing Python version.

Start simple and just texture the sphere first and add other code later.

This is a working Processing (JAVA) version:

```auto
PShape sph;
PImage img;

void setup() 
  {
  size(300, 300, P3D);
  img = loadImage("frog.png");
  sph = createShape(SPHERE, 100);
  sph.setTexture(img);
  shape(sph, width/2, height/2);
  noLoop();
  }

```

You will have to adapt this to Python; this is not difficult and I was able to do this in Python.

Reference to help with createShape() for Python:  
[https://py.processing.org/reference/createShape.html](https://py.processing.org/reference/createShape.html)

The Processing JAVA and Python version had the same output:

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/fb32ed801b14b827e359293003e5830286d694db.png)

The Processing resources are here:  
_[https://processing.org/](https://processing.org/)_  
And you can select Python from the menu along the top.

`:)`
