Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Web программирование > HTML и CSS
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 20.11.2024, 13:29   #201
MakarovDs
Форумчанин
 
Аватар для MakarovDs
 
Регистрация: 10.01.2020
Сообщений: 344
По умолчанию

ВОТ! Теперь это идеальный лабиринт!
Код:
import numpy as np
import trimesh
import matplotlib.pyplot as plt
import os
import random

def start_point_generate(n, m):
    """Функция выбора точки начала лабиринта"""
    if random.choice([True, False]):
        if random.choice([True, False]):
            start = (0, random.randint(0, m - 1))
        else:
            start = (n - 1, random.randint(0, m - 1))
    else:
        if random.choice([True, False]):
            start = (random.randint(0, n - 1), 0)
        else:
            start = (random.randint(0, n - 1), m - 1)
    return start

def finish_point_generate(start, n, m):
    """Выбор точки конца лабиринта"""
    return n - 1 - start[0], m - 1 - start[1]

def transition_choice(x, y, rm):
    """Функция выбора дальнейшего пути в генерации лабиринта"""
    choice_list = []
    if x > 0:
        if not rm[x - 1][y]:
            choice_list.append((x - 1, y))
    if x < len(rm) - 1:
        if not rm[x + 1][y]:
            choice_list.append((x + 1, y))
    if y > 0:
        if not rm[x][y - 1]:
            choice_list.append((x, y - 1))
    if y < len(rm[0]) - 1:
        if not rm[x][y + 1]:
            choice_list.append((x, y + 1))
    if choice_list:
        nx, ny = random.choice(choice_list)
        if x == nx:
            if ny > y:
                tx, ty = x * 2, ny * 2 - 1
            else:
                tx, ty = x * 2, ny * 2 + 1
        else:
            if nx > x:
                tx, ty = nx * 2 - 1, y * 2
            else:
                tx, ty = nx * 2 + 1, y * 2
        return nx, ny, tx, ty
    else:
        return -1, -1, -1, -1

def create_labyrinth(n=5, m=5):
    """Генерация лабиринта"""
    reach_matrix = []
    for i in range(n):  # создаём матрицу достижимости ячеек
        reach_matrix.append([])
        for j in range(m):
            reach_matrix[i].append(False)
    transition_matrix = []
    for i in range(n * 2 - 1):  # заполнение матрицы переходов
        transition_matrix.append([])
        for j in range(m * 2 - 1):
            if i % 2 == 0 and j % 2 == 0:
                transition_matrix[i].append(True)
            else:
                transition_matrix[i].append(False)
    start = start_point_generate(n, m)
    finish = finish_point_generate(start, n, m)
    list_transition = [start]
    x, y = start
    reach_matrix[x][y] = True
    x, y, tx, ty = transition_choice(x, y, reach_matrix)
    for i in range(1, m * n):
        while not (x >= 0 and y >= 0):
            x, y = list_transition[-1]
            list_transition.pop()
            x, y, tx, ty = transition_choice(x, y, reach_matrix)
        reach_matrix[x][y] = True
        list_transition.append((x, y))
        transition_matrix[tx][ty] = True
        x, y, tx, ty = transition_choice(x, y, reach_matrix)
    return transition_matrix, start, finish  # возвращаем матрицу проходов и начальную точку

def generate_labyrinth(width, height, depth, labyrinth_matrix):
    # Добавляем стены по лабиринту
    cell_width = 10
    labyrinth_height = height - 10
    labyrinth_depth = depth - 10
    labyrinth_width = width - 10
    vertices = []
    faces = []
    for i in range(len(labyrinth_matrix)):
        for j in range(len(labyrinth_matrix[i])):
            if not labyrinth_matrix[i][j]:
                # Если это стена, то добавляем ее в список вершин и граней
                x = 5 + j * cell_width
                y = labyrinth_height / 2
                z = 5 + i * cell_width
                cube_verts = np.array([
                    [x - cell_width / 2, y - cell_width / 2, z - cell_width / 2],
                    [x + cell_width / 2, y - cell_width / 2, z - cell_width / 2],
                    [x + cell_width / 2, y + cell_width / 2, z - cell_width / 2],
                    [x - cell_width / 2, y + cell_width / 2, z - cell_width / 2],
                    [x - cell_width / 2, y - cell_width / 2, z + cell_width / 2],
                    [x + cell_width / 2, y - cell_width / 2, z + cell_width / 2],
                    [x + cell_width / 2, y + cell_width / 2, z + cell_width / 2],
                    [x - cell_width / 2, y + cell_width / 2, z + cell_width / 2]
                ])
                cube_faces = np.array([
                    [0, 1, 2],
                    [0, 2, 3],
                    [4, 5, 6],
                    [4, 6, 7],
                    [0, 1, 5],
                    [0, 5, 4],
                    [1, 2, 6],
                    [1, 6, 5],
                    [2, 3, 7],
                    [2, 7, 6],
                    [3, 0, 4],
                    [3, 4, 7]
                ])
                vertices.extend(cube_verts)
                faces.extend(cube_faces + len(vertices) - len(cube_verts))
    mesh = trimesh.Trimesh(vertices=np.array(vertices), faces=np.array(faces))
    mesh.remove_duplicate_faces()
    mesh.remove_degenerate_faces()
    mesh.remove_unreferenced_vertices()
    return mesh

matrix, start, finish = create_labyrinth(10, 10)
labyrinth = generate_labyrinth(100, 50, 100, matrix)

# Сохранение изосурфейса в OBJ файл
filename = os.path.join(os.path.expanduser("~"), "Desktop", "labyrinth.obj")
labyrinth.export(filename)
print(f"Model saved as {filename}")

# Визуализация
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.add_collection3d(labyrinth)
ax.set_xlim(0, 100)
ax.set_ylim(0, 50)
ax.set_zlim(0, 100)
plt.show()

Последний раз редактировалось MakarovDs; 20.11.2024 в 13:32.
MakarovDs на форуме Ответить с цитированием
Старый 20.11.2024, 19:06   #202
MakarovDs
Форумчанин
 
Аватар для MakarovDs
 
Регистрация: 10.01.2020
Сообщений: 344
По умолчанию

Идеальная колонность!
Код:
import numpy as np
import trimesh
import matplotlib.pyplot as plt
import os

def generate_room_with_holes(width, height, depth, num_holes):
    # Определите вершины комнаты
    vertices = [
        [0, 0, 0],
        [width, 0, 0],
        [width, 0, depth],
        [0, 0, depth],
        [0, height, 0],
        [width, height, 0],
        [width, height, depth],
        [0, height, depth]
    ]

    # Определите грани комнаты
    faces = [
        [0, 1, 2],
        [0, 2, 3],
        [4, 5, 6],
        [4, 6, 7],
        [0, 1, 5],
        [0, 5, 4],
        [1, 2, 6],
        [1, 6, 5],
        [2, 3, 7],
        [2, 7, 6],
        [3, 0, 4],
        [3, 4, 7]
    ]

    # Генерируем продольные стены
    for x in range(0, width, 10):
        for z in range(0, depth, 10):
            wall_verts = np.array([
                [x, 0, z],
                [x + 2, 0, z],
                [x + 2, height, z],
                [x, height, z],
                [x, 0, z + 2],
                [x + 2, 0, z + 2],
                [x + 2, height, z + 2],
                [x, height, z + 2]
            ])
            wall_faces = np.array([
                [0, 1, 2],
                [0, 2, 3],
                [4, 5, 6],
                [4, 6, 7],
                [0, 1, 5],
                [0, 5, 4],
                [1, 2, 6],
                [1, 6, 5],
                [2, 3, 7],
                [2, 7, 6],
                [3, 0, 4],
                [3, 4, 7]
            ])
            vertices.extend(wall_verts.tolist())
            faces.extend(wall_faces + len(vertices) - 8)

    mesh = trimesh.Trimesh(vertices=np.array(vertices), faces=np.array(faces))
    return mesh

# Генерация комнаты с дырками
room = generate_room_with_holes(100, 10, 100, 100)

# Сохранение изосурфейса в OBJ файл
desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")
filename = os.path.join(desktop_path, "room_with_holes.obj")
room.export(filename)
print(f"Model saved as {filename}")

# Визуализация
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.add_collection3d(room)
ax.set_xlim(0, 100)
ax.set_ylim(0, 100)
ax.set_zlim(0, 10)
plt.show()
MakarovDs на форуме Ответить с цитированием
Старый 21.11.2024, 09:49   #203
MakarovDs
Форумчанин
 
Аватар для MakarovDs
 
Регистрация: 10.01.2020
Сообщений: 344
По умолчанию

Чисто пустая комната для экспериментов
Код:
import numpy as np
import trimesh
import matplotlib.pyplot as plt
import os

def generate_room_with_holes(width, height, depth, num_holes):
    # Определите вершины комнаты
    vertices = [
        [0, 0, 0],
        [width, 0, 0],
        [width, 0, depth],
        [0, 0, depth],
        [0, height, 0],
        [width, height, 0],
        [width, height, depth],
        [0, height, depth]
    ]

    # Определите грани комнаты
    faces = [
        [0, 1, 2],
        [0, 2, 3],
        [4, 5, 6],
        [4, 6, 7],
        [0, 1, 5],
        [0, 5, 4],
        [1, 2, 6],
        [1, 6, 5],
        [2, 3, 7],
        [2, 7, 6],
        [3, 0, 4],
        [3, 4, 7]
    ]

    mesh = trimesh.Trimesh(vertices=np.array(vertices), faces=np.array(faces))
    return mesh

# Генерация комнаты с дырками
room = generate_room_with_holes(100, 10, 100, 100)

# Сохранение изосурфейса в OBJ файл
desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")
filename = os.path.join(desktop_path, "room_with_holes.obj")
room.export(filename)
print(f"Model saved as {filename}")

# Визуализация
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.add_collection3d(room)
ax.set_xlim(0, 100)
ax.set_ylim(0, 100)
ax.set_zlim(0, 10)
plt.show()

Последний раз редактировалось MakarovDs; 21.11.2024 в 09:53.
MakarovDs на форуме Ответить с цитированием
Старый 21.11.2024, 13:20   #204
MakarovDs
Форумчанин
 
Аватар для MakarovDs
 
Регистрация: 10.01.2020
Сообщений: 344
По умолчанию

Бэкрумс но эти коридоры пологие в разные стороны
Код:
import numpy as np
import trimesh
import matplotlib.pyplot as plt
import os

# Функция для генерации 3D-поля с ровными коридорами
def generate_corridors(room_width, room_height, room_depth):
    points = []
    for _ in range(10):
        x = np.random.randint(10, room_width - 10)
        y = np.random.randint(10, room_height - 10)
        points.append([x, y])

    vertices = []
    faces = []

    for i in range(len(points) - 1):
        dx = points[i+1][0] - points[i][0]
        dy = points[i+1][1] - points[i][1]
        length = max(abs(dx), abs(dy))

        if abs(dx) > abs(dy):
            # Учитываем размеры комнаты
            x1 = max(0, points[i][0])
            x2 = min(room_width, points[i][0] + length)
            y1 = max(0, points[i][1])
            y2 = min(room_height, points[i][1] + 2)

            # Создаем коридор от потолка до пола
            z1 = 0
            z2 = room_depth

            vertices.extend([
                [x1, y1, z1],
                [x2, y1, z1],
                [x2, y2, z1],
                [x1, y2, z1],
                [x1, y1, z2],
                [x2, y1, z2],
                [x2, y2, z2],
                [x1, y2, z2]
            ])
            faces.extend([
                [i*8, i*8+1, i*8+2, i*8+3],
                [i*8+4, i*8+5, i*8+6, i*8+7],
                [i*8, i*8+1, i*8+5, i*8+4],
                [i*8+1, i*8+2, i*8+6, i*8+5],
                [i*8+2, i*8+3, i*8+7, i*8+6],
                [i*8+3, i*8, i*8+4, i*8+7]
            ])
        else:
            # Учитываем размеры комнаты
            x1 = max(0, points[i][0])
            x2 = min(room_width, points[i][0] + 2)
            y1 = max(0, points[i][1])
            y2 = min(room_height, points[i][1] + length)

            # Создаем коридор от потолка до пола
            z1 = 0
            z2 = room_depth

            vertices.extend([
                [x1, y1, z1],
                [x2, y1, z1],
                [x2, y2, z1],
                [x1, y2, z1],
                [x1, y1, z2],
                [x2, y1, z2],
                [x2, y2, z2],
                [x1, y2, z2]
            ])
            faces.extend([
                [i*8, i*8+1, i*8+2, i*8+3],
                [i*8+4, i*8+5, i*8+6, i*8+7],
                [i*8, i*8+1, i*8+5, i*8+4],
                [i*8+1, i*8+2, i*8+6, i*8+5],
                [i*8+2, i*8+3, i*8+7, i*8+6],
                [i*8+3, i*8, i*8+4, i*8+7]
            ])

    mesh = trimesh.Trimesh(vertices=np.array(vertices), faces=np.array(faces))
    return mesh

# Функция для генерации комнаты с дырками
def generate_room_with_holes(width, height, depth, num_holes):
    # Определите вершины комнаты
    vertices = [
        [0, 0, 0],
        [width, 0, 0],
        [width, 0, depth],
        [0, 0, depth],
        [0, height, 0],
        [width, height, 0],
        [width, height, depth],
        [0, height, depth]
    ]

    # Определите грани комнаты
    faces = [
        [0, 1, 2],
        [0, 2, 3],
        [4, 5, 6],
        [4, 6, 7],
        [0, 1, 5],
        [0, 5, 4],
        [1, 2, 6],
        [1, 6, 5],
        [2, 3, 7],
        [2, 7, 6],
        [3, 0, 4],
        [3, 4, 7]
    ]

    mesh = trimesh.Trimesh(vertices=np.array(vertices), faces=np.array(faces))
    return mesh

# Генерация 3D-поля с коридорами
corridors = generate_corridors(100, 100, 10)

# Генерация комнаты с дырками
room = generate_room_with_holes(100, 100, 10, 100)

# Объединение мешей
combined_mesh = trimesh.util.concatenate([corridors, room])

# Сохранение объединенного меша в OBJ файл
desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")
filename = os.path.join(desktop_path, "combined.obj")
combined_mesh.export(filename)
print(f"Model saved as {filename}")

# Визуализация
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.add_collection3d(combined_mesh)
ax.set_xlim(0, 100)
ax.set_ylim(0, 100)
ax.set_zlim(0, 10)
plt.show()
MakarovDs на форуме Ответить с цитированием
Старый 21.11.2024, 18:04   #205
MakarovDs
Форумчанин
 
Аватар для MakarovDs
 
Регистрация: 10.01.2020
Сообщений: 344
По умолчанию

Сломанный pitfalls
Код:
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
import numpy as np
import noise
import os

pygame.init()
display=(800,600)
pygame.display.set_mode(display, DOUBLEBUF | OPENGL)

gluPerspective(45,(display[0]/display[1]),0.1,100.0)
glTranslatef(0.0,0.0,-30)

glRotatef(45,1,0,0)

def generate_noise_2d(shape,x_offset,z_offset,scale=100.0,octaves=6,persistence=0.5,lacunarity=2.0):
    noise_map = np.zeros(shape)
    for i in range(shape[0]):
        for j in range(shape[1]):
            noise_map[i][j] = noise.pnoise2((i + x_offset) / scale,(j + z_offset) / scale,octaves=octaves, persistence=persistence,lacunarity=lacunarity,repeatx=1024,repeaty=1024,base=42)
    return noise_map

def create_terrain(width, height, x_offset, z_offset):
    noise_map=generate_noise_2d((width, height),x_offset,z_offset)
    vertices=[]
    for i in range(width):
        for j in range(height):
            x =i-width // 2
            z =j-height // 2
            y =noise_map[i][j] * 10
            vertices.append((x, y, z))
    return vertices

def create_tube(vertices, radius, slices):
    tube_vertices=[]
    tube_faces=[]

    for i in range(len(vertices)-1):
        v1=np.array(vertices[i])
        v2=np.array(vertices[i+1])

        direction=v2-v1
        length=np.linalg.norm(direction)
        direction /= length

        if np.linalg.norm(direction) == 0:
            continue
        perpendicular = np.cross(direction, np.array([0,1,0]))
        if np.linalg.norm(perpendicular) == 0:
            perpendicular = np.cross(direction, np.array([1,0,0]))

        perpendicular /= np.linalg.norm(perpendicular)

        for j in range(slices+1):
            angle=2* np.pi * j / slices
            offset=radius * (np.cos(angle) * perpendicular + np.sin(angle) * np.cross(direction, perpendicular))
            current_vertex=v1+offset

            tube_vertices.append(current_vertex)

            if i < len(vertices)-2:
                next_index=(i+1) * (slices+1)+j
                current_index =i * (slices+1)+j
                next_j =(j+1) % (slices+1)

                tube_faces.append([current_index, next_index, next_index+1])
                tube_faces.append([current_index, next_index+1, current_index+1])

    return tube_vertices,tube_faces

def save_to_obj(vertices,width,height,radius,slices,filename):
    tube_vertices = []
    tube_faces = []

    for i in range(width):
        for j in range(height-1):
            v1 = np.array(vertices[i * height+j])
            v2 = np.array(vertices[i * height+j + 1])

            direction=v2-v1
            length=np.linalg.norm(direction)
            direction /= length

            perpendicular = np.cross(direction, np.array([1, 0, 0]))
            if np.linalg.norm(perpendicular) == 0:
                continue
            perpendicular /= np.linalg.norm(perpendicular)

            for k in range(slices + 1):
                angle= 2 * np.pi * k / slices
                offset=radius * (np.cos(angle) * perpendicular + np.sin(angle) * np.cross(direction, perpendicular))

                tube_vertices.append(v1+offset)
                tube_vertices.append(v2+offset)

                if k < slices:
                    tube_faces.append([len(tube_vertices)-2,len(tube_vertices)-1,len(tube_vertices)-1+slices+ 1])
                    tube_faces.append([len(tube_vertices)-2,len(tube_vertices)-1+slices+1, len(tube_vertices)-2+slices+1])

    for j in range(height):
        for i in range(width-1):
            v1=np.array(vertices[j+i * height])
            v2=np.array(vertices[j+(i+1) * height])

            direction=v2-v1
            length=np.linalg.norm(direction)
            direction /= length

            perpendicular=np.cross(direction, np.array([0, 1, 0]))
            if np.linalg.norm(perpendicular) == 0:
                continue
            perpendicular /= np.linalg.norm(perpendicular)

            for k in range(slices + 1):
                angle = 2 * np.pi * k / slices
                offset = radius * (np.cos(angle) * perpendicular + np.sin(angle) * np.cross(direction, perpendicular))

                tube_vertices.append(v1+offset) 
                tube_vertices.append(v2+offset) 

                if k < slices:
                    tube_faces.append([len(tube_vertices)-2, len(tube_vertices)-1,len(tube_vertices)-1+slices + 1])
                    tube_faces.append([len(tube_vertices)-2,len(tube_vertices)-1+slices+1, len(tube_vertices) - 2 + slices + 1])

    with open(filename, "w") as f:
        for vertex in tube_vertices:
            f.write(f"v {vertex[0]:.4f} {vertex[1]:.4f} {vertex[2]:.4f}\n")
        for face in tube_faces:
            f.write(f"f {face[0] + 1} {face[1]+1} {face[2]+1}\n")
    print(f"Model saved as {filename}")

def draw_tube(vertices, width, height, radius, slices):
    for i in range(width):
        for j in range(height-1):
            v1=np.array(vertices[i * height+j])
            v2=np.array(vertices[i * height+j+1])

            direction=v2-v1
            length=np.linalg.norm(direction)
            direction /= length

            perpendicular=np.cross(direction, np.array([1, 0, 0]))
            if np.linalg.norm(perpendicular) == 0:
                continue
            perpendicular /= np.linalg.norm(perpendicular)

            glBegin(GL_QUAD_STRIP)
            for k in range(slices + 1):
                angle=2 * np.pi * k / slices
                offset=radius * (np.cos(angle) * perpendicular + np.sin(angle) * np.cross(direction, perpendicular))

                glVertex3fv(v1+offset)
                glVertex3fv(v2+offset)
            glEnd()

    for j in range(height):
        for i in range(width-1):
            v1 = np.array(vertices[j+i * height])
            v2 = np.array(vertices[j+(i+1) * height])

            direction=v2-v1
            length=np.linalg.norm(direction)
            direction /= length

            perpendicular=np.cross(direction, np.array([0,1,0]))
            if np.linalg.norm(perpendicular) == 0:
                continue
            perpendicular /= np.linalg.norm(perpendicular)

            glBegin(GL_QUAD_STRIP)
            for k in range(slices + 1):
                angle=2 * np.pi * k / slices
                offset=radius * (np.cos(angle) * perpendicular + np.sin(angle) * np.cross(direction, perpendicular))

                glVertex3fv(v1+offset)
                glVertex3fv(v2+offset)
            glEnd()

width,height=20,20
x_offset=0
z_offset=0
clock=pygame.time.Clock()
tube_radius=0.25
slices=10

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_w:
                z_offset += 5
            if event.key == pygame.K_s:
                z_offset -= 5
            if event.key == pygame.K_a:
                x_offset -= 5
            if event.key == pygame.K_d:
                x_offset += 5
            if event.key == pygame.K_r:
                desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")
                vertices = create_terrain(width, height, x_offset, z_offset)
                filename = os.path.join(desktop_path, "terrain_tube.obj")
                save_to_obj(vertices, width, height, tube_radius, slices, filename)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    vertices = create_terrain(width, height, x_offset, z_offset)
    tube_vertices, _ =create_tube(vertices, tube_radius, slices)  
    draw_tube(vertices, width, height, radius=tube_radius, slices=slices)  
    pygame.display.flip()
    clock.tick(60)
MakarovDs на форуме Ответить с цитированием
Старый 23.11.2024, 12:32   #206
MakarovDs
Форумчанин
 
Аватар для MakarovDs
 
Регистрация: 10.01.2020
Сообщений: 344
По умолчанию

Идеальная сфера
Код:
import numpy as np
from scipy import ndimage
from skimage import measure
import os

# Генерация синтвейв-шума
def generate_syntwave_noise(shape, scale=100.0, octaves=6, persistence=0.5, lacunarity=2.0):
    noise_map = np.zeros(shape)
    for i in range(shape[0]):
        for j in range(shape[1]):
            for k in range(shape[2]):
                x = i - shape[0] // 2
                y = j - shape[1] // 2
                z = k - shape[2] // 2
                r = np.sqrt(x ** 2 + y ** 2 + z ** 2)
                noise_map[i, j, k] = np.sin(r / scale)
    return noise_map

# Основной цикл
shape = (128, 128, 128)  # Размеры 3D массива
syntwave_noise = generate_syntwave_noise(shape)

# Создание изосурфейса
verts, faces, _, _ = measure.marching_cubes(syntwave_noise, level=0.5)

# Сохранение изосурфейса в OBJ файл
desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")
filename = os.path.join(desktop_path, "syntwave.obj")
with open(filename, "w") as f:
    for j, vert in enumerate(verts):
        f.write(f"v {vert[0]:.4f} {vert[1]:.4f} {vert[2]:.4f}\n")
    for face in faces:
        f.write(f"f {face[0] + 1} {face[1] + 1} {face[2] + 1}\n")
print(f"Model saved as {filename}")
MakarovDs на форуме Ответить с цитированием
Старый 23.11.2024, 12:45   #207
MakarovDs
Форумчанин
 
Аватар для MakarovDs
 
Регистрация: 10.01.2020
Сообщений: 344
По умолчанию

Гиперкуб залы будущего
Код:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from skimage import measure
from scipy.spatial import Delaunay
import os

def generate_delaunay_field(shape, num_cubes, distance):
    array = np.zeros(shape, dtype=float)

    points = []
    for i in range(num_cubes):
        x = (i % 4) * distance + distance // 2
        y = ((i // 4) % 4) * distance + distance // 2
        z = (i // 16) * distance + distance // 2
        if x < shape[0] and y < shape[1] and z < shape[2]:
            points.append([x, y, z]) 
            generate_sphere(array, (x, y, z), 5)

    for point in points:
        x, y, z = point
        for i in range(-1, 2):
            for j in range(-1, 2):
                for k in range(-1, 2):
                    new_x, new_y, new_z = x + i * distance, y + j * distance, z + k * distance
                    if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                        generate_sphere(array, (new_x, new_y, new_z), 5)

    for i in range(len(points)):
        x, y, z = points[i]
        for j in range(shape[0]):
            new_x = j
            new_y = y
            new_z = z
            if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                for k in range(-2, 3):
                    for l in range(-2, 3):
                        for m in range(-2, 3):
                            x1, y1, z1 = new_x + k, new_y + l, new_z + m
                            if 0 <= x1 < shape[0] and 0 <= y1 < shape[1] and 0 <= z1 < shape[2]:
                                array[x1, y1, z1] = 1.0
        for j in range(shape[1]):
            new_x = x
            new_y = j
            new_z = z
            if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                for k in range(-2, 3):
                    for l in range(-2, 3):
                        for m in range(-2, 3):
                            x1, y1, z1 = new_x + k, new_y + l, new_z + m
                            if 0 <= x1 < shape[0] and 0 <= y1 < shape[1] and 0 <= z1 < shape[2]:
                                array[x1, y1, z1] = 1.0
        for j in range(shape[2]):
            new_x = x
            new_y = y
            new_z = j
            if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                for k in range(-2, 3):
                    for l in range(-2, 3):
                        for m in range(-2, 3):
                            x1, y1, z1 = new_x + k, new_y + l, new_z + m
                            if 0 <= x1 < shape[0] and 0 <= y1 < shape[1] and 0 <= z1 < shape[2]:
                                array[x1, y1, z1] = 1.0

    for i in range(len(points) - 1):
        dx = points[i+1][0] - points[i][0]
        dy = points[i+1][1] - points[i][1]
        dz = points[i+1][2] - points[i][2]
        length = max(abs(dx), abs(dy), abs(dz))

        if abs(dx) > abs(dy) and abs(dx) > abs(dz):
            for j in range(abs(dx)):
                new_x = int(points[i][0] + j * np.sign(dx))
                new_y = points[i][1]
                new_z = points[i][2]
                if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                    for k in range(-2, 3):
                        for l in range(-2, 3):
                            for m in range(-2, 3):
                                x1, y1, z1 = new_x + k, new_y + l, new_z + m
                                if 0 <= x1 < shape[0] and 0 <= y1 < shape[1] and 0 <= z1 < shape[2]:
                                    array[x1, y1, z1] = 1.0
            for j in range(abs(dz)):
                new_x = new_x
                new_y = new_y
                new_z = int(points[i][2] + j * np.sign(dz))
                if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                    for k in range(-2, 3):
                        for l in range(-2, 3):
                            for m in range(-2, 3):
                                x1, y1, z1 = new_x + k, new_y + l, new_z + m
                                if 0 <= x1 < shape[0] and 0 <= y1 < shape[1] and 0 <= z1 < shape[2]:
                                    array[x1, y1, z1] = 1.0
        elif abs(dy) > abs(dx) and abs(dy) > abs(dz):
            for j in range(abs(dy)):
                new_x = points[i][0]
                new_y = int(points[i][1] + j * np.sign(dy))
                new_z = points[i][2]
                if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                    for k in range(-2, 3):
                        for l in range(-2, 3):
                            for m in range(-2, 3):
                                x1, y1, z1 = new_x + k, new_y + l, new_z + m
                                if 0 <= x1 < shape[0] and 0 <= y1 < shape[1] and 0 <= z1 < shape[2]:
                                    array[x1, y1, z1] = 1.0
            for j in range(abs(dz)):
                new_x = new_x
                new_y = new_y
                new_z = int(points[i][2] + j * np.sign(dz))
                if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                    for k in range(-2, 3):
                        for l in range(-2, 3):
                            for m in range(-2, 3):
                                x1, y1, z1 = new_x + k, new_y + l, new_z + m
                                if 0 <= x1 < shape[0] and 0 <= y1 < shape[1] and 0 <= z1 < shape[2]:
                                    array[x1, y1, z1] = 1.0
        else:
            for j in range(abs(dz)):
                new_x = points[i][0]
                new_y = points[i][1]
                new_z = int(points[i][2] + j * np.sign(dz))
                if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                    for k in range(-2, 3):
                        for l in range(-2, 3):
                            for m in range(-2, 3):
                                x1, y1, z1 = new_x + k, new_y + l, new_z + m
                                if 0 <= x1 < shape[0] and 0 <= y1 < shape[1] and 0 <= z1 < shape[2]:
                                    array[x1, y1, z1] = 1.0

    return array

def generate_sphere(array, point, size):
    x, y, z = int(point[0]), int(point[1]), int(point[2])
    for i in range(-size, size+1):
        for j in range(-size, size+1):
            for k in range(-size, size+1):
                new_x, new_y, new_z = x + i, y + j, z + k
                if 0 <= new_x < array.shape[0] and 0 <= new_y < array.shape[1] and 0 <= new_z < array.shape[2]:
                    if (i**2 + j**2 + k**2) <= size**2:
                        array[new_x, new_y, new_z] = 1.0

shape = (64, 64, 64) 
num_cubes = 50
distance = 20  

delaunay_field = generate_delaunay_field(shape, num_cubes, distance)

verts, faces, _, _ = measure.marching_cubes(delaunay_field, level=0.5)

desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")
filename = os.path.join(desktop_path, "delaunay.obj")
with open(filename, "w") as f:
    for j, vert in enumerate(verts):
        f.write(f"v {vert[0]} {vert[1]} {vert[2]}\n")
    for face in faces:
        f.write(f"f {face[0]+1} {face[1]+1} {face[2]+1}\n")
print(f"Model saved as {filename}")

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_trisurf(verts[:, 0], verts[:, 1], verts[:, 2], color='blue', alpha=0.5)
plt.show()
MakarovDs на форуме Ответить с цитированием
Старый 23.11.2024, 12:50   #208
MakarovDs
Форумчанин
 
Аватар для MakarovDs
 
Регистрация: 10.01.2020
Сообщений: 344
По умолчанию

Гиперкуб Сырные шарики
Код:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from skimage import measure
from scipy.spatial import Delaunay
import os

def generate_delaunay_field(shape, num_cubes, distance):
    array = np.zeros(shape, dtype=float)

    points = []
    for i in range(num_cubes):
        x = (i % 4) * distance + distance // 2
        y = ((i // 4) % 4) * distance + distance // 2
        z = (i // 16) * distance + distance // 2
        if x < shape[0] and y < shape[1] and z < shape[2]:
            points.append([x, y, z]) 
            generate_sphere(array, (x, y, z), 5)

    for point in points:
        x, y, z = point
        for i in range(-1, 2):
            for j in range(-1, 2):
                for k in range(-1, 2):
                    new_x, new_y, new_z = x + i * distance, y + j * distance, z + k * distance
                    if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                        generate_sphere(array, (new_x, new_y, new_z), 10)

    for i in range(len(points)):
        x, y, z = points[i]
        for j in range(shape[0]):
            new_x = j
            new_y = y
            new_z = z
            if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                for k in range(-2, 3):
                    for l in range(-2, 3):
                        for m in range(-2, 3):
                            x1, y1, z1 = new_x + k, new_y + l, new_z + m
                            if 0 <= x1 < shape[0] and 0 <= y1 < shape[1] and 0 <= z1 < shape[2]:
                                array[x1, y1, z1] = 1.0
        for j in range(shape[1]):
            new_x = x
            new_y = j
            new_z = z
            if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                for k in range(-2, 3):
                    for l in range(-2, 3):
                        for m in range(-2, 3):
                            x1, y1, z1 = new_x + k, new_y + l, new_z + m
                            if 0 <= x1 < shape[0] and 0 <= y1 < shape[1] and 0 <= z1 < shape[2]:
                                array[x1, y1, z1] = 1.0
        for j in range(shape[2]):
            new_x = x
            new_y = y
            new_z = j
            if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                for k in range(-2, 3):
                    for l in range(-2, 3):
                        for m in range(-2, 3):
                            x1, y1, z1 = new_x + k, new_y + l, new_z + m
                            if 0 <= x1 < shape[0] and 0 <= y1 < shape[1] and 0 <= z1 < shape[2]:
                                array[x1, y1, z1] = 1.0

    for i in range(len(points) - 1):
        dx = points[i+1][0] - points[i][0]
        dy = points[i+1][1] - points[i][1]
        dz = points[i+1][2] - points[i][2]
        length = max(abs(dx), abs(dy), abs(dz))

        if abs(dx) > abs(dy) and abs(dx) > abs(dz):
            for j in range(abs(dx)):
                new_x = int(points[i][0] + j * np.sign(dx))
                new_y = points[i][1]
                new_z = points[i][2]
                if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                    for k in range(-2, 3):
                        for l in range(-2, 3):
                            for m in range(-2, 3):
                                x1, y1, z1 = new_x + k, new_y + l, new_z + m
                                if 0 <= x1 < shape[0] and 0 <= y1 < shape[1] and 0 <= z1 < shape[2]:
                                    array[x1, y1, z1] = 1.0
            for j in range(abs(dz)):
                new_x = new_x
                new_y = new_y
                new_z = int(points[i][2] + j * np.sign(dz))
                if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                    for k in range(-2, 3):
                        for l in range(-2, 3):
                            for m in range(-2, 3):
                                x1, y1, z1 = new_x + k, new_y + l, new_z + m
                                if 0 <= x1 < shape[0] and 0 <= y1 < shape[1] and 0 <= z1 < shape[2]:
                                    array[x1, y1, z1] = 1.0
        elif abs(dy) > abs(dx) and abs(dy) > abs(dz):
            for j in range(abs(dy)):
                new_x = points[i][0]
                new_y = int(points[i][1] + j * np.sign(dy))
                new_z = points[i][2]
                if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                    for k in range(-2, 3):
                        for l in range(-2, 3):
                            for m in range(-2, 3):
                                x1, y1, z1 = new_x + k, new_y + l, new_z + m
                                if 0 <= x1 < shape[0] and 0 <= y1 < shape[1] and 0 <= z1 < shape[2]:
                                    array[x1, y1, z1] = 1.0
            for j in range(abs(dz)):
                new_x = new_x
                new_y = new_y
                new_z = int(points[i][2] + j * np.sign(dz))
                if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                    for k in range(-2, 3):
                        for l in range(-2, 3):
                            for m in range(-2, 3):
                                x1, y1, z1 = new_x + k, new_y + l, new_z + m
                                if 0 <= x1 < shape[0] and 0 <= y1 < shape[1] and 0 <= z1 < shape[2]:
                                    array[x1, y1, z1] = 1.0
        else:
            for j in range(abs(dz)):
                new_x = points[i][0]
                new_y = points[i][1]
                new_z = int(points[i][2] + j * np.sign(dz))
                if 0 <= new_x < shape[0] and 0 <= new_y < shape[1] and 0 <= new_z < shape[2]:
                    for k in range(-2, 3):
                        for l in range(-2, 3):
                            for m in range(-2, 3):
                                x1, y1, z1 = new_x + k, new_y + l, new_z + m
                                if 0 <= x1 < shape[0] and 0 <= y1 < shape[1] and 0 <= z1 < shape[2]:
                                    array[x1, y1, z1] = 1.0

    return array

def generate_sphere(array, point, size):
    x, y, z = int(point[0]), int(point[1]), int(point[2])
    for i in range(-size, size+1):
        for j in range(-size, size+1):
            for k in range(-size, size+1):
                new_x, new_y, new_z = x + i, y + j, z + k
                if 0 <= new_x < array.shape[0] and 0 <= new_y < array.shape[1] and 0 <= new_z < array.shape[2]:
                    if (i**2 + j**2 + k**2) <= size**2:
                        array[new_x, new_y, new_z] = 1.0

shape = (64, 64, 64) 
num_cubes = 50
distance = 20  

delaunay_field = generate_delaunay_field(shape, num_cubes, distance)

verts, faces, _, _ = measure.marching_cubes(delaunay_field, level=0.5)

desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")
filename = os.path.join(desktop_path, "delaunay.obj")
with open(filename, "w") as f:
    for j, vert in enumerate(verts):
        f.write(f"v {vert[0]} {vert[1]} {vert[2]}\n")
    for face in faces:
        f.write(f"f {face[0]+1} {face[1]+1} {face[2]+1}\n")
print(f"Model saved as {filename}")

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_trisurf(verts[:, 0], verts[:, 1], verts[:, 2], color='blue', alpha=0.5)
plt.show()
MakarovDs на форуме Ответить с цитированием
Старый 23.11.2024, 18:56   #209
MakarovDs
Форумчанин
 
Аватар для MakarovDs
 
Регистрация: 10.01.2020
Сообщений: 344
По умолчанию

Процедурной генератор случайной synthwave поверхность (версия 1)
Код:
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
import numpy as np
import noise
import os

# Инициализация Pygame
pygame.init()
display = (800, 600)
pygame.display.set_mode(display, DOUBLEBUF | OPENGL)

# Инициализация камеры
gluPerspective(45, (display[0] / display[1]), 0.1, 1000.0)
glTranslatef(0.0, 0.0, -30)
glRotatef(45, 1, 0, 0)  # Повернуть камеру на 45 градусов вокруг оси X

# Генерация шума
def generate_noise_2d(shape, x_offset, z_offset, scale=100.0, octaves=6, persistence=0.5, lacunarity=2.0):
    noise_map = np.zeros(shape)
    for i in range(shape[0]):
        for j in range(shape[1]):
            noise_map[i][j] = noise.pnoise2((i + x_offset) / scale, (j + z_offset) / scale, octaves=octaves,
                                              persistence=persistence, lacunarity=lacunarity, repeatx=1024,
                                              repeaty=1024, base=42)
    return noise_map

# Создание террейна
def create_terrain(width, height, x_offset, z_offset):
    noise_map = generate_noise_2d((width, height), x_offset, z_offset)
    vertices = []
    for i in range(width):
        for j in range(height):
            x = i - width // 2
            z = j - height // 2
            y = noise_map[i][j] * 10
            vertices.append((x, y, z))
    return vertices

# Отрисовка террейна
def draw_terrain(vertices, width, height):
    glBegin(GL_TRIANGLES)
    for i in range(width - 1):
        for j in range(height - 1):
            glVertex3fv(vertices[i * height + j])
            glVertex3fv(vertices[(i + 1) * height + j])
            glVertex3fv(vertices[i * height + j + 1])

            glVertex3fv(vertices[(i + 1) * height + j])
            glVertex3fv(vertices[(i + 1) * height + j + 1])
            glVertex3fv(vertices[i * height + j + 1])
    glEnd()

# Сохранение в OBJ файл
def save_to_obj(vertices, filename):
    with open(filename, "w") as f:
        for v in vertices:
            f.write(f"v {v[0]} {v[1]} {v[2]}\n")
        for i in range(len(vertices) - 1):
            if (i + 1) % 20!= 0:  # Не соединять последнюю точку в строке
                f.write(f"f {i + 1} {i + 2} {i + 21}\n")
                f.write(f"f {i + 2} {i + 21} {i + 22}\n")

# Основной цикл
width, height = 20, 20
x_offset = 0
z_offset = 0
clock = pygame.time.Clock()
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_w:
                z_offset += 5
            if event.key == pygame.K_s:
                z_offset -= 5
            if event.key == pygame.K_a:
                x_offset -= 5
            if event.key == pygame.K_d:
                x_offset += 5
            if event.key == pygame.K_r:  # Сохранение на нажатие R
                desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")
                filename = os.path.join(desktop_path, "terrain_chunk.obj")
                save_to_obj(create_terrain(width, height, x_offset, z_offset), filename)
                print(f"Model saved as {filename}")

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    vertices = create_terrain(width, height, x_offset, z_offset)
    draw_terrain(vertices, width, height)
    pygame.display.flip()
    clock.tick(60)

Последний раз редактировалось MakarovDs; 23.11.2024 в 19:00.
MakarovDs на форуме Ответить с цитированием
Старый 25.11.2024, 16:55   #210
MakarovDs
Форумчанин
 
Аватар для MakarovDs
 
Регистрация: 10.01.2020
Сообщений: 344
По умолчанию

Сломанные горы глюка
Код:
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
import numpy as np
import noise
import os

# Инициализация Pygame
pygame.init()
display = (800, 600)
pygame.display.set_mode(display, DOUBLEBUF | OPENGL)

# Инициализация камеры
gluPerspective(45, (display[0] / display[1]), 0.1, 1000.0)
glTranslatef(0.0, 0.0, -30)
glRotatef(45, 1, 0, 0)  # Повернуть камеру на 45 градусов вокруг оси X

# Генерация шума
def generate_noise_2d(shape, x_offset, z_offset, scale=100.0, octaves=6, persistence=0.5, lacunarity=2.0):
    noise_map = np.zeros(shape)
    for i in range(shape[0]):
        for j in range(shape[1]):
            noise_map[i][j] = noise.pnoise2((i + x_offset) / scale, (j + z_offset) / scale, octaves=octaves,
                                              persistence=persistence, lacunarity=lacunarity, repeatx=1024,
                                              repeaty=1024, base=42)
    return noise_map

# Создание террейна
def create_terrain(width, height, x_offset, z_offset):
    noise_map = generate_noise_2d((width, height), x_offset, z_offset)
    vertices = []
    for i in range(width):
        for j in range(height):
            x = i - width // 2
            z = j - height // 2
            y = noise_map[i][j] * 10
            vertices.append((x, y, z))
    # Добавляем вершины шипов
    for i in range(width):
        for j in range(height):
            x = i - width // 2
            z = j - height // 2
            y = noise_map[i][j] * 10
            vertices.append((x, y + 10, z))  # Вершины шипов
            vertices.append((x + 0.5, y + 5, z))  # Вершины шипов
            vertices.append((x - 0.5, y + 5, z))  # Вершины шипов
    return vertices

# Отрисовка террейна
# Отрисовка террейна
def draw_terrain(vertices, width, height):
    glBegin(GL_TRIANGLES)
    for i in range(width - 1):
        for j in range(height - 1):
            x = i - width // 2
            z = j - height // 2
            y_floor = vertices[i * height + j][1]
            y_ceiling = 10  # Высота потолка

            # Пол
            glVertex3fv(vertices[i * height + j])
            glVertex3fv(vertices[(i + 1) * height + j])
            glVertex3fv(vertices[i * height + j + 1])

            glVertex3fv(vertices[(i + 1) * height + j])
            glVertex3fv(vertices[(i + 1) * height + j + 1])
            glVertex3fv(vertices[i * height + j + 1])

            # Стены
            glVertex3fv((x, y_floor, z))
            glVertex3fv((x + 1, y_floor, z))
            glVertex3fv((x, y_ceiling, z))

            glVertex3fv((x + 1, y_floor, z))
            glVertex3fv((x + 1, y_ceiling, z))
            glVertex3fv((x + 1, y_floor, z + 1))

            glVertex3fv((x, y_floor, z + 1))
            glVertex3fv((x, y_ceiling, z + 1))
            glVertex3fv((x, y_floor, z))

            glVertex3fv((x, y_floor, z))
            glVertex3fv((x, y_ceiling, z))
            glVertex3fv((x + 1, y_floor, z))

            glVertex3fv((x + 1, y_floor, z + 1))
            glVertex3fv((x + 1, y_ceiling, z + 1))
            glVertex3fv((x, y_floor, z + 1))

    glEnd()

# Сохранение в OBJ файл
def save_to_obj(vertices, width, height, filename):
    with open(filename, "w") as f:
        for v in vertices:
            f.write(f"v {v[0]} {v[1]} {v[2]}\n")
        for i in range(width - 1):
            for j in range(height - 1):
                # Пол
                f.write(f"f {i * height + j + 1} {(i + 1) * height + j + 1} {i * height + j + 2}\n")
                f.write(f"f {(i + 1) * height + j + 1} {(i + 1) * height + j + 2} {i * height + j + 2}\n")
                # Стены
                f.write(f"f {i * height + j + 1} {(i + 1) * height + j + 1} {width * height * 3 + i * height + j + 1}\n")
                f.write(f"f {(i + 1) * height + j + 1} {width * height * 3 + i * height + j + 1} {width * height * 3 + (i + 1) * height + j + 1}\n")
                f.write(f"f {i * height + j + 1} {width * height * 3 + (i + 1) * height + j + 1} {width * height * 3 + i * height + j + 1}\n")
                f.write(f"f {width * height * 3 + i * height + j + 1} {width * height * 3 + i * height + j + 2} {width * height * 3 + (i + 1) * height + j + 1}\n")
                f.write(f"f {width * height * 3 + i * height + j + 2} {width * height * 3 + (i + 1) * height + j + 1} {width * height * 3 + (i + 1) * height + j + 1}\n")



# Основной цикл
width, height = 20, 20
x_offset = 0
z_offset = 0
clock = pygame.time.Clock()
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_w:
                z_offset += 5
            if event.key == pygame.K_s:
                z_offset -= 5
            if event.key == pygame.K_a:
                x_offset -= 5
            if event.key == pygame.K_d:
                x_offset += 5
            if event.key == pygame.K_r:  # Сохранение на нажатие R
                desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")
                filename = os.path.join(desktop_path, "terrain_chunk.obj")
                save_to_obj(create_terrain(width, height, x_offset, z_offset), width, height, filename)
                print(f"Model saved as {filename}")

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    vertices = create_terrain(width, height, x_offset, z_offset)
    draw_terrain(vertices, width, height)
    pygame.display.flip()
    clock.tick(60)
Не знаю зачем они нужны но пускай будут...

Хотел сделать уровень металлических шипов но получились металлические горы...

Последний раз редактировалось MakarovDs; 26.11.2024 в 12:31.
MakarovDs на форуме Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
помогите с генератором слов Мой повелитель Общие вопросы C/C++ 6 27.02.2016 23:46
Зарубежные микроконтроллеры с встроенным ШИМ-генератором MyLastHit Компьютерное железо 6 22.10.2013 14:33
написание генератора фракталов Жюлиа kyzmich2370 Visual C++ 1 06.11.2012 09:57
Помогите с генератором чисел на Pascal vadmaruschak Помощь студентам 6 13.09.2009 17:06
Игры фракталов на VB Kail Свободное общение 1 29.05.2009 09:30