xxxxxxxxxx
74
let totalTime= 100;
let initialTime = 0;
let currentColor=255;
let divisionRate=0.9;
let timeCheck=1;
let colorState=0;
let offset=0;
let goal=0;
let offsetFr=0;
function setup() {
createCanvas(400, 400);
let color1=red;
let color2=blue;
initialTime=totalTime;
goal=totalTime;
offsetFr=totalTime;
// frameRate(1);
}
function draw() {
background(220, 10);
changeColor();
push();
fill(0);
text(timeCheck, 10, 10);
text(totalTime, 10, 30);
text(colorState, 10, 50);
text(offset, 10, 70);
text(goal, 10, 90);
pop();
fill(currentColor);
ellipse(width/2, height/2, 100, 100);
line(colorState*width,(-timeCheck)*width, (timeCheck/totalTime)*width, (offset/timeCheck)*100);
}
function changeColor(){
// let i=0;
// for (i=0; i<1000; i++){
offsetFr=offsetFr*divisionRate;
goal+=offsetFr;
// }
if (offset!=goal){
timeCheck=offset+totalTime-frameCount;
if(timeCheck<=0){
offset=offset+totalTime;
totalTime=totalTime*divisionRate;
timeCheck=totalTime;
colorSwitch();
}
}
}
function colorSwitch(){
colorState++;
if (colorState==0){
currentColor=255;
}
if (colorState==1){
currentColor=0;
}
if (colorState==2){
colorState=0;
currentColor=255;
}
}