pygame单图伪3d

python 复制代码
import cv2
import pygame
import sys
from pygame import gfxdraw
import numpy as np

(width, height) = (800, 600)
pygame.init()
screen = pygame.display.set_mode((width, height))
image = pygame.image.load("11.jpg").convert()
d3=pygame.surfarray.array3d(image)
f=250#数字大会显示更前面的图片
sc=300#数字越大视角越高
color=(255, 255, 255)
#print(len(d3[0][0]))#len(d3 )就是有多少张表 一个[0]是有多高 两个是每个表有几列 三个就是具体数
#print(d3[0][0][0])
#print(d3)
#sarray=pygame.surfarray.array3d(pygame.surface((50,50)))
sarray=pygame.surfarray.array3d(pygame.Surface((width,height)))
#sarray[:]=(255,255,0)变成黄色,替换所有为(255,255,0)

tsize=image.get_size()#图片宽高
print(tsize)
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            mouse = pygame.mouse.get_pos()
            '''pxarray = pygame.PixelArray(screensurf)
            pixel = pygame.Color(pxarray[mouse[0], mouse[1]])#获取像素
            print (pixel)
            print (screensurf.get_at(mouse))#颜色
            print(mouse[0], mouse[1],mouse)#点击坐标
            print(img.get_at(mouse))#颜色'''
            #pygame.Surface.set_at(screen, (140, 140), (img.get_at(mouse)))
            print(mouse[0], mouse[1], mouse)  # 点击坐标
    for i in range(width):
        for j in range(int(height/2),height):
            x=(width/2)-i
            y=j+f
            z=j-(height/2)+0.01
            '''
            def huizhi(x, y, z):
            shiju = 300
            x1 = shiju * x / z
            y1 = shiju * y / z
            # p.append((x1,y1))
            return x1, y1
            '''
            px=x/z*sc
            py=y/z*90
            '''不重复图片'''
            #print(px, py)

            if 0 <= px < tsize[0] and 0 <= py< tsize[1]:
                #print(px, py)
                fp = int(px), int(py)
                #fc = d3[fp]
                #sarray[-i, j] = fc
                pygame.Surface.set_at(screen, (i, int(j/2)+260), (image.get_at((fp))))
                #pygame.Surface.set_at(screen, (int(i * 0.5), int(j * 0.5)), (image.get_at((fp))))
            #fp=int(px%tsize[0]),int(py%tsize[1])#tsize【0】,【1】是图片宽高


    #pygame.surfarray.blit_array(screen,sarray)
    pygame.display.update()
相关推荐
陈苏同学22 分钟前
4. 将pycharm本地项目同步到(Linux)服务器上——深度学习·科研实践·从0到1
linux·服务器·ide·人工智能·python·深度学习·pycharm
唐家小妹26 分钟前
介绍一款开源的 Modern GUI PySide6 / PyQt6的使用
python·pyqt
羊小猪~~1 小时前
深度学习项目----用LSTM模型预测股价(包含LSTM网络简介,代码数据均可下载)
pytorch·python·rnn·深度学习·机器学习·数据分析·lstm
Marst Code1 小时前
(Django)初步使用
后端·python·django
985小水博一枚呀2 小时前
【对于Python爬虫的理解】数据挖掘、信息聚合、价格监控、新闻爬取等,附代码。
爬虫·python·深度学习·数据挖掘
立秋67892 小时前
Python的defaultdict详解
服务器·windows·python
萧鼎2 小时前
Python第三方库选择与使用陷阱避免
开发语言·python
白拾2 小时前
使用Conda管理python环境的指南
开发语言·python·conda
是刃小木啦~3 小时前
三维模型点云化工具V1.0使用介绍:将三维模型进行点云化生成
python·软件工程·pyqt·工业软件
总裁余(余登武)3 小时前
算法竞赛(Python)-万变中的不变“随机算法”
开发语言·python·算法