xxxxxxxxxx
//
// Bernard MOUVAULT (décember 2023) - Paris France
//
// Made for 'Arc 🏹 #WCCChallenge'
//
//====================================================
//
// A fork of "Crossroads" by Naoki Tsutae
//
// https://openprocessing.org/sketch/2082773//
//
// Naoki Tsutae : I saw this idea on Twitter, but I forgot whose work it was.
//
//====================================================
//
// Dear fellow creative coders,
//
// The main algorithm used in this sketch is:
// At any time it is forbidden that 2 arcs of circle overlap.
// So when creating or moving an arc of circle it must be checked that
// there is no overlap with ALL the other present in the sketch
// (If an arc does not overlap any arc it does not overlap a neighbor ).
// This is a lot of calculations but the result is magical.
//
// Happy holidays all!!
//
let colors = ["#ed361a", "#06b4b0"];
let _RADIUS, _RADIUS_2, k_RADIUS, Y0;
let ALPHA;
let minD_ang, maxD_ang;
let minD_rad, maxD_rad;
let step_angle, step_rad;
let nb_A = 0;
let nb_R = 0;
let nb_max_A;
let nb_max_R;
let sector_0;
let ALT_Array = [];
let ALB_Array = [];
let ART_Array = [];
let ARB_Array = [];
let inA, newA;
let collide;
//++++++++++++++++++++++++++++++++++++++++++++++++++++
function setup() {
createCanvas(windowWidth, windowHeight);
angleMode(DEGREES);
strokeCap(SQUARE);
_RADIUS = 0.45 * windowHeight;
_RADIUS_2 = _RADIUS/2;
k_RADIUS = 1.5 * _RADIUS;
Y0 = 0.5 * windowHeight;
X0 = 0.75 * _RADIUS;
nb_max_A = 40;
nb_max_R = 75;
ALPHA = acos(0.75);
minD_ang = 5.0
maxD_ang = 12.0;
minD_rad = 0.02 * _RADIUS;
maxD_rad = 0.10 * _RADIUS;
let nb_frames_init = 500;
step_angle = 180.0/nb_frames_init;
if ( random(2.0) > 1.0 ) { step_angle = -step_angle }
step_rad = _RADIUS/nb_frames_init;
sector_0 = new arcs();
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++
function draw() {
background(255);
sector_0.tryCreateArc();
sector_0.update();
sector_0.is_out();
sector_0.two_donuts();
push();
translate( width/2 - X0, Y0);
show_sector (ALT_Array);
pop();
push();
translate( width/2 + X0, Y0);
show_sector (ARB_Array);
stroke(255);
strokeWeight ( _RADIUS_2 );
noFill();
arc( 0.0, 0.0, 1.5 * _RADIUS, 1.5 * _RADIUS, 180.0, 270.0);
pop();
push();
translate( width/2 - X0, Y0);
stroke(255);
strokeWeight ( _RADIUS_2 );
noFill();
arc( 0.0, 0.0, 1.5 * _RADIUS, 1.5 * _RADIUS, 0.0, 90.0);
show_sector (ALB_Array);
stroke(0);
strokeWeight (3);
noFill()
ellipse( 0.0, 0.0, _RADIUS, _RADIUS );
arc( 0.0, 0.0, 2 * _RADIUS, 2 * _RADIUS , 0.0, 360.0 - ALPHA );
pop();
push();
translate( width/2 + X0, Y0);
show_sector (ART_Array);
stroke(0);
strokeWeight (3);
ellipse( 0.0, 0.0, _RADIUS, _RADIUS );
arc( 0.0, 0.0, 2 * _RADIUS, 2 * _RADIUS , 180.0, 180.0 - ALPHA);
pop()
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++
function show_sector (A_Array) {
for ( let i = 0; i < A_Array.length; i++) {
inA = A_Array[i];
let angle_0 = inA.angle_0;
let angle_1 = inA.angle_1;
let d_angle = angle_0 - angle_1;
if ( d_angle < 45.0 ) { // anti-glitch ?
let rad_sup = inA.rad_0;
if ( rad_sup > _RADIUS ) rad_sup = _RADIUS;
let rad_inf = inA.rad_1;
if ( rad_inf < _RADIUS_2 ) rad_inf = _RADIUS_2;
let rad_mil = (rad_sup + rad_inf)/2;
let pt_t0 = createVector(rad_sup, 0.0);
let pt_b0 = createVector(rad_inf, 0.0);
let pt_t1 = pt_t0.copy()
let pt_b1 = pt_b0.copy();
pt_t0.rotate(angle_0);
pt_b0.rotate(angle_0);
pt_t1.rotate(angle_1);
pt_b1.rotate(angle_1);
strokeWeight( rad_sup - rad_inf );
noFill();
stroke(inA.color);
arc( 0.0, 0.0, 2 * rad_mil, 2 * rad_mil, angle_1, angle_0 );
stroke(0);
strokeWeight(1);
noFill();
arc( 0.0, 0.0, 2 * rad_sup, 2 * rad_sup, angle_1, angle_0 );
arc( 0.0, 0.0, 2 * rad_inf, 2 * rad_inf, angle_1, angle_0 );
line(pt_t0.x, pt_t0.y, pt_b0.x, pt_b0.y);
line(pt_t1.x, pt_t1.y, pt_b1.x, pt_b1.y);
}
else print ("GLITCH ? => angle_0 : " + angle_0 + " angle_1 : " + angle_1);
}
}