Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 18:28 12 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Armmite H7: V5.05.04, Turtle graphics

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10572
Posted: 07:58pm 14 Mar 2019
Copy link to clipboard 
Print this post

2019-03-15_055407_Armmite1.3.zip





Just for fun . Source of code with thanks

Works with any configured display. Attempting to draw outside of the screen will cause an error and stop the program.

Commands are:
[code]
TURTLE RESET ' clears the screen and re-initialises the turtle system. The turtle is located at MM.HRES\2, MM.VRES\2. The default pen colour is white and the fill colour is green. The orientation is up.

TURTLE DRAW TURTLE ' draws a turtle at the current location and in the current orientation

TURTLE PEN UP 'lifts the pen so moves do not write to the screen

TURTLE PEN DOWN 'lowers the pen so moves do write to the screen

TURTLE FORWARD n 'moves the turtle n pixels in the current heading

TURTLE BACKWARD n 'moves the turtle n pixels opposite the current heading

TURTLE DOT 'Draw a 1-pixel dot at the current location, regardless of pen status.

TURTLE TURN LEFT deg 'Turn the turtle to the left (anti-clockwise) by the specified number of degrees.

TURTLE TURN RIGHT deg 'Turn the turtle to the right (clockwise) by the specified number of degrees.

TURTLE BEGIN FILL 'Start filling. Call this before drawing a polygon to activate the bookkeeping required to run the filling algorithm later.

TURTLE END FILL 'End filling. Call this after drawing a polygon to trigger the fill algorithm. The filled polygon may have up to 128 sides.

TURTLE HEADING deg' Rotate the turtle to the given absolute heading (in degrees). 0 degrees means facing straight up. 90 degrees means facing to the right.

TURTLE PEN COLOUR col 'Set the current drawing colour. Colours are specified as per normal Micromite drawing commands

TURTLE FILL COLOUR col 'Set the current fill colour. Colours are specified as per normal Micromite drawing commands

TURTLE MOVE x, y 'Move the turtle to the specified location, drawing a straight line if the pen is down.

TURTLE DRAW PIXEL 'Draw a 1-pixel dot at the given location using the current draw colour, regardless of current turtle location or pen status.

TURTLE FILL PIXEL 'Draw a 1-pixel dot at the given location using the current fill colour, regardless of current turtle location or pen status.

TURTLE DRAW LINE 'Draw a straight line between the given coordinates, regardless of current turtle location or pen status.

TURTLE DRAW DIRCLE 'Draw a circle at the given coordinates with the given radius, regardless of current turtle location or pen status.
[/code]Edited by matherp 2019-03-16
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2171
Posted: 10:35pm 14 Mar 2019
Copy link to clipboard 
Print this post

Seymour Papert has a lot to answer for!
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10572
Posted: 02:10pm 15 Mar 2019
Copy link to clipboard 
Print this post

Here is an update (now 5.05.05) that uses some of the turtle code to implement arbitrary filled polygons. It also includes new buffered drivers for 800x480 SSD1963 displays with 64 colours. These have the advantage that they use very little memory but give flicker free performance during complex screen updates. The driver is specifically targeted at games programming. See the OPTION LCDPANEL section of the manual for the syntax needed to initialise the new drivers.

2019-04-07_035553_Armmite1.3.zip

Updated manual:

2019-04-07_040310_Armmite_H7_Manual.pdf

The new MMBasic command is

POLYGON xarray%(), yarray%() [, bordercolour] [, fillcolour]


If fill colour is omitted then just the polygon outline is drawn. If bordercolour is omitted then it will default to the current gui foreground colour. xarray% and yarray% are integer arrays holding the x-y coordinate pairs. The polygon should be closed with the first and last elements the same

my test code draws filled 5 pointed stars over the screen. It is pretty quick - see the video




option explicit
option default none
dim x%(9),xd%(9)
dim y%(9),yd%(9)
dim integer i,c,f, xp, yp
dim float s
cls
for i=0 to 9 step 2
x%(i)=-(SIN(rad(i*36))*200)
y%(i)=-(COS(rad(i*36))*200)
x%(i+1)=-(SIN(rad((i+1)*36))*76)
y%(i+1)=-(COS(rad((i+1)*36))*76)
next i
do
c=rnd()*255 + ((rnd()* 255)<<8) + ((rnd()* 255)<<16)
f=rnd()*255 + ((rnd()* 255)<<8) + ((rnd()* 255)<<16)
xp=rnd()*mm.hres
yp=rnd()*mm.vres
s=rnd()
for i=0 to 9
xd%(i)=x%(i)*s+xp
yd%(i)=y%(i)*s+yp
next i
polygon xd%(), yd%(), c, f
loop

Edited by matherp 2019-04-08
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025