在Kivy中逐个显示小部件,在Python中显示叶序

2024-10-03 00:20:09 发布

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

我做了叶序效应。你知道吗

工作原理如下:

  1. 循环整个循环(即15000次迭代)。你知道吗
  2. 做计算。你知道吗
  3. 得到X和Y的值
  4. 使用步骤1中计算的值打印所有点(椭圆)。你知道吗

我想要达到的目标。你知道吗

  1. 循环一次。你知道吗
  2. 对第1点进行计算。你知道吗
  3. 得到X和Y的值
  4. 使用一次迭代中的值X和Y打印点。你知道吗

N步。第N个循环。你知道吗

N+1步。对N点进行计算

N+2步。得到X和Y的值

N+3步。使用一次迭代中的值X和Y打印点。你知道吗

这是我的密码:

from kivy.graphics import *
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ListProperty, ObjectProperty
from kivy.graphics.vertex_instructions import (Rectangle, Ellipse, Line
import math

n = 0
c = 5
class PhyllotaxiswApp(App):
    def build(self):
        return boxOustide()
class boxOustide(BoxLayout):
    def __init__(self):
        super(boxOustide, self).__init__()
        with self.canvas:
            global n
            global c
            window_center_x = self.get_center_x() * 8
            window_center_y = self.get_center_y() * 6
            post = c * 3500
            for i in range(15200):
                a = n * 137.3
                r = c * math.sqrt(n)
                x = r * math.cos(a) + window_center_x
                y = r * math.sin(a) + window_center_y
                Color(n % .999, .999, .999, mode='hsv')
                Ellipse(pos=(x, y), size=(5, 5))
                n += 1
if __name__ == "__main__":
    PhyllotaxiswApp().run()

编辑1

好吧,在我发现这个之后,现在有一扇巨大的窗户为我打开了:

Clock.schedule_interval(class.function,1 / 60)

Tags: fromimportselfappdefmathwindowclass