Digital Scene- Final Group Project Code
Jack, Josh, Inal
//Executed Code
drawBackground("black");
drawAllStars(25);
drawAllPlanets(randomNumber(5, 10));
drawSun(randomNumber(20, 50), randomNumber(0, 320), randomNumber(0,450));
hide();
//Functions:
//Draw the background
function drawBackground (color) {
penColor(color);
dot(500);
}
function drawStar (size, sideLength, x, y){
//makes sure there's a 50/50 chance of a star being yellow or white
var randomNum = randomNumber(0, 1);
if (randomNum == 1){
penColor("white");
} else if (randomNum === 0){
penColor("#f6ff00");
}
penUp();
moveTo(x, y);
penWidth(size);
penDown();
//Draws the star
turnTo(0);
for (var i = 0; i < 5; i++){
moveForward(sideLength);
turnRight(144);
}
penUp();
}
//Draws a fixed number of stars
function drawAllStars(num){
for (var i = 0; i < num; i++){
drawStar(1, 10, randomNumber(0, 320), randomNumber(0,450));
}
}
//Function for drawing a planet
function drawPlanet(size, x, y){
penRGB(randomNumber(0,255), randomNumber(0,255), randomNumber(0,255), 1);
moveTo(x, y);
dot(size);
}
//Draws multiple planets
function drawAllPlanets(number){
for (var i = 0; i < number; i++) {
drawPlanet(randomNumber(10, 20), randomNumber(0, 320), randomNumber(0,450));
}
}
//Draws the Sun
function drawSun (size,x,y){
moveTo(x, y);
penColor("orange");
dot(size);
moveForward(size);
penDown();
penWidth(size/6);
// Arcs the turtle a certain amount around the Sun and draws the ray
for (var i = 0; i < 12; i++){
moveForward(size/1.7);
turnLeft();
turnLeft();
moveForward(size/1.7);
turnLeft();
turnLeft();
turnRight();
arcRight(30, size);
turnLeft();
}
}
Comments
Post a Comment