VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Draw fractal star

by oigres P (12 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

Draw fractal star recursively using the algorithm in the book by Robert Sedgewick 'Algorithms in C++'

Inputs
change r to have a denser or lighter pattern . 2..5 okay
Assumes
assume 800x600 screen res
Code Returns
Draws squares using lines 'b' style.
Side Effects
lower values of r increase the time to draw

Rate Draw fractal star

'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

Download this snippet    Add to My Saved Code

Draw fractal star Comments

No comments have been posted about Draw fractal star. Why not be the first to post a comment about Draw fractal star.

Post your comment

Subject:
Message:
0/1000 characters