Some superformula fun!
Code: Select all
;*******************************************************************************
;*
;* July-August 2014 PurePunch contest
;* PureBasic 5.22
;* 50 lines of 80 chars, 2 months delay
;*
;* Name : Superformula
;* Author : NicTheQuick
;* Date : 13.07.2014
;* Notes : Only tested on PB 5.30 b7 on Linux x64!
;* You can also resize the window.
;* l defines the precision of the line and it must not less than 20.
;* Used Variables: abcdefghijklmnopqrstuvwxyz
;* ^^^^^^^^^^^^^^^^ ^M^^^^^^^
;*******************************************************************************
l=1000:w=600:h=600:Define.d a,b,c,d,e,j,k,n,o,p,r,t,x,y,z:OpenWindow(0,0,0,w,
h,"Superformula",#PB_Window_MaximizeGadget):CanvasGadget(0,0,0,w,h):Macro s(a)
Sin(t*a):EndMacro:Repeat:v=WaitWindowEvent(9):f=WindowWidth(0):g=WindowHeight(0)
t=ElapsedMilliseconds():If f!w|g!h:w=f:h=g:ResizeGadget(0,0,0,w,h):ElseIf t>u+20
StartDrawing(CanvasOutput(0)):u=t:t/5000:m=2+2*Int(t)%20:t/2:d=9+9*s(3):e=9*s(5+
0)+9:c=10+9*s(2):a=Abs(s(7)*0.6)+0.1:b=Abs(s(11)*0.6)+0.1:y=Cos(t*9):x=100*s(1)+
150:GrabDrawingImage(0,0,0,w,h):DrawingMode(#PB_2DDrawing_Gradient):j=w/2*(1+y)
DrawAlphaImage(ImageID(0),w*y/x,h*s(9)/x,150):k=h/2*(1+s(9)):LinearGradient(j,k,
w-j,h-k):BackColor(RGB(127*(1+s(7)),127*(1+s(11)),127*(1+s(13)))):FrontColor(0+
RGB(127*(1+s(2)),127*(1+s(3)),127*(1+s(5)))):For i=0 To l:r=i*2*#PI/l:p+s(1+
0)/30000:z=Pow(Pow(Abs(Cos(m*r/4)/a),d)+Pow(Abs(Sin(m*r/4)/b),e),1/c):x=w/2*(1+
Cos(r+p)/z):y=h/2*(1+Sin(r+p)/z):If i:LineXY(n,o,x,y):EndIf:n=x:o=y:Circle(x,y,
Bool(i%(l/20)=0)*w/50/z):Next:StopDrawing():EndIf:Until v=#PB_Event_CloseWindow
Edit: Some bugfixes
Edit2: Better effects
Edit3: Shortened to 19 lines of code
Edit4: Shortened to 17 lines of code and better "randomness"
Edit5: Should now run on Windows
Edit6: Minor bugfix for the rotation speed
Edit7: Shrinked to 13 lines of code. Now EnabledExplicit will not work.
Edit8: Circles added. l defines the precision of the line and it must not less than 20.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.