can some one plz help me sort out this code so it will record my sketch
in
Programming Questions
•
1 year ago
hi everyone don't know what i am doing wrong here. it says it can not find MovieMaker
import toxi.geom.*;
ArrayList ballNetwork;
import processing.video.*;
MovieMaker mm;
void setup(){
size(1300,300);
smooth();
mm = new MovieMaker(this, width, height, "drawing.mov",30, MovieMaker.H263, MovieMaker.HIGH);
ballNetwork = new ArrayList();
for (int i = 0; i < 150; i++){
Vec3D origin = new Vec3D(random(width),random(200),0);
ball myBall = new ball(origin);
ballNetwork.add(myBall);
}
}
void draw(){
background(#62AFFA);
mm.addFrame(pixels,width,height);
if(frameCount == 30*30){
for(int i = 0; i < ballNetwork.size(); i++) {
ball mb = (ball) ballNetwork.get(i);
mb.run();
}
}
}
void mousePressed() {
if(key==' ') {
mm.finishMovie();
exit();
}
}
class ball{
Vec3D loc = new Vec3D (0,0,0);
Vec3D speed = new Vec3D (random(-2,5), random(-2,5),0);
Vec3D acc = new Vec3D ();
ball(Vec3D _loc) {
loc = _loc;
}
void run(){
display();
move();
bounce();
lineBetween();
flock();
}
void flock(){
separate(4);
cohesion(0.001);
//align();
}
void cohesion(float magnitude){
Vec3D sum = new Vec3D();
int count = 0;
for (int i = 0; i < ballNetwork.size(); i++) {
ball other = (ball) ballNetwork.get(i);
float distance = loc.distanceTo(other.loc);
if (distance> 0 && distance < 60){
sum.addSelf(other.loc);
count++;
}
}
if (count > 0){
sum.scaleSelf(1.0/count);
}
Vec3D steer = sum.sub(loc);
steer.scaleSelf(magnitude);
acc.addSelf(steer);
}
void separate (float magnitude){
Vec3D steer = new Vec3D();
int count = 0;
for (int i = 0; i < ballNetwork.size(); i++) {
ball other = (ball) ballNetwork.get(i);
float distance = loc.distanceTo(other.loc);
if (distance> 0 && distance < 30){
Vec3D diff = loc.sub(other.loc);
diff. normalizeTo(1.0/distance);
steer.addSelf(diff);
count++;
}
}
if(count > 0){
steer.scaleSelf(1.0/count);
}
steer.scaleSelf(4);
acc.addSelf(steer);
}
void lineBetween(){
for (int i = 0; i < ballNetwork.size(); i++) {
ball other = (ball) ballNetwork.get(i);
float distance = loc.distanceTo(other.loc);
if (distance> 0 && distance < 90){
stroke(250);
strokeWeight(0.1);
line(loc.x,loc.y,other.loc.x,other.loc.y);
}
}
}
void move(){
speed.addSelf(acc);
speed.limit(2);
loc.addSelf(speed);
acc.clear();
}
void bounce() {
if(loc.x > width) {
speed.x = speed.x * -1;
}
if(loc.x < 0) {
speed.x = speed.x * -1;
}
if(loc.y > height) {
speed.y = speed.y * -1;
}
if(loc.y < 0) {
speed.y = speed.y * -1;
}
}
void display(){
fill(0);
stroke(0);
ellipse(loc.x,loc.y,2,2);
}
}
1