Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UseJPEGImageEncoder()
- #Window1 = 0
- #Image1 = 0
- #ImgGadget = 0
- #NUM_PARTICLES = 8000
- #width = 800
- #height = 800
- #xmax = #width -3
- #ymax = #height -3
- Define.i Event ,i ,x,y
- Declare Draw_Image(*Value)
- If OpenWindow(#Window1, 0, 0, #width, #height, "Brownian Tree PureBasic Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
- If CreateImage(#Image1, #width, #height)
- ; --- Off
- ;ImageGadget(#ImgGadget, 0, 0, #width, #height, ImageID(#Image1))
- StartDrawing(ImageOutput(#Image1))
- FrontColor($FFFFFF)
- Plot( #xmax/2 , #ymax/2)
- StopDrawing()
- ; --- Off
- ; SetGadgetState(#ImgGadget, ImageID(#Image1))
- CreateThread(@Draw_Image(), *Value)
- EndIf
- Repeat
- Event = WaitWindowEvent()
- Until Event = #PB_Event_CloseWindow
- ; --- Save and display result file.
- SetCurrentDirectory(GetTemporaryDirectory())
- File_Name.s = "BROWNIAN_"+FormatDate("%yyyy%mm%dd_%hh%ii%ss", Date())+".jpg"
- SaveImage(0, File_Name, #PB_ImagePlugin_JPEG, 9)
- RunProgram(File_Name)
- EndIf
- Procedure Draw_Image(*Value)
- For i = 1 To #NUM_PARTICLES
- SetWindowTitle(#Window1, "Loop: " + Str(i) + "/" + Str(#NUM_PARTICLES) + " (Close before end if you want)")
- x = Random(#xmax)+1 : y = Random (#ymax)+1
- StartDrawing(ImageOutput(#Image1))
- While Point(x+1, y+1) + Point(x, y+1)+Point(x+1, y)+Point(x-1, y-1)+Point(x-1, y)+Point(x, y-1)+Point(x+1,y-1)+Point(x-1,y+1) = 0
- x = x + (Random(2)-1) : y = y + (Random(2)-1)
- If x < 1 Or x > #xmax Or y < 1 Or y > #ymax
- x = Random(#xmax)+1 : y = Random (#ymax)+1
- EndIf
- Wend
- Plot(x,y)
- StopDrawing()
- ; --- Off
- ;SetGadgetState(#ImgGadget, ImageID(#Image1))
- Next
- EndProcedure
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement