apde吧 关注:15贴子:57
  • 3回复贴,共1

apde代码效果

只看楼主收藏回复

视频来自:百度贴吧


IP属地:广东1楼2020-12-05 09:19回复
    /**
    * Wiggling.
    *
    * Press 'w' to start wiggling, space to restore
    * original positions.
    */
    PShape cube;
    float cubeSize = 450;
    float circleRad = 400;
    int circleRes = 15;
    float noiseMag = 1;
    boolean wiggling = false;
    void setup() {
    size(displayWidth,displayHeight, P3D);
    createCube();
    }
    void createCube() {
    cube = createShape(GROUP);
    PShape face;
    // Front face
    face = createShape();
    face.beginShape(POLYGON);
    face.stroke(255, 0, 0);
    face.fill(255);
    face.beginContour();
    face.vertex(-cubeSize/2, -cubeSize/2, +cubeSize/2);
    face.vertex(+cubeSize/2, -cubeSize/2, +cubeSize/2);
    face.vertex(+cubeSize/2, +cubeSize/2, +cubeSize/2);
    face.vertex(-cubeSize/2, +cubeSize/2, +cubeSize/2);
    face.endContour();
    face.beginContour();
    for (int i = 0; i < circleRes; i++) {
    float angle = TWO_PI * i / circleRes;
    float x = circleRad * sin(angle);
    float y = circleRad * cos(angle);
    float z = +cubeSize/2;
    face.vertex(x, y, z);
    }
    face.endContour();
    face.endShape(CLOSE);
    cube.addChild(face);
    // Back face
    face = createShape();
    face.beginShape(POLYGON);
    face.stroke(255, 0, 0);
    face.fill(255);
    face.beginContour();
    face.vertex(+cubeSize/2, -cubeSize/2, -cubeSize/2);
    face.vertex(-cubeSize/2, -cubeSize/2, -cubeSize/2);
    face.vertex(-cubeSize/2, +cubeSize/2, -cubeSize/2);
    face.vertex(+cubeSize/2, +cubeSize/2, -cubeSize/2);
    face.endContour();
    face.beginContour();
    for (int i = 0; i < circleRes; i++) {
    float angle = -TWO_PI * i / circleRes;
    float x = circleRad * sin(angle);
    float y = circleRad * cos(angle);
    float z = -cubeSize/2;
    face.vertex(x, y, z);
    }
    face.endContour();
    face.endShape(CLOSE);
    cube.addChild(face);


    IP属地:广东来自Android客户端2楼2020-12-05 09:21
    回复
      // Top face
      face = createShape();
      face.beginShape(POLYGON);
      face.stroke(255, 0, 0);
      face.fill(255);
      face.beginContour();
      face.vertex(-cubeSize/2, +cubeSize/2, +cubeSize/2);
      face.vertex(+cubeSize/2, +cubeSize/2, +cubeSize/2);
      face.vertex(+cubeSize/2, +cubeSize/2, -cubeSize/2);
      face.vertex(-cubeSize/2, +cubeSize/2, -cubeSize/2);
      face.endContour();
      face.beginContour();
      for (int i = 0; i < circleRes; i++) {
      float angle = -TWO_PI * i / circleRes;
      float x = circleRad * sin(angle);
      float y = +cubeSize/2;
      float z = circleRad * cos(angle);
      face.vertex(x, y, z);
      }
      face.endContour();
      face.endShape(CLOSE);
      cube.addChild(face);
      // Bottom face
      face = createShape();
      face.beginShape(POLYGON);
      face.stroke(255, 0, 0);
      face.fill(255);
      face.beginContour();
      face.vertex(+cubeSize/2, -cubeSize/2, +cubeSize/2);
      face.vertex(-cubeSize/2, -cubeSize/2, +cubeSize/2);
      face.vertex(-cubeSize/2, -cubeSize/2, -cubeSize/2);
      face.vertex(+cubeSize/2, -cubeSize/2, -cubeSize/2);
      face.endContour();
      face.beginContour();
      for (int i = 0; i < circleRes; i++) {
      float angle = TWO_PI * i / circleRes;
      float x = circleRad * sin(angle);
      float y = -cubeSize/2;
      float z = circleRad * cos(angle);
      face.vertex(x, y, z);
      }
      face.endContour();
      face.endShape(CLOSE);
      cube.addChild(face);
      }


      IP属地:广东来自Android客户端4楼2020-12-05 09:24
      回复
        void draw() {
        background(65,165,255);
        translate(width/2, height/2);
        rotateX(frameCount * 0.01f);
        rotateY(frameCount * 0.01f);
        // rotateX(mouseY * 0.01f);
        //rotateY(mouseX * 0.01f);
        shape(cube);
        if (wiggling) {
        PVector pos = null;
        for (int i = 0; i < cube.getChildCount(); i++) {
        PShape face = cube.getChild(i);
        for (int j = 0; j < face.getVertexCount(); j++) {
        pos = face.getVertex(j, pos);
        pos.x += random(-noiseMag/2, +noiseMag/2);
        pos.y += random(-noiseMag/2, +noiseMag/2);
        pos.z += random(-noiseMag/2, +noiseMag/2);
        face.setVertex(j, pos.x, pos.y, pos.z);
        }
        }
        }
        println(frameRate);
        }


        IP属地:广东来自Android客户端5楼2020-12-05 09:25
        回复