Created
August 28, 2021 02:49
-
-
Save champierre/2c1c005600b72c5592fe80eb97ddc18a to your computer and use it in GitHub Desktop.
Scratchで楽しく学ぶアート&サイエンス 改訂第2版 p.98(初版ではp.118) 「万華鏡を描くProcessingプログラム」
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
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