Graphics Doodle 2: Tentacle dance (Sample Programs)

by UglyMike @, Brussels, Monday, February 14, 2011, 20:46 (2832 days ago)

I accidentally developed this. It started with code to draw a spline curve and I just kept adding things.... The result is quite mesmerizing, if I say so myself (but then of course I would....)

This program is not very clearly documented, sorry for that.
It also has a issue with the control points going further and further away, so you can't let it run indefinitely. Still a nice effect. I hope you agree...

print "Cubic Bezier Curve Tentacle Animation- by M. Vilain"
rem ************ Initialization **************
rem for holding the 4 control points of our Cubic Bezier curve
dim row(4,2)
Rem for holding 100 points on the calculated Bezier curve
dim bez(101,2)
graphsize 600,600
Fastgraphics
Rem variables to control the movement of the tentacle
p1=4
p2=6
p3=5
jp1=0
jp2=0
jp3=0
incp1=0.3
incp2=0.3
incp3=0.3
q1=3
q2=7
q3=4
jq1=0
jq2=0
jq3=0
incq1=0.3
incq2=0.3
incq3=0.3
rem ********* Create Initial Points **********
rem this creates the initial 4 points of the curve
gosub CreateInitpoint
loop:
clg
rem here we interpolate the bezier curve
gosub CreateInterpolated
rem here we place circles along the Bezier path
gosub DrawCircleonPath
rem now we show it all
refresh
rem here we slightly change the initial 4 point between qx and rx
gosub JigglePoints
rem here we loop the creation
goto loop
end
rem ******* Here the Subroutines start ********
rem ********* Create Initial Points **********
rem first we create 4 control points
rem the four points are spaced evenly apart with a random offset
rem we try to put them in more or less the same horizontal plane with a random offset from the initial point
CreateInitpoint:
row[0,0]= 300
row[0,1] = 300
row[1,0] = 300 +(rand*60-30)
row[1,1] = 270+(rand*60-30)
row[2,0] = 300+(rand *100-50)
row[2,1] = 110+(rand*100-50)
row[3,0] = 300-(rand*150-75)
row[3,1] = 200+(rand*150-75)
return
rem ********* Interpolate the curve **********
rem here we create a 100-element set of interpolated points. These are on the Bezier spline
CreateInterpolated:
for i = 0 to 100 step 1
ix=i/100
x1=(1-ix)*(1-ix)*(1-ix)*row[0,0]
y1=(1-ix)*(1-ix)*(1-ix)*row[0,1]
x2=3*(1-ix)*(1-ix)*ix*row[1,0]
y2=3*(1-ix)*(1-ix)*ix*row[1,1]
x3=3*(1-ix)*ix*ix*row[2,0]
y3=3*(1-ix)*ix*ix*row[2,1]
x4= ix*ix*ix*row[3,0]
y4= ix*ix*ix*row[3,1]
bez[i,0]=x1+x2+x3+x4
bez[i,1]=y1+y2+y3+y4
next i
return
rem ****** Create circles of decreasing ******
rem ****** size and mirror them *******
rem for all the points on the Bezier curve defined by Bez[], we draw white circles with a red edge (actually red circles with smaller white ones)
DrawCircleonPath:
outer =38
for i = 0 to 100
color red
outer =outer - 0.34
surf=380+(300-bez[i,1])
if surf >350 then
circle bez[i,0],380+(300-bez[i,1]),outer
circle 380+(300-bez[i,0]),380+(300-bez[i,1]),outer
end if
if outer < 2 then
color red
inner = 1
else
color grey
inner = outer -1
end if
if surf >350 then
circle bez[i,0],380+(300-bez[i,1]),outer
circle 380+(300-bez[i,0]),380+(300-bez[i,1]),outer
end if
next i
outer =38
for i = 0 to 100
color red
outer =outer - 0.34
surf2=bez[i,1]
if surf2 < 350 then
circle bez[i,0],bez[i,1],outer
circle 380+(300-bez[i,0]),bez[i,1],outer
endif
if outer < 2 then
color red
inner = 1
else
color white
inner = outer -1
end if
if surf2 <350 then
circle bez[i,0],bez[i,1],inner
circle 380+(300-bez[i,0]),bez[i,1],inner
endif
next i
return
rem ****** Offset the control points to ******
rem ****** give a feeling of movement *****
Rem here we take the original control points stored in row[](except for the first one) and move them around between parameters px and qx where px=left to right, qx= up and down The parameters are being changed by incpx and incqx
JigglePoints:
row[0,0]= 300
row[0,1] = 300
if jp1 > p1 then
incp1 = -0.2
end if
if jp1 < -p1 then
incp1 = 0.2
end if
if jp2 > p2 then
incp2 = -0.2
end if
if jp2 < -p2 then
incp2 = 0.2
end if
if jp3 > p3 then
incp3 = -0.2
end if
if jp3 < -p3 then
incp3 = 0.2
end if
jp1=jp1+incp1
jp2=jp2+incp2
jp3=jp3+incp3/2
if jq1 > q1 then
incq1 = - 0.2
end if
if jq1 < -q1 then
incq1 = 0.2
end if
if jq2 > q2 then
incq2 = - 0.2
end if
if jq2 < -q2 then
incq2 = 0.2
end if
if jq3 > q3 then
incq3 = - 0.2
end if
if jq3 < -q3 then
incq3 = 0.2
end if
jq1=jq1+incq1
jq2=jq2+incq2
jq3=jq3+incq3/2
row[0,0] = row[0,0] - jp3
row[0,1] = row[0,1] - jq3
row[1,0] = row[1,0] - jp1
row[1,1] = row[1,1] - jq1
row[2,0] = row[2,0] - jp2
row[2,1] = row[2,1] - jq2
row[3,0] = row[3,0] - jp3
row[3,1] = row[3,1] - jq3
return


Complete thread:

 RSS Feed of thread

powered by my little forum