Duffings

Post Reply
DrChip
Posts: 167
Joined: Wed Oct 22, 2014 3:26 pm
My devices: iPhone 4 to 6+,iPad mini to iPad air 2

Duffings

Post 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
Attachments
image.jpg
image.jpg (242.44 KiB) Viewed 2141 times
image.jpg
image.jpg (247.38 KiB) Viewed 2141 times

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: Duffings

Post by Dav »

Pretty cool!
I like your demos.

- Dav

User avatar
dE.niz
Posts: 17
Joined: Tue Jan 27, 2015 10:35 am
My devices: Ipad 2 / iphone 4s / macbook / imac .
Location: Belgium
Flag: Belgium

Re: Duffings

Post by dE.niz »

Amazing !!!


dE.niz

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Duffings

Post 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

Post Reply