M1D23 – ITP1 – Week 5

function setup() //if placed in setup, this doesn't do a loop
{
	createCanvas(512, 512);
        console.log(random()); //displays random number between 0 and 1 on the console log
    
        ellipse(width/2, height/2, random() * 250, random() * 250); //number between 0 and 1 multipled by 250 for the height and width of ellipse
}

function draw()
{

}

This code above creates an ellipse in random size and within the given conditions in every refresh- width/2, height/2, random() * 250, random() * 250

function setup() //if placed in setup, this doesn't do a loop
{
	createCanvas(512, 512);
    console.log(random()); //displays random number between 0 and 1 on the console log
}

function draw() //if placed in draw, the code within here creates a loop, creating different ellipses over and over
{
    background(255);
    ellipse(width/2, height/2, random() * 250, random() * 250); //number between 0 and 1 multipled by 250 for the height and width of ellipse
}

Code placed inside draw creates a loop. In this example code above, it creates the ellipses over and over in given conditions.

var r; //this creates a variable for random

function setup() //if placed in setup, this doesn't do a loop
{
	createCanvas(512, 512);
        console.log(random()); //displays random number between 0 and 1 on the console log
}

function draw() //if placed in draw, the code within here creates a loop, creating different ellipses over and over
{
        background(255);
        r = random() // this sets a single value for r to use in the code below
        ellipse(width/2, height/2, r * 250, r * 250); //single value of r multiplied by 250 for height and width of the ellipse, since its a single value it creates an ellipse with same size of height and width
}

In this code above, I set a single value for random() by creating a variable for r, setting it for the random() value, and using it in the conditions of the ellipse. This then creates ellipses with same height and width.

var r; //this creates a variable for random

function setup() //if placed in setup, this doesn't do a loop
{
	createCanvas(512, 512);
        console.log(random(50/*minimum*/, 250/*maximum*/)); //displays random number between 0 and 1 on the console log
}

function draw() //if placed in draw, the code within here creates a loop, creating different ellipses over and over
{
        background(255);
        r = random(50/*minimum*/, 250/*maximum*/) // this sets a single value for r to use in the code below
        ellipse(width/2, height/2, r/*remove this, because already set the min and max * 250*/, r/* * 250*/); //single value of r multiplied by 250 for height and width of the ellipse, since its a single value it creates an ellipse with same size of height and width
}

In this code above, I set a minimum value of 50 and maximum value of 250 for random function. Then I removed the *250 from the conditions of the ellipse, since I already set the min and max value, it will no longer use any numbers between 0 and 1.

min() function

min(0,1);

The min function always takes the smallest number from the set of numbers.

This entry was posted in Study Notes and tagged , , , . Bookmark the permalink.

Leave a Reply