Skip to content

Instantly share code, notes, and snippets.

@IosysPio
Last active April 12, 2018 09:57
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 IosysPio/bbdac4f26966b10c7e2228c0721335f3 to your computer and use it in GitHub Desktop.
Save IosysPio/bbdac4f26966b10c7e2228c0721335f3 to your computer and use it in GitHub Desktop.
bullet_curtain
// bullet count init
int bullet_count = 200; // 弾丸数
int bul_rad[] = new int[200]; // int[bullet_count]
float bul_the[] = new float[200]; // float[bullet_count]
int bullet_interval = 15; // 発射間隔
int pos_x = 200, pos_y = 200; // 砲台位置というか発射点
int bullet_pnt = 5; // 弾丸の大きさ
int bul_speed = 3; // スピード
int bullet_ell = 1; // 最初に表示される弾丸数みたいなアレ
int uzumaki = 6; // 渦巻きの数 1周当たり弾丸数はcount/uzumaki
int kaiten_houkou = -1; // -1: clockwise 1:counter clockwise
float bullet_z = 0.04; // 円弧方向のずらし角度 マイナスも可
boolean mv; // マウスクリック停止用フラグ
void setup(){
// screen init
size(400, 400);
background(225);
noStroke();
frameRate(15);
// default plot mode
mv = true;
loop();
for(int i = 0; i < bullet_count; i++){
// bullet init
bul_rad[i] = 0 - (bullet_ell * i);
if(bul_rad[i] == 0) {
bul_the[i] = 0;
} else {
bul_the[i] = (uzumaki * TWO_PI / float(bullet_count)) * float(i) * kaiten_houkou;
}
// bullet_plot(bul_rad[i], bul_the[i]);
}
}
void draw(){
// bullet draw
// background(#a0a0a0);
clear();
background(#a0a0a0);
for(int i = 0; i < bullet_count; i++){
bul_rad[i] += bul_speed;
bul_the[i] += bullet_z;
if(bul_rad[i] > (width / 2)) bul_rad[i] -= (width / 2);
if(bul_rad[i] > 0) bullet_plot(bul_rad[i], bul_the[i]);
}
}
void bullet_plot(int radius, float theta) {
fill(#800080);
ellipse(pos_x + (radius * sin(theta)), pos_y + (radius * cos(theta)), bullet_pnt, bullet_pnt);
}
void mousePressed(){
mv = !mv;
if(mv){
loop();
} else {
noLoop();
}
}
@IosysPio
Copy link
Author

(x, y) = (0, 0)でθを求めたときにzero divideが起こるのを修正

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment