PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/IronPython_Main/Languages/IronPython/Samples/BadPaint/demo_snippets.py

#
Python | 61 lines | 20 code | 8 blank | 33 comment | 2 complexity | 53d39668e6a99824f676f12007b7f414 MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  1. #####################################################################################
  2. #
  3. # Copyright (c) Microsoft Corporation. All rights reserved.
  4. #
  5. # This source code is subject to terms and conditions of the Apache License, Version 2.0. A
  6. # copy of the license can be found in the License.html file at the root of this distribution. If
  7. # you cannot locate the Apache License, Version 2.0, please send an email to
  8. # ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. # by the terms of the Apache License, Version 2.0.
  10. #
  11. # You must not remove this notice, or any other, from this software.
  12. #
  13. #
  14. #####################################################################################
  15. #------------------------------------------------------------------------------
  16. #--INSERTS RANDOM SQUARES
  17. from System.Windows.Controls import Canvas
  18. from System.Windows.Shapes import *
  19. from System.Windows.Media import *
  20. from System import Random
  21. rand = Random()
  22. for i in xrange(100):
  23. rect = Rectangle(Width=20, Height=20, Fill=Brushes.Blue)
  24. Application.Painting.Children.Add(rect)
  25. Canvas.SetLeft(rect, rand.Next(Application.Painting.ActualWidth))
  26. Canvas.SetTop(rect, rand.Next(Application.Painting.ActualHeight))
  27. #------------------------------------------------------------------------------
  28. #--INSERT A CIRCLE CONSISTING OF SQUARES OF DIFFERENT COLORS
  29. # setup circle
  30. from System.Windows.Controls import Canvas
  31. from System.Windows.Shapes import *
  32. from System.Windows.Media import *
  33. import math
  34. dim = min(Application.Painting.ActualWidth - 20, Application.Painting.ActualHeight - 20)/2
  35. for i, color in zip(xrange(0, 360, 10), dir(Brushes)):
  36. rect = Rectangle(Width=20, Height=20, Fill=getattr(Brushes, color))
  37. Application.Painting.Children.Add(rect)
  38. Canvas.SetTop(rect, dim * math.sin(i * math.pi*2/360) + dim)
  39. Canvas.SetLeft(rect, dim * math.cos(i * math.pi*2/360)+ dim)
  40. #--IRONRUBY CODE TO SPIN THE CIRCLE ABOVE
  41. # rotate
  42. #Canvas = System::Windows::Controls::Canvas
  43. #def callback
  44. # self.application.painting.children.each do |child|
  45. # top, left = Canvas.get_top(child), Canvas.get_left(child)
  46. # run = (left - dim) / dim
  47. # rise = (top - dim) / dim
  48. # angle = Math.atan2 rise, run
  49. # angle += Math::PI / 100
  50. # Canvas.set_top child, dim * Math.sin(angle) + dim
  51. # Canvas.set_left child, dim * Math.cos(angle)+ dim
  52. # end
  53. #end