jiarong701
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ###### tags:`Precessing` `2023寒假` `Beady` `找專研題目` `寫程式` # 2023寒假_串珠Beady [Beady: Interactive Beadwork Design and Construction](https://www.is.ocha.ac.jp/~yuki/beady/index-e.html?fbclid=IwAR2IUOgB1pi31MR6ELdc6QyLu-EWcxvQiPpRAnbF7hKQN4yN4xMqplPbdLc) ## processing 的基礎3D功能 ### 角度、打光、移動、旋轉 <font color="#f00">P3D</font> 開啟processing的OpenGL 3D功能 <font color="#f00">box( )</font> 類似電腦圖學C語言中的 glutSolidCube() 座標原點在左上角 為了讓物體在畫面中心,需要將物體移到==translate(寬度/2,高度/2)== ==radians( )== 是換算 degrees度數 及 radians弧度 <font color="#f00">linghts( )</font> 打光 ```p void setup(){ size(300, 300, P3D); } void draw(){ lights(); background(#FFFFF2); pushMatrix(); translate(150,150); rotateY(-radians(mouseX)); rotateX(-radians(mouseX)); box(100); popMatrix(); } ``` ![](https://i.imgur.com/0AmaN78.png) ### 頂點、畫圖、球體 ==beginShape()== 開始畫 // glBegin(POLYGON); ==endShape()== 結束畫 // glEnd(); ==vertex()== 頂點 // glVertex2f(x,y); ```p void setup(){ size(300, 300, P3D); } void draw(){ lights(); background(#FFFFF2); pushMatrix(); translate(150,150); rotateX(-radians(mouseY)); rotateY(-radians(mouseX)); myShape();//box(100); popMatrix(); } void myShape(){ beginShape(); // glBegin(POLYGON); vertex(-50, -50); // glVertex2f(x,y); vertex(-50, 50); vertex(50, 50); vertex(50, -50); endShape(CLOSE); // glEnd(); } ``` 四個頂點 >>矩形 三個頂點 >>三角形.. ![](https://i.imgur.com/PFBke8Q.png) ==sphere( )== 表面有線條的球 加上 ==noStroke( )== 不要線條 加上打光、移動至視窗中心 ```size(300,300,P3D); lights(); noStroke(); translate(150,150); sphere(112); ``` ![](https://i.imgur.com/d4GCKdM.png) ## 模仿Beady(1)在box的邊上擺球 * 方塊、球不相關 把sphere( )、box( )放進來 ```p= void setup(){ size(300,300,P3D); } void draw(){ lights(); background(255,255,250); pushMatrix(); translate(150,150); rotateY(-radians(mouseX)); fill(255,228,97); box(100); popMatrix(); drawshape(0,0,0); } void drawshape(float x,float y, float z){ fill(#6AA5F5); translate(x,y,z); noStroke(); sphere(50); } ``` ![](https://i.imgur.com/8DpLlt3.png) 為什麼這兩顆球會疊在一起啊? :::danger 新手茫區 :dart: : ![](https://i.imgur.com/uTFONZm.png) 記得要在pushMatrix、popMatrix的組合裡。不然移動會疊加 ::: * 把球放在方塊的邊上 ```processing= void setup(){ size(300,300,P3D); } void draw(){ lights(); background(255,255,250); pushMatrix(); translate(150,150); rotateY(-radians(mouseX)); fill(255,228,97); box(100); drawshape(50,0,50); drawshape(-50, 0, 50); drawshape( 50, 0, -50); drawshape(-50, 0, -50); popMatrix(); } void drawshape(float x,float y, float z){ pushMatrix(); fill(#6AA5F5); translate(x,y,z); noStroke(); sphere(50); popMatrix(); } ``` ![](https://i.imgur.com/IZznUL0.png) processing裡的Z軸指向使用者 ![](https://i.imgur.com/i0N369T.png) ## 讀入OBJ檔、縮放 下載[beady_en.zip](https://www.is.ocha.ac.jp/~yuki/beady/beady_en.zip)解壓縮,找到模型檔以記事本打開 ![](https://i.imgur.com/ajD80cS.png)>>發現頂點的範圍介於-1~1之間 把penguin.obj檔丟進processing裡 ==**PShape**== name ; 宣告 name = ==**loadShape**("name.obj")==; 讀檔 ==**shape**( name );== 畫出模型 因為頂點太小>>要放大 <font color="#f00">scale( )</font> 縮放 ### 轉動的企鵝 ```p PShape penguin; void setup() { size(500, 500, P3D); penguin =loadShape("penguin.obj"); } void draw() { background(255, 255, 255); lights(); translate(250, 250); rotateZ(radians(161)); rotateX(radians(379)); println(mouseX); rotateY(radians(mouseX)); scale(300); shape(penguin); } ``` ![](https://i.imgur.com/vwF8LKa.png) ### 用sphere( )秀出頂點 ![](https://i.imgur.com/9KygOaG.png) v(頂點) 點座標 f(面) int1 int2 int3...第幾個頂點 把第一個面的頂點秀出來>>> f 2 3 8 12 17 * **<font color="#f00">陣列</font>** : 設***已知數量***的點座標 * 宣告 float [ ][ ]v =new float[5][3]; [5][3]因為f1有五個點、每個點有xyz值 直接給每個頂點的值,再把五個頂點讀入v裡 把penguin秀出來 mySphere()在(x,y,z)處畫出球體 用迴圈在5個頂點處 畫出球體 ==frameCount==楨數(60Hz) ```p void draw(){ background(#FFFFF2); lights(); translate(250,250); rotateY(radians(frameCount)); noStroke(); scale(300); shape(penguin); for(int i=0; i<5; i++){ mySphere( v[i][0], v[i][1], v[i][2]); } } void mySphere(float x, float y, float z){ pushMatrix(); translate(x,y,z); sphere(0.03); popMatrix(); } ``` ### 用線串珠_把球連起來 :::danger **第i個點與下一個點連接**,避免超出範圍 迴圈的範圍要減一 ![](https://i.imgur.com/caU0YVp.png) **頭跟尾無法連接、少一條** ![](https://i.imgur.com/tWzxSqn.png) ::: ```p for(int i=0;i<5;i++){ stroke(255,0,0); //紅色的線 strokeWeight(0.01); //線的粗細 line(v[i][0],v[i][1],v[i][2],v[(i+1)%5][0],v[(i+1)%5][1],v[(i+1)%5][2]); //第i個頂點x、y、z } ``` **i=0~i < N ==(i+1)%N取餘數==**... v[0]-v[1] v[1]-v[2] v[2]-v[3] v[3]-v[4] v[4]-v[0] i的範圍:0 1 2 3 4 當i=4時 與第一個點(整除為0)相連 ![](https://i.imgur.com/ZrDfZI7.png) ## 自動讀obj檔,根據頂點找到邊edge,把邊變成珠珠 ### 讀入模型的所有頂點 * 宣告字串,把模型檔以字串讀入 **String[] lines= ==loadStrings==(file);** ![](https://i.imgur.com/WFFduR4.png) ![](https://i.imgur.com/jfLze7U.png) * 把頂點v和面f 分開 **字串的第幾個**lines[i]==**.charAt()**== ```p= void myLoadShape(String file){ String[] lines=loadStrings(file); int V=0,F=0;// How much vertex for(int i=0;i<lines.length;i++){ println(lines[i]); char c=lines[i].charAt(0); if(c=='v')V++; if(c=='f')F++; } println("total vertex:"+V,"total face:"+F); } void setup(){ myLoadShape("penguin.obj"); } ``` ![](https://i.imgur.com/HUizy6O.png) * 把讀到的頂點由String變成PVector ![](https://i.imgur.com/buh5Fz6.png) 1. 宣告陣列來放頂點PVector [ ]OBJv; 2. 決定陣列大小=V+1(因為模型檔f的頂點v是由1開始數的) 3. 用 ==**split()**== 以空白鍵**分割字串**後,放入新設定的字串nums裡![](https://i.imgur.com/yMyoOal.png) 4. V=1,由第一個點開始把向量丟進去x,y,z 5. 每丟好一個後,V++ ```p OBJv=new PVector[V+1];//obj檔裡的f的頂點v是由1開始數,盒子的總數要加一 V=1;//obj檔裡的f的頂點v是由1開始數 for(int i=0;i<lines.length;i++){ char c=lines[i].charAt(0); if(c=='v'){ String[]nums=split(lines[i]," ");//把lines[i]切成3個數字 OBJv[V]=new PVector(float(nums[1]),float(nums[2]),float(nums[3]));//第一個是v println(OBJv[V]); V++; } } ``` * 用頂點做出模型 **beginShape()** vertex.... **endShape()** ![](https://i.imgur.com/C0JfOrD.png) ```p void draw(){ background(#FFFFF3); scale(300); lights(); beginShape(); for(int i=1;i<V;i++){ vertex(OBJv[i].x,OBJv[i].y,OBJv[i].z); } endShape(); } ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully