/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.qNuJZ9CZ9BK/rev.679
*
* authors:
* gregsaul
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
// Pressing Control-R will render this sketch.
int cellWidth = 45;
int cellHeight = 45;
void setup() { // this is run once.
// set the background color
background(255);
// specify canvas size
size(800, 600);
// smooth edges
smooth();
background(200,200,200);
for(int x = 0; x < width; x += cellWidth){
for(int y = 0; y < height; y += cellHeight){
fill(255);
noStroke();
rect(x+1,y+1,cellWidth-2,cellHeight -2);
Diatom d = new Diatom(x+(cellWidth/2),y+ (cellHeight/2));
d.setSize(cellWidth - 9);
d.render();
}
}
}
void draw() { // this is run repeatedly.
}
class Diatom{
float x = 0;
float y = 0;
float size = 10;
int points = 4;
Diatom(float x, float y){
this.x = x;
this.y = y;
this.points = random(2,10);
}
void setSize(float s){
this.size = s;
}
void render(){
strokeWeight(1);
stroke(100,100,100);
float px = 0;
float py = 0;
float len = this.size/2;
beginShape();
for(int i = 0; i <= this.points ; i++){
px = sin((TWO_PI/this.points) * i) * len;
py = cos((TWO_PI/this.points) * i) * len;
vertex(px+x, py+y);
}
endShape(CLOSE);
// ellipse(this.x,this.y,this.size,this.size);
}
}