Page 1 of 1

Duffings

Posted: Tue Feb 10, 2015 1:43 am
by DrChip
rem Duffings Oscillator
rem iPhone 6 plus / iOS 8.2 b5

graphics

pi=3.141592653589793

graphics clear 0,0,0

x=1.0
y=0.0
t=0.0
a=0.3
twopi=2.0*pi
k1=0

do
k1=k1+1
x1=x+y/twopi
y1=y+(-(x*x*x)+x-0.25*y+a*cos(t))/twopi
t=0.01*(k1%628)
x=x1
y=y1
if t>pi then
cl=1
gosub drawball
else
cl=128/255
gosub drawball
end if
until 1=0

'draws a shiny ball
drawball:
xd=x
yd=y
c=cl
k=7

i1=150*x+screen_width()/2
j1=-88*y+screen_height()/2

for i=127 to 255 step 16
c=0.09*(7-k)
fill color c1,i/255,i/255
fill circle i1+c,j1+c size k
k=k-1
next i
return

Re: Duffings

Posted: Tue Feb 10, 2015 3:21 am
by Dav
Pretty cool!
I like your demos.

- Dav

Re: Duffings

Posted: Tue Feb 10, 2015 7:55 am
by dE.niz
Amazing !!!


dE.niz

Re: Duffings

Posted: Tue Feb 10, 2015 9:30 am
by Mr. Kibernetik
Very interesting!

I made a modification: added color, changed speed, adapted for any screen:

Code: Select all

rem Duffings Oscillator by DrChip
rem color by Mr.K

graphics
refresh off

pi=3.141592653589793
twopi=2.0*pi
x=1.0
y=0.0
t=0.0
a=0.3
k1=0
centx=screen_width()/2
centy=screen_height()/2
maxk=min(centx,centy)/50
cd=0.005
cdr=-cd!cdg=cd!cdb=-cd
cr=2!cg=0!cb=0

do
k1+=1
x1=x+y/twopi
y1=y+(-(x*x*x)+x-0.25*y+a*cos(t))/twopi
t=0.01*(k1%628)
x=x1
y=y1

cr+=cdr!if cr<=-1 or cr>=2 then cdr=-cdr
cg+=cdg!if cg<=-1 or cg>=2 then cdg=-cdg
cb+=cdb!if cb<=-1 or cb>=2 then cdb=-cdb
gosub drawball 
until forever

'draws a shiny ball
drawball: 
xd=x
yd=y

i1=centx/2*x+centx
j1=-centy/4*y+centy

for k=maxk to 1 step -1
s=0.09*(maxk-k)
c=(maxk-k)/maxk
fill color c*cr,c*cg,c*cb
fill circle i1+s,j1+s size k
next k
refresh
return
Image