Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 19:45 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 : Random ellipses: MMX or Armmite H7

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10572
Posted: 03:28pm 21 Mar 2019
Copy link to clipboard 
Print this post



Please watch the video

This demo will run on an ARMMITE H7 or a Micromite eXtreme with the latest firmware versions, not unfortunately on a Maximite


option explicit
option default NONE
dim INTEGER x(60), y(60), xd(60), yd(60) , xe(60), ye(60)
dim integer i, c, f, xp, yp
dim float a, s, e, sine, cosine
for i=0 to 60 'store coordinates for a 60 point closed circle, radius 100
x(i)=sin(rad(i*6)) * 100
y(i)=COS(rad(i*6)) * 100
next i
CLS
do
c=rnd()*255 + ((rnd()* 255)<<8) + ((rnd()* 255)<<16) ' random colour for border
f=rnd()*255 + ((rnd()* 255)<<8) + ((rnd()* 255)<<16) ' random colour for fill
xp=rnd()*mm.hres 'random x position of centre
yp=rnd()*mm.vres 'random y position of centre
s=rnd() 'random size
a=rnd()* 360 'random angle
sine=sin(rad(a)): cosine=cos(rad(a))
e=rnd()* 8/3 + (1/3) ' random aspect ratio between one third and three
for i=0 to 60 ' first convert the aspect ratio and resize the coordinates
xd(i)=x(i) * s * e
yd(i)=y(i) *s
next i
for i=0 to 60 ' now rotate the coordinates by an angle between 0 and 360 degrees
xe(i)=xd(i)*cosine - yd(i) * sine + xp
ye(i)=yd(i)*cosine + xd(i) * sine + yp
next i
polygon xe(), ye(), c, f 'plot a filled ellipse
loop
Edited by matherp 2019-03-23
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2171
Posted: 03:38pm 21 Mar 2019
Copy link to clipboard 
Print this post

irresistible

very good - can I pop it in the library?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10572
Posted: 04:36pm 21 Mar 2019
Copy link to clipboard 
Print this post

  Quote  very good - can I pop it in the library?


Any of my posted code is free to use / abuse in whatever way anyone wants. I actually prefer the star demo but both are based on the excellent fill algorithm that I found by chance when googling turtle graphics. It even seems to deal with crossed vertices OK.

Demo also works on the Armmite L4 with latest firmware.Edited by matherp 2019-03-23
 
CaptainBoing

Guru

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

I always ask Peter... seems a presumption just to take.

I will put the Star and Ellipse codes all in the same wiki.

cheers
 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 655
Posted: 10:09pm 21 Mar 2019
Copy link to clipboard 
Print this post

G'Day Peter & Capt.

I knew you would. Now I just have to understands how it works.
Perhaps later today I will get the chance.

Peter
 
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