We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge 14 - Rainbow
#7
Hi everyone, a bit late to this one but I enjoyed the challenge, so here is my take on a rainbow.

Instead of outlines, it fills seven concentric circles from the outside in (red first, violet last), then covers the centre with the sky colour and the bottom half with a hill, so only the arcs remain. Changing the variable "band" changes the thickness of each colour.

Code:
' Challenge 14 - Rainbow
GraphicsWindow.Title = "Rainbow"
GraphicsWindow.Width = 640
GraphicsWindow.Height = 380
sky = "LightSkyBlue"
GraphicsWindow.BackgroundColor = sky
GraphicsWindow.PenWidth = 0

colors = "1=Red;2=Orange;3=Yellow;4=Green;5=Blue;6=Indigo;7=Violet;"
cx = 320
cy = 330
r = 280
band = 20

For i = 1 To Array.GetItemCount(colors)
  GraphicsWindow.BrushColor = colors[i]
  GraphicsWindow.FillEllipse(cx - r, cy - r, 2 * r, 2 * r)
  r = r - band
EndFor

' hollow out the centre
GraphicsWindow.BrushColor = sky
GraphicsWindow.FillEllipse(cx - r, cy - r, 2 * r, 2 * r)

' ground
GraphicsWindow.BrushColor = "ForestGreen"
GraphicsWindow.FillRectangle(0, cy, GraphicsWindow.Width, GraphicsWindow.Height - cy)

A nice variation: put the loop in a Sub and call it with a smaller radius and lighter colours (e.g. using GraphicsWindow.GetColorFromRGB) to add a faint second rainbow above the first, with the colour order reversed as in a real double rainbow.
Consultor de TI em Portugal (PME). Guia de licenciamento: Office 2024 Professional Plus
[-] The following 3 users Like tiagomoreira41's post:
  • AbsoluteBeginner, litdev, z-s
Reply


Messages In This Thread
Challenge 14 - Rainbow - by litdev - 09-15-2025, 08:38 AM
RE: Challenge 14 - Rainbow - by martmen - 09-16-2025, 02:34 PM
RE: Challenge 14 - Rainbow - by litdev - 09-16-2025, 07:02 PM
RE: Challenge 14 - Rainbow - by martmen - 09-18-2025, 03:15 PM
RE: Challenge 14 - Rainbow - by martmen - 09-18-2025, 04:33 PM
RE: Challenge 14 - Rainbow - by martmen - 09-20-2025, 01:42 PM
RE: Challenge 14 - Rainbow - by tiagomoreira41 - 10-07-2026, 12:51 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)