python边缘检测代码_Python中的边缘检测
我试着写一个程序,用户输入一个数字,它在屏幕上画出那么多的矩形,但是三角形不能重叠。我对最后一部分有问题,我正在寻求帮助。我借用了Al-Sweigart的一本书中的边缘检测方法,他编写的完整程序可以在这里找到:
以下是我正在执行的程序:import pygame, sys, random
from pygame.locals import *
def doRectsOverlap(rect1, rect2):
for a, b in [(rect1, rect2)]:
# Check if a's corners are inside b
if ((isPointInsideRect(a.left, a.top, b)) or
(isPointInsideRect(a.left, a.bottom, b)) or
(isPointInsideRect(a.right, a.top, b)) or
(isPointInsideRect(a.right, a.bottom, b))):
return True
return False
def isPointInsideRect(x, y, rect):
if (x > rect.left) and (x < rect.right) and (y > rect.top) and (y < rect.bottom):
return True
else:
return False
# set up pygame
pygame.init()
# set up the window
WINDOWWIDTH = 600
WINDOWHEIGHT = 600
windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)
pygame.display.set_caption('Rectangles')
# set up the colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
from random import choice
foo = [BLACK, RED, GREEN, BLUE]
# draw the background
windowSurface.fill(WHITE)
print('Please enter a number:')
number = input()
x = 0
array = []
for i in array:
while int(number) > x:
x = x+1
x1 = random.randint(1, 400)
y1 = random.randint(1, 400)
x2 = random.randint(1, 400)
y2 = random.randint(1, 400)
x3 = random.randint(1, 400)
y3 = random.randint(1, 400)
x4 = random.randint(1, 400)
y4 = random.randint(1, 400)
box = pygame.draw.rect(windowSurface,random.choice(foo), (x1, y1, x2, y2))
if doRectsOverlap(box, box) == False:
box
else:
x = x-1
# draw the window onto the screen
pygame.display.update()
任何帮助都将不胜感激。谢谢您!在
python边缘检测代码_Python中的边缘检测相关推荐
- python 字典代码_python中的字典用法大全的代码
标签: 如下代码是关于python中的字典用法大全的代码. #!/usr/bin/env python # # [SNIPPET_NAME: Dictionaries 101] # [SNIPPET_ ...
- python结束代码_Python中的退出代码
The optional argument arg can be an integer giving the exit status (defaulting to zero), or another ...
- python逗号代码_python中的逗号
广告关闭 腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元! mycursor = mydb.cursor() sql = select * ...
- python平均值代码_python中的运行平均值
我有两个可能的解决办法.这两个函数都是通用的运行平均值函数,适用于任何数字列表.(可以与任何无法识别的人一起工作) 基于发电机: nums = [cauchy(3,1) for x in xrange ...
- python归一化代码_python中的快速图像归一化
我觉得你的时间安排得很慢.也许你的安装出了问题?在 我试过这个测试程序:#!/usr/bin/python3 import sys import numpy as np import cv2 from ...
- python添加横线代码_Python中的五种下划线
1 1.单前导下划线 _var2 3 单个下划线是一个Python命名约定,表示这个名称是供内部使用的. 它通常不由Python解释器强制执行,仅仅作为一种对程序员的提示4 5 程序员使用名称前的单下 ...
- python map用法_Python中ChainMap的一种实用用法
Python部落(python.freelycode.com)组织翻译,禁止转载,欢迎转发. 简而言之ChainMap:将多个字典视为一个,解锁Python超能力. Python标准库中的集合模块包含 ...
- python numpy教程_Python中的Numpy入门教程
这篇文章主要介绍了 Python 中的 Numpy 入门教程,着重讲解了矩阵中的数组操作 , 需要的 朋友可以参考下 1 . Numpy 是什么 很简单, Numpy 是 Python 的一个科学计算 ...
- 用python进行因式分解_python中怎么对一个数进行因式分解?
1.Python因式分解代码:import time # 对一个数进行因式分解 def factorization(num): factor = [] while num > 1: for i ...
最新文章
- php 转义 回车 空格 file put content,为什么在服务器上php里执行file_put_contents创建文件返回是false呢,文件目录已经设置为777的权限了,不解...
- Python3 正则表达式特殊符号及用法(详细列表)
- CANVAS运用-对图片的压缩上传(仅针对移动浏览器)
- Android的ELF文件重定位详解,包括64位
- 东山里的传说——《荒原的呼唤》选载之四
- 【转】mysql数据库中实现内连接、左连接、右连接
- 2022年第十四届电工杯赛题分析
- 小莫微信影视机器人-自定义对接影视教程
- java读取pdf文档
- 【JZOJ2109】清兵线【dp】
- 测量频率和占空比的几种方法
- 计算机视觉未来的挑战,搜狗斩获ICPR 2020人脸关键点检测挑战赛冠军 计算机视觉技术持续领先...
- json格式问题解决方式!
- Esxi6.7-7.0设置自动启动无效原因
- Java基础系列【导读】
- pyqt5可以写手机apk吗_不需要写代码,直接在unity实现手机可以跑的毛发效果
- HMS Core 6.8.0版本发布公告
- VCS和Verdi联合仿真
- CVE-2022-32991
- 第三大的数、字符串中的单词数、排列硬币
热门文章
- 编程方法学笔记:karel
- Ubuntu10.04各文件夹的作用
- mybatis的学习笔记01
- 【Python】for 循环倒叙遍历
- [MATLAB粒子模拟]Energy Vx(X) Vy(X) Vz(X)
- 云炬Android开发笔记 17商品详情功能开发
- SVM熟练到精通4:偏离点与松弛变量
- Android常用的开源框架
- 未能加载文件或程序集“Iesi.Collections”或它的某一个依赖项。参数错误。 (异常来自 HRESULT:0x80070057 (E_INVALIDARG))
- SQLite注意以下几点