用户:秤杆不平衡查看:0 回复:0 评论:0 创建时间:2022-07-24T18:33:50
【作品展示】

【作品介绍】
分形图上帝的指纹上下左右键移动视角
ws键放大缩小
ad键减少,增加精度
空格输出参数
q键还原
【作品源代码】
import pygame
import sys
import math
from pygame.locals import*
screen_length = 900
centrex = -0.45
centrey = 0
zx = 0
zy = 0
TULV_TO_ASP = 3/screen_length
cnt = 20
cnt_print=1
pygame.init()
screen = pygame.display.set_mode((screen_length, screen_length))
pygame.display.set_caption("曼得勃罗集")
def z(zx, zy, cx, cy, cnt):
a = (zx, zy)
b = (zx, zy)
for i in range(cnt):
b = (a[0]**2-a[1]**2+cx, 2*a[0]*a[1]+cy)
if math.sqrt(abs(b[0])**2+abs(b[1])**2) >= 2:
return "big"
a = b
return b
#print(z(zx, zy, -1.8, -0.3, cnt))
def draw():
global screen_length, centrex, centrey, zx, zy, TULV_TO_ASP, cnt, screen
screen.fill((255, 255, 255))
range_cnt = int(screen_length/5+1)
for x in range(range_cnt):
for y in range(range_cnt):
cx = centrex+TULV_TO_ASP*(5*x+3-screen_length/2)
cy = centrey+TULV_TO_ASP*(5*y+3-screen_length/2)
return_z = z(zx, zy, cx, cy, cnt)
if return_z != "big":
pygame.draw.rect(screen, (0, 0, 0), (x*5, y*5, 5, 5))
pygame.display.update()
draw()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYUP:
# 上下左右移动
if event.key == pygame.K_UP:
centrey -= 50*TULV_TO_ASP
draw()
if event.key == pygame.K_LEFT:
centrex -= 50*TULV_TO_ASP
draw()
if event.key == pygame.K_DOWN:
centrey += 50*TULV_TO_ASP
draw()
if event.key == pygame.K_RIGHT:
centrex += 50*TULV_TO_ASP
draw()
# w大a小,a多d少
if event.key == pygame.K_w:
TULV_TO_ASP = TULV_TO_ASP/1.1
draw()
if event.key == pygame.K_a:
cnt = int(cnt*1.1)
draw()
if event.key == pygame.K_s:
TULV_TO_ASP = TULV_TO_ASP*1.1
draw()
if event.key == pygame.K_d and cnt/1.1 >= 10:
cnt = int(cnt/1.1)
draw()
if event.key == pygame.K_q:
centrex = -0.45
centrey = 0
cnt = 20
draw()
if event.key == pygame.K_SPACE:
print(cnt_print)
print()
print("------------------")
print("|TULV_TO_ASP")
print("|cnt")
print("|centrex", "centrey")
print("------------------")
print("|", TULV_TO_ASP)
print("|", cnt)
print("|", centrex, centrey)
print("------------------")
cnt_print+=1
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn