Create intricate designs by drawing shapes and rotating them in various directions using three.js

Imagine I have a box in Three.js that I want to draw incrementally in various directions. Currently, the line is drawn from left to right by simply incrementing the x value. Is there a way to rotate the rectangle so that it moves in different directions without changing the x increment in the update function?

It would be useful to have a method similar to "rotating the canvas".

Here is the code snippet on CodePen: https://codepen.io/haangglide/pen/vYGbQRm

Code:

var scene, camera, renderer, material, plane;

init();

function init() {
    scene = new THREE.Scene();
    camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
    camera.position.z = 100;

    renderer = new THREE.WebGLRenderer({ alpha: true, preserveDrawingBuffer: true });
    renderer.autoClearColor = false;

    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);

    scene = new THREE.Scene();

    window.addEventListener('resize', onResize, false);
    drawLines();

    update();
}

function drawLines() {
    var col = new THREE.Color(Math.random(), Math.random(), Math.random());
    material = new THREE.LineBasicMaterial({ color: col, linewidth: 5 })
    var geometry = new THREE.PlaneBufferGeometry(5, 20, 32);
    plane = new THREE.Mesh(geometry, material);
    scene.add(plane);
}

function update() {
    setTimeout(function () {
        requestAnimationFrame(update);
    }, 1000 / 60);

    plane.position.x += 1;
    if (plane.position.x > 50) drawLines()
    renderer.render(scene, camera);
}

function onResize() {
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();
    renderer.setSize(window.innerWidth, window.innerHeight);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Effective approach for incorporating external stylesheets and additional resources in Vue

When it comes to loading style sheets in Vue, what is considered the most effective method for placement? Should code or style sheets be loaded within the components that utilize them, or is it more favorable to load the resource in the parent page/contai ...

Ways to execute JavaScript code exclusively on a particular section of the DOM

Currently, I am enhancing a project by adding new features. However, I came across a situation where I need to import a different version of jQuery because a plugin requires that specific version. But there is another plugin in the project that relies on t ...

Having trouble implementing a multi-level sub menu in a popup menu in Vue.js?

data: { menuItems: [{ name: 'Item 1', children: [{ name: 'Subitem 1' }, { name: 'Subitem 2' }, { name: 'Subitem 3' }] }, { ...

Firefox fails to trigger HTML drag event

After successfully implementing draggable header columns on a table using Chrome as my browser, I encountered an issue when testing it in Firefox (version 17.0.1). It seems that the drag event does not fire in Firefox, although the dragstart event does. ...

Unveiling concealed data within ajax responses

On every cart change, I am attempting to reset my shipping estimator using ajax. The process works well across the entire page except for the shipping estimate section. Hidden values in use include: <input type="hidden" id="sendto" ...

Monitoring web traffic on an AJAX website using Google Analytics

Is it possible for Google Analytics to track pageviews if the URL of a page changes dynamically using Javascript? For instance, let's say I visit the page example.com/about(1 pageview) in my browser. Then, I click on the "contacts" link, but instead ...

Automatically adjusting tab heights with jQuery

Having an issue with the jQuery tabs on a school website project. Looking for some assistance with JavaScript. Check out the page here: 71.50.205.125/staugie.net/school/admin, it's my current work in progress. Created a user account with username "tes ...

Implementing a JavaScript polyfill on a webpage using Selenium and PhantomJS

There has been a lot of discussion surrounding the absence of a Function.prototype.bind method in PhantomJS, and many generous individuals have created shims/polyfills or directed others to those resources. I am currently integrating PhantomJS via Selenium ...

Updating the count property of an object using setState in React

I have an array of integers ranging from 0 to 6 as my input. My goal is to create an object that gives the count of each number in the array. edition = [6, 6, 6, 1, 1, 2]; const [groupedEdition, setGroupedEdition] = useState([{"0": 0, "1&quo ...

Standard Table within ngTable

I received the following HTML code with multiple columns trimmed: <table ng-table="NewIntroCtrl.tableParams" class="table table-striped table-bordered table-hover table-condensed" sortable="true"> <tr ng-repeat="pilot in $data"> ...

Reorganize the data in a different manner (collections of items instead of individual items linked to groups)

Is there a way to create a function that converts data from `DevicesType` to `GroupsType` below? Instead of having a list of devices showing the groups they belong to, I need a list of groups with their respective devices. type DevicesType = { id: string ...

Using a React component to trigger an action when the Enter key

I have a react component that needs to respond to the "Enter" key press event. class MyComponent extends Component { componentDidMount() { console.log('componentDidMount'); document.removeEventListener('keypress', t ...

Insert discover within the tube

Can I modify the following code to add a pipe before the subscribe method that performs the find operation, so that only one panel is returned by the subscription? await this.panelService.getActivePanels() .pipe( map(activePanels => active ...

Issue with Axios in my React Application: Unidentified SyntaxError

As I attempt to connect to my database using axios, a frustrating error appears in my vsCode terminal. The error message reads as follows: SyntaxError: C:\Users\Kelly Owoju\Desktop\Kelly Bright\my-web-app\node_modules\a ...

Vue warning: You are trying to access a property or method that is not defined on the instance but is being referenced during

The code snippet above was created to manage an event triggered by a button click var MainTable = Vue.extend({ template: "<ul>" + "<li v-for='(set,index) in settings'>" + "{{index}}) " + &qu ...

What is the best way to activate a Modal using JavaScript?

I am having trouble displaying a modal in my document when I click on an element. The default bootstrap 'data-toggle' and 'data-target' attributes work, but I cannot achieve the same effect using JavaScript. When I try to show the modal ...

Using a GET request in JavaScript to access a RESTful web service

I'm having trouble making a GET request to my web service. My web service is configured with x and y values, where x ranges from A-E and y ranges from 1-5. For example, let's say the values are set to C1. When I try to access the URL: x.x.x.x:x ...

HTML Action Identifier using the GET method

There is a possibility that this question may be a duplicate, but I am unable to locate the original. Within my form, there is an action: <form id="bug-form" action="/AST_14/Bugg.ly2/index.php/bug/update/" method="post"> The process in my system i ...

Show the value of a JavaScript object in VueJS

New to Vue and need some guidance... I'm having trouble accessing the values in a JS object displayed in the DevTools within one of my routes in a Vue app. Specifically, how can I display the values from filteredData:Array[1]? https://i.sstatic.net/ ...

Seeking assistance with downloading a collection of images as a zipped file using AngularJS

My code was previously working with jszip 2x but now I'm getting an error stating "This method has been removed in JSZip 3.0, please check the upgrade guide.". Even after following the upgrade guide, my code is still not functioning properly. I need a ...