draw error
in
Programming Questions
•
1 years ago
I can't see why the ellipse getting pushed to the side in this program. When I separate the ellipse and the sphere out from each other they run fine. I'm miffed, lol!
PFont f;
float r = 200; //radius
float w1 = 40;
float h1 = 15;
float w2 = 15;
float h2 = 40;
void setup() {
size(600, 600, P3D);
background(0);
}
void draw() {
background(235);
noFill();
stroke(255, 100);
strokeWeight(10);
fill(255);
//ellipse(300, 300, 400, 400);
lights();//set a default light
translate(300, 300, 0);//move the sphere to the center of the canvas
rotateY(random(-.08, .01));
rotateX(random(-.08, .01));
rotateZ(random(-.08, .01));
sphere(200);//draw the sphere
delay(50);
//start in the center and draw the circle
translate(300,300);
noFill();
noStroke();
ellipse(width/2,height/2,r*2,r*2);
//10 crosses along the curve
int totalCrosses = 25;
// We must keep track of our position along the curve
float arclength = 0;
// for every cross
for (int i = 0; i < totalCrosses; i++) {
arclength += w1/2; //each cross is centered so we move half the width
float theta = arclength/r; // angle in radians is the arclength divided by the radius
pushMatrix();
//polar to cartesian coordinate conversion
translate (r*cos(theta), r*sin(theta));
rotate(theta); //rotate the cross
//display the cross
fill(0,100);
rectMode(CENTER);
rect(0,0,w1,h1);
rectMode(CENTER);
rect(0,0,w2,h2);
popMatrix();
arclength += w1/2; //move halfway again
}
}
1