Skip to content

Instantly share code, notes, and snippets.

@pandr
Created November 9, 2017 06:45
Show Gist options
  • Save pandr/21ce81d39bf2c552b0e24c80816fdf9b to your computer and use it in GitHub Desktop.
Save pandr/21ce81d39bf2c552b0e24c80816fdf9b to your computer and use it in GitHub Desktop.
function setup()
{
createCanvas(700, 500);
background(220);
strokeWeight(10);
}
function transform(shape, angle, factor)
{
shape.x += shape.size * Math.cos(shape.angle);
shape.y += shape.size * Math.sin(shape.angle);
shape.angle += angle;
shape.size *= factor;
}
var angle1 = Math.random();
var angle2 = -Math.random();
var factor1 = 0.3 * Math.random() + 0.55;
var factor2 = 0.3 * Math.random() + 0.55;
function draw()
{
var shape = { x:350, y:400, angle:-Math.PI/2, size:80 };
for (var i = 0; i < 12; ++i)
{
if (i < 11)
{
var x2 = shape.x + shape.size * Math.cos(shape.angle);
var y2 = shape.y + shape.size * Math.sin(shape.angle);
stroke(100,50,0);
strokeWeight(shape.size/10);
line(shape.x, shape.y, x2, y2);
}
else
{
stroke(0,150,0);
fill(0,255,0);
ellipse(shape.x,shape.y,shape.size);
}
if (Math.random() < 0.5)
{
transform(shape, angle1, factor1);
}
else
{
transform(shape, angle2, factor2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment