P2D
in
Contributed Library Questions
•
11 months ago
I made a paint program a while back, and it works fine, however I decided to add a few things. I can now save my images, and I was working on getting a circe to appear above where you are about to paint, as it does in MS Paint. I experimented with PGraphics, but the P2D renderer messes with my shapes, and turns them into weird lines, and I can't get the mouse image to clear from the screen. Help anybody?
- import controlP5.*;
- ControlP5 slider;
- PGraphics mouse;
- int r = 255;
- int g = 255;
- int b = 255;
- float s = 50;
- float br=0;
- float bg=0;
- float bb=0;
- void setup() {
- size(screen.width, screen.height);
- mouse=createGraphics(width-350, height, P2D);
- smooth();
- mouse.smooth();
- frameRate(500);
- background(br, bg, bb);
- strokeWeight(50);
- stroke(255, 0, 0);
- cursor(CROSS);
- slider=new ControlP5(this);
- slider.addSlider("r", 0, 255, 10, 10, 255, 30);
- slider.addSlider("g", 0, 255, 10, 50, 255, 30);
- slider.addSlider("b", 0, 255, 10, 90, 255, 30);
- slider.addSlider("s", 0, 100, 10, 130, 255, 30);
- slider.addSlider("br", 0, 255, 10, 510, 255, 30);
- slider.addSlider("bg", 0, 255, 10, 550, 255, 30);
- slider.addSlider("bb", 0, 255, 10, 590, 255, 30);
- }
- void draw() {
- noStroke();
- fill(0);
- rect(0, 0, 350, height);
- fill(r, g, b);
- ellipse(100, 300, s, s);
- fill(br, bg, bb);
- ellipse(100, 500, 50, 50);
- fill(200, 0, 0);
- textSize(48);
- text("SAVE", 90, height-90);
- mouse.stroke(r, g, b);
- mouse.strokeWeight(s);
- mouse.beginDraw();
- mouse.background(0, 0, 0, 0);
- mouse.ellipse(mouseX-350, mouseY, s/2, s/2);
- mouse.endDraw();
- stroke(r, g, b);
- strokeWeight(s);
- if (mousePressed) {
- if (mouseButton==LEFT&&mouseX>350) {
- line(mouseX, mouseY, pmouseX, pmouseY);
- }
- }
- image(mouse, 350, 0);
- }
- void keyPressed() {
- if (keyCode==' ') {
- background(br, bg, bb);
- }
- if (keyCode=='z'||keyCode=='Z') {
- color c=get(mouseX, mouseY);
- slider.controller("r").setValue(red(c));
- slider.controller("g").setValue(green(c));
- slider.controller("b").setValue(blue(c));
- }
- if (keyCode=='x'||keyCode=='X') {
- color c=get(mouseX, mouseY);
- slider.controller("br").setValue(red(c));
- slider.controller("bg").setValue(green(c));
- slider.controller("bb").setValue(blue(c));
- }
- }
- void mouseReleased() {
- if (mouseX<=350&&mouseY>=650) {
- PImage frame = get(350, 0, width, height);
- String savePath=selectOutput("Save Image");
- frame.save(savePath);
- cursor(CROSS);
- }
- }
1