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> |
<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 |
|||
Until is_inrange(x,y) |
|||
R.f=Sqr(x*x+y*y) |
|||
Until 10<=R And R<=15 |
|||
⚫ | |||
Plot(x+15,y+15,#Red) |
|||
⚫ | |||
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, |
ImageGadget(0,0,0,ImageWidth(0),ImageHeight(0),ImageID(0)) |
||
Repeat: |
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]] |
||