Mod: Coding Challenge #81.2: Circle Morphing - Part 2
p5.jsで書かれてたコードを読み解きながらProcessingにポーティングした.
コード
ArrayList<Point> circlePath = new ArrayList<Point>(); int spacing = 1; float t; void setup() { size(960, 540); colorMode(HSB, 360, 100, 100); setN(); strokeJoin(ROUND); strokeCap(ROUND); } void setN() { circlePath.clear(); float radius = 200; int n = (int)random(3, 7); for (int angle = 0; angle < 360; angle += spacing) { float theta = radians(angle); Point cv = polarToCartesian(radius, theta); cv.active = true; if (angle%(360/n) == 0) { cv.fixed = true; } circlePath.add(cv); } t = random(radians(360)); } void draw() { background(0, 0, 85); translate(width/2, height/2); rotate(t); stroke(0, 0, 0); strokeWeight(5); noFill(); beginShape(); for (int i = 0; i < circlePath.size(); i++) { Point v = circlePath.get(i); if (v.active) { vertex(v.x, v.y); } } endShape(CLOSE); ArrayList<Point> activeList = new ArrayList<Point>(); for (int i = 0; i < circlePath.size(); i++) { Point v = circlePath.get(i); if (v.active && !v.fixed) { activeList.add(v); } } if (activeList.size() == 0) { } int index = 0; if (activeList.size() > 0 && activeList.get(index) != null) { Point v = activeList.get(index); v.active = false; } else { delay(1000); setN(); } } Point polarToCartesian(float r, float theta) { return new Point(cos(theta)*r, sin(theta)* r); } class Point extends PVector { boolean active = false; boolean fixed = false; Point(float x, float y) { super(x, y); } }