We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello I am trying to draw a rectangle that is positioned inside a mouseY responsive ellipse. The code I have right now has a radian of PI/4.0f trail of ellipses drawn. However, I would like to have the angle of the ellipses trail upstraight, same as the rectangle so that it looks like they are wrapping the rectangle.
I tried to change the Z-axis but it doesn't work. Can anyone give me some suggestions please? Please also let me know if you need further elaboration.
Cheers, Karen
float rectX = 30;
float rectY = 100;
int num = 30;
float [] ypos = new float [num];
float radius = 200.0;
void setup() {
size(400, 400, P3D);
for (int i = 0; i <num; i ++) {
ypos[i] = 0;
}
noFill();
strokeWeight(1);
}
void draw() {
background(0);
stroke(255);
translate(width/2, height/2);
rotateY(-PI/4.0f);
drawRect();
drawResponsiveEllipse();
}
void drawRect() {
pushMatrix();
beginShape();
fill(255);
vertex(-rectX, rectY);
vertex(rectX, rectY);
vertex(rectX, -rectY);
vertex(-rectX, -rectY);
endShape(CLOSE);
noFill();
popMatrix();
}
void drawResponsiveEllipse() {
translate (0,0);
rotateX(PI/6.0f);
pushMatrix();
beginShape();
ypos[num - 1] = mouseY;
for ( int i = 0; i < num-1; i++ ) {
ypos[i] = ypos[i+1];
}
noCursor();
noStroke();
for (int i = 0; i < num - 1; i+=2.5f ) {
float b = map(i, 0, num, 0, 255);
stroke(b);
ellipse (-rectX, ypos[i]-rectY, radius, radius);
noFill();
}
endShape(CLOSE);
popMatrix();
}
Answers
It’s probably not cool to try ellipse in 3D
Try using translate together with
Please edit your post and format the code better
Or try translate with ellipse but use 0,0 as ellipse position and put the real position into the translate command
In setup () say ellipseMode(CENTER); iirc
new version: