Ⅰ python畫圓開頭的#寫什麼
'#'開頭的行為注釋行,不會被編譯。
可以記錄程序路徑、python版本號、運行平台標識、作者信息、功能信息、用途信息、開發日期、代碼實現思路等。
Ⅱ python怎麼實現畫圓功能
你可以用下面的庫:import numpy as npimport matplotlib.pyplot as plt fig = plt.figure(figsize=(8,8))ax = fig.add_subplot("11")
theta = np.arange(0, 2 * np.pi + 0.1,2 * np.pi / 1000)x = np.cos(theta)y = np.sin(theta) v = np.linspace(0, 10, 100)v.shape = (100, 1) x = v * xy = v * y plt.plot(x, y, color='pink')# plt.savefig('ball1.jpg')plt.show()
Ⅲ python編寫程序繪制一個以點為圓心,半徑為80的固定圓.無論何時單擊滑鼠
我用的是import pyHook模塊
import pythoncom
import pyHook
def onMouseEvent(event):
print "Position:", event.Position
return True
def main():
hm = pyHook.HookManager()
hm.HookKeyboard()
hm.MouseAll = onMouseEvent
hm.HookMouse()
pythoncom.PumpMessages()
if __name__ == "__main__":
main()
Ⅳ python海龜繪圖怎麼增加每次畫圓的半徑
importturtle#導入海龜制圖庫
r=10#每次增加的半徑,也是初始半徑
foriinrange(9):#批量比循環
turtle.penup()#抬你筆
turtle.goto(0,-r*(i+1))#在Y軸上移動,
turtle.pendown()#放下你的筆
turtle.circle(r*(i+1))#化圓,半徑按照一定順序增加
turtle.done()#保持畫面,不退出
Ⅳ python turtle畫4個同心圓方法
importturtle
#drawfirstcircle
turtle.penup()
turtle.goto(0,-200)
turtle.pendown()
turtle.circle(200)
#drawsecondcircle
turtle.penup()
turtle.goto(0,-150)
turtle.pendown()
turtle.circle(150)
#drawthirdcircle
turtle.penup()
turtle.goto(0,-100)
turtle.pendown()
turtle.circle(100)
#drawfourthcircle
turtle.penup()
turtle.goto(0,-50)
turtle.pendown()
turtle.circle(50)
畫筆的坐標默認在0,0,就以它為圓心。
因為turtle畫圓的時候是從圓的底部開始畫的,所以需要找到四個圓底部的坐標
比如:
第一個半徑為200的圓,底部為(0,-200)
第二個半徑為150的圓,底部為(0,-150)
第三個半徑為100的圓,底部為(0,-100)
第四個半徑為 50的圓,底部為(0, -50)
畫的時候按下面的步驟:
抬起畫筆:turtle.penup()
移動到相應坐標:turtle.goto(坐標)
放下畫筆:turtle.pendown()
畫圓:turtle.circle(半徑)
效果如下圖所示:
Ⅵ 用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如何用點畫一個黑圓
用到Image, ImageDraw模塊
importImage,ImageDraw
image=Image.new('RGBA',(200,200))
draw=ImageDraw.Draw(image)
draw.ellipse((20,180,180,20),fill='blue',outline='blue')
#draw.ellipse((20,20,180,180),fill='black',outline='black')
draw.point((100,100),'red')
image.save('test.png')
Ⅷ python pyqt怎麼畫圓
這個例子我做了好幾天:
1)官網C++的源碼,改寫成PyQt5版本的代碼,好多細節不會轉化
2)網上的PyQt的例子根本運行不了
填了無數個坑,結合二者,終於能完成了一個關於繪圖的東西。這個過程也掌握了很多新的知識點
【知識點】
1、關於多個點的使用
poitns = [QPoint(10, 80), QPoint(20, 10), QPoint(80, 30), QPoint(90, 70)]
請看:
import sysfrom PyQt5.QtCore import *from PyQt5.QtGui import *from PyQt5.QtWidgets import *class StockDialog(QWidget): def __init__(self, parent=None):
super(StockDialog, self).__init__(parent)
self.setWindowTitle("利用QPainter繪制各種圖形")
mainSplitter = QSplitter(Qt.Horizontal)
mainSplitter.setOpaqueResize(True)
frame = QFrame(mainSplitter)
mainLayout = QGridLayout(frame) #mainLayout.setMargin(10)
mainLayout.setSpacing(6)
label1=QLabel("形狀:")
label2=QLabel("畫筆線寬:")
label3=QLabel("畫筆顏色:")
label4=QLabel("畫筆風格:")
label5=QLabel("畫筆頂端:")
label6=QLabel("畫筆連接點:")
label7=QLabel("畫刷風格:")
label8=QLabel("畫刷顏色:")
self.shapeComboBox = QComboBox()
self.shapeComboBox.addItem("Line", "Line")
self.shapeComboBox.addItem("Rectangle", "Rectangle")
self.shapeComboBox.addItem('Rounded Rectangle','Rounded Rectangle')
self.shapeComboBox.addItem('Ellipse','Ellipse')
self.shapeComboBox.addItem('Pie','Pie')
self.shapeComboBox.addItem('Chord','Chord')
self.shapeComboBox.addItem('Path','Path')
self.shapeComboBox.addItem('Polygon','Polygon')
self.shapeComboBox.addItem('Polyline','Polyline')
self.shapeComboBox.addItem('Arc','Arc')
self.shapeComboBox.addItem('Points','Points')
self.shapeComboBox.addItem('Text','Text')
self.shapeComboBox.addItem('Pixmap','Pixmap')
self.widthSpinBox = QSpinBox()
self.widthSpinBox.setRange(0,20)
self.penColorFrame = QFrame()
self.penColorFrame.setAutoFillBackground(True)
self.penColorFrame.setPalette(QPalette(Qt.blue))
self.penColorPushButton = QPushButton("更改")
self.penStyleComboBox = QComboBox()
self.penStyleComboBox.addItem("Solid",Qt.SolidLine)
self.penStyleComboBox.addItem('Dash', Qt.DashLine)
self.penStyleComboBox.addItem('Dot', Qt.DotLine)
self.penStyleComboBox.addItem('Dash Dot', Qt.DashDotLine)
self.penStyleComboBox.addItem('Dash Dot Dot', Qt.DashDotDotLine)
self.penStyleComboBox.addItem('None', Qt.NoPen)
self.penCapComboBox = QComboBox()
self.penCapComboBox.addItem("Flat",Qt.FlatCap)
self.penCapComboBox.addItem('Square', Qt.SquareCap)
self.penCapComboBox.addItem('Round', Qt.RoundCap)
self.penJoinComboBox = QComboBox()
self.penJoinComboBox.addItem("Miter",Qt.MiterJoin)
self.penJoinComboBox.addItem('Bebel', Qt.BevelJoin)
self.penJoinComboBox.addItem('Round', Qt.RoundJoin)
self.brushStyleComboBox = QComboBox()
self.brushStyleComboBox.addItem("Linear Gradient",Qt.LinearGradientPattern)
self.brushStyleComboBox.addItem('Radial Gradient', Qt.RadialGradientPattern)
self.brushStyleComboBox.addItem('Conical Gradient', Qt.ConicalGradientPattern)
self.brushStyleComboBox.addItem('Texture', Qt.TexturePattern)
self.brushStyleComboBox.addItem('Solid', Qt.SolidPattern)
self.brushStyleComboBox.addItem('Horizontal', Qt.HorPattern)
self.brushStyleComboBox.addItem('Vertical', Qt.VerPattern)
self.brushStyleComboBox.addItem('Cross', Qt.CrossPattern)
self.brushStyleComboBox.addItem('Backward Diagonal', Qt.BDiagPattern)
self.brushStyleComboBox.addItem('Forward Diagonal', Qt.FDiagPattern)
self.brushStyleComboBox.addItem('Diagonal Cross', Qt.DiagCrossPattern)
self.brushStyleComboBox.addItem('Dense 1', Qt.Dense1Pattern)
self.brushStyleComboBox.addItem('Dense 2', Qt.Dense2Pattern)
self.brushStyleComboBox.addItem('Dense 3', Qt.Dense3Pattern)
self.brushStyleComboBox.addItem('Dense 4', Qt.Dense4Pattern)
self.brushStyleComboBox.addItem('Dense 5', Qt.Dense5Pattern)
self.brushStyleComboBox.addItem('Dense 6', Qt.Dense6Pattern)
self.brushStyleComboBox.addItem('Dense 7', Qt.Dense7Pattern)
self.brushStyleComboBox.addItem('None', Qt.NoBrush)
self.brushColorFrame = QFrame()
self.brushColorFrame.setAutoFillBackground(True)
self.brushColorFrame.setPalette(QPalette(Qt.green))
self.brushColorPushButton = QPushButton("更改")
labelCol=0
contentCol=1
#建立布局
mainLayout.addWidget(label1,1,labelCol)
mainLayout.addWidget(self.shapeComboBox,1,contentCol)
mainLayout.addWidget(label2,2,labelCol)
mainLayout.addWidget(self.widthSpinBox,2,contentCol)
mainLayout.addWidget(label3,4,labelCol)
mainLayout.addWidget(self.penColorFrame,4,contentCol)
mainLayout.addWidget(self.penColorPushButton,4,3)
mainLayout.addWidget(label4,6,labelCol)
mainLayout.addWidget(self.penStyleComboBox,6,contentCol)
mainLayout.addWidget(label5,8,labelCol)
mainLayout.addWidget(self.penCapComboBox,8,contentCol)
mainLayout.addWidget(label6,10,labelCol)
mainLayout.addWidget(self.penJoinComboBox,10,contentCol)
mainLayout.addWidget(label7,12,labelCol)
mainLayout.addWidget(self.brushStyleComboBox,12,contentCol)
mainLayout.addWidget(label8,14,labelCol)
mainLayout.addWidget(self.brushColorFrame,14,contentCol)
mainLayout.addWidget(self.brushColorPushButton,14,3)
mainSplitter1 = QSplitter(Qt.Horizontal)
mainSplitter1.setOpaqueResize(True)
stack1 = QStackedWidget()
stack1.setFrameStyle(QFrame.Panel|QFrame.Raised)
self.area = PaintArea()
stack1.addWidget(self.area)
frame1 = QFrame(mainSplitter1)
mainLayout1 = QVBoxLayout(frame1) #mainLayout1.setMargin(10)
mainLayout1.setSpacing(6)
mainLayout1.addWidget(stack1)
layout = QGridLayout(self)
layout.addWidget(mainSplitter1,0,0)
layout.addWidget(mainSplitter,0,1)
self.setLayout(layout)
#信號和槽函數 self.shapeComboBox.activated.connect(self.slotShape)
self.widthSpinBox.valueChanged.connect(self.slotPenWidth)
self.penColorPushButton.clicked.connect(self.slotPenColor)
self.penStyleComboBox.activated.connect(self.slotPenStyle)
self.penCapComboBox.activated.connect(self.slotPenCap)
self.penJoinComboBox.activated.connect(self.slotPenJoin)
self.brushStyleComboBox.activated.connect(self.slotBrush)
self.brushColorPushButton.clicked.connect(self.slotBrushColor)
self.slotShape(self.shapeComboBox.currentIndex())
self.slotPenWidth(self.widthSpinBox.value())
self.slotBrush(self.brushStyleComboBox.currentIndex())
def slotShape(self,value):
shape = self.area.Shape[value]
self.area.setShape(shape)
def slotPenWidth(self,value):
color = self.penColorFrame.palette().color(QPalette.Window)
style = Qt.PenStyle(self.penStyleComboBox.itemData(self.penStyleComboBox.currentIndex(),Qt.UserRole))
cap = Qt.PenCapStyle(self.penCapComboBox.itemData(self.penCapComboBox.currentIndex(),Qt.UserRole))
join = Qt.PenJoinStyle(self.penJoinComboBox.itemData(self.penJoinComboBox.currentIndex(),Qt.UserRole))
self.area.setPen(QPen(color,value,style,cap,join))
def slotPenStyle(self,value):
self.slotPenWidth(value)
def slotPenCap(self,value):
self.slotPenWidth(value)
def slotPenJoin(self,value):
self.slotPenWidth(value)
def slotPenColor(self):
color = QColorDialog.getColor(Qt.blue)
self.penColorFrame.setPalette(QPalette(color))
self.area.setPen(QPen(color))
def slotBrushColor(self):
color = QColorDialog.getColor(Qt.blue)
self.brushColorFrame.setPalette(QPalette(color))
self.slotBrush(self.brushStyleComboBox.currentIndex())
def slotBrush(self,value):
color = self.brushColorFrame.palette().color(QPalette.Window)
style = Qt.BrushStyle(self.brushStyleComboBox.itemData(value,Qt.UserRole))
if(style == Qt.Lin
Ⅸ 如何用python在正方形中畫圓
來畫出一個正方形,然後通過旋轉3°後,繼續畫一樣的正方形,在通過120次循環後就實現了完整的圓,這里當然也可以用其他的角度和次數,只要能完成360度就可以了。
Ⅹ python怎麼用turtle畫圓
turtle.circle ()
Turtle庫是Python語言中一個很流行的繪制圖像的函數庫,想像一個小烏龜,在一個橫軸為x、縱軸為y的坐標系原點,(0,0)位置開始,它根據一組函數指令的控制,在這個平面坐標系中移動,從而在它爬行的路徑上繪制了圖形。