# How to create a 3D star?

please format code with </> button * homework policy * asking questions

I trying create 3d star but this not good wraiting cone

``````  // звезда 3д модель
function zvezda ( per_x, per_y, per_z) {
for (i=0; i <=4; i=i+1) {
rotateX (radians(0) ) ; // обнуляю угол что трасляте норм было

translate(per_x, per_y, per_z) ; // уст располож

fill("yellow") ; // цвет
cone (2 , 10) ; // конус
pop() ; // вост сост системы
push() ; // сохр сост в стек

}
}
``````

push is directly after the for loop command line

pop can stay

So both surround the part with rotate/ translate/ cone

1 Like

This not work

Can’t you draw lines from the center to the
outside like this: `*`

with i from 0 to 360 with step +10

``````float x1=cos(radians(i)) * 40 + width/2 ;
float y1=sin(radians(i)) * 40 + height/2 ;

line (width/2, height/2,
x1,y1);
``````
1 Like

Hi

1 Like

Hello @timob256 ,

Try this with one cone first:

• push
• rotateZ
• translate < Translate from center… try one axis at a time to see the changes
• cone < large enough to see
• pop

After you have translated the cone to where you want it then try a for loop.

Note:
360/5 = 72

References:

`:)`

1 Like

Hello @glv .

Please show the code from the given example. I still don’t understand how to set the angle correctly.

`````` // звезда 3д модель
function zvezda ( per_x, per_y, per_z) {
// луч 1
push();
fill("yellow") ; // цвет
//rotateX(PI/2);
translate(per_x, per_y+10, per_z) ; // уст располож
cone(w=2, h=10);
pop();
// луч2
push();
fill("yellow") ; // цвет
translate(per_x, per_y+5, per_z+5) ; // уст располож
cone(w=2, h=10);
pop();
// луч3
push();
fill("yellow") ; // цвет
translate(per_x, per_y, per_z+5) ; // уст располож
cone(w=2, h=10);
pop();
// луч4
push();
fill("yellow") ; // цвет
translate(per_x, per_y, per_z-5) ; // уст располож
cone(w=2, h=10);
pop();
// луч5
push();
fill("yellow") ; // цвет
translate(per_x, per_y+5, per_z-5) ; // уст располож
cone(w=2, h=10);
pop();
}
``````

Hello @timob256,

You need to progress in steps.

This is what I see with your code:

With a larger cone (10x bigger):

Using `rotate()` which is the same as `rotateZ()`:

I suggest that you try working with one cone and see how the translation and rotation work.

The cone is initially centered and you need to:

There is a Processing JAVA tutorial here and the concepts apply to p5.js:

`:)`

`````` // рисую зведу
function setup()  {
createCanvas( 200, 200, WEBGL); //3д
angle =0; // угол
noStroke(); // делаем рëбра фигур невидимыми
scale(1) ; // можно менять маштаб
push() ; // сохраняем состояние в стек
}

// звезда 3д модель
function zvezda ( per_x, per_y, per_z) {

// луч 1
push();
fill("yellow") ; // цвет
//translate(per_x, per_y+10, per_z) ; // уст располож
cone(w=20, h=100);
pop();
// луч2
push();
fill("yellow") ; // цвет
//translate(per_x, per_y+5, per_z+5) ; // уст располож
cone(w=20, h=100);
pop();
// луч3
push();
fill("yellow") ; // цвет
//translate(per_x, per_y, per_z+5) ; // уст располож
cone(w=20, h=100);
pop();
// луч4
push();
fill("yellow") ; // цвет
//translate(per_x, per_y, per_z-5) ; // уст располож
cone(w=20, h=100);
pop();
// луч5
push();
fill("yellow") ; // цвет
//translate(per_x, per_y+5, per_z-5) ; // уст располож
cone(w=20, h=100);
pop();
}

function my_rotate() {
//rotateX(angle);
rotateY(angle);
// rotateZ(_angle);

angle += 0.01;

}

function draw() {
background(220,220,220, 5);

my_rotate(); // крутим
rotateX ( radians(180)); // поварачиваем звезду
zvezda(0, 0, 0) ;
}
``````

1 Like

Hello @timob256!
This is such a great question!
I hope you don’t mind but I changed the title of your topic

from:
“How create star?”
to:
“How to create a 3D star?”

This better reflects the complexity of your question and will make it more search-friendly for others with the same issue in the future!
Of course, if you feel this new title does not accurately represent your topic, please feel free to write a new title with searchable keywords.

3 Likes

Nice work!

`:)`