Hello!
I'm new to the processing community and new to programming (total noob) in general. In this sketch I am trying to make a super basic color picker/drawing program. My main problem is that I cannot figure out how to make a default color that can then be altered. For instance, when my sketch is started, you have to choose from the two color bars in order to get a color that is then used for the drawing. I would like to make it so when you open the sketch it starts with a color and then I can select from the bars when I want to change the color. I'm sure this isn't very efficient code, but I'm not really worried about that right now. Thanks in advance for any help!
- int bwbar;
- int colorbar;
- int s;
- void setup() {
- size(600, 600);
- background(255);
- //smooth();
- }
- void draw() {
- colorfields();
- if (mousePressed) {//darkness/lightness
- if (mouseY > 1 && mouseY<height/20 && mouseX < width-1 && mouseX > width/20) {
- bwbar = abs(mouseX % width);
- }
- }
- if (mousePressed) { //color select
- if (mouseY < height-1 && mouseY>height/20 && mouseX < width/20 && mouseX >1) {
- colorbar = abs(mouseY % height);
- }
- }
- stroke(0);
- noFill();
- strokeWeight(2);
- rect(width/20+1, height/20+1, width, height);
- stroke(255);
- strokeWeight(0);
- line(bwbar+1, 0, bwbar+1, height/20-2);
- line(bwbar-1, 0, bwbar-1, height/20-2);
- line(0, colorbar-1, width/20-2, colorbar-1);
- line(0, colorbar+1, width/20-2, colorbar+1);
- color x;
- color y;
- color z;
- y = get(0, colorbar);
- x = get(bwbar, 0);
- z = blendColor(x, y, OVERLAY);
- fill(z);
- rect (0, 0, width/20, height/20);
- drawing();
- }
- void keyReleased() {
- s ++;
- if (key == 's' || key == 'S') {
- PImage partialSave = get(width/20+2, width/20+2, width, height);
- partialSave.save("pic" + s);
- }
- }
- void colorfields() {
- color black;
- color white;
- black = #000000;
- white = #FFFFFF;
- for (int x = 0+width/20; x < width; x++) {
- float percent = norm(x, 0, width);
- stroke(lerpColor(black, white, percent, HSB));
- line(x, 0, x, height/20);
- }
- color one = #0033ee;
- color two = #00ee33;
- one = #ff0000;
- two = #00ff00;
- for (int y=0+height/20;y < height; y++) {
- float percent2 = norm (y, 0, height/3);
- stroke(lerpColor(one, two, percent2, HSB));
- line(0, y, width/20, y);
- }
- }
- void drawing() {
- if (mousePressed) {
- if (mouseX > width/20+1 && mouseY>height/20+1) {
- stroke(get(1, 1));
- strokeWeight(10);
- line(pmouseX, pmouseY, mouseX, mouseY);
- stroke(255);
- strokeWeight(5);
- }
- }
- }
1