3次元の結び目
結び目理論のコードがいまいち理解できてなかったので,もう少しやってみることにして,リファレンスのページにあったCのコードをProcessingにポーティングしてみた.座標算出のコードぽかったのでグラフィカルになるようにアレンジした.
コード
float n_segment = 1000; float degree = 0; float radius = 30; float x, y, z, px, py, pz; ArrayList<PVector> points = new ArrayList<PVector>(); void setup() { size(960, 540, P3D); colorMode(HSB, 360, 100, 100); noFill(); stroke(0, 0, 100); } void draw() { background(0, 0, 0); translate(width/2, height/2, -500); rotateY(frameCount*0.01); float mu = degree * TWO_PI / n_segment; x = 10 * (cos(mu) + cos(3 * mu)) + cos(2 * mu) * cos(4 * mu); y = 6 * sin(mu) + 10 * sin(3 * mu); z = 4 * sin(3 * mu) * sin(5 * mu / 2) + 4 * sin(4 * mu) - 2 * sin(6 * mu); PVector p = new PVector(x, y, z); p.mult(radius); points.add(p); beginShape(); int i = 0; for (PVector point : points) { stroke(i%360, 80, 100); strokeWeight(sin(i*0.1)*20+10); vertex(point.x, point.y, point.z); i++; } endShape(); degree += 3; }