Information Technology - Computer Programming - Source Code - Homebrew - Open Source - Software - Hardware - 8 bit - 16 bit - 32 bit - 64 bit - x86 - x64 - DOS - Windows - Linux - Arduino - Embedded - Development - Retro - Vintage - Math - Science - History - Hobby - Beginners - Professionals - Experiment - Research - Study - Fun - Games

SVG examples

Share your Net Basic creations here.
Post Reply
admin
Site Admin
Posts: 106
Joined: Wed Feb 22, 2023 6:51 am

SVG examples

Post by admin »

I realized that Net Basic could generate graphics by printing HTML with SVG tags. I'm still figuring out how to use SVG and what's possible, but for now I went ahead and made some SVG examples.

To use SVG in Net Basic, first call the HTML command to break from the text output area.

Code: Select all

5 PRINT "SVG sine wave"
10 HTML
20 PRINT "<svg width = '640' height = '480'>"
30 FOR i = 1 TO 360
40 PRINT "<rect x = '"; i / 360 * 320; "' y = '"; sin(i / 180 * 3.14) * 50 + 50; "' width = '1' height = '1' />"
50 NEXT i
60 PRINT "</svg>"
Program encoded URL: https://www.lucidapogee.com/netbasic/?l ... Fsvg%3E%22

Code: Select all

1 REM https://rosettacode.org/wiki/Draw_a_sphere
5 PRINT "SVG sphere"
10 HTML
20 PRINT "<svg width = '640' height = '480'>"
30 LET j = 2
40 FOR i = 221 TO 0 STEP j * -1
50 FOR k = -3.14 TO 3.14 STEP .02
60 PRINT "<rect x = '"; 221 + i * sin(k); "' y = '"; 222 + 221 * cos(k); "' width = '1' height = '1' />"
70 PRINT "<rect x = '"; 221 + 221 * sin(k); "' y = '"; 222 + (i - 1) * cos(k); "' width = '1' height = '1' />"
80 NEXT k
90 LET j = j + 1
100 NEXT i
Program encoded URL: https://www.lucidapogee.com/netbasic/?l ... %20i%0D%0A

Code: Select all

1 REM https://rosettacode.org/wiki/Barnsley_fern
5 PRINT "SVG Barnsley fern"
10 HTML
20 PRINT "<svg width = '640' height = '480' style = 'background-color:red;'>"
30 FOR i = 1 TO 10000
40 LET r = RND
50 IF NOT(r > 0 AND r < .01) THEN 80
60 LET x = .0
70 LET y = .16 * y
80 IF NOT(r > .01 AND r < .08) THEN 110
90 LET x = .22 * x - .26 * y
100 LET y = -.23 * x + .22 * y + 1.6
110 IF NOT(r > .075 AND r < .15) THEN 140
120 LET x = .15 * x + .28 * y
130 LET y = -.29 * x + .24 * y + .44
140 LET x = .85 * x + .04 * y
150 LET y = -.04 * x + .85 * y + 1.6
160 LET x1 = (x + 3) * 70
170 LET y1 = 700 - y * 70
180 PRINT "<rect x = '"; x1; "' y = '"; y1; "' width = '1' height = '1' fill = 'green' />"
190 NEXT i
200 PRINT "</svg>"
Program encoded URL: https://www.lucidapogee.com/netbasic/?l ... Fsvg%3E%22

Code: Select all

1 REM https://rosettacode.org/wiki/Archimedean_spiral
5 PRINT "SVG Archimedean spiral"
10 HTML
20 PRINT "<svg width = '640' height = '480'>"
30 LET size = 80
40 LET x = 250
50 LET y = 200
60 LET a = 1.5
70 LET b = .7
80 FOR t = 0 TO size * PI STEP .1
90 LET r = a + b * t
100 PRINT "<rect x = '"; r * cos(t) + x; "' y = '"; r * sin(t) + y; "' width = '1' height = '1' />"
110 NEXT t
120 PRINT "</svg>"
Program encoded URL: https://www.lucidapogee.com/netbasic/?l ... Fsvg%3E%22

Code: Select all

5 PRINT "SVG curlicue"
10 HTML
20 PRINT "<svg width = '640' height = '480'>"
30 FOR f = 0 TO 1000 STEP .1
40 LET x = x + SIN(f * f)
50 LET y = y + COS(f * f)
60 PRINT "<rect x = '"; x; "' y = '"; y; "' width = '1' height = '1' />"
70 NEXT f
80 PRINT "</svg>"
Program encoded URL: https://www.lucidapogee.com/netbasic/?l ... Fsvg%3E%22
Post Reply