From d28bcb8a0264b62c5d873c2c78f3ec537d5e8970 Mon Sep 17 00:00:00 2001 From: Mak Sim <130763512+mak8kammerer@users.noreply.github.com> Date: Sat, 6 Apr 2024 12:58:28 +0300 Subject: [PATCH] Add example for `Smooth*` graphics instructions (#8545) * Create antialiasing.py Add example * Add description * Fix typos * Fix typo --- examples/canvas/antialiasing.py | 84 +++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 examples/canvas/antialiasing.py diff --git a/examples/canvas/antialiasing.py b/examples/canvas/antialiasing.py new file mode 100644 index 000000000..67e1afa39 --- /dev/null +++ b/examples/canvas/antialiasing.py @@ -0,0 +1,84 @@ +''' +Antialiasing Example +==================== + +Kivy 2.3.0 introduced several vertex instructions with antialiasing: +SmoothRectangle, SmoothEllipse, SmoothRoundedRectangle, SmoothQuad and +SmoothTriangle. This demo script shows the difference between 'standard' +(non-antialiased) and antialiased graphics. + +''' + +from kivy.app import App +from kivy.lang import Builder + +kv = ''' +GridLayout: + rows: 6 + columns: 2 + spacing: [2] + Label: + height: '50sp' + size_hint_y: None + font_size: '25sp' + text: "Standard" + Label: + height: '50sp' + size_hint_y: None + font_size: '25sp' + text: "Antialiased" + Widget: + canvas: + Color: + rgb: 1.0, 0.0, 0.0 + RoundedRectangle: + pos: self.pos + size: self.size + segments: 50 + radius: [(200, 200), (100, 50), (250, 250),(100, 250),] + Widget: + canvas: + SmoothRoundedRectangle: + pos: self.pos + size: self.size + segments: 50 + radius: [(200, 200), (100, 50), (250, 250),(100, 250),] + Widget: + canvas: + Color: + rgb: 0.0, 1.0, 0.0 + Triangle: + points: [self.x, self.y + self.height, self.x + self.width, \ + self.y + self.height / 2, self.x + 150, self.y] + Widget: + canvas: + SmoothTriangle: + points: [self.x, self.y + self.height, self.x + self.width, \ + self.y + self.height / 2, self.x + 150, self.y] + Widget: + canvas: + Color: + rgb: 0.0, 0.0, 1.0 + Ellipse: + pos: self.pos + size: self.size + angle_start: 20 + angle_end: 300 + Widget: + canvas: + SmoothEllipse: + pos: self.pos + size: self.size + angle_start: 20 + angle_end: 300 +''' + + +class AntialiasDemoApp(App): + + def build(self): + return Builder.load_string(kv) + + +if __name__ == '__main__': + AntialiasDemoApp().run()