Bitmap/Bézier curves/Quadratic: Difference between revisions
Content deleted Content added
Added Commodore BASIC solution |
|||
Line 174: | Line 174: | ||
#undef plot |
#undef plot |
||
#undef line</lang> |
#undef line</lang> |
||
=={{header|Commodore Basic}}== |
|||
<lang basic> |
|||
10 rem bezier curve algorihm |
|||
20 rem translated from purebasic |
|||
30 ns=25 : rem num segments |
|||
40 dim pt(ns,2) : rem points in line |
|||
50 sc=1024 : rem start of screen memory |
|||
60 sw=40 : rem screen width |
|||
70 sh=25 : rem screen height |
|||
80 pc=42 : rem plot character '*' |
|||
90 dim bp(2,1) : rem bezier curve points |
|||
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 |
|||
120 dim pt%(ns,2) : rem individual lines in curve |
|||
130 gosub 3000 |
|||
140 end |
|||
1000 rem plot line |
|||
1010 se=0 : rem 0 = steep 1 = !steep |
|||
1020 if abs(y1-y0)>abs(x1-x0) then se=1:tp=y0:y0=x0:x0=tp:tp=y1:y1=x1:x1=tp |
|||
1030 if x0>x1 then tp=x1:x1=x0:x0=tp:tp=y1:y1=y0:y0=tp |
|||
1040 dx=x1-x0 |
|||
1050 dy=abs(y1-y0) |
|||
1060 er=dx/2 |
|||
1070 y=y0 |
|||
1080 ys=-1 |
|||
1090 if y0<y1 then ys = 1 |
|||
1100 for x=x0 to x1 |
|||
1110 if se=1 then p0=y: p1=x:gosub 2000:goto 1130 |
|||
1120 p0=x: p1=y: gosub 2000 |
|||
1130 er=er-dy |
|||
1140 if er<0 then y=y+ys:er=er+dx |
|||
1150 next x |
|||
1160 return |
|||
2000 rem plot individual point |
|||
2010 rem p0 == plot point x |
|||
2020 rem p1 == plot point y |
|||
2030 sl=p0+(p1*sw) |
|||
2040 rem make sure we dont write beyond screen memory |
|||
2050 if sl<(sw*sh) then poke sc+sl,pc |
|||
2060 return |
|||
3000 rem bezier curve |
|||
3010 for i=0 to ns |
|||
3020 t=i/ns |
|||
3030 t1=1.0-t |
|||
3040 a=t1^2 |
|||
3050 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) |
|||
3080 pt(i,1)=a*bp(0,1)+b*bp(1,1)+c*bp(2,1) |
|||
3090 next i |
|||
3100 for i=0 to ns-1 |
|||
3110 x0=int(pt(i,0)) |
|||
3120 y0=int(pt(i,1)) |
|||
3130 x1=int(pt(i+1,0)) |
|||
3140 y1=int(pt(i+1,1)) |
|||
3150 gosub 1000 |
|||
3160 next i |
|||
3170 return |
|||
</lang> |
|||
[https://www.worldofchris.com/assets/c64-bezier-curve.png Screenshot of Bézier curve on C64] |
|||
=={{header|D}}== |
=={{header|D}}== |