What interests you is not the code, but the algorithm, the solution.
Also interesting is how to draw a color selection gradient on js.
What interests you is not the code, but the algorithm, the solution.
Also interesting is how to draw a color selection gradient on js.
So, the technique of drawing diamonds on js (to draw circles, you need to take the function of a semicircle, but the idea is exactly the same):
var obj = document.getElementById('container'); var tmp, k = 0, m = 100; for (var i = 0; i < m; i++) { if (i > m / 2) k--; else k++; tmp = document.createElement('div'); tmp.width = k + 'px'; tmp.height = '1px'; obj.appendChild(tmp); }
In general, everything is right for you hinting at the use of canvas
, since under IE there is support from Google, and in adequate browsers it already works with a bang.
function calcPoints(X0, Y0, R, N) { var points = []; for(var i = 0; i < N; i++) { x = X0 + R*Math.sin(i*2*Math.PI/N); y = Y0 + R*Math.cos(i*2*Math.PI/N); total[i] = {'x': x,'y': y}; } return points; }
Algorithm Description:
Or maybe just apply the attributes that round the corners, that is:
border-radius -webkit-border-radius -moz-border-radius
And set a radius equal to half the length / height of the element.
Dumb way: draw in dots, creating something like div
.
The correct way: use <canvas>
or the JS library that emulates it. What is Canvas .
See Raphaël - an example of drawing a circle is on the same page.
Source: https://ru.stackoverflow.com/questions/2855/
All Articles