MCPcopy Create free account
hub / github.com/aosabook/500lines / drawCircle

Function drawCircle

blockcode/code/turtle.js:52–73  ·  view source on GitHub ↗
(radius)

Source from the content-addressed store, hash-verified

50 }
51
52 function drawCircle(radius){
53 // Math for this is from http://www.mathopenref.com/polygonradius.html
54 var userPen = pen; // save pen state
55 if (visible){
56 penUp(); _moveForward(-radius); penDown();
57 _turn(-90);
58 var steps = Math.min(Math.max(6, Math.floor(radius / 2)), 360);
59 var theta = 360 / steps;
60 var side = radius * 2 * Math.sin(Math.PI / steps);
61 _moveForward(side / 2);
62 for (var i = 1; i < steps; i++){
63 _turn(theta); _moveForward(side);
64 }
65 _turn(theta); _moveForward(side / 2);
66 _turn(90);
67 penUp(); _moveForward(radius); penDown();
68 if (userPen){
69 penDown(); // restore pen state
70 }
71 }
72
73 }
74
75
76 function _moveForward(distance){

Callers 1

circleFunction · 0.85

Calls 6

penUpFunction · 0.85
_moveForwardFunction · 0.85
penDownFunction · 0.85
_turnFunction · 0.85
minMethod · 0.80
maxMethod · 0.80

Tested by

no test coverage detected