2021年3月31日 星期三

熊貓大人到此一遊 week 06

 PImage imgBG;

PGraphics pg;

//https://gentlejourneysbirthing.com/home/colorful_watercolor_texture_by_connyduck-d6o409f/

ArrayList<PVector> points;

void setup(){

  size(800,600,P2D);  

  stroke(255);

  noFill();

  points = new ArrayList<PVector>();

  angle = atan2(-cy, -cx);//一開始mouseX,mouseY為0,所以角度向左上角

  imgBG=loadImage("watercolor_texture.png");

  pg = createGraphics(800,600);

  drawPG();

}//之後可引導 mousePressed 在小齒輪後, 才能開始控制轉動

float r0=225, r1=57, r2=37.3;

float cx=320, cy=240;

float angle;

void drawPG(){

  pg.beginDraw();

  pg.noFill();

  pg.strokeWeight(2);

  pg.stroke(255);

  pg.beginShape();

  int a = points.size();

  if(a>2){

    pg.vertex(points.get(a-2).x, points.get(a-2).y);

    pg.vertex(points.get(a-1).x, points.get(a-1).y);

  }//只畫最後的點,前面不用再畫,可能會快一點

/*  for( PVector pt : points ){

    pg.vertex(pt.x, pt.y);//之後可變彩色漸層色彩

  }*/

  pg.endShape();

  pg.endDraw();

}

void draw(){

  background(0);

  imgBG.mask(pg);

  image(imgBG,0,0);

  colorMode(RGB);

  stroke(128);

  strokeWeight(1);

  ellipse(cx,cy, r0*2, r0*2);

  angle += deltaAngle();

  float angle2= -angle * r0 / r1;

  float x=cx+(r0-r1)*cos(angle), y=cy+(r0-r1)*sin(angle);

  //line(cx,cy, x, y);//不要畫線,比較好看

  circle2(x,y, r1, angle2);

  //if(mousePressed) saveFrame();

}

void circle2(float cx, float cy, float r, float angle){

  ellipse(cx,cy, r*2, r*2);

  for(float a=angle; a<angle+PI*2;a+=PI/4){

    line(cx,cy, cx+r*cos(a), cy+r*sin(a));

  }

}

float deltaAngle(){

  float angleNow=atan2(mouseY-cy,mouseX-cx);

  float angleOld=atan2(pmouseY-cy,pmouseX-cx);

  float delta = angleNow - angleOld;

  if( abs(delta)> PI ){

    if(delta>0) delta-=PI*2;

    else delta += PI*2;

  }

  return delta;

}

void mouseDragged(){//按下mouse才開始記錄點

  float angle2= -angle * r0 / r1;

  float x=cx+(r0-r1)*cos(angle), y=cy+(r0-r1)*sin(angle);  

  float x2=x+r2*cos(angle2), y2=y+r2*sin(angle2); 

  points.add( new PVector(x2,y2) );

  drawPG();

}
















 #include <GL/glut.h>///使用glut外掛



int N=0,vx[3000],vy[3000];///放點3000個

float angle=0;///初始角度



void display()



{



    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清空

    glPushMatrix();///備份矩陣

    glRotatef (angle,0,0,1);///旋轉 對 z軸轉

    glutSolidCube(1);
    glPopMatrix();
     glutSwapBuffers();
    angle++;
}



int main(int argc,char**argv)///glut初始設定



{



    glutInit(&argc,argv);



    glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);///顯示模式



    glutCreateWindow("WEEK04");///視窗



    glutDisplayFunc(display);///顯示的函示








    glutMainLoop();///主要迴圈



}





 #include <GL/glut.h>///使用glut外掛


int N=0,vx[3000],vy[3000];///放點3000個
float angle=0;///初始角度


void display()


{


    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清空
    glPushMatrix();///備份矩陣
        glRotatef (angle,0,0,1);///旋轉 對 z軸轉        glTranslatef(0.25,0,0);///把關節移到中心        glScalef(0.5,0.1,0.1);///細長的        glColor3f(0,0,1);///藍色的        glutSolidCube(1);///方塊    glPopMatrix();    glutSwapBuffers();    angle++;}


int main(int argc,char**argv)///glut初始設定


{


    glutInit(&argc,argv);


    glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);///顯示模式


    glutCreateWindow("WEEK04");///視窗


    glutDisplayFunc(display);///顯示的函示    glutIdleFunc(display);







    glutMainLoop();///主要迴圈


}























#include <GL/glut.h>///使用glut外掛
float angle=0;///初始角度

void hand()
{
    glPushMatrix();///備份矩陣
        glScalef(0.5,0.1,0.1);///細長的
        glColor3f(0,0,1);///藍色的
        glutSolidCube(1);///方塊
    glPopMatrix();
}

void display()



{



    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清空
    glColor3f(1,1,1); glutSolidCube(1);///大身體
    glPushMatrix();///備份矩陣
        glTranslatef(0.5,0.5,0);///整個移到右上角掛著
        glRotatef (angle,0,0,1);///旋轉 對 中心轉
        glTranslatef(0.25,0,0);///把關節移到中心
        hand();///細長的藍色的小手
    glPopMatrix();
    glutSwapBuffers();
    angle++;
}



int main(int argc,char**argv)///glut初始設定



{



    glutInit(&argc,argv);



    glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);///顯示模式



    glutCreateWindow("WEEK04");///視窗



    glutDisplayFunc(display);///顯示的函示
    glutIdleFunc(display);








    glutMainLoop();///主要迴圈



}


                                                                                                                           

#include <GL/glut.h>///使用glut外掛
float angle=0;///初始角度

void hand()
{
    glPushMatrix();///備份矩陣
        glScalef(0.5,0.1,0.1);///細長的
        glColor3f(0,0,1);///藍色的
        glutSolidCube(1);///方塊
    glPopMatrix();
}

void display()



{



    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清空
    glColor3f(1,1,1); glutSolidCube(1);///大身體
    glPushMatrix();///右半邊
        glTranslatef(0.25,0.25,0);///整個移到右上角掛著
        glRotatef (angle,0,0,1);///旋轉 對 中心轉
        glTranslatef(0.25,0,0);///把關節移到中心
        hand();///細長的藍色的上手臂
        glPushMatrix();
            glTranslatef(0.25,0,0);///往右拉過去
            glRotatef (angle,0,0,1);///旋轉 對 中心轉
            glTranslatef(0.25,0,0);///把關節移到中心
        hand();///下手臂
        glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
    angle++;
}



int main(int argc,char**argv)///glut初始設定



{



    glutInit(&argc,argv);



    glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);///顯示模式



    glutCreateWindow("WEEK04");///視窗



    glutDisplayFunc(display);///顯示的函示
    glutIdleFunc(display);








    glutMainLoop();///主要迴圈

}





























#include <GL/glut.h>///使用glut外掛
float angle=0;///初始角度

void hand()
{
    glPushMatrix();///備份矩陣
        glScalef(0.5,0.1,0.1);///細長的
        glColor3f(0,0,1);///藍色的
        glutSolidCube(1);///方塊
    glPopMatrix();
}

void display()



{



    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清空
    glColor3f(1,1,1); glutSolidCube(1);///大身體
    glPushMatrix();///右半邊
        glTranslatef(0.25,0.25,0);///整個移到右上角掛著
        glRotatef (angle,0,0,1);///旋轉 對 中心轉
        glTranslatef(0.25,0,0);///把關節移到中心
        hand();///細長的藍色的上手臂
        glPushMatrix();
            glTranslatef(0.25,0,0);///往右拉過去
            glRotatef (angle,0,0,1);///旋轉 對 中心轉
            glTranslatef(0.25,0,0);///把關節移到中心
        hand();///下手臂
        glPopMatrix();
    glPopMatrix();

     glPushMatrix();///左半邊
        glTranslatef(-0.25,0.25,0);///整個移到左上角掛著
        glRotatef (-angle,0,0,1);///旋轉 對 中心轉
        glTranslatef(-0.25,0,0);///把關節移到中心
        hand();///細長的藍色的上手臂
        glPushMatrix();
            glTranslatef(-0.25,0,0);///往左拉過去
            glRotatef (-angle,0,0,1);
            glTranslatef(-0.25,0,0);
        hand();///下手臂
        glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
    angle++;
}



int main(int argc,char**argv)///glut初始設定



{



    glutInit(&argc,argv);



    glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);///顯示模式



    glutCreateWindow("WEEK04");///視窗



    glutDisplayFunc(display);///顯示的函示
    glutIdleFunc(display);








    glutMainLoop();///主要迴圈



}



沒有留言:

張貼留言

距地表面160 Week11

 #include "glm.h" GLMmodel* pmodel = NULL; void drawmodel(void) {     if (!pmodel) { pmodel = glmReadOBJ("data/porsche.obj...