From: Edwin Fine Date: 2006-12-08T02:15:50+09:00 Subject: Re: Turtle Graphics (#104) > # Move forward by turtle steps. > def forward(steps) > raise ArgumentError unless steps.is_a?(Numeric) > @xy = [ @xy.first + sin(@heading * DEG) * steps, > @xy.last + cos(@heading * DEG) * steps ] > @track.last << @xy if @pen_is_down > end I think that you should mention a subtlety here. The calculation of a new point is usually [x,y] = [x_old + dist * cos(theta), y_old + dist * sin(theta)] Because the turtle geometry is 90 degrees out of phase and rotating in the other direction, Pete has flipped the x and y so the new point is [x,y] = [x_old + dist * sin(theta), y_old + dist * cos(theta)] Another subtlety is that Pete used atan2, which handles division by zero and the ambiguity of which quadrant you are in. (Well, it was subtle to me!!) -- Posted via http://www.ruby-forum.com/.