Skip to content

Instantly share code, notes, and snippets.

@loadedsith
Created March 9, 2013 19:49
Show Gist options
  • Save loadedsith/5125485 to your computer and use it in GitHub Desktop.
Save loadedsith/5125485 to your computer and use it in GitHub Desktop.
A quick processing sketch demonstrating Perlin Noise and basic object oriented programming.
int starCount=0;
fallingStar[] stars;
int size = 10;
float seed = 0.0;
void setup() {
size(480, 480);
stars = new fallingStar[1];
stars[0] = new fallingStar(10,10);
noStroke();
}
void draw() {
background(0,0,0,.1);
for(fallingStar aStar : stars) {
// print(aStar);
aStar.update();
aStar.draw();
}
if (mousePressed) {
size =(int) (noise(seed)*100);
println( noise(seed)*100+", size: "+size);
seed +=.1;
stars= (fallingStar[] )append(stars, new fallingStar(mouseX,mouseY,size));
// stars[starCount++] = new fallingStar(mouseX, mouseY);
} else {
}
}
class fallingStar
{
int myX;
int myY;
int mySize;
int mx;
int my;
fallingStar(){
println("I'm a falling star named "+this);
};
fallingStar(int inX, int inY){
myX = inX;
myY = inY;
println("I'm a falling star named "+this+"located: x:"+myX+" y:"+myY+".");
ellipse(myX,myY,30,30);
}
fallingStar(int inX, int inY, int inSize){
myX = inX;
myY = inY;
mySize = inSize;
if(mySize<1){
mySize=10;
}
println("I'm a falling star named "+this+"located: x:"+myX+" y:"+myY+".");
println("mySize: "+mySize+".");
ellipse(myX,myY,mySize,mySize);
}
void draw(){
ellipse(myX,myY,mySize,mySize);
// println("drawing" + myX + ", " + myY);
}
void update(){
//println("updating" + myX + ", " + myY);
if(myY <= (height+50)){
myY++;
}else{
myY = -50;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment