xxxxxxxxxx
let sizeSlider;
function setup() {
createCanvas(windowWidth, windowHeight);
sizeSlider = createSlider(0,200,100);
sizeSlider.position(width/2-200, windowHeight*7/8);
sizeSlider.style ("width","400px");
}
function draw() {
background(255);
fill(0);
noStroke();
//let r ;
//r = map(mouseX, 0, width, 0, 200, true);
rectMode(CENTER);
rect(width / 2, height / 2, 400, 400, sizeSlider.value() );
}
function setup() {
createCanvas(windowWidth, windowHeight);
background('white');
penColor = 'red';
}
function draw() {
noStroke();
drawColorBar ();
if (mouseIsPressed) {
if (mouseY < 20) {
//if mouse in color bar
changeColor();
} else {
fill (penColor);
ellipse(mouseX, mouseY, 20, 20);
}
}
}
function changeColor() {
if (mouseX < windowWidth/6) {
penColor = 'red';
} else {
if (mouseX < windowWidth/3) {
penColor = 'orange'
} else {
if (mouseX < windowWidth/2) {
penColor = 'yellow';
} else {
if (mouseX < windowWidth/1.5) {
penColor = 'green';
} else {
if (mouseX < windowWidth/1.2) {
penColor = 'blue';
} else {
if (mouseX < windowWidth) {
penColor = 'purple';
} else {
}
}
}
}
}
}
}
function drawColorBar() {
fill ('red');
rect(0,0,windowWidth/6,20);
fill ('orange');
rect(windowWidth/6,0,windowWidth/6,20);
fill ('yellow');
rect(windowWidth/3, 0, windowWidth/6,20);
fill ('green');
rect(windowWidth/2, 0, windowWidth/6,20);
fill ('blue');
rect(windowWidth/1.5, 0, windowWidth/6, 20)
fill ('purple');
rect(windowWidth/1.2, 0, windowWidth/6,20);
}