summaryrefslogtreecommitdiff
path: root/js/modularcircles.js
blob: 8e346e04f0c4cb4041ac68e0a58045701c614721 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function setup()
{
	createCanvas(600, 600);
}

function nPoints()
{
	return parseInt($("#npoints").val());
}

function shouldMul()
{
	return $("#should_mul").prop("checked");
}

function amount()
{
	return parseFloat($("#amount").val());
}

function getPos(number)
{
	angle = 2*PI * number/(nPoints());
	return [cos(angle)*250+300, sin(angle)*250+300];
}

function draw()
{
	if (shouldMul())
		$("#amount").prop("step", 0.1);
	else
		$("#amount").prop("step", 1);
	background(255);
	ellipseMode(CENTER);
	noStroke();
	fill(0);
	for (var i = 0; i < nPoints(); i++)
		ellipse(getPos(i)[0], getPos(i)[1], 3, 3);

	stroke(0);
	for (var i = 0; i < nPoints(); i++)
	{
		if (shouldMul())
		{
			stroke(map(map((amount()*i)%nPoints(), 0, nPoints(), 0, 256) - map(i, 0, nPoints(), 0, 256), -256, 256, 0, 256), map(i, 0, nPoints(), 0, 256), map((amount()*i)%nPoints(), 0, nPoints(), 0, 256));
			line(getPos(i)[0], getPos(i)[1], getPos((amount()*i)%nPoints())[0], getPos((amount()*i)%nPoints())[1]);
		}
		else
		{
			stroke(0, map(i, 0, nPoints(), 0, 256), map((amount()+i)%nPoints(), 0, nPoints(), 0, 256));
			line(getPos(i)[0], getPos(i)[1], getPos((amount()+i)%nPoints())[0], getPos((amount()+i)%nPoints())[1]);
		}
	}
}