Skip to content

Instantly share code, notes, and snippets.

@ynaoto
Last active December 11, 2016 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ynaoto/7bc3e4e784bae2140a29717a622b4925 to your computer and use it in GitHub Desktop.
Save ynaoto/7bc3e4e784bae2140a29717a622b4925 to your computer and use it in GitHub Desktop.
// http://qiita.com/massa142/items/3285a1b1ed12a6ab0299
void setup() {
size(500, 500);
}
void plot() {
float x = random(-2, 2);
float y = random(-2, 2);
PVector P = new PVector(x, y);
PVector Q = new PVector(-x, -y);
PVector R = new PVector(1, 0);
PVector PQ = PVector.sub(Q, P);
PVector PR = PVector.sub(R, P);
PVector QP = PVector.sub(P, Q);
PVector QR = PVector.sub(R, Q);
PVector RP = PVector.sub(P, R);
PVector RQ = PVector.sub(Q, R);
float p = PVector.angleBetween(PQ, PR);
float q = PVector.angleBetween(QP, QR);
float r = PVector.angleBetween(RP, RQ);
if (p < PI/2 && q < PI/2 && r < PI/2) {
stroke(255, 0, 0);
} else {
stroke(0);
}
float gx = map(x, -2, 2, 0, width);
float gy = map(y, -2, 2, height, 0);
point(gx, gy);
}
void draw() {
for (int i = 0; i < 1000; i++) {
plot();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment