Last active
October 19, 2020 06:04
-
-
Save YuukiToriyama/b3123af434ed5843ab3495c3cd9e830c to your computer and use it in GitHub Desktop.
Processing Sample
This file contains hidden or 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
// drawing_a_star.pde | |
int t; | |
boolean flag; | |
PVector location; | |
PVector[] vertices = new PVector[5]; | |
PVector[] velocity = new PVector[5]; | |
void setup() { | |
// 画面の初期化 | |
background(0); | |
fill(255); | |
frameRate(60); | |
background(0); | |
size(500, 500); | |
// verticesの初期化 | |
for (int i = 0; i < 5; i++) { | |
vertices[i] = new PVector(100 * cos(i * 2 * PI / 5), 100 * sin(i * 2 * PI / 5)); | |
} | |
// velocityの初期化 | |
for (int i = 0; i < 5; i++) { | |
velocity[i] = PVector.div(PVector.sub(vertices[(i + 2) % 5], vertices[i]), 100); | |
} | |
// 時間変数の初期化 | |
t = 0; | |
// メッセージの表示 | |
text("Click/tap on this window wherever you like!", width / 2, height / 2); | |
} | |
void draw() { | |
if (flag == true) { | |
stroke(255); | |
for (int i = 0; i < 5; i++) { | |
PVector p = PVector.add(vertices[i], velocity[i]); | |
line(vertices[i].x, vertices[i].y, p.x, p.y); | |
vertices[i] = p; | |
t = t + 1; | |
} | |
if (t == 500) { | |
flag = false; | |
} | |
} | |
} | |
void mousePressed() { | |
// 初期化 | |
setup(); | |
// マウスの位置ベクトルを保存 | |
location = new PVector(mouseX, mouseY); | |
// ベクトルlocationぶん星型を原点から平行移動し表示する | |
for (int i = 0; i < 5; i++) { | |
vertices[i] = PVector.add(vertices[i], location); | |
ellipse(vertices[i].x, vertices[i].y, 10, 10); | |
} | |
flag = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment