拾色器不可见

时间:2018-09-06 17:55:41

标签: java intellij-idea generative

我遇到一个看不见拾色器的问题。
我正在尝试生成很多行来制作模式,使我感到很熟练。这是一个附属项目。
我不是最擅长编码的人,所以我需要帮助。另外,您还必须最小化窗口,然后将其打开以使其正常运行。

*更新我已经发现颜色选择器在那里,但是在我绘制的所有线条的后面。

这是我的代码。

import controlP5.ColorPicker;
import controlP5.ControlEvent;
import controlP5.ControlP5;

import processing.core.PApplet;


public class main extends PApplet {
ControlP5 cp5;
ColorPicker cp;
boolean guiState;
int col;

public static void main(String[] args) {
    PApplet.main("main");
}

void drawLines() {

    float lineLength = sqrt(height * height + width * width);

    float nsHueStart = random((float) 10);
    float nsSatStart = random((float) 10);
    float nsRotStart = random((float) 10);
    float nsHStart = random((float) 10);
    float nsWStart = random((float) 10);

    int lineWidthMax = 50;

    for (int lineWidth = 1; lineWidth <= lineWidthMax; ++lineWidth) {

        strokeWeight((5 * pow(lineWidth, 2)));

        nsHueStart += 001;
        float nsHue = nsHueStart;
        float nsSat = nsSatStart;
        float nsH = nsHStart;

        float divH;
        float divW;

        for (float idxH = 0; idxH < height; idxH += divH) {

            divH = map(noise(nsH), 0, 1, 80, 200); 
            float nsRot = nsRotStart;
            float nsW = nsWStart;

            for (float idxW = 0; idxW < width; idxW += divW) {

                divW = map(noise(nsW), 0, 1, 0, 5); // do not use 2D noise
                float brushHue = map(noise(nsHue), 0, 1, 0, 720) % 360; // various colors
                float brushSat = map(noise(nsSat), 0, 1, 20, 70) / map(lineWidth, 1, lineWidthMax, 1, (float) 1.8);
                float brushBri = map(noise(nsSat), 0, 1, 8, 15) / map(lineWidth, 1, lineWidthMax, 1, (float) (lineWidthMax * 2.8));
                float brushAlp = 100;

                float brushSiz = lineLength;
                float brushRot = map(noise(nsRot), 0, 1, -60, 60);

                pushMatrix();
                translate(idxW, idxH);
                canvasRotation(brushRot);
                stroke(brushHue, brushSat, brushBri, brushAlp);
                line(-brushSiz, 0, brushSiz, 0);
                popMatrix();

                nsHue += 002;
                nsRot += 005;
                nsW += 01 + noise(nsH) / 10; // not to be same shape
            }

            nsSat += 5;
            nsH += 8;
        }
    }
}

public void settings() {
    size(2560, 1395);
    smooth(8);
}

public void setup() {
    noStroke();
    cp5 = new ControlP5(this);
    cp = cp5.addColorPicker("picker")
            .setPosition(60, 100)
            .setColorValue(color(0, 128, 255, 128))
    ;
    colorMode(HSB, 360, 100, 100, 100);
    blendMode(SCREEN);
    cp5.show();
    frameRate(60);
}



public void draw() {
    background(cp.getColorValue());
    fill(0, 80);
    rect(50, 90, 275, 80);
    translate(0, 0);
    drawLines();



}

public void controlEvent(ControlEvent c) {
    if (c.isFrom(cp)) {
        float r = (c.getArrayValue(0));
        float g = (c.getArrayValue(1));
        float b = (c.getArrayValue(2));
        float a = (c.getArrayValue(3));

        col = color(r, g, b, a);
        println("event\talpha:"+a+"\tred:"+r+"\tgreen:"+g+"\tblue:"+b+"\tcol"+col);
    }
}


void canvasRotation(float degrees) {

    rotate(radians(degrees));
}

public void toggleGUI(boolean state) {
    if (state) {
        cp5.show();
    } else {
        cp5.hide();
        background(200);
    }
    guiState = state;
}

public void keyPressed() {
    if (keyCode == LEFT) toggleGUI(guiState);
    switch (key) {
        case ('1'):
            cp.setArrayValue(new float[]{120, 0, 120, 255});
            break;
            case ('2'):
            cp.setColorValue(color(255, 0, 0, 255));
            break;
    }

}



}

0 个答案:

没有答案