0% found this document useful (0 votes)
9 views2 pages

Procedure Name - drawRandomColors

The document contains two JavaScript functions: drawRandomColors and drawDiceRolls. The first function draws 10 squares of random colors on the screen, while the second function simulates rolling 6 dice, displaying their values alongside the dice graphics. Both functions utilize a graphical interface to render their outputs.

Uploaded by

sekilel380
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Procedure Name - drawRandomColors

The document contains two JavaScript functions: drawRandomColors and drawDiceRolls. The first function draws 10 squares of random colors on the screen, while the second function simulates rolling 6 dice, displaying their values alongside the dice graphics. Both functions utilize a graphical interface to render their outputs.

Uploaded by

sekilel380
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

// Procedure Name: drawRandomColors

// Parameter: None
// Argument: N/A
// Return: Draws 10 random color squares on the screen

function drawRandomColors() {
for (var i = 0; i < 10; i++) { // Draw 10 squares
var x = i * 50; // X position for each square
var y = 100; // Y position (all squares in one row)
var size = 50; // Square size
var color = Randomizer.nextColor(); // Generate a random color

var square = new Rectangle(size, size); // Create square


square.setPosition(x, y);
square.setColor(color);
add(square); // Add square to canvas
}
}

// Call the function to display random colors


drawRandomColors();

function drawDiceRolls(numDice) {
for (var i = 0; i < numDice; i++) {
var roll = Randomizer.nextInt(1, 6); // Generate a number between 1 and 6
var x = i * 60 + 20; // X position for each die
var y = 50; // Y position for dice
var size = 50; // Size of dice

// Draw dice (square)


var dice = new Rectangle(size, size);
dice.setPosition(x, y);
dice.setColor(Color.WHITE);
dice.setBorderColor(Color.BLACK);
add(dice);
// Draw dice number (text)
var number = new Text(roll, "20px Arial");
number.setPosition(x + size / 3, y + size / 1.5);
add(number);
}
}

// Call the function to visually roll 6 dice


drawDiceRolls(6);

You might also like