Created
November 2, 2015 08:42
-
-
Save naoyashiga/d9413e35466cc3a21268 to your computer and use it in GitHub Desktop.
Grid Display 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
class BaseParticleWithVector implements BaseParticleWithVectorInterface { | |
PVector location; | |
PVector velocity; | |
float scalarVelocity; | |
float r; | |
BaseParticleWithVector() { | |
location = new PVector(random(width), random(height)); | |
velocity = new PVector(0, 0); | |
scalarVelocity = 0; | |
r = 5; | |
} | |
void render() { | |
fill(255); | |
noStroke(); | |
ellipse(location.x,location.y,r,r); | |
} | |
void walk() { | |
//override in subclass | |
} | |
} | |
interface BaseParticleWithVectorInterface { | |
void walk(); | |
} |
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
//可変長配列 | |
ArrayList<Particle> particles; | |
int cols = 10; | |
int rows = 10; | |
int cellWidth = 0; | |
int cellHeight = 0; | |
void setup() { | |
//スクリーンの大きさはディスプレイに合わせる | |
size(displayWidth, displayHeight); | |
cellWidth = width / cols; | |
cellHeight = cellWidth; | |
// cellHeight = height / rows; | |
//パーティクルの数 | |
int particlesSize = cols * rows; | |
particles = new ArrayList<Particle>(); | |
for (int i = 0; i < cols; i++) { | |
for (int j = 0; j < rows; j++) { | |
Particle u = new Particle(cellWidth * i + cellWidth / 2, cellHeight * j + cellHeight / 2); | |
particles.add(u); | |
} | |
} | |
rectMode(CENTER); | |
background(0); | |
} | |
void draw() { | |
fill(0); | |
rect(0, 0, width, height); | |
//ArrayListのfor文の省略記法 | |
for (Particle u : particles) { | |
u.walk(); | |
u.render(); | |
} | |
//フレームのキャプチャ保存 | |
// saveFrame("frames/######.tif"); | |
} |
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
class Particle extends BaseParticleWithVector { | |
float angle; | |
float startAngle; | |
PVector center; | |
Particle(int centerX, int centerY) { | |
location = new PVector(centerX, centerY); | |
angle = 0; | |
//位相のズレ | |
startAngle = random(PI * 2); | |
//画面の中心 | |
center = new PVector(width / 2, height / 2); | |
//スカラー量の速度 | |
scalarVelocity = 1; | |
velocity.x = random(-scalarVelocity, scalarVelocity); | |
velocity.y = random(-scalarVelocity, scalarVelocity); | |
} | |
void render() { | |
fill(210,252,254,255); | |
noStroke(); | |
ellipse(location.x,location.y,r,r); | |
} | |
void walk() { | |
// location.x += velocity.x; | |
// location.y += velocity.y; | |
//画面外に出た時の処理 | |
if(location.x < 0 || location.x > width) { | |
velocity.x *= -1; | |
} else if(location.y < 0 || location.y > height) { | |
velocity.y *= -1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment