page_title: DrGeo
section_title: Sierpinski triangle
hierarchical_section_title: DrGeo / Programming / Pharo sketch / Sierpinski triangle
caption_attribution_description: English: An interactive Sierpinksi triangle computed by Dr. Geo software
context_page_description: GNU Dr. Geo is interactive geometry software that allows its users to design & manipulate interactive geometric sketches. It is free software, created by Hilaire Fernandes, it is part of the GNU project.
  It runs over a Morphic graphic system. Current version of Dr. Geo is also called Dr. Geo II. Historically Dr. Geo was developed in C++ and Dr. Geo II is a complete rewrite using Pharo that happened in 2005.
context_section_description: Here is how to program a Sierpinski triangle recursively:
  | triangle c |c := DrGeoSketch new.triangle := [].triangle := [:s1 :s2 :s3 :n |
      c segment: s1 to: s2; segment: s2 to: s3; segment: s3 to: s1.
      n >0 ifTrue: [
          triangle
              value: s1
              value: (c middleOf: s1 and: s2) hide
              value: (c middleOf: s1 and: s3) hide
              value: n-1.
          triangle
              value: (c middleOf: s1 and: s2) hide
              value: s2
              value: (c middleOf: s2 and: s3) hide
              value: n-1.
          triangle
              value: (c middleOf: s1 and: s3) hide
              value: (c middleOf: s2 and: s3) hide
              value: s3
              value: n-1.]].triangle value: 0@3 value:  4@ -3 value: -4@ -3 value: 3.
  (c point: 0@3) show
caption: Computed interactive Sierpinski triangle
exif: {}