# Can you please tell me what I am doing wrong?

**URL:** https://discourse.processing.org/t/can-you-please-tell-me-what-i-am-doing-wrong/37330
**Category:** Coding Questions
**Tags:** homework
**Created:** [June 5, 2022, 5:09pm UTC](https://discourse.processing.org/t/can-you-please-tell-me-what-i-am-doing-wrong/37330 "2022-06-05T17:09:33Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![eve](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@eve](https://discourse.processing.org/u/eve)
#### Post date: [June 5, 2022, 5:09pm UTC](https://discourse.processing.org/t/can-you-please-tell-me-what-i-am-doing-wrong/37330/1 "2022-06-05T17:09:33Z")

</div>

Hi there!  
I’m a real real beginner student…  
I’ve got a problem while doing my homework.  
the task is to

1. make 3D QUAD that can be textured in ‘class’ using  
beginShape(QUADS), endShape(), vertex(x,y,z,tx,ty), texture().

2. make step 1 with ‘class array’ and use ‘for(){ }’ to create 3 object

3. prepare the texture image with ‘PImage’,  
and the image file name using ‘String’ that’s going to be used inside ‘loadImage(" ")’

4. randomly bring the img file name from the ‘String’  
and use it as a texture image of each 3 class objects that’s been made in step 2.

the problem is that I have a feeling that I’m doing this in a completely… wrong way…  
I’ve been working on this for like… a week and still got no clue…  
It’s an uncompleted version, but still could you please tell me  
what parts should I fix in here?

\<PImage img;  
String pic= {“pk.png”, “bl.png”, “yl.png”};

void setup(){  
size(800, 500, P3D);  
background(0);  
noStroke();

fl tx= new fl[3];  
for(int i=0; i\<tx.length; i++) {  
img= loadImage(random(pic.length));  
}

textureMode(NORMAL);  
camera(70.0, 35.0, 120.0, 50.0, 50.0, 0.0,  
0.0, 1.0, 0.0);  
}

void draw(){  
for(int i=0; i\<tx.length; i++) {  
TexturedQuad(tx);  
}  
}

class fl {

void TextureQuad(PImage img){  
beginShape(QUADS);  
texture(img);  
vertex(-1, -1, 1, 0, 0);  
vertex( 1, -1, 1, 1, 0);  
vertex( 1, 1, 1, 1, 1);  
vertex(-1, 1, 1, 0, 1);  
endShape();

```
beginShape(QUADS);
texture(img);
vertex(-1, -1, -1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, -1, 1, 1, 1);
vertex(-1, -1, 1, 0, 1);
endShape();

beginShape(QUADS);
texture(img);
vertex( 1, -1, 1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, 1, -1, 1, 1);
vertex( 1, 1, 1, 0, 1);
endShape();

```

}\>

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [June 5, 2022, 6:56pm UTC](https://discourse.processing.org/t/can-you-please-tell-me-what-i-am-doing-wrong/37330/2 "2022-06-05T18:56:36Z")

</div>

here is a version that at least does SOMETHING

BUT as you said, the principle of a class is not applied correctly.

- inside a class should be only ONE shape. Remember that the class is the cookie maker and the objects the cookies. When you have an array of the class, each slot in the array is one object. The class is the same for all of the 3. But each object has another position.
- by using an array of 3 shapes of the class you draw it in 3 different positions
- use x,y in the class as variables
- you form is over 0,0; so you need pushMatrix and translate and scale and popMatrix  
your class doesn’t have a constructor or variables (x,y). Please read: [Objects / Processing.org](https://processing.org/tutorials/objects)

**Old Version**

here is a version that at least does SOMETHING

```auto
// ‘class array’ 
QUAD3D[] tx = new QUAD3D[3];

String[] pic = {
  "pk.png", 
  "bl.png", 
  "yl.png"
};

PImage[] img = new PImage[3];

void setup() {
  size(800, 500, P3D);
  background(0);
  noStroke();

  for (int i=0; i<tx.length; i++) {
    img[i] = loadImage (pic[int(random(pic.length))]);
    tx[i] = new QUAD3D();
  }

  for (int i=0; i<tx.length; i++) {
    println(img[i].height);
  }

  textureMode(NORMAL);
  camera(70.0, 35.0, 120.0, 
    50.0, 50.0, 0.0, 
    0.0, 1.0, 0.0);
}

void draw() {

  scale (16); 

  for (int i=0; i<tx.length; i++) {
    tx[i].TextureQuad(img[i]);
  }
}

//==============================================================

class QUAD3D {

  void TextureQuad(PImage img) {

    beginShape(QUADS);
    texture(img);
    vertex(-1, -1, 1, 0, 0);
    vertex( 1, -1, 1, 1, 0);
    vertex( 1, 1, 1, 1, 1);
    vertex(-1, 1, 1, 0, 1);
    endShape();

    beginShape(QUADS);
    texture(img);
    vertex(-1, -1, -1, 0, 0);
    vertex( 1, -1, -1, 1, 0);
    vertex( 1, -1, 1, 1, 1);
    vertex(-1, -1, 1, 0, 1);
    endShape();

    beginShape(QUADS);
    texture(img);
    vertex( 1, -1, 1, 0, 0);
    vertex( 1, -1, -1, 1, 0);
    vertex( 1, 1, -1, 1, 1);
    vertex( 1, 1, 1, 0, 1);
    endShape();
  }
}//class
//

```

---

<div class="post-metadata">

### Author: ![eve](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@eve](https://discourse.processing.org/u/eve)
#### Post date: [June 6, 2022, 9:48am UTC](https://discourse.processing.org/t/can-you-please-tell-me-what-i-am-doing-wrong/37330/3 "2022-06-06T09:48:22Z")

</div>

Thank you so much for your help!  
I read your explanation and tried it couple more times, and finally made it!  
Thanks!!

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [June 6, 2022, 11:14am UTC](https://discourse.processing.org/t/can-you-please-tell-me-what-i-am-doing-wrong/37330/4 "2022-06-06T11:14:57Z")

</div>

Really?

There is so much to do.

Can I see your entire code please?
