Processing基礎圖形繪制

Basic setup

定義畫布大小犁罩,邊框大小拙友、顏色辟癌,填充色
以下所有案例均在size(600, 200)中繪制

size(width, height);
smooth();

stroke(color);
strokeWeight(20);
// or
noStroke();

fill(); // RGBA,HUE...
// or
noFill();

Drawing points

point(x, y)氏身,大小通過stroke控制

stroke(#ffffff);
strokeWeight(20);

point(100,100);
point(200,100);
point(300,100);
point(400,100);
point(500,100);
Points

Drawing lines

line(x1, y1, x2, y2)

stroke(#e2e1dc);
strokeWeight(2);
line(100, 50, 500, 50);
line(100, 150, 500, 150);

stroke(#791f33);
strokeWeight(8);
line(100, 50, 100, 150);
line(100, 50, 200, 150);
line(100, 50, 300, 150);
line(100, 50, 400, 150);

line(200, 50, 500, 150);
line(300, 50, 500, 150);
line(400, 50, 500, 150);
line(500, 50, 500, 150);
Lines

Drawing ellipses and circles

ellipse(x, y, width, height); 默認(x,y)為中心巍棱,即CENTER; ellipseMode(CORNER)從左上角(x,y)開始畫起

noStroke();
fill(#8fa89b, 200);
ellipse(100, 100, 150, 100);
fill(#a2bab0, 200);
ellipse(200, 100, 150, 100);
fill(#d0edde, 200);
ellipse(300, 100, 150, 100);
fill(#8fa89b, 200);
ellipse(400, 100, 150, 100);

ellipseMode(CORNER);
fill(#b3b597);
ellipse(500, 100, 150, 150);
Ellipses and Circles

Drawing arcs

arc(x, y, width, height, start, stop); start=0時默認從三點鐘方向順時針畫起,以此往后推蛋欣,start=PI則從9點鐘方向畫起

strokeWeight(5);

arc(100, 100, 75, 75, 0, PI*0.5);

noFill();
arc(233, 100, 75, 75, 0, PI);

fill(0, 191, 255);
noStroke();
arc(367, 100, 75, 75, 0, radians(270));

stroke(0);
arc(500, 100, 75, 75, 0, TWO_PI);
Arcs

Drawing rectangles and squares

rect(top_left_x, top_left_y, width, height) 默認為rectMode(CORNER)航徙,即以左上角的點為定向往后畫;CENTER則定義中心點陷虎,往四周畫到踏;CORNERS,則定左上角的點和右下角的點尚猿,即rect(top_left_x, top_left_y, right_bottom_x, right_bottom_y);

strokeWeight(5);
rectMode(CORNER); // defalut
rect(60, 60, 80, 80);


rectMode(CENTER);
noStroke();
fill(#cc5c54);
rect(300, 100, 80, 80);

rectMode(CORNERS); // top left and bottom right
stroke(#f69162);
noFill();
rect(460, 60, 540, 140);
Rectangle and Square

Drawing quadrangles

quad(x1, y1, x2, y2, x3, y3, x4, y4)四邊形窝稿,直接定四個點的x,y

strokeWeight(5);
quad(150, 50, 200, 100, 150, 150, 100, 100);

noStroke();
fill(#a3d0c1);
quad(300, 50, 350, 100, 300, 150, 250, 100);

stroke(#fdf6dd);
noFill();
quad(450, 50, 500, 100, 450, 150, 400, 100);
Quadrangles

Drawing triangles

同樣定義三角形三個點的x,y

triangle(150, 50, 200, 150, 100, 150);
Triangle

Drawing polygons

beginShape(kind)kind可以是POINTS, LINES, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, QUADS, or QUAD_STRIP,Processing會自動根據(jù)點和所要畫的形狀來分配凿掂。endShape(mode)可填CLOSE也可不填伴榔,CLOSE表示閉合形狀

beginShape();
vertex(200, 150);
vertex(150, 125);
vertex(150, 75);
vertex(200, 50);
vertex(250, 75);
vertex(250, 125);
endShape(CLOSE);
Polygons

Drawing simple curves

curve(Cx1,Cy1, x1, y1, x2, y2, Cx2, Cy2);前后為控制曲度的點的坐標,中間為繪制的定點坐標庄萎;curveTightness()踪少,為0時正常曲度,1時為直線惨恭。在-5.0和5.0之間變化會畸形變化

Float i = 1.0;
Float j = 1.0;
void setup() {
  size(600, 200);
  smooth();
  frameRate(2);
}
void draw() {
  background(#c3ccc8);
  strokeWeight(5);
  stroke(#442412);
  curveTightness(0);
  curve(100, 300, 100, 100, 200, 100, 200, 300);
  
  noFill();
  stroke(#b9961c);
  i = i-.1;
  curveTightness(i);
  curve(250, 300, 250, 100, 350, 100, 350, 300);
  
  j = j + .1;
  stroke(#475d1c);
  curveTightness(j);
  curve(400, 300, 400, 100, 500, 100, 500, 300);
}
Curves

Drawing complex curves

多點繪制

noFill();

strokeWeight(3);
stroke(255);
curveTightness(0);
beginShape();
curveVertex(100, 100);
curveVertex(100, 100);
curveVertex(150, 150);
curveVertex(250, 50);
curveVertex(300, 10);
curveVertex(400, 150);
curveVertex(500, 100);
curveVertex(500, 100);
endShape();

strokeWeight(3);
stroke(130);
curveTightness(-3);
beginShape();
curveVertex(100, 100);
curveVertex(100, 100);
curveVertex(150, 150);
curveVertex(250, 50);
curveVertex(300, 10);
curveVertex(400, 150);
curveVertex(500, 100);
curveVertex(500, 100);
endShape();

strokeWeight(3);
stroke(0);
curveTightness(4);
beginShape();
curveVertex(100, 100);
curveVertex(100, 100);
curveVertex(150, 150);
curveVertex(250, 50);
curveVertex(300, 10);
curveVertex(400, 150);
curveVertex(500, 100);
curveVertex(500, 100);
endShape();
// red dots
strokeWeight(6);
stroke(200, 0, 0);
point(100, 100);
point(150, 150);
point(250, 50);
point(300, 10);
point(400, 150);
Curves

Drawing Bezier curves

bezier(x1,y1,Cx1,Cy1,Cx2,Cy2,x2,y2)類似于用鋼筆繪畫秉馏,前后兩個為定點,中間兩個點為鋼筆柄的端點脱羡,以此控制曲度萝究。vertex(x1,y1);bezierVertex(Cx1, Cy1, Cx2, Cy2, x2, y2)相當于把原來的bezier拆分成一個一個點來繪制

noFill();
stroke(#f1e6d4);
strokeWeight(2);
line(100, 50, 250, 50);
line(250, 150, 100, 150);

stroke(#ba3d49);
strokeWeight(3);
bezier(100, 50, 250, 50, 100, 150, 250, 150);

stroke(#f1e6d4);
strokeWeight(2);
line(350, 75, 500, 25);
line(500, 175, 350, 125);

stroke(#ba3d49);
strokeWeight(3);
bezier(350, 75, 500, 25, 500, 175, 350, 125);
Bezier
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市锉罐,隨后出現(xiàn)的幾起案子帆竹,更是在濱河造成了極大的恐慌,老刑警劉巖脓规,帶你破解...
    沈念sama閱讀 216,496評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件栽连,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機秒紧,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,407評論 3 392
  • 文/潘曉璐 我一進店門绢陌,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人熔恢,你說我怎么就攤上這事脐湾。” “怎么了叙淌?”我有些...
    開封第一講書人閱讀 162,632評論 0 353
  • 文/不壞的土叔 我叫張陵秤掌,是天一觀的道長。 經(jīng)常有香客問我鹰霍,道長闻鉴,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,180評論 1 292
  • 正文 為了忘掉前任茂洒,我火速辦了婚禮孟岛,結果婚禮上,老公的妹妹穿的比我還像新娘督勺。我一直安慰自己蚀苛,他們只是感情好,可當我...
    茶點故事閱讀 67,198評論 6 388
  • 文/花漫 我一把揭開白布玷氏。 她就那樣靜靜地躺著,像睡著了一般腋舌。 火紅的嫁衣襯著肌膚如雪盏触。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,165評論 1 299
  • 那天块饺,我揣著相機與錄音赞辩,去河邊找鬼。 笑死授艰,一個胖子當著我的面吹牛辨嗽,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播淮腾,決...
    沈念sama閱讀 40,052評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼糟需,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了谷朝?” 一聲冷哼從身側響起洲押,我...
    開封第一講書人閱讀 38,910評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎圆凰,沒想到半個月后杈帐,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,324評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,542評論 2 332
  • 正文 我和宋清朗相戀三年挑童,在試婚紗的時候發(fā)現(xiàn)自己被綠了累铅。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,711評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡站叼,死狀恐怖娃兽,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情大年,我是刑警寧澤换薄,帶...
    沈念sama閱讀 35,424評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站翔试,受9級特大地震影響轻要,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜垦缅,卻給世界環(huán)境...
    茶點故事閱讀 41,017評論 3 326
  • 文/蒙蒙 一冲泥、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧壁涎,春花似錦凡恍、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,668評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至竟坛,卻和暖如春闽巩,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背担汤。 一陣腳步聲響...
    開封第一講書人閱讀 32,823評論 1 269
  • 我被黑心中介騙來泰國打工涎跨, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人崭歧。 一個月前我還...
    沈念sama閱讀 47,722評論 2 368
  • 正文 我出身青樓隅很,卻偏偏與公主長得像,于是被迫代替她去往敵國和親率碾。 傳聞我的和親對象是個殘疾皇子叔营,可洞房花燭夜當晚...
    茶點故事閱讀 44,611評論 2 353

推薦閱讀更多精彩內(nèi)容