xxxxxxxxxx
262
/*
2020/01/05 - clean up and comment
*/
var sliderOC, sliderR, sliderICG, sliderA, sliderIC, sliderOC;
var add, sub, colA, fillA, innerB, outerB, polyB, bgB, ccB, aStroB, bStroB, cStroB;
var inner = 0;
var outer = 0;
var poly = true;
var bg = 0;
var N, R, X, Y, D;
var colors = [];
var A, B;
var F = true;
function info() {
text(" # circles: " + N, 0, 235);
text(" radius: " + R, 0, 270);
text(" spacing: " + D, 0, 310);
text(" stroke: " + colors[A].channelName + ", " + sliderA.value(), 0, 370);
text(" background: " + colors[bg].channelName + ", " + sliderICG.value(), 200, 335);
}
function setup() {
//frameRate(12);
createCanvas(windowWidth*.75,windowHeight*.75); // 8.5 x 11 * 72
//pixelDensity(2);
X = random(0,width*.75);
Y = random(0,height*.75);
N = round(random(3,12));
inner = round(random(0,3));
outer = round(random(0,3));
colors = [
new Riso("brightred"),
new Riso("black"),
new Riso("orange"),
new Riso("cornflower"),
new Riso("fluorescentpink"),
new Riso("lightteal"),
new Riso("green"),
new Riso("violet")
];
A = round(random(0,colors.length));
//console.log(A);
B = round(random(0,colors.length));
//console.log(B);
bg = round(random(0, colors.length));
// multiple circles
add = createButton("add circle");
add.position(0,200);
add.mousePressed( function() {
N++;
});
add = createButton("sub circle");
add.position(70,200);
add.mousePressed( function() {
N--;
});
sliderR = createSlider(20, width/2, round(random(20, width/2)));
sliderR.position(0, 240);
// spacing
sliderD = createSlider(0, width/2, round(random(50, width/2)));
sliderD.position(0, 280);
colA = createButton("stroke");
colA.position(0,320);
colA.mousePressed( function() {
A++;
if (A >= colors.length) {
A = 0;
}
});
fillA = createButton("fill");
fillA.position(70,320);
fillA.mousePressed( function() {
if (F == false) {
F = true;
} else {
F = false;
}
});
sliderA = createSlider(0, 255, 255);
sliderA.position(0, 340);
bgB = createButton("background");
bgB.position(200,300);
bgB.mousePressed( function() {
bg++;
if (bg >= colors.length) {
bg = 0;
}
});
sliderICG = createSlider(0, 100, 15);
sliderICG.position(200, 340);
polyB = createButton("polygon");
polyB.position(200,360);
polyB.mousePressed( function() {
if (poly == false) {
poly = true;
} else {
poly = false;
}
});
innerB = createButton("inner circle");
innerB.position(420,300);
innerB.mousePressed( function() {
console.log(inner);
if (inner > 2) {
inner = 0;
}
inner++;
});
sliderIC = createSlider(0, 255, 100);
sliderIC.position(420, 320);
outerB = createButton("outer circle");
outerB.position(420,340);
outerB.mousePressed( function() {
if (outer > 2) {
outer = 0;
}
outer++;
console.log(outer);
});
ccB = createButton("fill");
ccB.position(420,380);
ccB.mousePressed( function() {
if (B == A) {
B = bg
} else if (B == bg) {
B = A
} else {
B = bg;
}
});
sliderOC = createSlider(0, 255, 100);
sliderOC.position(420, 360);
}
function draw() {
background(255);
clearRiso();
colors[bg].noStroke();
colors[bg].fill(sliderICG.value());
colors[bg].rect(0,0,width,height);
R = sliderR.value();
D = sliderD.value();
circ2soleil(X, Y, R, D, colors[B]);
if (poly == true) {
colors[B].cutout(polygon(X, Y, R, N));
colors[bg].cutout(polygon(X, Y, R, N));
}
if (F == true) {
colors[A].noFill();
colors[A].stroke(sliderA.value());
}
else {
colors[A].noStroke();
colors[A].fill(sliderA.value());
}
circlez(X, Y, R, N, D, colors[A]);
// info();
if (bg != A) {
colors[bg].cutout(colors[A]);
}
if (A != B) {
colors[A].cutout(colors[B]);
}
if (bg != B) {
colors[bg].cutout(colors[B]);
}
drawRiso();
}
function polygon(x, y, radius, npoints) {
var polygraph = createGraphics(width, height);
// radians = degrees × π /180°, degrees = radians × 180° / π
var angle = TWO_PI / npoints; // TWO_PI is the equivalent of 360 degrees
//console.log("radians: " + angle);
//console.log("degrees: " + (angle * 180/PI));
polygraph.beginShape();
for (var a = 0; a <= TWO_PI; a = a + angle) {
var sx = x + cos(a) * radius;
var sy = y + sin(a) * radius;
polygraph.vertex(sx, sy);
//text((sx + ", " + sy), sx, sy);
}
polygraph.endShape(CLOSE);
return polygraph;
}
function circ2soleil(x,y,radius, spacing, ink) {
if (inner == 0 || inner == 2) {
ink.noStroke();
ink.fill(sliderIC.value())
ink.circle(x, y, radius)
} else if (inner == 1) {
ink.noFill();
ink.stroke(sliderIC.value());
ink.circle(x,y,radius);
}
if (outer == 0 || outer == 2) {
ink.noStroke();
ink.fill(sliderOC.value())
ink.circle(x, y, radius*2+spacing)
} else if (outer == 1) {
ink.noFill();
ink.stroke(sliderOC.value());
ink.circle(x, y, radius*2+spacing)
}
}
function circlez(x,y,radius, howmany, spacing, ink) {
var angle = TWO_PI / howmany;
//console.log(angle);
for (var a = angle; a <= TWO_PI; a = a + angle) {
var cx = x + cos(a) * spacing;
var cy = y + sin(a) * spacing;
ink.ellipse(cx,cy,radius, radius);
}
}
function keyPressed() {
if (keyCode == 32) {
exportRiso();
}
}