Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dressers&Pans-Rushil Chopra #990

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions art/DressersandPans-RushilChopra/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
@title: DressersandPans
@author: Rushil Chopra
@snapshot: 0.png
*/

// Constants
const WIDTH = 50;
const HEIGHT = 50;
const DRAWER_WIDTH = 35;
const DRAWER_HEIGHT = 8;
const HANDLE_SIZE = 2;

// Set document dimensions
setDocDimensions(WIDTH, HEIGHT);

// Initialize shapes array
const shapes = [];

/**
* Creates the dresser base.
* @returns {bt.Turtle} The turtle object representing the dresser base.
*/
function createDresserBase() {
const t = new bt.Turtle();
t.forward(40);
t.right(90);
t.forward(30);
t.right(90);
t.forward(40);
t.right(90);
t.forward(30);
return t;
}

/**
* Creates a single tiny drawer with a handle.
* @param {number} index The index of the drawer.
* @returns {bt.Turtle} The turtle object representing the drawer.
*/
function createDrawer(index) {
const t = new bt.Turtle();
const handleType = Math.floor(Math.random() * 2);

// Create the drawer
t.forward(DRAWER_WIDTH);
t.right(90);
t.forward(DRAWER_HEIGHT);
t.right(90);
t.forward(DRAWER_WIDTH);
t.right(90);
t.forward(DRAWER_HEIGHT);

// Move to the handle position
t.left(90);
t.forward(DRAWER_WIDTH / 2 - HANDLE_SIZE / 2);
t.right(90);
t.forward(DRAWER_HEIGHT / 2 - HANDLE_SIZE / 2);

// Create the handle
if (handleType === 0) {
// Square handle
for (let i = 0; i < 4; i++) {
t.forward(HANDLE_SIZE);
t.right(90);
}
} else if (handleType === 1) {
// Triangular handle
for (let i = 0; i < 3; i++) {
t.forward(HANDLE_SIZE);
t.right(120);
}
}

return t;
}

/**
* Creates the tiny dresser with a specified number of tiny drawers.
* @param {number} numDrawers The number of drawers.
*/
function createDresser(numDrawers) {
const dresserBase = createDresserBase();
// Move the dresser base higher
bt.translate(dresserBase.path, [WIDTH / 2 - 20, HEIGHT / 2 + 10]);
bt.join(shapes, dresserBase.path);

for (let i = 0; i < numDrawers; i++) {
const drawer = createDrawer(i);
// Move each drawer higher
bt.translate(drawer.path, [WIDTH / 2 - DRAWER_WIDTH / 2, HEIGHT / 2 + 10 - (i * (DRAWER_HEIGHT + 2))]);
bt.join(shapes, drawer.path);
}
}

// Randomly choose between 1 and 4 drawers
const numDrawers = Math.floor(Math.random() * 4) + 1;
createDresser(numDrawers);

// Draw the shapes
drawLines(shapes);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading