Today's topic is how to draw (paint) pictures by programs (or via programming) with Small Basic.
Program can repeat, simulate, calculate and convert. Following pictures are the samples of these features.
Using Repeat
Have you felt complicated to repeat drawing something similar? That will be easily done with program. Following example is to draw geometric pattern. Program ID is JTH842. This program draws two patterns alternately in loop for x direction. And that is repeated also for y direction.
Following kaleidoscope (GTB559-4) is more complex sample of repeat. This program uses Shapes so that flips the original shapes and rotates them, then repeats to copy them.
Using Random Numbers
To use random numbers is useful to draw such as many stars and flowers. Program XKB601 determines x and y position using random numbers and draws 1000 stars in the background.
Program VFC190-0 determines x and y positions as well using random numbers, then draws petals for 3000 cherry flowers.
Using Functions and Maths
Program WRG641 draws arcs (for the nose and the tail of an elephant). The arcs are drawn by arranging circles like fans. And that are done by calculating with trigonometric functions. Small Basic does not have an operation to draw arc, but we can draw arc with trigonometric functions.
Program KFJ748-2 is an updated version to draw wood grain. This program decides colors to draw by the distance from the center of the wood grain. To let dark part of the ring thin, this program calculates the color with an equation of parabola.
Program KCG090-0 draws sunflowers. As well as the cherry, positions of flowers are calculated with random numbers. The seeds (small squares) are calculated with the golden ratio for the angles and trigonometric functions for the positions. The detail of the golden ratio is written in this site.
Converting Drawn Pictures
Pictures drawn with computers are digital data. So that can be converted the other format.
Following program Icon Editor can convert raster (dot) picture to PPM file format. PPM can be read into an free software GIMP. GIMP can convert it to BMP format, and with other tool it can be converted to icon (ICO fomat) also.
Following screen shot shows that GIMP reads the PPM file created by the Icon Editor.
And the Shapes editor can convert vector (line) pictures to SVG format. We can write programs to read/write SVG with Small Basic because SVG is a text base file format. Program XMZ657-1 outputs HTML including SVG of go game board.
Following screen shot is the output HTML generated by this program.
I think the biggest feature of SVG is that can be included directly in HTML5. But also SVG can be treated by such as GIMP, Inkscape, Illustrator. Inkscape can convert SVG to WMF (Windows Metafile) or EMF (Enhanced Metafile) format that can be used as clip art from such as PowerPoint (Office suites).
Have fun with Small Basic!
See Also
- Wood Grain Drawn with Small Basic
- Nature, the Golden Ratio, and Fibonacci too ... (MathsIsFun.com)
- Raster and Vector Graphics in Small Basic
- Icon Editor (CodePlex)
- Shapes (CodePlex)