Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int i, col, unit, radius, np, num=7;
- float r1, r2, t;
- Star[] stars = new Star[num*num];
- color[] palette = {
- #490A3D, #BD1550, #E97F02, #F8CA00, #8A9B0F
- }
- ;
- void setup() {
- size(500, 500, P3D);
- unit = width/(num+2);
- radius = unit/2;
- noStroke();
- for (int y=unit+unit/2; y<height-unit; y += unit) {
- for (int x=unit+unit/2; x<width-unit; x += unit) {
- r1 = random(radius*.25, radius*.65) ;
- r2 = random(radius*.75, radius*.90);
- np = (int) random(5, 10);
- col = (int) random(0, 5);
- stars[i]= new Star(x, y, r1, r2, np, col, t);
- i++;
- t += (TWO_PI/(num*num));
- }
- }
- }
- void draw() {
- background(20);
- for (int j=0; j<stars.length; j++) {
- stars[j].display();
- }
- if (frameCount%4==0 && frameCount<241) saveFrame("image-###.gif");
- }
- class Star {
- float x, y, radius1, radius2, angle, halfAngle, theta;
- int npoints, col;
- Star(float _x, float _y, float _radius1, float _radius2, int _npoints, int _col, float _theta) {
- x = _x;
- y = _y;
- radius1 = _radius1;
- radius2 = _radius2;
- npoints = _npoints;
- col = _col;
- angle = TWO_PI / npoints;
- halfAngle = angle/2.0;
- theta = _theta;
- //theta = random(TWO_PI);
- }
- void display() {
- fill(palette[col]);
- pushMatrix();
- translate(x,y);
- rotateY(theta);
- rotateZ(theta/2);
- beginShape();
- for (float a = 0; a < TWO_PI; a += angle) {
- float sx = cos(a) * radius2;
- float sy = sin(a) * radius2;
- float sz = map(sin(theta),-1,1,0,20);
- //float sz = 0;
- vertex(sx, sy,sz);
- sx = cos(a+halfAngle) * radius1;
- sy = sin(a+halfAngle) * radius1;
- vertex(sx, sy,sz);
- }
- endShape(CLOSE);
- popMatrix();
- theta += 0.0523;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement