How to resolve the algorithm Color wheel step by step in the Smart BASIC programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Color wheel step by step in the Smart BASIC programming language

Table of Contents

Problem Statement

Write a function to draw a HSV color wheel completely with code. This is strictly for learning purposes only. It's highly recommended that you use an image in an actual application to actually draw the color wheel   (as procedurally drawing is super slow). This does help you understand how color wheels work and this can easily be used to determine a color value based on a position within a circle.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Color wheel step by step in the Smart BASIC programming language

Source code in the smart programming language

' Runs on iOS
GET SCREEN SIZE sw,sh
xmax=0.45*3/7*(sw+sh)
x0=sw/2!y0=sh/2
twopi=2*3.1415926
GRAPHICS
GRAPHICS CLEAR
DIM triX(1000), triY(1000)
triX(0)=x0 ! triY(0)=y0
steps=INT(1^2*360)+1
dAngle=twopi/steps
dAngle2=dAngle/2
REFRESH OFF
FOR i=0 TO steps-1
  pal(i/steps+TintOffset)
  ANGLE=i*dAngle
  FILL COLOR pal.r,pal.g,pal.b
  DRAW COLOR pal.r,pal.g,pal.b
  x=x0+(xmax-radius)*COS(ANGLE)
  y=y0-(xmax-radius)*SIN(ANGLE)
  k=0
  FOR j=-dAngle2 TO dAngle2 STEP 0.02
    k+=1
    triX(k)=x0+xmax*COS(ANGLE+j)
    triY(k)=y0-xmax*SIN(ANGLE+j)
  NEXT j
  k+=1
  triX(k)=x0+xmax*COS(ANGLE+dAngle2)
  triY(k)=y0-xmax*SIN(ANGLE+dAngle2)
  DRAW POLY triX,triY COUNT k+1
  FILL POLY triX,triY COUNT k+1
NEXT i
REFRESH ON
END

DEF pal(tint)
tint=tint*360
h=(tint%360)/60 ! f=FRACT(h) ! z=1-f ! ic=FLOOR(h)+1
ON ic GOTO s1,s2,s3,s4,s5,s6
  s1: r=1 ! g=f ! b=0 ! GOTO done
  s2: r=z ! g=1 ! b=0 ! GOTO done
  s3: r=0 ! g=1 ! b=f ! GOTO done
  s4: r=0 ! g=z ! b=1 ! GOTO done
  s5: r=f ! g=0 ! b=1 ! GOTO done
  s6: r=1 ! g=0 ! b=z ! done:
END DEF

  

You may also check:How to resolve the algorithm Cullen and Woodall numbers step by step in the Haskell programming language
You may also check:How to resolve the algorithm Graph colouring step by step in the Java programming language
You may also check:How to resolve the algorithm Integer sequence step by step in the 6502 Asembler programming language
You may also check:How to resolve the algorithm Balanced brackets step by step in the FutureBasic programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the TMG programming language