Hello! Can somebody help me with moving a piñata in Greenfoot or in simple words making a pendulum that just swings around?
Thanks in advance! :D
int iterador = 1; boolean bandera = false; public void act() { while(!bandera) { negativeBalance(); Greenfoot.delay(50); if(iterador == 90) { bandera = true; } } while(bandera) { positiveBalance(); Greenfoot.delay(50); if(iterador == -90) { bandera = false; } } } public void negativeBalance() { turn(1); iterador++; } public void positiveBalance() { turn(-1); iterador--; }
counter = (counter + frequency) % 360;
// using these instance fields private static final int FREQ=5; private int counter; private double range; // in the act method or method it calls counter = (counter + FREQ) % 360; double factor = Math.sin(Math.PI*(double)counter/180.0); setRotation((int)(factor*range));
range *=0.9; // some value just under one