What looks like a simple rotate problem...
in
Programming Questions
•
10 months ago
Hi all,
Here is a program that I am making that generates a shape based on which number you type into the keyboard. The number determines how many 'legs' the shape has, and the shape looks like a starfish. I am doing it by rotating the canvas then drawing each line. The trouble is, it is only drawing things some of the time. The attached image shows what should be a starfish shape (5 has been pressed), but instead only draws 3 of the legs. I've been printing the angle, and it definitely cycles through all of them but just doesn't draw the line sometimes.
Cheers, Laurie
//////////////////
char[] keyChar = {'1','2','3','4','5','6','7','8','9'};
int[] numbers = {1,2,3,4,5,6,7,8,9};
float x = 0,y,r = 400;
void setup(){
size(800,800);
background(0);
strokeWeight(8);
rectMode(CENTER);
}
void draw(){
translate(width/2,height/2);
fill(0,50);
rect(0,0,1000,1000);
}
void keyPressed(){
for(int i = 0;i < 9;i++){
if(key == keyChar[i]){
for(int j = 0;j <= numbers[i];j++){
stroke(255,170);
line(0,0,0,-350);
rotate(radians(j*(360/numbers[i])));
println(j*(360/numbers[i]));
}
}
}
}
1