xxxxxxxxxx
128
// http://kll.engineering-news.org/kllfusion01/articles.php?article_id=154#here21
// V0.21 ( p5.js version ) with brush color and size
let rval=0, gval=0, bval=0; // drawn circle fill color RGB
let brush;// =color();
let wval=5; // brush size
let c;
let outfile = "mypic.png";
function setup() {
c = createCanvas(400, 400);
print("use mouse LEFT press for paint, RIGHT press for erase");
print("use key [s] for save picture");
print("MousewheelPlusPlus: \npress key [r] red [g] green [b] blue [w] brush size and turn mousewheel");
colorMode(RGB, 50);
brush = color(0, 0, 0, 50);
fill(brush);
noStroke();
background(50);
}
function draw() {
if ( mouseIsPressed ) {
if ( mouseButton == LEFT ) fill(brush);
else if ( mouseButton == RIGHT ) fill(50);
circle(mouseX, mouseY, wval);
}
}
function mouseWheel(event) { // online editor: p5.js ( 0.9.0 )
// Win 10 / Firefox / see +-3 ??
// Raspbian / Chrome / see +- 53 ??
// MAC untested
let e = int( event.delta/3.0 ); // /3.0 windows /50.0 linux /?? mac
print(event.delta+" e "+e); // disable when all ok
if ( keyIsPressed && key == 'r' ) rval += e;
if ( keyIsPressed && key == 'g' ) gval += e;
if ( keyIsPressed && key == 'b' ) bval += e;
if ( keyIsPressed && key == 'w' ) wval += e;
rval = constrain(rval, 0, 50);
gval = constrain(gval, 0, 50);
bval = constrain(bval, 0, 50);
wval = constrain(wval, 1, 50);
print("R "+rval+" G "+gval+" B "+bval+" brushsize "+wval);
brush = color(rval, gval, bval);
fill(brush);
//return false; //uncomment to block page scrolling
}
document.oncontextmenu = function() {
return false;
}
function keyPressed() {
if ( key == 's' ) saveCanvas(c, outfile);
}
/* //JAVA
// painter_basic_mousewheelplusplus
// V0.2 with cursorimage ( brush color and size )
int rval, gval, bval; // drawn circle fill color RGB
color brush =color(0, 0, 0, 100);
int wval=5; // brush size
String outfile = "data/mypic.png";
PImage mycursor;
int csize = 30;
//_______________________________________________ SETUP
void setup() {
size(300, 300);
println("use mouse LEFT press for paint, RIGHT press for erase");
println("use key: \n[s] for save picture\n mousewheelplusplus: press\n[r] red\n[g] green\n[b] blue\n[w] brush size\nand turn mousewheel");
colorMode(RGB, 100);
fill(brush);
noStroke();
background(100);
mycursor = createImage(csize, csize, ARGB);
set_cursor();
}
//_______________________________________________ DRAW
void draw() { // drawing mode background(200,200,0);
if ( mousePressed ) {
if ( mouseButton == LEFT ) fill(brush);
else if ( mouseButton == RIGHT ) fill(100);
circle(mouseX, mouseY, wval);
}
}
//_______________________________________________ OPERATION Mouse Wheel Plus Plus
void mouseWheel(MouseEvent event) { // move mouse wheel
float e = event.getCount();
if ( keyPressed && key == 'r' ) rval += e;
if ( keyPressed && key == 'g' ) gval += e;
if ( keyPressed && key == 'b' ) bval += e;
if ( keyPressed && key == 'w' ) wval += e;
rval = constrain(rval, 0, 100);
gval = constrain(gval, 0, 100);
bval = constrain(bval, 0, 100);
wval = constrain(wval, 1, 30);
println("R "+rval+" G "+gval+" B "+bval+" brushsize "+wval);
brush = color(rval, gval, bval);
fill(brush);
noStroke();
set_cursor();
}
void keyPressed() {
if ( key == 's' ) {
save(outfile);
println("saved to "+outfile);
}
}
void set_cursor() {
for ( int i = 0; i<mycursor.width; i++ ) for ( int j = 0; j<mycursor.height; j++) mycursor.set(i, j, color(0, 0, 0, 0)); // set cursor transparent
for ( int i = 0; i<wval; i++ ) for ( int j = 0; j<wval; j++) mycursor.set(i, j, color(rval, gval, bval, 100)); // show brush color and size
cursor(mycursor, 0, 0);
}
*/