在处理过程中在白盒上绘制图形

2024-04-19 18:29:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我对处理相当陌生,但我已经设法在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()

Tags: selfisdeffloatbackground矩形p1ceil
1条回答
网友
1楼 · 发布于 2024-04-19 18:29:34

我遇到的第一个问题是原点,(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循环。。。你知道吗

相关问题 更多 >