xxxxxxxxxx
150
var count=20; // How many numbers in the puzzle
var order=[]; // Order of numbers in the puzzle
var bigSz=300; // Size of the big circle
var smallSz=45; // Size of number circles
var customOrder=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,17,20,19];
var mixFlag=true;
function setup() {
createCanvas(450, 450);
for(var i=0; i<count; i++)
{
if(customOrder.length<count)
{
order.push(i+1);
}
else
{
order.push(customOrder[i]);
}
}
if((customOrder.length!=count) && (mixFlag==true))
{
mix();
}
}
function draw() {
background('white');
fill('rgb(0,206,209)')
circle(width/2, height/2, bigSz);
fill('grey');
x=(bigSz/2 * cos(radians(28+270)) + width/2);
y=(bigSz/2 * sin(radians(28+270)) + height/2);
circle(x,y, smallSz*4.10);
x=(bigSz/2 * cos(radians(75+270)) + width/2);
y=(bigSz/2 * sin(radians(75+270)) + height/2);
//circle(x,y, smallSz*2.5);
var ang=360/count; // Evenly spread out numbers
for(var i=0; i<count; i++)
{
//x3 = (bmht * Math.cos(angle+offset)) + x2;
//y3 = (bmht * Math.sin(angle+offset)) + y2;
var x= (bigSz/2 * cos(radians(ang*i+270)) + width/2);
var y= (bigSz/2 * sin(radians(ang*i+270)) + height/2);
fill('white');
circle(x,y, smallSz);
fill('black');
textSize(20);
textAlign(CENTER);
textStyle(BOLD);
text(order[i], x,y+5);
}
}
function keyPressed()
{
console.log(keyCode);
switch(keyCode)
{
case 39: moveRight();
break;
case 37: moveLeft();
break;
case 32: swap();
break;
case 77: mix();
break;
}
}
function moveLeft()
{
temp=order[0];
for(var i=0; i<order.length-1; i++)
{
order[i]=order[i+1];
}
order[order.length-1]=temp;
}
function moveRight()
{
temp=order[order.length-1];
for(var i=order.length-1; i>0; i--)
{
order[i]=order[i-1];
}
order[0]=temp;
}
function swap()
{
temp=order[0];
order[0]= order[3];
order[3]=temp;
temp=order[1];
order[1]=order[2];
order[2]=temp;
}
function mix()
{
for(var i=0; i<1000; i++)
{
nextMove=floor(random(3));
switch(nextMove)
{
case 0: moveLeft();
break;
case 1: moveRight();
break;
case 2: swap();
break;
}
}
}