Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 03:00 22 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 : PicoMite Spirograph random colours

Author Message
asknik2022
Regular Member

Joined: 26/03/2022
Location: United Kingdom
Posts: 94
Posted: 05:08pm 03 Mar 2023
Copy link to clipboard 
Print this post

OPTION BASE 1

'Define color lookup table

DIM rgb%(4,3)
rgb%(1,1)=255: rgb%(1,2)=255: rgb%(1,3)=0 'YELLOW
rgb%(2,1)=255: rgb%(2,2)=0: rgb%(2,3)=0 'RED
rgb%(3,1)=0: rgb%(3,2)=0: rgb%(3,3)=255 'BLUE
rgb%(4,1)=0: rgb%(4,2)=128: rgb%(4,3)=0 'GREEN
'Set up the Spirograph parameters
r1 = 90
r2 = 30
p = 60
colorindex =0
'Set up the rotation parameters
cx = 120
cy = 160
angle = 0
angle_step = 0.5

CLS

DO
   getcol
   sa = SIN(angle)
   ca = COS(angle)
   'Calculate the Spirograph path
   FOR t = 0 TO 360 STEP 1
       a = (r1-r2)/r2
       x = (r1-r2)*COS(t) + p*COS(a*t)
       y = (r1-r2)*SIN(t) - p*SIN(a*t)
       
       'Rotate the coordinates and draw a pixel
       xp = cx + INT(x*ca - y*sa)
       yp = cy + INT(x*sa + y*ca)
       Pixel xp,yp,rgb(rgb%(colorindex,1),rgb%(colorindex,2),rgb%(colorindex,3))
       
   NEXT t
   ' Update the angle and wait a bit before redrawing
   angle = angle + angle_step
 
LOOP


sub getcol
' Set color
colorindex=int(rnd*3)+1
end sub
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 496
Posted: 08:36pm 03 Mar 2023
Copy link to clipboard 
Print this post

cx = 120
cy = 160

switch to

cy = 120
cx = 160

and add at the beginning

mode 2
Edited 2023-03-04 06:38 by homa
 
asknik2022
Regular Member

Joined: 26/03/2022
Location: United Kingdom
Posts: 94
Posted: 08:04am 04 Mar 2023
Copy link to clipboard 
Print this post

This is for the picomite and the screen was set to portrait ili9341
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 496
Posted: 11:26am 04 Mar 2023
Copy link to clipboard 
Print this post

  asknik2022 said  This is for the picomite and the screen was set to portrait ili9341

Ah, sorry. I use the PicoMiteVGA.
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 873
Posted: 05:22am 05 Mar 2023
Copy link to clipboard 
Print this post

@asknik,
G'day and a belated "welcome" to the forum.
A nice program, thanks. It is one of those things I enjoyed in my youth and it is good to now see it in MMBasic.
I've fiddled with r1 & r2 (as well as Cx and Cy).
I'll add it to the programs for my grandchildren.

Cheers,

Andrew
 
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