Skip to content

Instantly share code, notes, and snippets.

@2bbb
Last active August 29, 2015 13:59
Show Gist options
  • Save 2bbb/10588556 to your computer and use it in GitHub Desktop.
Save 2bbb/10588556 to your computer and use it in GitHub Desktop.
from micromeeeter
// https://gist.github.com/micromeeeter/10586065
void setup(){
colorMode(HSB,360,100,100);
size(600,600);
background(1,0,99);
stroke(189,99,99);
strokeWeight(1);
frameRate(20);
}
void draw(){
noStroke();
fill(1,0,99,100);
rect(0,0,600,600);
stroke(189,99,99);
translate(300,300);
// float a = random(3);
// ...
// float l = random(3);
float[] as = new float[12];
for(int i = 0; i < 12; i++) {
as[i] = random(3);
}
// float x0 = 250 * cos(radians(30*0));
// float y0 = 250 * sin(radians(30*0));
// ...
// float x11 = 250 * cos(radians(30*11));
// float y11 = 250 * sin(radians(30*11));
float[] xs = new float[12];
float[] ys = new float[12];
for(int i = 0; i < 12; i++) {
xs[i] = 250 * cos(radians(30 * i));
ys[i] = 250 * sin(radians(30 * i));
}
for(int z = 0; z < 12; z++){
float x = 250 * cos(radians(30 * z));
float y = 250 * sin(radians(30 * z));
// if(a>1){
// line(x,y,x0,y0);
// }else{
// ...
// }if(l>1){
// line(x,y,x11,y11);
// }else{
// }
for(int i = 0; i < 12; i++) {
if(as[i] > 1){
line(x, y, xs[i], ys[i]);
}
}
}
rotate(PI/4);
for(int z = 0;z < 12;z++){
float x = 250 * cos(radians(30*z));
float y = 250 * sin(radians(30*z));
// if(a>1){
// line(x,y,x0,y0);
// }else{
// ...
// }if(l>1){
// line(x,y,x11,y11);
// }else{
// }
for(int i = 0; i < 12; i++) {
if(as[i] > 1){
line(x, y, xs[i], ys[i]);
}
}
}
}
// https://gist.github.com/micromeeeter/10586065
// よく使う数値は定数にしておくと幸せになれる
// (WIDTH, HEIGHTは組み込みのwidth, heightで動的に取ることも出来る)
final int WIDTH = 600;
final int HEIGHT = 600;
final int VERTECIES_NUM = 12;
final float radius = WIDTH / 2.4;
final float degreePerVertex = 360.0 / VERTECIES_NUM;
float[] xs = new float[VERTECIES_NUM];
float[] ys = new float[VERTECIES_NUM];
void setup(){
colorMode(HSB,360,100,100);
size(WIDTH, HEIGHT);
background(1,0,99);
stroke(189,99,99);
strokeWeight(1);
frameRate(20);
// xsとysの初期化
setupVertecies();
}
// xs, ysは毎回同じ値だからまとめる
void setupVertecies() {
for(int i = 0; i < VERTECIES_NUM; i++) {
xs[i] = radius * cos(radians(degreePerVertex * i));
ys[i] = radius * sin(radians(degreePerVertex * i));
}
}
void draw() {
noStroke();
fill(1,0,99,100);
rect(0,0,600,600);
stroke(189,99,99);
translate(WIDTH / 2, HEIGHT / 2);
drawStuff();
rotate(PI/4);
drawStuff();
}
// rotateを挟んで2回同じことをやってたからまとめる
void drawStuff() {
float[] as = new float[VERTECIES_NUM];
for(int i = 0; i < VERTECIES_NUM; i++) {
as[i] = random(3);
}
// zをjに変更. (x, y, zだとなんか座標っぽいので)
// x, y も xs[j], ys[j] と同じだったのでそっちを使う
for(int j = 0; j < VERTECIES_NUM; j++) {
for(int i = 0; i < VERTECIES_NUM; i++) {
if(j == i) {
continue;
}
if(as[i] > 1) {
line(xs[i], ys[i], xs[j], ys[j]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment