We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hello, i am experimenting with vormplus' code that produces shapes with holes in them. however, the program produces an outer contour that exceeds the height of the screen even though i have used rectMode(CENTER) and assigned the value of the radius in the equation to be the height:
float outerRadius;
float innerRadius;
float outerAngle;
float innerAngle;
void setup()
{
size(450, 320, P2D);
smooth();
outerAngle = TWO_PI / 4;
innerAngle = TWO_PI / 4;
rectMode(CENTER);
noStroke();
}
void draw()
{
background(#3B8686);
stroke(255);
noFill();
rect(width/2, height/2, 100, 100);
noStroke();
outerRadius = height;
innerRadius = 100;
fill(#0B486B);
translate(width/2, height/2);
beginShape();
for(int i = 0; i < 4; i++)
{
float x = cos(i * outerAngle) * outerRadius;
float y = sin(i * outerAngle) * outerRadius;
vertex(x, y);
println("x" + i + ": " + x + ", " + "y" + i + ": " + y);
//why does this output negative and scientific notation for x and y?
// shouldn't the points lie within the plane of the set size?
//i would expect points {(0,0) (0, height) (height, height) (height, 0)}
}
beginContour();
for(int i = 0; i < 4; i++)
{
float x = cos(i * innerAngle) * innerRadius;
float y = sin(i * innerAngle) * innerRadius;
vertex(x, y);
}
endContour();
rotate(HALF_PI/2);
endShape(CLOSE);
}
Answers
Because sin() and cos() will return values from -1 to 1, depending on your input. Given your formular sin(i * outerAngle) * outerRadius the output range will spread from -outerRadius to outerRadius (-height to height).
hi poersh,
thanks for the reply. i think the question i should have asked is if there is a way to generating the shape i am looking for with rotating the rhombus only. as it stands, i would have to us scale to make it it the frame of the window by using arbitrary values to figure out what the magnification is.
No, translate() only alters the internal transformation matrix, it basically transforms a copy of the values it receives from vertex(), not the values (variables) itself. The reason your outer border is out of screen is that the distance between -height and +height is 2 * height = 2 * 320 = 640, while your dominant screen dimension, the width, is only 450. So your border has to be out of screen by 95px per side.
Try to set outerRadius to height / 2 and you'll seed your outer borders.
hi again,
i thought that would be the solution, but while it brings the whole shape within the borders of the window, what i am seeking is to have the entire shape within the border the window where the points of the rectangle (outerradius) are {(0,0) (0, height) (height, height) (height, 0)}. height/2 works for a circle. i thought 3* height/4 worked, but it still leaves a bit of border (35px at outerRadius =600) outside the window. unfortunately, the ratio changes depending on the height.
i also realized that i forgot that i was rotating the shape to make it into a square instead of a rhombus, so that's making it difficult as well. this also accounts for my earlier questions about the coordinates. i guess i asked the wrong question to begin with. as soon as i figure out the right question to ask, i'll post it.
thanks for responding.
hi,
forgetting about the rotation was an important issue. you're right, without the rotation height/2 is the correct value for the outerRadius.
thanks for your help.
this is for anyone who cares...
even after drawing sketch, the point of what i wanted to do escaped me for a bit. anyway, this seems to work. the code above creates a rhombus, so i used the points of the rhombus to frame the square i needed: