xxxxxxxxxx
63
/**
* A second painting app created entirely by Chat GPT4 using chat.bing.com on Jan 26, 2024
* See the first painting app here: https://editor.p5js.org/jonfroehlich/sketches/jnliJsIwb
*
* The prompt:
*
* "Can you make it so that the color of the brush depends on the speed of my mouse. Also, use partial transparency."
*
* See the other painting apps here:
*
* - Version 1 (basic app): https://editor.p5js.org/jonfroehlich/sketches/jnliJsIwb
* - This version (added translucency): https://editor.p5js.org/jonfroehlich/sketches/EjBgSYhBE
* - Version 3 (added color): https://editor.p5js.org/jonfroehlich/sketches/Ajylq5-Fe
* - Version 4 (added erase brush): https://editor.p5js.org/jonfroehlich/sketches/4Yxtt4bJV
*
* By Professor Jon E. Froehlich
* https://jonfroehlich.github.io/
* https://makeabilitylab.github.io/p5js/
* http://makeabilitylab.cs.washington.edu
**/
// Here is Chat GPT4's description of the code
// In this code:
//
// * The draw function calculates the speed of the mouse as the distance it has traveled since the last frame.
// * It then maps this speed to a range of RGB values to get a color.
// * The fill function sets this color with an alpha value of 100 for partial transparency.
// * The rest of the code is the same as before.
//
// You can run this code in the p5.js web editor or in any HTML file where the p5.js library is
// included. To paint, simply click and drag the mouse across the canvas. The color of the brush will change
// depending on the speed of your mouse. To clear the canvas, press any key. Enjoy painting! 🎨
let px, py;
function setup() {
createCanvas(800, 600);
background(255);
px = mouseX;
py = mouseY;
}
function draw() {
if (mouseIsPressed) {
let mouseSpeed = dist(px, py, mouseX, mouseY);
let r = map(mouseSpeed, 0, 50, 0, 255);
let g = map(mouseSpeed, 0, 50, 64, 255);
let b = map(mouseSpeed, 0, 50, 128, 255);
fill(r, g, b, 100);
noStroke();
ellipse(mouseX, mouseY, 20, 20);
}
px = mouseX;
py = mouseY;
}
function keyPressed() {
background(255);
}