Project 05: Wallpaper

sketchDownload
 /*
Nicholas Wong
Section A
*/
var spacing = 6; //Spacing between waves
var offset; //Wave offset

function setup() {
    createCanvas(600,400);
    offset = 23;

}
 
function draw() 
{   

    background(20,10,15)
    //Star grid
    for (let x = 0; x <= width; x += 15) //Cols
    {
        for (let y = 0; y <= height / 2; y += 15) //Rows
        {   
            push();
            noStroke();
            fill(255)
            circle(x+(random(0,20)),y+(random(0,20)),random(0.5,1.5)) //Offsets each star X and Y by a random amount
            pop();
        }
    }

    //Wave generation
    for(let w = 0; w <= height; w += spacing) //Number of waves
    {       
        fill(0.75*w,0.15*w,0.25*w) //Color darkens with number of loops
            strokeWeight(0.25)
            stroke(w)
            wave(w, offset*w); //Offset of waves and wave pattern determined by number of loops
    }
    noLoop(); 

}
// Wave function
function wave(yOffset, offset)
{
    beginShape();
    for(let x = 0; x < width; x++)
    {
        let angle = offset + x *0.01;
        let y = map(sin(angle), -1, 1, 100, 200);
        vertex(x,y + yOffset);
    }
    vertex(width,height);
    vertex(0,height);
    endShape();

}

Leave a Reply