How to generate random 2D geometry with random color when release button in Kivy?

I would like to make an app that could generate random 2D geometry (like circle rectangle…) and fill with random color. I don’t know how complex or hard this project would be and as for now I could only figure out how to make my app create a rectangle ( my random color is only activate when re-run the code and not when press button ).

Here is the .py file

#test.py
from kivy.app import App
from kivy.uix.scatter import Scatter
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.properties import ListProperty
from random import random

class Scatterer(Scatter):
    color = ListProperty([random() for i in range (3)] + [1])

class MainWindowWidget(FloatLayout):

    def addfunction(self, *args):

        s = Scatterer()
        self.add_widget(s)

class TestApp(App):
    def build(self):
        return MainWindowWidget()

if __name__ == '__main__':
    TestApp().run()

and .kv file

#:kivy 2.0
#test.kv

<MainWindowWidget>

    Button:
        text: 'Hit me'
        size_hint: None, None
        size: 100, 100
        pos: 350, 250

        on_release: root.addfunction()

<Scatterer>:
    size_hint: None, None
    size: self.size

    canvas.after:
        Color:
            rgba: self.color
        Rectangle:
            size: self.size
            pos: self.pos

Answer

To set a random color every time, you have to assign it when you create the scatter:

# test.py
from kivy.app import App
from kivy.uix.scatter import Scatter
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ColorProperty
from random import random


class Scatterer(Scatter):
    color = ColorProperty()

    def __init__(self, w, h):
        super(Scatterer, self).__init__()
        self.color = [random() for i in range(3)] + [1]  # <<<<
        self.pos = w * random(), h * random()


class MainWindowWidget(FloatLayout):

    def addfunction(self, *args):
        w, h = self.get_parent_window().size
        s = Scatterer(w, h)
        self.add_widget(s)


class TestApp(App):
    def build(self):
        return MainWindowWidget()


if __name__ == '__main__':
    TestApp().run()

#:kivy 2.0
#test.kv

<MainWindowWidget>

    Button:
        text: 'Hit me'
        size_hint: None, None
        size: 100, 100
        pos: 350, 250

        on_release: root.addfunction()

<Scatterer>:
    size_hint: None, None
    size: self.size

    canvas.after:
        Color:
            rgba: root.color
        Rectangle:
            size: self.size
            pos: self.pos

For the stuff to draw, there are ellipses, rectangles, lines… you can find them all here: Kivy docs (graphics)