SHARE
TWEET

Untitled

a guest Sep 30th, 2018 128 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. UseJPEGImageEncoder()
  2.  
  3. #Window1   = 0
  4. #Image1    = 0
  5. #ImgGadget = 0
  6.  
  7. #NUM_PARTICLES = 8000
  8. #width         = 800
  9. #height        = 800
  10. #xmax          = #width  -3
  11. #ymax          = #height -3
  12. Define.i Event ,i ,x,y
  13.  
  14. Declare Draw_Image(*Value)
  15.  
  16. If OpenWindow(#Window1, 0, 0, #width, #height, "Brownian Tree PureBasic Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
  17.      If CreateImage(#Image1, #width, #height)
  18.           ; --- Off
  19.           ;ImageGadget(#ImgGadget, 0, 0, #width, #height, ImageID(#Image1))
  20.           StartDrawing(ImageOutput(#Image1))
  21.           FrontColor($FFFFFF)
  22.           Plot( #xmax/2 , #ymax/2)
  23.           StopDrawing()
  24.           ; --- Off
  25.           ; SetGadgetState(#ImgGadget, ImageID(#Image1))
  26.           CreateThread(@Draw_Image(), *Value)
  27.      EndIf
  28.      Repeat
  29.           Event = WaitWindowEvent()
  30.      Until Event = #PB_Event_CloseWindow
  31.      
  32.      ; --- Save and display result file.
  33.      SetCurrentDirectory(GetTemporaryDirectory())
  34.      File_Name.s = "BROWNIAN_"+FormatDate("%yyyy%mm%dd_%hh%ii%ss", Date())+".jpg"
  35.      SaveImage(0, File_Name, #PB_ImagePlugin_JPEG, 9)
  36.      RunProgram(File_Name)
  37. EndIf
  38.  
  39.  
  40. Procedure Draw_Image(*Value)
  41.      For i = 1 To #NUM_PARTICLES
  42.           SetWindowTitle(#Window1, "Loop: " + Str(i) + "/" + Str(#NUM_PARTICLES) + " (Close before end if you want)")
  43.           x = Random(#xmax)+1 : y = Random (#ymax)+1
  44.           StartDrawing(ImageOutput(#Image1))
  45.           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
  46.                x = x + (Random(2)-1) : y = y + (Random(2)-1)
  47.                If x < 1 Or x > #xmax Or y < 1 Or y > #ymax
  48.                     x = Random(#xmax)+1 : y = Random (#ymax)+1
  49.                EndIf  
  50.           Wend
  51.           Plot(x,y)
  52.           StopDrawing()
  53.           ; --- Off
  54.           ;SetGadgetState(#ImgGadget, ImageID(#Image1))        
  55.      Next
  56. EndProcedure
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top