java - Drawing a circle in a turtle program -
i working on processing (as in language) sketch, driven turtle logic (see https://en.wikipedia.org/wiki/turtle_graphics ). means draw line current coordinate supplied coordinate. supplied coordinate become new current coordinate. want approximate circle , have written simple piece of code using trigonometrics. code looks follow: void drawcircle(int radius){ // circle center radius amount left of current xpos int steps = 16; double step = two_pi /steps; for(double theta = step; theta <= two_pi; theta += step){ float deltax = cos((float)theta) - cos((float)(theta - step)); float deltay = sin((float)theta) - sin((float)(theta - step)); movexy(deltax*radius, deltay*radius); } } the program logic simple. use variable theta loop through radians in circle. amount of steps indicate how large each theta chunk is. calculate x,y values specific point in circle governed theta. deduct x,y values of previous cycle (hence theta-step ) amount have move