Textured circles - issues

Just starting out? Need help? Post your questions and find answers here.
firace
Addict
Addict
Posts: 899
Joined: Wed Nov 09, 2011 8:58 am

Textured circles - issues

Post by firace »

In the below example, I'm trying to make new circles appear "textured", just like the 3 initial ones.
Thanks for any help.

Also, is the approach I am using reasonably efficient ? Although the code is already fast enough for me, I would be interested in possible optimizations.

EDIT: minor changes to the code for clarification

Code: Select all


UseJPEGImageDecoder()

CSize = 600

LoadImage(0, #PB_Compiler_Home + "\Examples\3D\Data\Textures\dirt.jpg")  
ResizeImage(0,1000,1000)

OpenWindow(0, 0, 0, CSize, CSize, "Mask demo", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
;
CreateImage(1, CSize , CSize, 32)

StartDrawing(ImageOutput(1))

Box(0,0,1000,1000,$FFFFFFFF)      
Circle( 300,300,40, RGBA(255,  0,   255, 255))
Circle( 200,200,40, RGBA(255,  255,   0, 255))
Circle( 100,200,40, RGBA(0  ,  0,   255, 255))

DrawAlphaImage(ImageID(0),25,25,230)

DrawingMode(#PB_2DDrawing_Outlined)
Circle( 300,300,40, RGBA(0,0,0, 255))
Circle( 200,200,40, RGBA(0,0,0, 255))
Circle( 100,200,40, RGBA(0,0,0, 255))

FillArea(0,0,0,0)

StopDrawing()

ImageGadget(0, 0, 0, CSize, CSize, ImageID(1))

AddWindowTimer(0, 1, 200)

Repeat
  e = WaitWindowEvent()
  Select e
    Case  #PB_Event_Timer
      
      StartDrawing(ImageOutput(1))
      newPositionX = Random(CSize)      
      newPositionY = Random(CSize)      
      newSize = Random(20)
      
      Circle( newPositionX, newPositionY, newSize, RGBA(Random(255),  Random(255),   Random(255), 255))
      ;    DrawAlphaImage(ImageID(0),25,25,200)
      
      DrawingMode(#PB_2DDrawing_Outlined)
      Circle( newPositionX, newPositionY, newSize, RGBA(0,0,0, 255))
      FillArea(0,0,0,0)
      StopDrawing()
      
      SetGadgetState(0, ImageID(1))
      
    Case  #PB_Event_CloseWindow : End
  EndSelect
ForEver

User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 285
Joined: Thu Jul 09, 2015 9:07 am

Re: Textured circles - issues

Post by pf shadoko »

for this you have to use vectordrawing lib

Code: Select all

OpenWindow(0, 0, 0, 800, 600, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 800, 600)

UseJPEGImageDecoder()
LoadImage(0, #PB_Compiler_Home + "\Examples\3D\Data\Textures\dirt.jpg")  

StartVectorDrawing(CanvasVectorOutput(0))

For i=0 To 20
	AddPathCircle(Random(800), Random(600),Random(200))
	VectorSourceImage(ImageID(0), 255, ImageWidth(0), ImageHeight(0), #PB_VectorImage_Repeat)
	FillPath(#PB_Path_Preserve)
	VectorSourceColor($77000000|Random($ffffff))
	FillPath()
Next

StopVectorDrawing()

Repeat
	Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
firace
Addict
Addict
Posts: 899
Joined: Wed Nov 09, 2011 8:58 am

Re: Textured circles - issues

Post by firace »

Awesome, thank you pf shadoko.
Post Reply