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
#1
Write a program to draw a rainbow in the GraphicsWindow.
Reply
#2
Hello Small Basic fans,

here is my rainbow FZSV873.000.

Description:
  • This program draws six overlapping ellipses in different pastel colors to simulate a rainbow.
  • The ellipses are centered horizontally and stacked vertically with increasing size.
  • The last color blends into the background, creating a smooth fade-out effect.

Best regards
martmen

   
[-] The following 1 user Likes martmen's post:
  • AbsoluteBeginner
Reply
#3
Nice effect, isn't red on the outer and violet on the inner edge.
Reply
#4
Hello LitDev,
You're right — the colors of a rainbow are different. Here's an example with the correct color selection and order.

FZSV873.000-0

I had the color choices created by Copilot.

See you soon,
martmen
Reply
#5
Hello everyone,

In version FZSV873.000-0, I find the colors too bright. I'm providing version FZSV873.000-1 instead. This version uses shapes with increased transparency.

See you soon,
martmen
[-] The following 2 users Like martmen's post:
  • AbsoluteBeginner, litdev
Reply
#6
Hello friends of the rainbow,

here is my new version FZSV873.000-2. In this version, commands from the LitDev extension are used.
At the beginning of the program, there are three variables that are assigned values. These can be used to change the appearance of the rainbow.

Have fun experimenting!
martmen
Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)