Friday, September 10, 2010

Processing methods

  1. 画面サイズ: size(x, y)
  2. 点と線: point(x, y), line(x1, y1, x2, y2)
  3. 多角形: rect(x1, y1, w, h), triangle(x1, y1, x2, y2, x3, y3), quad(x1, y1, x2, y2, x3, y3, x4, y4)
  4. 多角形モード: rectMode([CORNER, CENTER, CORNERS])
  5. 円と弧: ellipse(xc, yc, dw, dh), arc(xc, yc, dw, dh, radians(rs), radians(re))
  6. 曲線: curve(x1, y1, x2, y2, x3, y3, x4, y4), bezier(x1, y1, cx1, cy1, x2, y2, cx2, cy2)
  7. 複雑な形: beginShape(); vertex(x1, y1); vertex(x2, y2).. endShape(CLOSE);
  8. 複雑な曲形: beginShape(): curveVertex(x1, y1).. endShape();
  9. 色モード: colorMode([HSB, RGB], range(h_range, s_range, b_range))
  10. 背景色: background([grayscale, 16bit, (H, S, B/R, G, B)])
  11. 線の属性: stroke([grayscale, 16bit, (H, S, B/R, G, B)], opac), noStroke(), strokeWeight(w)
  12. 面の属性: fill([grayscale, 16bit, (H, S, B/R, G, B)], opac), noFill()
  13. エッジの属性: smooth(), noSmooth()
  14. データ型: boolean, int, float, color, byte, char
  15. 変数宣言: int i_data; float f1_data, f2_data; int i_data = 10
  16. 型変換: boolean(string_data), int(data)
  17. 色データ型: color c = color(h, s, b); fill(c)
  18. システム変数: width, height
  19. 座標変換: translate(moveX, moveY), rotate(radians(120)), scale(0.5), pushMatrix(), popMatrix()
  20. 画像の読み込み: PImage img = loadImage("sample.jpg")
  21. 画像の表示: image(img, x, y, w, h)
  22. 画像モード: imageMode([CORNER, CORNERS, CENTER])
  23. 画像の色指定: tint([grayscale, 16bit, (H, S, B/R, G, B)]), noTint()
  24. 画像の操作: img.width, img.height, img.copy(), img.mask(other_pimage)
  25. 文字の表示: textSize(24); textAlign(CENTER), text("hello", x, y (w, h))
  26. フォントの指定: PFont font = loadFont("sample.vlw"); textFont(font)
  27. コンソール出力: println(x)
  28. ゆらぎの表現: rect(x+random(-range, range), y+random(-range, range), 10, 10)
  29. マウスの移動距離: dist(mouseX, mouseY, pmouseX, pmouseY)
  30. PDFに出力: import processing.pdf.*; size(x, y, "out.pdf"); exit()
  31. 初期化: void setup(){ size(x, y); background(); colorMode(); frameRate(r); }
  32. メインループ: void draw(){ stroke(color); int x = int(random(w)); int y = int(random(h)); rect(...) }
  33. 関数定義: void fadeToWhite(c, f){ noStroke(); fill(c, f); rectMode(CORNER); rect(0,0,width,height); }
  34. スピードの減衰: float FRICTION = 0.94; SpeedX *= FRICTION; X += SpeedX
  35. 円の動き: Angle += 10; X = CircleX + (R * cos(radians(Angle))); Y = CircleY + sin(radians(Angle))
  36. 落下の動き: float GRAVITY = 3; SpeedY += GRAVITY; Y += Speedy
  37. バネの動き: float distY = Y - SpringLen; Accy = -K * distY; SpeedY = FRICTION * (SpeedY + Accy)
  38. 引力の動き: float SCALE = 0.0005; float distX = X - targetX; Accx = SCALE * sq(distX); if(X>targeX) Accx = -Accx
  39. マウスの動き: float speed = dist(mouseX, mouseY, pmouseX, pmouseY)
  40. マウスクリック: void mousePressed(){ if(mouseButton == LEFT) ... }
  41. マウスの移動: void mouseMoved(){...}, void mouseDragged(){...}
  42. キーの入力: void keyPressed(){ switch(key){ case 'a':...break;}}, void keyReleased(){...}
  43. 配列宣言: int[] X = new int[Length], int[][] map = {{1,2,3},{4,5,6},{7,8,9}}
  44. マウスドラッグ: void mousePressed(){ if(OnMouse) onDrag = true }; void mouseReleased(){ OnDrag = false}
  45. 力をためる: if(mousePressed){ Power += 1}
  46. ピクセル操作: PImage img = loadImage("s.jpg"); img.loadPixels(); pos = (y*img.width)+x; pixels[pos] = img.pixels[pos]; updatePixels();
  47. 3D座標: size(x, y, P3D); line(x1, y1, z1, x2, y2, z2)
  48. クラス定義: public class Ball(){ Ball(){ ..initialize..} public void move(){...} }
  49. テキストファイルの読み込み: String[] Str; Str = loadString("data.txt"); text(Str, x, y)
  50. 時間の表示: text(year() + "/" + month() + "/" + day())
  51. 範囲変換: float mapped_val = map(mouseX, 0, width, 0, 100)
  52. 中間色変換:color c = lerpColor(color1, color2, map(x, 0, width, 0, 1))
  53. XMLを読む: XMLElement Xml = new XMLElement(this, xml_data); Xml.getChild(0).getContent()
  54. 音楽再生: import ddf.minim.*; Minim m = new Minim(this); AudioPlayer audio = m.loadFile("s.mp3", 2048);
  55. 音楽再生2: audio.play(), pause(), isPlaying, length, position, close(); m.stop()
  56. 波形発振: import ddf.minim.*;import ddf.minim.signals.*; Minim minim; AudioOutput out; SineWave sine; SquareWave square;
  57. 波形発振2: minim = new Minim(this); out = minim.getLineOut(Minim.STEREO); sine = new SineWave(440, 0.5, out.sampleRate()); out.addSignal(sine)

No comments: