Processing 字体变形
生活随笔
收集整理的這篇文章主要介紹了
Processing 字体变形
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
在Processing中做字體變形通常需要有以下基礎(chǔ)知識(shí):
1、PGraphics對(duì)象
2、圖片像素化
制作過程也不復(fù)雜,代碼如下:
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對(duì)象上的操作,這個(gè)對(duì)象就類似于畫布上的畫布,而draw里面兩個(gè)for循環(huán)則是實(shí)現(xiàn)字體變形的關(guān)鍵,將圖片像素化以后比對(duì)字體顏色和背景顏色就可以將字體從背景中“摳”出來,然后想捏扁還是捏圓就看各人的喜好了~
轉(zhuǎn)載于:https://www.cnblogs.com/x5115x/p/3901196.html
總結(jié)
以上是生活随笔為你收集整理的Processing 字体变形的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: #python计算结果百位500向下取整
- 下一篇: 网上看到的一道题,分享一下