Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Yabasic => Topic started by: Xone on October 26, 2008
-
rem Coil Worm v3.1 Code by Xone(c)2k8
rem ==================================
rem Note: Set the Particle Amount that
rem gives fast smooth motion for best effect.
rem USER SETTINGS Def = Default Values
rem @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
rem Primary Settings
rem ----------------------------------------------------------------------
P = 60 rem Particles
rem Colour Settings
rem ----------------------------------------------------------------------
CStat = 1 rem Colour Status (0/1)
rem 0 = Fixed RGB, 1 = Cycling RGB
rem If Fixed, set your own RGB, (0=None to 1=Full, 1+ = Gradients)
Red = 0.8 rem Red Value [0.8]Preset
Grn = 1.6 rem Green Value [1.6]Preset
Blu = 0 rem Blue Value [0]Preset
rem Draw Settings
rem ----------------------------------------------------------------------
Wide = 2 rem Path Widths, CARE!!! (0 to 5 recommended) [2]Def
WSpc = 0.3 rem Width Spacing (0.3=tight, 0.4+ =open) [0.3]Def
Wfad = 0 rem Fade the Width Out (0/1) [0]Def
rem @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Px=320:Py=256
for p = 1 to P
dim x(p,2):x(p,1)=Px:x(p,2)=Py
dim c(p,3):c(p,1)=0:c(p,2)=0:c(p,3)=0
dim s(p,2):s(p,1)=0:s(p,2)=0
next
u=0:k1=0:k2=4:k3=8:n=1:o=0
Open Window 640,512
setrgb 0,0,0,0
Label Loop
setdrawbuf Cbu: Cbu=1-Cbu
setdispbuf Cbu: clear window
if u<P u=u+1:o=o+0.011:y=y+0.008
if m<80 then m=m+1:M=m-8 fi
g=cos(o):h=sin(y):a=g*m+h*m:c=g*M-h*M:U=(n*I)+0.5:
for i = 1 to u
if i=1 then
if x(1,1)<Px+a s(1,1)=s(1,1)+0.05
if x(1,1)>Px+a s(1,1)=s(1,1)-0.05
if x(1,2)<Py+c s(1,2)=s(1,2)+0.05
if x(1,2)>Py+c s(1,2)=s(1,2)-0.05
else
O=((P-i)/200)+0.4
if x(i,1)<x(i-1,1) s(i,1)=s(i,1)+(O*(U*4))
if x(i,1)>x(i-1,1) s(i,1)=s(i,1)-(O*(U*4))
if x(i,2)<x(i-1,2) s(i,2)=s(i,2)+(O*(U*4))
if x(i,2)>x(i-1,2) s(i,2)=s(i,2)-(O*(U*4))
fi
if s(i,1)>3 s(i,1)=3: if s(i,1)<-3 s(i,1)=-3
if s(i,2)>3 s(i,2)=3: if s(i,2)<-3 s(i,2)=-3
x(i,1)=x(i,1)+(s(i,1)*0.9):x(i,2)=x(i,2)+(s(i,2)*0.9)
if i>1 then
gosub CS: setrgb 3,0,0,0
setrgb 2, c(i,1)*U,c(i,2)*U,c(i,3)*U
setrgb 1, c(i,1)*U,c(i,2)*U,c(i,3)*U
gtriangle x(i-1,1),x(i-1,2) to x(i,1),x(i,2) to Px,Py
fi
next
for i = 1 to u
s1=s(i,1):s2=s(i,2):v1=x(i,1):v2=x(i,2)
if i>1 then
gosub CS
setrgb 1,c(i,1),c(i,2),c(i,3)
line v1,v2 to x(i-1,1),x(i-1,2)
if Wide>0 then
for j = 1 to Wide
if Wfad<>0 w = 1.3-((0.8/Wide)*j)
if Wfad=0 w = 1
setrgb 1, c(i,1)*w, c(i,2)*w, c(i,3)*w
jR = (j*WSpc)
line v1-jR, v2-jR to x(i-1,1)-jR, x(i-1,2)-jR
line v1+jR, v2+jR to x(i-1,1)+jR, x(i-1,2)+jR
next
fi:fi
next
gosub R
Goto Loop
label CS
l = 220-((200/P)*(i*1.2))
if CStat<>0 then
k1=k1+(0.00002):k2=k2+(0.000026):k3=k3+(0.000034)
t=(cos(k1)+1):e=(cos(k2)+1):q=(cos(k3)+1)
c(i,1)=((l)*t)+20:c(i,2)=((l)*e)+20:c(i,3)=((l)*q)+20
else
c(i,1)=(l)*(Red*4):c(i,2)=(l)*(Grn*4):c(i,3)=(l)*(Blu*4)
fi
return
label R
for i = 1 to u
x(i,1)=x(i,1)+(a/3000)*s(i,1):x(i,2)=x(i,2)-(c/3000)*s(i,2)
if i=1 then
h = (ran(0.2)-(0.2/2))*5
x(i,1)=x(i,1)+(h*(i/10)):x(i,2)=x(i,2)+(h*(i/10))
fi
line x(i,1), x(i,2) to x(i,1), x(i,2)
next
return
A wriggly worm thing :)
A few settings available, so you can set your own colour or use the auto cycle.
A preset colour is set as an example.
Sync to PC for best result.
-
Nice effect ;D
-
Funky
-
For anyone who doesn't want to tamper with the code, here
are two other setups that you can drop into jims PS2yabasic and run instantly:
rem Coil Worm v3.1 Code by Xone(c)2k8
rem ==================================
rem Note: Set the Particle Amount that
rem gives fast smooth motion for best effect.
rem USER SETTINGS Def = Default Values
rem @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
rem Primary Settings
rem ----------------------------------------------------------------------
P = 120 rem Particles
rem Colour Settings
rem ----------------------------------------------------------------------
CStat = 0 rem Colour Status (0/1)
rem 0 = Fixed RGB, 1 = Cycling RGB
rem If Fixed, set your own RGB, (0=None to 1=Full, 1+ = Gradients)
Red = 1 rem Red Value [0.8]Preset
Grn = 0.2 rem Green Value [1.6]Preset
Blu = 0 rem Blue Value [0]Preset
rem Draw Settings
rem ----------------------------------------------------------------------
Wide = 0 rem Path Widths, CARE!!! (0 to 5 recommended) [2]Def
WSpc = 0.6 rem Width Spacing (0.3=tight, 0.4+ =open) [0.3]Def
Wfad = 1 rem Fade the Width Out (0/1) [0]Def
rem @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Px=320:Py=256
for p = 1 to P
dim x(p,2):x(p,1)=Px:x(p,2)=Py
dim c(p,3):c(p,1)=0:c(p,2)=0:c(p,3)=0
dim s(p,2):s(p,1)=0:s(p,2)=0
next
u=0:k1=0:k2=4:k3=8:n=1:o=0
Open Window 640,512
setrgb 0,0,0,0
Label Loop
setdrawbuf Cbu: Cbu=1-Cbu
setdispbuf Cbu: clear window
if u<P u=u+1:o=o+0.011:y=y+0.008
if m<80 then m=m+1:M=m-8 fi
g=cos(o):h=sin(y):a=g*m+h*m:c=g*M-h*M:U=(n*I)+0.5:
for i = 1 to u
if i=1 then
if x(1,1)<Px+a s(1,1)=s(1,1)+0.05
if x(1,1)>Px+a s(1,1)=s(1,1)-0.05
if x(1,2)<Py+c s(1,2)=s(1,2)+0.05
if x(1,2)>Py+c s(1,2)=s(1,2)-0.05
else
O=((P-i)/200)+0.4
if x(i,1)<x(i-1,1) s(i,1)=s(i,1)+(O*(U*4))
if x(i,1)>x(i-1,1) s(i,1)=s(i,1)-(O*(U*4))
if x(i,2)<x(i-1,2) s(i,2)=s(i,2)+(O*(U*4))
if x(i,2)>x(i-1,2) s(i,2)=s(i,2)-(O*(U*4))
fi
if s(i,1)>3 s(i,1)=3: if s(i,1)<-3 s(i,1)=-3
if s(i,2)>3 s(i,2)=3: if s(i,2)<-3 s(i,2)=-3
x(i,1)=x(i,1)+(s(i,1)*0.9):x(i,2)=x(i,2)+(s(i,2)*0.9)
next
for i = 1 to u
s1=s(i,1):s2=s(i,2):v1=x(i,1):v2=x(i,2)
if i>1 then
gosub CS
setrgb 1,c(i,1),c(i,2),c(i,3)
line v1,v2 to x(i-1,1),x(i-1,2)
if Wide>0 then
for j = 1 to Wide
if Wfad<>0 w = 1.3-((0.8/Wide)*j)
if Wfad=0 w = 1
setrgb 1, c(i,1)*w, c(i,2)*w, c(i,3)*w
jR = (j*WSpc)
line v1-jR, v2-jR to x(i-1,1)-jR, x(i-1,2)-jR
line v1+jR, v2+jR to x(i-1,1)+jR, x(i-1,2)+jR
next
fi:fi
next
gosub R
Goto Loop
label CS
l = 220-((200/P)*(i*1.2))
if CStat<>0 then
k1=k1+(0.00002):k2=k2+(0.000026):k3=k3+(0.000034)
t=(cos(k1)+1):e=(cos(k2)+1):q=(cos(k3)+1)
c(i,1)=((l)*t)+20:c(i,2)=((l)*e)+20:c(i,3)=((l)*q)+20
else
c(i,1)=(l)*(Red*4):c(i,2)=(l)*(Grn*4):c(i,3)=(l)*(Blu*4)
fi
return
label R
for i = 1 to u
x(i,1)=x(i,1)+(a/3000)*s(i,1):x(i,2)=x(i,2)-(c/3000)*s(i,2)
if i=1 then
h = (ran(0.2)-(0.2/2))*5
x(i,1)=x(i,1)+(h*(i/10)):x(i,2)=x(i,2)+(h*(i/10))
fi
line x(i,1), x(i,2) to x(i,1), x(i,2)
next
return
Background fade removed and replaced with a 1 pixel wide, very long worm.
rem Coil Worm v3.1 Code by Xone(c)2k8
rem ==================================
rem Note: Set the Particle Amount that
rem gives fast smooth motion for best effect.
rem USER SETTINGS Def = Default Values
rem @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
rem Primary Settings
rem ----------------------------------------------------------------------
P = 60 rem Particles
rem Colour Settings
rem ----------------------------------------------------------------------
CStat = 0 rem Colour Status (0/1)
rem 0 = Fixed RGB, 1 = Cycling RGB
rem If Fixed, set your own RGB, (0=None to 1=Full, 1+ = Gradients)
Red = 0 rem Red Value [0.8]Preset
Grn = 0.3 rem Green Value [1.6]Preset
Blu = 0.8 rem Blue Value [0]Preset
rem Draw Settings
rem ----------------------------------------------------------------------
Wide = 5 rem Path Widths, CARE!!! (0 to 5 recommended) [2]Def
WSpc = 0.8 rem Width Spacing (0.3=tight, 0.4+ =open) [0.3]Def
Wfad = 1 rem Fade the Width Out (0/1) [0]Def
rem @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Px=320:Py=256
for p = 1 to P
dim x(p,2):x(p,1)=Px:x(p,2)=Py
dim c(p,3):c(p,1)=0:c(p,2)=0:c(p,3)=0
dim s(p,2):s(p,1)=0:s(p,2)=0
next
u=0:k1=0:k2=4:k3=8:n=1:o=0
Open Window 640,512
setrgb 0,0,0,0
Label Loop
setdrawbuf Cbu: Cbu=1-Cbu
setdispbuf Cbu: clear window
if u<P u=u+1:o=o+0.011:y=y+0.008
if m<80 then m=m+1:M=m-8 fi
g=cos(o):h=sin(y):a=g*m+h*m:c=g*M-h*M:U=(n*I)+0.5:
for i = 1 to u
if i=1 then
if x(1,1)<Px+a s(1,1)=s(1,1)+0.05
if x(1,1)>Px+a s(1,1)=s(1,1)-0.05
if x(1,2)<Py+c s(1,2)=s(1,2)+0.05
if x(1,2)>Py+c s(1,2)=s(1,2)-0.05
else
O=((P-i)/200)+0.4
if x(i,1)<x(i-1,1) s(i,1)=s(i,1)+(O*(U*4))
if x(i,1)>x(i-1,1) s(i,1)=s(i,1)-(O*(U*4))
if x(i,2)<x(i-1,2) s(i,2)=s(i,2)+(O*(U*4))
if x(i,2)>x(i-1,2) s(i,2)=s(i,2)-(O*(U*4))
fi
if s(i,1)>3 s(i,1)=3: if s(i,1)<-3 s(i,1)=-3
if s(i,2)>3 s(i,2)=3: if s(i,2)<-3 s(i,2)=-3
x(i,1)=x(i,1)+(s(i,1)*0.9):x(i,2)=x(i,2)+(s(i,2)*0.9)
next
for i = 1 to u
s1=s(i,1):s2=s(i,2):v1=x(i,1):v2=x(i,2)
if i>1 then
gosub CS
setrgb 1,c(i,1),c(i,2),c(i,3)
line v1,v2 to x(i-1,1),x(i-1,2)
if Wide>0 then
for j = 1 to Wide
if Wfad<>0 w = 1.3-((0.8/Wide)*j)
if Wfad=0 w = 1
setrgb 1, c(i,1)*w, c(i,2)*w, c(i,3)*w
jR = (j*WSpc)
line v1-jR, v2-jR to x(i-1,1)-jR, x(i-1,2)-jR
line v1+jR, v2+jR to x(i-1,1)+jR, x(i-1,2)+jR
next
fi:fi
next
gosub R
Goto Loop
label CS
l = 220-((200/P)*(i*1.2))
if CStat<>0 then
k1=k1+(0.00002):k2=k2+(0.000026):k3=k3+(0.000034)
t=(cos(k1)+1):e=(cos(k2)+1):q=(cos(k3)+1)
c(i,1)=((l)*t)+20:c(i,2)=((l)*e)+20:c(i,3)=((l)*q)+20
else
c(i,1)=(l)*(Red*4):c(i,2)=(l)*(Grn*4):c(i,3)=(l)*(Blu*4)
fi
return
label R
for i = 1 to u
x(i,1)=x(i,1)+(a/3000)*s(i,1):x(i,2)=x(i,2)-(c/3000)*s(i,2)
if i=1 then
h = (ran(0.2)-(0.2/2))*5
x(i,1)=x(i,1)+(h*(i/10)):x(i,2)=x(i,2)+(h*(i/10))
fi
line x(i,1), x(i,2) to x(i,1), x(i,2)
next
return
Background fade removed and replaced with a wide worm (more like a ribbon).
Plenty more to come, its just finding the time to do it.
-
I like it very much, and the variations are cool too :)
Jim
-
Wow. You could title this: 'A spider trying to find an anchor point in the wind'
-
Thx for the comments :)
The coiling aspect of the path is part of the research I'm doing to try and understand how electrical arcs
can be coded between a positive and negative charge. Maybe in future I'll figure it out and post
the results in yabasic.
I'm sure it can be done quite easily with a turbulenced sine wave, but i'm trying a different approach :P
-
Are you planning to make an accurate representation or do you just want it to look good?
Beziers are really nice for making electrical patterns that arc around.
-
The plan was to make it look and move realisticly, but unlike this worm thing, I'll
be trying to cause the path to jump from X number of points.
I'd like it to be entirely unpredictable in the way it emits, arcs/loops and finally connects.
So I'll have a critical energy charge applied to the points, and when they reach critical charge
level, the paths will jump from the two nearest charge points and be released at the point of contact.
Taking a fair bit of thinking about :-\