Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _____ _ _ _____ _ _ _____ _
- | __ (_) | |/ ____| | (_) / ____| | |
- | |__) |__ _____| | | | |__ _ _ __ | | ___ __| | ___
- | ___/ \ \/ / _ \ | | | '_ \| | '_ \| | / _ \ / _` |/ _ \
- | | | |> < __/ | |____| | | | | |_) | |___| (_) | (_| | __/
- |_| |_/_/\_\___|_|\_____|_| |_|_| .__/ \_____\___/ \__,_|\___|
- | |
- |_|
- // Define the vertices of the cube in 3D space
- cube_vertices = [
- // Each vertex is defined by its X, Y, and Z coordinates
- [-1, -1, -1], // Vertex 0: back-bottom-left
- [ 1, -1, -1], // Vertex 1: back-bottom-right
- [ 1, 1, -1], // Vertex 2: back-top-right
- [-1, 1, -1], // Vertex 3: back-top-left
- [-1, -1, 1], // Vertex 4: front-bottom-left
- [ 1, -1, 1], // Vertex 5: front-bottom-right
- [ 1, 1, 1], // Vertex 6: front-top-right
- [-1, 1, 1] // Vertex 7: front-top-left
- ];
- // Define the edges of the cube by specifying pairs of connected vertices
- cube_edges = [
- [0, 1], [1, 2], [2, 3], [3, 0], // Back face edges: connecting vertices of the back face
- [4, 5], [5, 6], [6, 7], [7, 4], // Front face edges: connecting vertices of the front face
- [0, 4], [1, 5], [2, 6], [3, 7] // Connecting edges between front and back faces
- ];
- // Initialize the rotation angles for X and Y axes (in degrees)
- rotation_angle_x = 0; // Angle of rotation around the X-axis
- rotation_angle_y = 0; // Angle of rotation around the Y-axis
- // Set the color for drawing the cube
- draw_set_color(c_white); // Set the drawing color to white for visibility
- // Clear the canvas with a background color
- draw_clear_alpha(c_black, 1); // Clear the canvas with a black color (full opacity)
- // Define the center of the canvas (where the cube will be centered)
- var center_x = 32; // X-coordinate of the center (assuming a 64x64 canvas size)
- var center_y = 32; // Y-coordinate of the center
- // Define the rotation speed for X and Y axes
- var rotation_speed_x = 1.03; // Speed at which the cube rotates around the X-axis
- var rotation_speed_y = 1.05; // Speed at which the cube rotates around the Y-axis
- // Update the rotation angles by adding the speed to create continuous rotation
- rotation_angle_x += rotation_speed_x; // Increase the rotation angle for X
- rotation_angle_y += rotation_speed_y; // Increase the rotation angle for Y
- // Precalculate the sine and cosine values for both rotation angles to improve performance
- var cos_x = dcos(rotation_angle_x); // Cosine of the rotation angle around X
- var sin_x = dsin(rotation_angle_x); // Sine of the rotation angle around X
- var cos_y = dcos(rotation_angle_y); // Cosine of the rotation angle around Y
- var sin_y = dsin(rotation_angle_y); // Sine of the rotation angle around Y
- // Loop through each edge of the cube to draw them
- for (var i = 0; i < array_length(cube_edges); i++) {
- // Get the starting and ending vertex indices for the current edge
- var start_idx = cube_edges[i][0]; // Index of the start vertex for this edge
- var end_idx = cube_edges[i][1]; // Index of the end vertex for this edge
- // Retrieve the coordinates of the start and end vertices
- var start_vertex = cube_vertices[start_idx]; // Coordinates of the start vertex
- var end_vertex = cube_vertices[end_idx]; // Coordinates of the end vertex
- // Rotate the start vertex around the Y axis
- var start_x_y = start_vertex[0] * cos_y - start_vertex[2] * sin_y; // X coordinate after Y rotation
- var start_z_y = start_vertex[0] * sin_y + start_vertex[2] * cos_y; // Z coordinate after Y rotation
- // Rotate the end vertex around the Y axis
- var end_x_y = end_vertex[0] * cos_y - end_vertex[2] * sin_y; // X coordinate after Y rotation
- var end_z_y = end_vertex[0] * sin_y + end_vertex[2] * cos_y; // Z coordinate after Y rotation
- // Rotate the start vertex around the X axis
- var start_y = start_vertex[1] * cos_x - start_z_y * sin_x; // Y coordinate after X rotation
- var start_z = start_vertex[1] * sin_x + start_z_y * cos_x; // Z coordinate after X rotation
- // Rotate the end vertex around the X axis
- var end_y = end_vertex[1] * cos_x - end_z_y * sin_x; // Y coordinate after X rotation
- var end_z = end_vertex[1] * sin_x + end_z_y * cos_x; // Z coordinate after X rotation
- // Project the 3D coordinates to 2D space using a simple orthographic projection
- var projected_start_x = center_x + start_x_y * 16; // Projected X coordinate of start vertex, scaled by 16
- var projected_start_y = center_y + start_y * 16; // Projected Y coordinate of start vertex, scaled by 16
- var projected_end_x = center_x + end_x_y * 16; // Projected X coordinate of end vertex, scaled by 16
- var projected_end_y = center_y + end_y * 16; // Projected Y coordinate of end vertex, scaled by 16
- // Draw a line between the projected start and end points
- draw_line(projected_start_x, projected_start_y, projected_end_x, projected_end_y);
- }
Advertisement
Add Comment
Please, Sign In to add comment