拼图的画面多以自然风光、建筑物以及一些为人所熟识的图案的为题材。
城堡和山峦是两类传统的主题,
不过任何图画和影像都可以用做拼图的素材。
有一些公司还提供将私人摄影作品制成拼图的服务。
图片素材
这个大家可以自行准备或者在文末推广领取哦~
图片可以准备大家喜欢的人物、风景、美女等等哦~不限哒
🎯 这里仅展示部分代码,完整的免费源码领取处:点击这里
import os
import sys
import random
import pygame
from pygame.locals import *
BACKGROUNDCOLOR = (255, 255, 255)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
BLACK = (0, 0, 0)
FPS = 40
NUMRANDOM = 100
def Stop():pygame.quit()sys.exit()
# 源码解答加Q裙:660193417
def isOver(board, size):try:num_cells = size * sizeexcept:num_cells = size[0] * size[1]for i in range(num_cells-1):if board[i] != i:return Falsereturn True
def moveR(board, blank_cell_idx, num_cols):if blank_cell_idx % num_cols == 0:return blank_cell_idxboard[blank_cell_idx-1], board[blank_cell_idx] = board[blank_cell_idx], board[blank_cell_idx-1]return blank_cell_idx-1
def moveL(board, blank_cell_idx, num_cols):if (blank_cell_idx+1) % num_cols == 0:return blank_cell_idxboard[blank_cell_idx+1], board[blank_cell_idx] = board[blank_cell_idx], board[blank_cell_idx+1]return blank_cell_idx+1
def moveD(board, blank_cell_idx, num_cols):if blank_cell_idx < num_cols:return blank_cell_idxboard[blank_cell_idx-num_cols], board[blank_cell_idx] = board[blank_cell_idx], board[blank_cell_idx-num_cols]return blank_cell_idx-num_cols
def moveU(board, blank_cell_idx, num_rows, num_cols):if blank_cell_idx >= (num_rows-1) * num_cols:return blank_cell_idxboard[blank_cell_idx+num_cols], board[blank_cell_idx] = board[blank_cell_idx], board[blank_cell_idx+num_cols]return blank_cell_idx+num_cols
# 源码解答加Q裙:660193417#
def CreateBoard(num_rows, num_cols, num_cells):board = []for i in range(num_cells):board.append(i)# 去掉右下角那块blank_cell_idx = num_cells - 1board[blank_cell_idx] = -1for i in range(NUMRANDOM):# 0: left, 1: right, 2: up, 3: downdirection = random.randint(0, 3)if direction == 0:blank_cell_idx = moveL(board, blank_cell_idx, num_cols)elif direction == 1:blank_cell_idx = moveR(board, blank_cell_idx, num_cols)elif direction == 2:blank_cell_idx = moveU(board, blank_cell_idx, num_rows, num_cols)elif direction == 3:blank_cell_idx = moveD(board, blank_cell_idx, num_cols)return board, blank_cell_idx
def GetImagePath(filepath):imgs = os.listdir(filepath)if len(imgs) == 0:raise ValueError('No pictures in <%s>...' % filepath)return os.path.join(filepath, random.choice(imgs))
def ShowEndInterface(screen, width, height):screen.fill(BACKGROUNDCOLOR)font = pygame.font.Font('font/simkai.ttf', width // 8)title = font.render('Finished!', True, (233, 150, 122))rect = title.get_rect()rect.midtop = (width/2, height/2.5)screen.blit(title, rect)pygame.display.update()pygame.time.wait(500)# 源码解答加Q裙:660193417#while True:for event in pygame.event.get():if event.type == QUIT:Stop()elif event.type == KEYDOWN:if event.key == K_ESCAPE:Stop()
🎯 博主所有文章素材、解答、源码领取处:点击