我对处理相当陌生,但我已经设法在Python模式下制作了大量的GUI。我想在一个白盒子上画一些数据。我不想使用background(0)
,因为那样会使整个窗口变白。在draw()
函数中使用矩形也没有帮助,因为矩形一直在刷新图形。我试图在MATLAB中模拟hold on
函数
下面是我的伪代码:
class plotEverything:
def __init__
def plotAxis
def plotGraph
def clearGraph
def setup():
size (800,600)
p1 = plotEverything()
background(0)
def draw():
rect (100,100,200,200)
fill(255)
p1.drawAxis()
p1.plotGraph()
有没有办法把那个矩形固定在背景上?你知道吗
编辑添加的图形类|忽略缩进(假设它们都正确缩进)--
class graphData:
def __init__(self, originX, originY, xUpper, yUpper):
self.originX = originX
self.originY = originY
self.xUpper = xUpper
self.yUpper = yUpper
self.pointX1 = originX
self.pointX2 = xUpper
self.pointY1 = originY
self.pointY2 = yUpper
self.scaleFactorX = 10.0/(xUpper - originX) #Assuming data is between is 0 and 10
self.scaleFactorY = 10.0/(originY - yUpper) #Assuming data is between is 0 and 1
def drawAxis(self):
stroke(255)
strokeWeight(1.5)
line(self.originX, self.originY, self.originX, self.yUpper) #y axis
line(self.originX, self.originY, self.xUpper, self.originY) #x axis
def plotStaticData(self,data2Plot): #X-axis static
ab = zip(data2Plot,data2Plot[1:],data2Plot[2:],data2Plot[3:])[::2]
if ab:
(X1,Y1,X2,Y2) = ab[-1]
print (X1,Y1,X2,Y2)
self.pointX1 = self.originX + ceil((float(X1) - 0.0)/self.scaleFactorX)
self.pointX2 = self.originX + ceil((float(X2) - 0.0)/self.scaleFactorX)
self.pointY1 = self.originY - ceil((float(Y1) - 0.0)/self.scaleFactorY)
self.pointY2 = self.originY - ceil((float(Y2) - 0.0)/self.scaleFactorY)
stroke(255)
strokeWeight(2.0)
line(self.pointX1,self.pointY1,self.pointX2,self.pointY2)
def clearPlot(self):
background(0)
self.drawAxis()
我遇到的第一个问题是原点,(0,0),在JS中它在左上角,但在数学中它应该在左下角。。。我做的是旋转画布
负45度,然后,我把画布翻译到左下角
是的。然后我画了几条线和一条抛物线。使用函数。。。你知道吗
如果您有更多的问题或想要一些澄清,请问。你知道吗
在此处查看演示https://www.khanacademy.org/computer-programming/graphing-with-functions/5021275506900992
编辑 另外,你的问题与背景刷新和掩盖你的图形,你的for循环或while循环。。。你知道吗
相关问题 更多 >
编程相关推荐