Draw fractal star
Draw fractal star recursively using the algorithm in the book by Robert Sedgewick 'Algorithms in C++'
AI
Yapay Zeka Özeti: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Kaynak Kod
'From the book by Robert Sedgewick 'Algorithms in C++' 'It is a very useful book. Can you find a non recursive way of doing this? 'Recursion makes progs smaller and elegant whilst also making them 'more difficult to understand ( the implicit stack and unwinding of the calls) Private Sub Form_Load() Form1.WindowState = 2 'maximum Form1.ScaleMode = 3 'pixel Show Call star(ScaleWidth \ 2, ScaleHeight \ 2, 90) End Sub Private Sub star(x As Integer, y As Integer, r As Integer) If r > 1 Then Call star(x - r, y + r, r \ 2) Call star(x + r, y + r, r \ 2) Call star(x - r, y - r, r \ 2) Call star(x + r, y - r, r \ 2) Call box(x, y, r) End If End Sub Private Sub box(x1 As Integer, y1 As Integer, r1 As Integer) Line (x1 - r1, y1 - r1)-(x1 + r1, y1 + r1), , B 'Form1.Circle (x1 - r1, y1 - r1), r1 'Line (x1 - r1, y1 - r1)-(x1 + r1, y1 - r1), , B 'Line -(x1 - (r1 \ 2), y1 + r1) 'Line -(x1 - r1, y1 - r1) 'trying to draw triangle instead of sqr- not work accurately End Sub
Orijinal Yorumlar (3)
Wayback Machine'den kurtarıldı