Skip to content

Instantly share code, notes, and snippets.

@champierre
Created August 28, 2021 02:49
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 champierre/2c1c005600b72c5592fe80eb97ddc18a to your computer and use it in GitHub Desktop.
Save champierre/2c1c005600b72c5592fe80eb97ddc18a to your computer and use it in GitHub Desktop.
Scratchで楽しく学ぶアート&サイエンス 改訂第2版 p.98(初版ではp.118) 「万華鏡を描くProcessingプログラム」
int n = 64;
void setup(){
size(600, 600);
}
void draw() {
if (mousePressed == true) {
for (int i = 1; i <= n; i++) {
float[] rmouse = rotate(mouseX - 300, mouseY - 300, 360.0 / n * i);
float[] rpmouse = rotate(pmouseX - 300, pmouseY - 300, 360.0 / n * i);
line(300 + rmouse[0], 300 + rmouse[1], 300 + rpmouse[0], 300 + rpmouse[1]);
}
}
}
float[] rotate(float x, float y, float degree) {
float theta = radians(degree);
float rx = x * cos(theta) - y * sin(theta);
float ry = x * sin(theta) + y * cos(theta);
float[] array = {rx, ry};
return array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment