Created
August 2, 2017 11:19
-
-
Save micromeeeter/cc4085690f817de6f8b6def78bb9f4ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//import "img.png" as a background image to "data" | |
final int n = 5; | |
PVector[] p1 = new PVector[n]; | |
PVector[] p2 = new PVector[n]; | |
PVector[] p3 = new PVector[n]; | |
PVector[] v1 = new PVector[n]; | |
PVector[] v2 = new PVector[n]; | |
PVector[] v3 = new PVector[n]; | |
int r; | |
PImage img; | |
void setup() { | |
size(800, 800); | |
background(55, 55, 55); | |
noFill(); | |
smooth(); | |
strokeCap(ROUND); | |
img = loadImage("img.png"); | |
p1[0] = new PVector(width / 2.3 * cos(PI / 6), height / 2.3 * sin(PI / 6)); | |
p2[0] = new PVector(width / 2.3 * cos(PI * 5 / 6), height / 2.3 * sin(PI * 5 / 6)); | |
p3[0] = new PVector(width / 2.3 * cos(PI * 9 / 6), height / 2.3 * sin(PI * 9 / 6)); | |
} | |
void draw() { | |
//background(img); | |
strokeWeight(4); | |
translate(width / 2, height / 2 + width / 2.5 / 2 / 3); | |
r = 10; | |
p1[1] = new PVector((p2[0].x + p3[0].x) / 2, (p2[0].y + p3[0].y) / 2); | |
p2[1] = new PVector((p3[0].x + p1[0].x) / 2, (p3[0].y + p1[0].y) / 2); | |
p3[1] = new PVector((p1[0].x + p2[0].x) / 2, (p1[0].y + p2[0].y) / 2); | |
v1[0] = p1[0]; | |
v2[0] = p2[0]; | |
v3[0] = p3[0]; | |
for (int i = 2; i < n; i++) { | |
p1[i] = new PVector((p1[i-1].x + p2[0].x) / 2, (p1[i-1].y + p2[0].y) / 2); | |
p2[i] = new PVector((p3[i-1].x + p1[i-1].x) / 2, (p3[i-1].y + p1[i-1].y) / 2); | |
p3[i] = new PVector((p3[i-1].x + p2[0].x) / 2, (p3[i-1].y + p2[0].y) / 2); | |
} | |
for (int i = 1; i < n; i++) { | |
v1[i] = new PVector(p1[i].x + r * cos(PI / 6), p1[i].y + r * sin(PI / 6)); | |
v2[i] = new PVector(p2[i].x - r * cos(PI / 6), p2[i].y + r * sin(PI / 6)); | |
v3[i] = new PVector(p3[i].x, p3[i].y - r); | |
} | |
stroke(255, 255, 255); | |
for (int i = 0; i < n; i++) { | |
triangle(v1[i].x, v1[i].y, v2[i].x, v2[i].y, v3[i].x, v3[i].y); | |
} | |
save("output.png"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment