//Thomas Wrabetz
//Section C
//twrabetz@andrew.cmu.edu
//Project-07
var CVAR = 45;
var prevX = 100;
var prevY = 100;
function cubic( x )
{
return ( x - mouseX / 25 ) * ( x + mouseY / 25 ) * ( x + ( mouseX - width / 2 ) / 25 + ( mouseY - height / 2 ) / 25);
}
function setup()
{
createCanvas( 480, 480 );
noStroke();
}
function draw()
{
if( prevX == mouseX & prevY == mouseY ) return;
background(220);
prevX = mouseX;
prevY = mouseY;
circX = width / 3 + mouseX / 3;
circY = height / 3 - mouseY / 5;
fill(255);
for( var i2 = 0; i2 < 480; i2 += random(10,14) )
{
i = i2;
for( var j = 0; j < 480; j += random(10,14) )
{
if( j < (height / 2) - cubic( (i - 240)/10 ) / 100 ) fill( random(0,CVAR), 100 + random(0,CVAR), 175 + random(0,CVAR) );
else fill( random(0,CVAR), 150 + random(0,CVAR), random(0,CVAR) );
if( ( j - circY ) * ( j - circY ) + ( i - circX ) * ( i - circX ) < 1250 ) fill( 175 + random( 0, CVAR ), 175 + random( 0, CVAR ), random(0, CVAR) );
ellipse( i, j, 18, 21 );
i = random( i2-2, i2+2 );
}
}
}
I used a cubic function to make a hill. The sun is also there.
I used a grid of points with small random offsets and determined their color based on their relation to the equation; their color also varies slightly to create a pointillism-like effect.