我编码着着色刷,但在P5J中不起作用
我正在创建一个基于鼠标的画家应用程序。我想一个刷子,其颜色是由P5J中的颜色拾取器选择的。而且我认为我完成了编码,但是它根本没有起作用...并且有人可以帮助我吗?我想看看我在哪里犯了错误。 thanx,进步!
```
var brushSize;
let activeBrush = 0;
function setup() {
brushSize = 10;
createCanvas(800, 800);
colorPicker = createColorPicker('#ed225d');
colorPicker.position(600, 20);
background(220);
function draw() {
colorMode(RGB);
brushColor = colorPicker.color();
noStroke();
function keyTyped() {
if (key == '=') { //becomes bigger and smaller by 10% with [=] and [-] keys, respectively, but not working...
brushSize = brushSize + brushSize*0.1;
} else if (key == '-') {
brushSize = brushSize - brushSize*0.1;
} else if (key == 'c') { //when [C] is pressed, everything on canvas gets deleted, but it's not working at all..
noStroke();//clear button
fill(220);
rectMode(CORNER);
rect(0, 0, 800, 800);
} else if (key == 's') { //when [S] is pressed, current content on canvas is saved as an image file ,, but it's not working at all..
let b = createCanvas(800, 800);
saveCanvas(b, 'myCanvas', 'jpg');
}
}
}
function mouseDragged(){
fill(colorPicker);
ellipse(mouseX, mouseY, brushSize, brushSize)}} // plus why this isn't working..?? TT
```
I was creating a mouse-based painter app. I wanna a brush whose color is chosen by a color picker in p5js. And I think I finished coding, but it's not working at all... and is there anybody who can help me? I wanna see where I did make mistake....!
thanx, advance!
```
var brushSize;
let activeBrush = 0;
function setup() {
brushSize = 10;
createCanvas(800, 800);
colorPicker = createColorPicker('#ed225d');
colorPicker.position(600, 20);
background(220);
function draw() {
colorMode(RGB);
brushColor = colorPicker.color();
noStroke();
function keyTyped() {
if (key == '=') { //becomes bigger and smaller by 10% with [=] and [-] keys, respectively, but not working...
brushSize = brushSize + brushSize*0.1;
} else if (key == '-') {
brushSize = brushSize - brushSize*0.1;
} else if (key == 'c') { //when [C] is pressed, everything on canvas gets deleted, but it's not working at all..
noStroke();//clear button
fill(220);
rectMode(CORNER);
rect(0, 0, 800, 800);
} else if (key == 's') { //when [S] is pressed, current content on canvas is saved as an image file ,, but it's not working at all..
let b = createCanvas(800, 800);
saveCanvas(b, 'myCanvas', 'jpg');
}
}
}
function mouseDragged(){
fill(colorPicker);
ellipse(mouseX, mouseY, brushSize, brushSize)}} // plus why this isn't working..?? TT
```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论
MouseX
和Mousey
来自OP代码中,它们都是错误的。在阻力上绘画是直截了当的。根据OP中所述的要求,不需要绘制功能,只需在拖动时添加到画布中即可。这是一些工作代码,以用作起动器。
It's likely that, wherever
mouseX
andmouseY
are coming from in the OP code, they are wrong. Painting on drag is straight-forward. From the requirements stated in the OP, there's no need for a draw function, just add to the canvas on drag.Here's some working code to use as a starter....