Constrained random points on a circle: Difference between revisions

Content added Content deleted
No edit summary
m (→‎{{header|PureBasic}}: Optimized the code a little)
Line 314: Line 314:


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang PureBasic>Procedure is_inrange(x,y,minlimit.f=10,maxlimit.f=15)
<lang PureBasic>CreateImage(0,31,31)
Protected.f z=Sqr(x*x+y*y)
If minlimit<=z And z <=maxlimit
ProcedureReturn 1
EndIf
EndProcedure

CreateImage(0,31,31)
StartDrawing(ImageOutput(0))
StartDrawing(ImageOutput(0))
For i=1 To 100
For i=1 To 100
Repeat
Repeat
x=Random(30)-15: y=Random(30)-15
x=Random(30)-15
y=Random(30)-15
Until is_inrange(x,y)
Plot(x+15,y+15,$0000FF)
R.f=Sqr(x*x+y*y)
Until 10<=R And R<=15
Next
Plot(x+15,y+15,#Red)
Next
StopDrawing()
StopDrawing()


Line 334: Line 329:
Flags=#PB_Window_SystemMenu
Flags=#PB_Window_SystemMenu
OpenWindow(0,#PB_Ignore,#PB_Ignore,ImageWidth(0),ImageHeight(0),Title$,Flags)
OpenWindow(0,#PB_Ignore,#PB_Ignore,ImageWidth(0),ImageHeight(0),Title$,Flags)
ImageGadget(0,0,0,30,30,ImageID(0))
ImageGadget(0,0,0,ImageWidth(0),ImageHeight(0),ImageID(0))
Repeat: Event=WaitWindowEvent()
Repeat: Until WaitWindowEvent()=#PB_Event_CloseWindow</lang>
Until Event=#PB_Event_CloseWindow</lang>
[[File:PureBasic_Circle_plot.png‎|155px]]
[[File:PureBasic_Circle_plot.png‎|155px]]