Bitmap/Bézier curves/Cubic: Difference between revisions

Content added Content deleted
(Added Commodore BASIC solution)
m (Fix redim array error when run more than once)
Line 255: Line 255:
100 bp(0,0)=1:bp(1,0)=70:bp(2,0)=1
100 bp(0,0)=1:bp(1,0)=70:bp(2,0)=1
110 bp(0,1)=1:bp(1,1)=8:bp(2,1)=23
110 bp(0,1)=1:bp(1,1)=8:bp(2,1)=23
120 dim pt%(ns,2) : rem individual lines in curve
120 gosub 3000
130 end
130 gosub 3000
140 end
1000 rem plot line
1000 rem plot line
1010 se=0 : rem 0 = steep 1 = !steep
1010 se=0 : rem 0 = steep 1 = !steep
Line 282: Line 283:
2060 return
2060 return
3000 rem bezier curve
3000 rem bezier curve
3010 dim pt%(ns,2)
3010 for i=0 to ns
3020 for i=0 to ns
3020 t=i/ns
3030 t=i/ns
3030 t1=1.0-t
3040 t1=1.0-t
3040 a=t1^2
3050 a=t1^2
3050 b=2.0*t*t1
3060 b=2.0*t*t1
3060 c=t^2
3070 pt(i,0)=a*bp(0,0)+b*bp(1,0)+c*bp(2,0)
3070 c=t^2
3080 pt(i,0)=a*bp(0,0)+b*bp(1,0)+c*bp(2,0)
3080 pt(i,1)=a*bp(0,1)+b*bp(1,1)+c*bp(2,1)
3090 next i
3090 pt(i,1)=a*bp(0,1)+b*bp(1,1)+c*bp(2,1)
3100 next i
3100 for i=0 to ns-1
3110 for i=0 to ns-1
3110 x0=int(pt(i,0))
3120 x0=int(pt(i,0))
3120 y0=int(pt(i,1))
3130 y0=int(pt(i,1))
3130 x1=int(pt(i+1,0))
3140 x1=int(pt(i+1,0))
3140 y1=int(pt(i+1,1))
3150 y1=int(pt(i+1,1))
3150 gosub 1000
3160 gosub 1000
3160 next i
3170 next i
3170 return
3180 return
</lang>
</lang>
[https://www.worldofchris.com/assets/c64-bezier-curve.png Screenshot of Bézier curve on C64]
[https://www.worldofchris.com/assets/c64-bezier-curve.png Screenshot of Bézier curve on C64]



=={{header|D}}==
=={{header|D}}==