円を表示する
Processingには専用の統合開発環境が用意されており、それを使います。Processingにおいて、「Hello World」になるものは円を描くことです。
ellipse(25,25,50,50);
この一行で円が描けます。簡単です。
円と線を描画
設定と背景
size(500,300); smooth(); background(230,230,230);
sizeで描画範囲を定義して、smooth()でアンチエイリアスさせて、線を滑らかにします。backgroundには16進数のカラーコードを入力しても大丈夫です。
描画とスタイル
//線のスタイル stroke(130,0,0); strokeWeight(4); //線を引く line(width / 2 - 70,height/2 - 70,width / 2 + 70,height/2 + 70); line(width / 2 + 70,height/2 - 70,width / 2 - 70,height/2 + 70); fill(255,150); ellipse(width/2,height/2,50,50);
width,heightは定義されている変数のようで、sizeの値が入っています。制約が多いように感じましたが、記述量はぐっと減りますね。
変数化
float centX = width / 2; float centY = height / 2; line(centX - 70,centY - 70,centX + 70,centY + 70); line(centX + 70,centY - 70,centX - 70,centY + 70);
float型で変数にすることもできます。
三角を描く
triangle(width/2,height/3,width/3,(height/3)*2,(width/3)*2,(height/3)*2);
3つの頂点の座標を指定します。
・参考
https://processing.org/reference/triangle_.html