python画圆代码(python画圆代码重叠)

http://www.itjxue.com  2023-04-10 01:15  来源:未知  点击次数: 

python 绘制一个圆,当单击窗口的任意位置时圆移动到单击的位置,如何编写代码?

#-*-?coding:?UTF-8?-*-

import?pygame,?sys

from?pygame.locals?import?*

white?=?255,?255,?255

blue?=?0,?0,?200

pygame.init()

screen?=?pygame.display.set_mode((600,?800))

myfont?=?pygame.font.Font(None,?20)

textImage?=?myfont.render("hello?game",?True,?white)

position?=?200,?200

print(position)

while?True:

for?event?in?pygame.event.get():

if?event.type?in?(QUIT,?KEYDOWN):

sys.exit()

elif?event.type?==?MOUSEBUTTONDOWN:

position?=?event.pos

screen.fill(blue)

screen.blit(textImage,?(100,?100))

#position?=?200,?200

radius?=?100

width?=?10

pygame.draw.circle(screen,?white,?position,?radius,?width)

pygame.display.update()

用pygame创建界面并监控鼠标按下事件,获得按下位置,画圆

代码注意缩进如下图:

用python画一个圆

###################################

# coding=utf-8

# !/usr/bin/env python

# __author__ = 'pipi'

# ctime 2014.10.11

# 绘制椭圆和圆形

###################################

from matplotlib.patches import Ellipse, Circle

import matplotlib.pyplot as plt

fig = plt.figure()

ax = fig.add_subplot(111)

ell1 = Ellipse(xy = (0.0, 0.0), width = 4, height = 8, angle = 30.0, facecolor= 'yellow', alpha=0.3)

cir1 = Circle(xy = (0.0, 0.0), radius=2, alpha=0.5)

ax.add_patch(ell1)

ax.add_patch(cir1)

x, y = 0, 0

ax.plot(x, y, 'ro')

plt.axis('scaled')

# ax.set_xlim(-4, 4)

# ax.set_ylim(-4, 4)

plt.axis('equal') #changes limits of x or y axis so that equal increments of x and y have the same length

plt.show()

你可以试试,谢谢。

python怎么在不同点上画相交的圆

1、首先进入软件主界面,使用python编程语言。

2,其次在用matplotlib画图的模板。

3、最后利用参数方程会来画圆即可画出不同点上画相交的圆。

Python语句中light.circle(20)中20指的什么意思?

圆的直径

python画圆代码from matplotlib.patches import Ellipse, Circle

import matplotlib.pyplot as plt

def plot_cicle():

fig = plt.figure()

ax = fig.add_subplot(111)

cir1 = Circle(xy = (0.0, 0.0), radius=2, alpha=0.5)

ax.add_patch(cir1)

x, y = 0, 0

ax.plot(x, y, 'ro')

plt.axis('scaled')

plt.axis('equal') #changes limits of x or y axis so that equal increments of x and y have the same length

plt.show()

plot_cicle()

(责任编辑:IT教学网)

更多

推荐服务器空间文章