I am working on a project to design systematic artworks using an HTML 5 canvas. To give my artworks a more organic and diverse feel I wanted to have a function that created reuleaux polygons. I think there may be a way to convert my draw_sharp_polygon(center_position, radius, number_of_sides, regular, anticlockwise)
function into the function I need but I'm unsure of how to do this. Would I need to use a large amount of context.lineTo()
functions or would I be able to use the context.arcTo()
function in some way?
function draw_sharp_polygon(center_position, radius, number_of_sides, regular, anticlockwise)
{
if(typeof center_position == 'undefined')
center_position = new Position();
if(typeof radius == 'undefined')
radius = dice_roll(diagonal);
if(typeof number_of_sides == 'undefined' || number_of_sides < 3)
number_of_sides = dice_roll(10);
if(typeof regular == 'undefined')
regular = coin_toss();
if(typeof anticlockwise == 'undefined')
anticlockwise = coin_toss();
context.moveTo(center_position.x + radius, center_position.y)
if(regular)
{
var circular_angle_division = (Math.PI * 2)/number_of_sides;
circular_angle_division = anticlockwise ? -1 * circular_angle_division : circular_angle_division;
for(var i = 1; i < number_of_sides; i++)
{
context.lineTo(radius * Math.cos(circular_angle_division * i),radius * Math.sin(circular_angle_division * i));
}
}
else
{
var amount_of_circle_taken = 0;
var direction = anticlockwise ? -1 : 1;
var sides_left = number_of_sides;
for(var i = 1; i < number_of_sides; i++)
{
if(i < number_of_sides -1)
{
var circular_angle_division = get_random_value(1, (((Math.PI * 2) - amount_of_circle_taken)/number_of_sides*(sides_left / 2)));
amount_of_circle_taken += circular_angle_division;
}
else
{
var circular_angle_division = (Math.PI * 2) - amount_of_circle_taken;
}
context.lineTo(radius * Math.cos(direction * circular_angle_division * i),radius * Math.sin(direction * circular_angle_division * i));
}
}
}
That's what I have for my flat edged polygons. I was wondering if there was a way to use context.arcTo()
instead of context.lineTo()
to create reuleaux polygons.
I was going to post an example of a Reuleaux Triangle but I don't have enough reputation. Wikipedia has a great example though.
P.S. I don't use jQuery in any of my personal projects yet because I feel that most of them could become part of a stand alone javascript library. So please no answers using jQuery.