我对Processing很新,但我已经设法在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)
我遇到的第一个问题是原点,(0,0)在JS的左上角,但在数学中它应该在左下角...我做的是旋转画布
rotate(-45);
负45度然后,我将画布翻译到左下角
translate(-83,200);
。然后我画了一些线和抛物线。功能......
var f = function(c){
var v = c*2;
stroke(255, 255, 255);
strokeWeight(3);
line(0,0,v,c);
noStroke();
fill(255, 255, 255);
textSize(20);
pushMatrix();
rotate(90);
text("v=2c",120,-203);
popMatrix();
};// v=2c
var v = function(c){
var v = c;
stroke(0, 255, 4);
strokeWeight(3);
line(0,0,v,c);
noStroke();
fill(9, 255, 0);
textSize(20);
pushMatrix();
rotate(90);
text("v=c",98,-75);
popMatrix();
};//v=c
var e = function(c){
var dependant = 60;
var v = 2*c+dependant;
stroke(255, 136, 0);
strokeWeight(3);
line(dependant,0,v,c);
noStroke();
fill(255, 136, 0);
textSize(20);
pushMatrix();
rotate(90);
text("v = 2*c+dependant*\n *=origin point",11,-380);
popMatrix();
};v=2*c+dependant (in most cases the dependant point is 0,0 but here it is 0,60)
var c = function(c){
while(c<=400) {
fill(255, 0, 221);
ellipse((sq(c)/width),c, 3, 3);
c+=0.5;
}
fill(255, 0, 255);
textSize(20);
pushMatrix();
rotate(90);
text("y=x^2",289,-205);
popMatrix();
};//parabola | y=x^2 | ellipse((sq(c)/width),c, 3, 3);
`
如果您有更多问题或需要澄清,请询问。
在此处观看演示 https://www.khanacademy.org/computer-programming/graphing-with-functions/5021275506900992
修改强> 另外,你有问题的背景刷新和掩盖你的图形,你是一个for循环或一个while循环......