I would like to animate a square around a square leaving behind different colored squares. When I am writing to control the animation I place the code in a while loop and it flies across the screen but outside a while loop it just scooches along at what I consider to be a normal speed, why do I need to keep my drawn statements outside of a loop to animate them at a palatable controllable speed?
The classic problem still eludes me ... I do not know why this program is looping through up the divisor variable without stopping and going to the final "else if" ... it will identify a non prime number fine but then it loops through all of the divisors or a prime number until it becomes equal to itself and it declares it self not prime.
if (number == 0) {
println(number + " is undefined");
} else if (number > 0 && number <= 3) {
println(number + " is prime");
} else if (number % 2 == 0 && number > 2) {
println(number + " is not prime") ;
} else if (number > 2 && number % 2 !=0) {
while ( is_prime == true) {
if (number % divisor == 0) {
is_prime = false;
divisor = 3;
println(number+ " is not prime");
number = number +1;
} else if ( number % divisor !=0) { // problem line :: I dont know why it always loops HERE
divisor = divisor + 1;
println(number + "number" + divisor + "divisor");
} else if ( number -1 == divisor) {
println(number + " is prime");
is_prime = true;
}
}
}
}
Ive been studying processing for about a month now and i believe I have just crafted the first code that i am happy with , it is special to me because i am a writer not a programmer yet. How do you feel about this code and what would you do to improve the visualization within reason?
for (int y =0; y < 250; y += 10) {
for(int x = 0; x < 250; x += 10) {
fill((x+y)*animate/1.7);
rect(x,y, 10, 10);
rect(width-x-10, y, 10,10);
rect(x,height-y-10,10,10);
rect(width-x-10, height-y-10,10,10);
}
}
}
I know the following code could be made more simply with maybe one or two arrays ... how do i go about approaching simplifying this code to enable it to be more effective code.
I think I finally have the logic worked out for first thousand primes puzzle that i have been puzzling over ever since I found MIT OPEN COURSEWARE ... I think there may be some bugs but overall the logic should work as far as I can tell. Why is there a sytax error in the second line of the while loop asking for a semicolon when there doenst need to be one as far as I can tell ... does this code look like it is going in the right direction to solve the problem of 1st thousand primes?
int prime_counter = 0;
int current_odd_number = 0;
int divisor_tester = 0;
void setup() {
size(500,500);
background(255);
}
void draw() {
while (prime_counter < 1000) {
for (i < int(sqrt(current_odd_number)); i = i + 1) {
if (current_odd_number) % i == 0) {
current_odd_number = current_odd_number + 2 }
} else if (current_odd_number) % i != 0 && i < (int(sqrt(current_odd_number))) {
i++
} else {
prime_counter = prime_counter + 1;
current_odd_number = current_odd_number + 2;
println(current_odd_number + "is prime" + prime_counter);
}
}
}
I am trying to build a square that collapses in on itself. I have used beginShape as the means of building a square that when a mouse is pressed will fold its corners down to the center, that is the goal.
I have a button created that when pressed is supposed to create a number of iterators in the draw loop which pull the corners in slowly right now.
i am getting an error that my arguments are not applicable to my method and i could use some clarity as to how to build this function so that when the mouse is pressed the corners converge ... i will take care of stopping them at the center later but if you could help me bring the corners in i would appreciate it.