# Here is a code of a circle. How to get it spinning round and round

Here is a code of a circle. How to get it spinning round and round.

First, we do not see any code.

Second, it seems to me that a circle that is rotated will look the same, regardless of the angle.

``````<!DOCTYPE html>
<html lang='pt-BR'>
<meta charset='UTF-8' />
<body>
<canvas id="myCan" width="600" height="600"></canvas>
<script>

ctx.fillStyle=fillColor; //
}

canv = document.getElementById('myCan');
ctx = canv.getContext('2d');

ctx.arc(50,50,45,0,2*Math.PI, false); ctx.fill();

ctx.beginPath();
set_radial(120,50,0, 160,50,45, 'red', 'yellow', 'blue', 0.30);
ctx.arc(160,50,45,0,2*Math.PI.false);ctx.fill();

ctx_beginPath();
set_radial(120,50,0, 270,50,45, 'red', 'yellow', 'blue', 0.50);
//smaller enner circle
ctx.arc(270,50,45,0,2*Math.PI,false); ctx.fill();

</script>
</body>
</html>
``````

You can draw a circular radial gradient by creating a Brush of type Brush.Radial. For example, if you use this:

``````\$(go.Node,
\$(go.Shape, "Circle",
{
width: 100, height: 100,
strokeWidth: 0,
fill: \$(go.Brush, go.Brush.Radial, { 0.0: "red", 0.5: "yellow", 1.0: "blue" })
})
)
``````

you get:

But I still have no idea of what you mean by spinning a circle. If you want to “spin” anything in GoJS, you’ll need to frequently increment the GraphObject.angle using setTimeout or requestAnimationFrame. You can see examples of this by searching the sources of the samples. If you have the UndoManager enabled, remember to temporarily turn it off by setting Diagram.skipsUndoManager to true, as the samples do.

Ah, so you don’t want to rotate the circle but have it revolve around a point. OK, here you go: http://gojs.net/extras/revolvingCircle.html.

The Node.locationSpot is Spot.Center so that the Node.location point actually is at the center of the node. All nodes using that template initially are located at the origin, but the animation code modifies the location of the “Beta” node.

Note that the UndoManager is enabled, but because the animation changes are performed while Diagram.skipsUndoManager is temporarily true, the animation changes are not recorded. So you can move the “Alpha” node around in the normal fashion, including undoing and redoing those moves. Of course you don’t need to enable the UndoManager at all, if your app doesn’t need it.

The code:

``````<!DOCTYPE html>
<html>
<title>Eternal Revolution</title>
<!-- Copyright 1998-2015 by Northwoods Software Corporation. -->
<meta charset="UTF-8">
<script src="go.js"></script>
<script id="code">
function init() {
var \$ = go.GraphObject.make;

myDiagram =
\$(go.Diagram, "myDiagram",
{
initialContentAlignment: go.Spot.Center,
"animationManager.isEnabled": false,
"undoManager.isEnabled": true
});

myDiagram.nodeTemplate =
\$(go.Node,
{ locationSpot: go.Spot.Center, location: new go.Point(0, 0) },
\$(go.Shape, "Circle",
{
width: 100, height: 100,
strokeWidth: 0,
fill: \$(go.Brush, go.Brush.Radial, { 0.0: "red", 0.5: "yellow", 1.0: "blue" })
})
);

var alpha = myDiagram.findNodeForKey("Alpha");
var beta = myDiagram.findNodeForKey("Beta");
var loc = alpha.location.copy().offset(250, 0);  // the starting location for Beta
beta.location = loc;
function loop() {
myDiagram.skipsUndoManager = true;   // don't record anything in UndoManager, if it isEnabled
beta.location = loc.rotate(3);       // modifies LOC, 3 degrees at a time, about the origin
myDiagram.skipsUndoManager = false;
window.requestAnimationFrame(loop);  // keep going
}
window.requestAnimationFrame(loop);
});