xxxxxxxxxx
/*
Shayne Shen
DES INV 23 2023
*/
r1 = 0
g1 = 10;
b1 = 199;
r2 = 0;
g2 = 255;
b2 = 71;
var segmentCount = 30;
var radius = 300;
var count = 0;
function setup() {
createCanvas(600,600);
colorMode(HSB,100);
}
function draw() {
background("black");
noStroke();
fill("white");
keyPressed()
gradCir();
}
function gradCir(){
//create a circle by generating a bunch of triangle fans.
colorMode(RGB, 255);
var angleStep = 360 / segmentCount;
beginShape(TRIANGLE_FAN);
vertex(width/2, height/2);
var angleOfRef = atan((mouseY-height/2)/(mouseX-width/2))
if (mouseX < width/2){
angleOfRef+=PI;}
// Compensate for the phase difference of PI when mouseX-width/2 is negative
for (var count = 0; count <= 360; count += angleStep) {
// Calculate the angle between the line of mouse position and the center of the circle(width/2,height/2) and horizontal line.
var angleDraw = angleOfRef + radians(count);
// Calculate the angle between the adjancent side of the next triangle and the horizontal line.
var vx = width/2 + cos(angleDraw) * radius;
var vy = height/2 + sin(angleDraw) * radius;
vertex(vx, vy);
fill(r1, g1+count*(g2-g1)/360, b1+count*(b2-b1)/360);
}
endShape();
}
function keyPressed() {
if (key == 's' || key == 'S') saveCanvas(gd.timestamp(), 'png');
switch (key) {
case '1':
segmentCount = 360;
r1 = 0
g1 = 10;
b1 = 199;
r2 = 0;
g2 = 255;
b2 = 71;
break;
case '2':
segmentCount = 24;
r1 = 0
g1 = 10;
b1 = 199;
r2 = 0;
g2 = 255;
b2 = 71;
break;
case '3':
segmentCount = 12;
r1 = 0
g1 = 10;
b1 = 199;
r2 = 0;
g2 = 255;
b2 = 71;
break;
case '4':
segmentCount = 12;
r1 = 69;
g1 = 65;
b1 = 255;
r2 = 69;
g2 = 253;
b2 = 56;
break;
// Fill a gradient starting from blue (0,10,199) to green (0,255,71).
case '5':
segmentCount = 12;
r1 = 123;
g1 = 255;
b1 = 123;
r2 = 131;
g2 = 129;
b2 = 255;
break;
// Fill a gradient starting from pink (255,0,255) to yellow (252, 218,0)
case '6':
segmentCount = 12;
r1 = 204;
g1 = 255;
b1 = 165;
r2 = 204;
g2 = 129;
b2 = 255;
break;
}
}