Processing 字型變形

來源:互聯網
上載者:User

標籤:style   blog   http   color   java   os   for   2014   

在Processing中做字型變形通常需要有以下基礎知識:

1、PGraphics對象

2、圖片像素化

製作過程也不複雜,代碼如下:

 1 color ELLIPSE_COLOR = color(0); 2 color LINE_COLOR = color(0, 125); 3 color PGRAPHICS_COLOR = color(0); 4 int LINE_LENGTH = 25; 5 boolean reverseDrawing = false; 6 PGraphics pg; 7 PFont f = createFont("宋體", 42); 8 void setup() { 9   size(1280, 720,P2D);10   pg = createGraphics(width, height, JAVA2D);11   pg.beginDraw();12   pg.textFont(f);13   pg.textSize(300);14   pg.textAlign(CENTER, CENTER);15   pg.fill(PGRAPHICS_COLOR);16   pg.text("麥塔威", pg.width/2, pg.height/2);17   pg.endDraw();18 }19 void draw() {20   int gridH = (int) map(mouseX, 0, width, 30, 100);21   int gridV = (int) map(mouseY, 0, height, 15, 100);22   float w = width/gridH;23   float h = height/gridV;24   float r = min(w, h);25 26   background(255);27   strokeWeight(1);28   for (int y=0; y<gridV; y++) {29     for (int x=0; x<gridH; x++) {30       float _x = x*w;31       float _y = y*h;32       color c = pg.get(int(_x), int(_y));33       boolean textDraw = (c == PGRAPHICS_COLOR);34       if (textDraw) {35         noStroke();36         fill(ELLIPSE_COLOR);37         ellipse(_x, _y, r, r);38       } else {39         stroke(LINE_COLOR);40         line(_x, _y, _x+LINE_LENGTH, _y+LINE_LENGTH);41       }42     }43   }44 }

其中,setup部分的pg操作都是在PGraphics對象上的操作,這個對象就類似於畫布上的畫布,而draw裡面兩個for迴圈則是實現字型變形的關鍵,將圖片像素化以後比對字型顏色和背景顏色就可以將字型從背景中“摳”出來,然後想捏扁還是捏圓就看各人的喜好了~

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.