Еще одно тормознутое изобретение. Жаль, раскраска в цвет не получилась:
Procedure.i IsPrime(myNum.q)
Protected x.q
If myNum <= 3
ProcedureReturn Bool(myNum > 1)
EndIf
If (Mod(myNum, 2) = 0) Or (Mod(myNum, 3) = 0)
ProcedureReturn 0
EndIf
x = 5
While x * x <= myNum
If (Mod(myNum,x) = 0) Or (Mod(myNum,(x + 2)) = 0)
ProcedureReturn 0
EndIf
x = x + 6
Wend
ProcedureReturn 1
EndProcedure
If InitSprite() And OpenWindow(0,0,0,640,480,"SineWave",#PB_Window_SystemMenu) And OpenWindowedScreen(WindowID(0),0,0,640,480,0,0,0)
; Repeat
StartDrawing(ScreenOutput())
For y=0 To 479
For x=0 To 639
v=x!y
If isprime(v)
col=$FFFFFF
Else
col=0
EndIf
Box(x,y,1,1,col)
Next x
Next y
StopDrawing()
FlipBuffers()
Repeat
Until WindowEvent()=#PB_Event_CloseWindow
EndIf
Protected x.q
If myNum <= 3
ProcedureReturn Bool(myNum > 1)
EndIf
If (Mod(myNum, 2) = 0) Or (Mod(myNum, 3) = 0)
ProcedureReturn 0
EndIf
x = 5
While x * x <= myNum
If (Mod(myNum,x) = 0) Or (Mod(myNum,(x + 2)) = 0)
ProcedureReturn 0
EndIf
x = x + 6
Wend
ProcedureReturn 1
EndProcedure
If InitSprite() And OpenWindow(0,0,0,640,480,"SineWave",#PB_Window_SystemMenu) And OpenWindowedScreen(WindowID(0),0,0,640,480,0,0,0)
; Repeat
StartDrawing(ScreenOutput())
For y=0 To 479
For x=0 To 639
v=x!y
If isprime(v)
col=$FFFFFF
Else
col=0
EndIf
Box(x,y,1,1,col)
Next x
Next y
StopDrawing()
FlipBuffers()
Repeat
Until WindowEvent()=#PB_Event_CloseWindow
EndIf
Комментарии
Отправить комментарий