var PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062;
var TWO_PI = 2 * 3.1415926535897932384626433832795028841971693993751058209749445923078164062;
var remap_angle = PI * 0.67;
createCanvas( 850, 200 );
for ( var i = 0; i < radcount; ++i ) {
radians_init[i] = ( i + 0.5 ) * TWO_PI / radcount;
radians[i] = radians_init[i];
var unit = 200 / ( BOUND_OUT - BOUND_IN );
if (mouseIsPressed && (mouseButton == LEFT)) {
remap_angle = ( mouseX - ( offset_x + BOUND_OUT * unit ) ) / unit;
} else if (mouseIsPressed && (mouseButton == RIGHT)) {
remap_range = abs( ( mouseX - ( offset_x + BOUND_OUT * unit + ( remap_angle * unit ) ) ) / unit );
for ( var i = 0; i < radcount; ++i ) {
remap_angle - remap_range,
remap_angle + remap_range
for ( var i = 0; i < 3; ++i ) {
var startx = offset_x + unit * BOUND_OUT * i;
var endx = startx + unit * BOUND_OUT;
line( startx, init_liney - 10, startx, init_liney + 10 );
line( endx, init_liney - 10, endx, init_liney + 10 );
line( startx, init_liney, endx, init_liney );
line( startx, result_liney - 10, startx, result_liney + 10 );
line( endx, result_liney - 10, endx, result_liney + 10 );
line( startx, result_liney, endx, result_liney );
push(); translate( offset_x + unit * BOUND_OUT + 5, init_liney - 15 );
rotate( -HALF_PI ); text( BOUND_IN, 0, 0 );
push(); translate( offset_x + unit * 2 * BOUND_OUT + 5, init_liney - 15 );
rotate( -HALF_PI ); text( BOUND_OUT, 0, 0 );
for ( var i = 0; i < radcount; ++i ) {
var bri = cyclic_bound( radians_init[i], BOUND_IN, BOUND_OUT );
offset_x + BOUND_OUT * unit + bri * unit, init_liney,
offset_x + BOUND_OUT * unit + radians[i] * unit, result_liney
offset_x + BOUND_OUT * unit + bri * unit,
offset_x + BOUND_OUT * unit + radians[i] * unit,
offset_x + BOUND_OUT * unit + ( remap_angle ) * unit,
offset_x + BOUND_OUT * unit + ( remap_angle ) * unit,
var BOUND_MID = (BOUND_OUT-BOUND_IN) * 0.5;
offset_x + BOUND_OUT * unit + cyclic_bound( remap_angle - BOUND_MID, BOUND_IN, BOUND_OUT ) * unit,
offset_x + BOUND_OUT * unit + cyclic_bound( remap_angle - BOUND_MID, BOUND_IN, BOUND_OUT ) * unit,
offset_x + BOUND_OUT * unit + cyclic_bound( remap_angle + BOUND_MID, BOUND_IN, BOUND_OUT ) * unit,
offset_x + BOUND_OUT * unit + cyclic_bound( remap_angle + BOUND_MID, BOUND_IN, BOUND_OUT ) * unit,
offset_x + BOUND_OUT * unit + cyclic_bound( remap_angle - remap_range, BOUND_IN, BOUND_OUT ) * unit,
offset_x + BOUND_OUT * unit + cyclic_bound( remap_angle - remap_range, BOUND_IN, BOUND_OUT ) * unit,
offset_x + BOUND_OUT * unit + cyclic_bound( remap_angle + remap_range, BOUND_IN, BOUND_OUT ) * unit,
offset_x + BOUND_OUT * unit + cyclic_bound( remap_angle + remap_range, BOUND_IN, BOUND_OUT ) * unit,
-5 + offset_x + BOUND_OUT * unit + cyclic_bound( remap_angle - remap_range, BOUND_IN, BOUND_OUT ) * unit,
-10 + offset_x + BOUND_OUT * unit + cyclic_bound( remap_angle + remap_range, BOUND_IN, BOUND_OUT ) * unit,
ellipse( 100,100, init_rad*2, init_rad*2 );
ellipse( 100,100, result_rad*2, result_rad*2 );
for ( var i = 0; i < radcount; ++i ) {
100 + cos( radians_init[i] ) * init_rad,
100 + sin( radians_init[i] ) * init_rad,
100 + cos( radians[i] ) * result_rad,
100 + sin( radians[i] ) * result_rad
100 + cos( radians_init[i] ) * init_rad,
100 + sin( radians_init[i] ) * init_rad,
100 + cos( radians[i] ) * result_rad,
100 + sin( radians[i] ) * result_rad,
stroke( 0,255,255, 130 );
100 + cos( remap_angle ) * (result_rad + 10),
100 + sin( remap_angle ) * (result_rad + 10)
100 + cos( remap_angle - remap_range ) * (result_rad + 10),
100 + sin( remap_angle - remap_range ) * (result_rad + 10)
100 + cos( remap_angle + remap_range ) * (result_rad + 10),
100 + sin( remap_angle + remap_range ) * (result_rad + 10)
(result_rad + 10) * 2, (result_rad + 10) * 2,
remap_angle - remap_range,
remap_angle + remap_range
"angle: " + remap_angle + " / range: " + remap_range,
function cyclic_bound( value, from_in, from_out ) {
if ( value >= from_in && value <= from_out ) {
var d = from_out - from_in;
while( value < from_in ) {
while( value > from_out ) {
function cyclic_map( value, from_in, from_out, to_in, to_out ) {
var half = ( from_out - from_in ) * 0.5;
var bvalue = cyclic_bound( value, from_in, from_out );
var bin = cyclic_bound( to_in, from_in, from_out );
var bout = cyclic_bound( to_out, from_in, from_out );
var bmid = cyclic_bound( to_in + ( to_out - to_in ) * 0.5, from_in, from_out );
var pc = cyclic_bound( ( bvalue - bmid ) / half, -1, 1 );
var brange = cyclic_bound( half - ( bmid - bin ), -half, half );
return cyclic_bound( bout + (brange * pc), from_in, from_out );
return cyclic_bound( bin + (brange * pc), from_in, from_out );