Showing posts with label colors. Show all posts
Showing posts with label colors. Show all posts

Sunday, April 12, 2026

Numworks: Text Demos with a Poem and Rolling Screen Credits

Numworks: Text Demos with a Poem and Rolling Screen Credits 


The two scripts, which developed in Numworks:



nwtext1.py: Displaying a poem one line at a time.

nwtext2d.py: Presenting the credits in a classic TV show format.



They can be downloaded here:

https://drive.google.com/file/d/1IEDbLV4-mz9kngj0bBOkvBLrgKYg_5ha/view?usp=sharing



Display a Poem: newtext.py



Code:


# nwtext1.py

# Text Animation Demo 1

# Numworks

# Edward Shore, 2/18/2026



# import modules

from math import *

from kandinsky import *

from time import *



# Screen: 320 x 220 pixels



# list of text

t=['Roses are red','violets are blue','Nuwmorks is great','and so are you!']

# list of colors: red, violet, amber, ghost white

c=[(255,0,0),(178,0,237),(255,191,0),(245,245,245)]

# black background

fill_rect(0,0,320,220,(0,0,0))



# list the text

# each line is 20 pixels

for i in range(len(t)):

  # draw the string for each line

  # must include the black background

  # draw_string assumes white background if second color

  # is left off

  draw_string(t[i],60,60+20*i,c[i],(0,0,0))

  # time module's sleep

  sleep(1)



Notes:

1. Modules used: math, kandinsky, time. Math was entered by default every time a new script is started in Numworks. The kandinsky and time modules are specific to Numworks. The kandinsky module includes the drawing commands fill_rec and draw_string while the time module has the command sleep.

2. The line fill_rect(0,0,320,220,(0,0,0)) gives the drawing screen a black background.

3. The syntax for kandinsky’s draw_string is: draw_string(string of text, x y, text color, background color). The colors are optional, with the default set at black text color and white background. Since we have a black background for the entire screen, the background color (0,0,0) must be included.

4. To give readability I estimate that each line has a height of 20 pixels.



TV Screen Credits: nwtext2d.py





Code:

# nwtext2d.py

# Text Animation Demo 2

# Numworks

# Edward Shore, 2/19/2026



# Goal: give a classic TV style flashing of credits



# import modules

from math import *

from kandinsky import *

from time import *



# Screen: 320 x 220 pixels



# lists of text

# I'm not going to worry about center justification on this demo



# unicode for pi is u\03C0



# top line

t0=['CREDITS','Programmer','Supervisor','Directed By','Studio','Written By','A Pisces','']

# bottom line

t1=['','PI MAN','MS. SQUARE ROOT','PYTHAGOREAN THEOREM','SINE STUDIOS','PI MAN','Python Production 2026',':) \u03C0']

# black background in the loop, see comments





# roll credits

# each line is 20 pixels

for i in range(len(t0)):

  # draw a string for each line

  # text is in emerald green

  # background is black, must be included

  # since text is being replaced, we must refresh the      screen every time

  fill_rect(0,0,320,220,(0,0,0))

  draw_string(t0[i],40,60,(80,200,120),(0,0,0))

  draw_string(t1[i],40,100,(80,200,120),(0,0,0))

  # delay by 2 seconds

  sleep(2)



Notes:

1. Modules used: math, kandinsky, time. Math was entered by default every time a new script is started in Numworks. The kandinsky and time modules are specific to Numworks. The kandinsky module includes the drawing commands fill_rec and draw_string while the time module has the command sleep.

2. The line fill_rect(0,0,320,220,(0,0,0)) gives the drawing screen a black background.

3. The syntax for kandinsky’s draw_string is: draw_string(string of text, x y, text color, background color). The colors are optional, with the default set at black text color and white background. Since we have a black background for the entire screen, the background color (0,0,0) must be included.

4. In attempt to vertically center the credits, I put the top line at y = 60 and the bottom line at y = 100. In this demo, I did not worry about center justification, only choosing to left justify all the lines. The strings for the top line are stored in the list t0 while the strings for the bottom line are stored in the list t1.



I hope you enjoy these programs as I did making them,



Eddie

All original content copyright, © 2011-2026. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.



Saturday, October 14, 2023

TI-84 Plus CE Python and Numworks Python: Color Contrast

 TI-84 Plus CE Python and Numworks Python:  Color Contrast



Introduction and Calculation


The following Python script compares a contrast of colored text (foreground) color against a background color.  It is important to have good, high contrast.  High contrast allows for easy readability and it's easier on the eyes.   This becomes more important when considering web page development to allow accessibility.  


Steps:


1.  Get the RGB color code for the background color.  Here the decimal values of 0-255 are used.   R is red, G is green, and B is blue.   Black has all three entered as 0.  White has all three values entered as 255.  


2.  Take the ratio of each color out of 255 as such:


x = x ÷ 255


Where x stands for R, G, and B.  Do this for each color.  We want to the decimal answer, not the percentage.  


3.  For each color (R, G, B), do this calculation:


If x ≤ 0.03928

Then x = x ÷ 12.92

Else x = ((x + 0.055) ÷ 1.055)^2.4


Again, x stands for R, G, and B.  Do this for each color.


4.  Calculate the luminosity as:


L = 0.02126 * R + 0.7152 * G + 0.0722 * B


Let l1 = L (background color).


5.  Do steps 1-4 for the text color.  Let l2 = L (text color).


6.  Set the light color as the maximum between the background color and text color.  Set the dark color as the minimum between the background color and text color.  The contrast is calculated as follows:


c = (light + 0.05) ÷ (dark + 0.05)


If c = 21, you have perfect contrast.  If c = 1, you have the worst contrast.  Hence, we want as high contrast as possible.  This is one measure of how good colors compare to each other.  


The script presented is for the TI-84 Plus CE Python (and TI-83 CE Premium Python Edition) and Numworks. There are slight differences between the scripts, which will be highlighted in each section.




TI-84 Plus CE Python script:  CNTRST84.py









Notes:


The Texas Instruments version uses the following modules:  math, ti_system, and ti_draw.   


The ti_system has the wait_key() command, which allows us to stop the program execution until a key is pressed.


Code:


from math import *

from ti_system import *

from ti_draw import *

# 2023-08-12 EWS

# Contrast - TI-84 Plus CE Python Version


# Source:

# www.w3.org, "WCAG 2.0"

# ADG*, "How to calculate colour contrast"


# CODE:

# subs

def lumin(r,g,b):

  r=compare(r/255)

  g=compare(g/255)

  b=compare(b/255)

  return .2126*r+.7152*g+.0722*b

def compare(x):

  if x<=.03928:

    x=x/12.92

  else:

    x=((x+.055)/1.055)**2.4

  return x


# main

print("Color Contrast \n(0-255) \nBackground color:")

r1=int(input("red? "))

g1=int(input("green? "))

b1=int(input("blue? "))

print("Text color:")

r2=int(input("red? "))

g2=int(input("green? "))

b2=int(input("blue? "))


# calc

l1=lumin(r1,g1,b1)

l2=lumin(r2,g2,b2)

cntr=(max(l1,l2)+.05)/(min(l1,l2)+.05)

print("Contrast: ",str(cntr))


# pause the screen

k=0

while k==0:

  k=wait_key()


# draw

clear()

set_color(r1,g1,b1)

fill_rect(0,0,319,200)

set_color(r2,g2,b2)

draw_text(25,65,"Contrast test: TI-84+ CE")

draw_text(25,125,"Press clear to continue.")

show_draw()



Numworks script:  CNTRSTNW.py







Notes:


The Nuwmorks version uses the following modules:   math and kandinsky.  The kandinsky module is one of the graphics modules Numworks has.  


Due to a lack of a get key command, I have decided to display both the contrast and the color test as the last step.  The calculated contrast will always be printed with black text on white background.


Code:


from math import *

from kandinsky import *

# 2023-08-13 EWS

# Contrast - Numworks Version


# Source:

# www.w3.org, "WCAG 2.0"

# ADG*, "How to calculate colour contrast"


# CODE:

# subs

def lumin(r,g,b):

  r=compare(r/255)

  g=compare(g/255)

  b=compare(b/255)

  return .2126*r+.7152*g+.0722*b

def compare(x):

  if x<=.03928:

    x=x/12.92

  else:

    x=((x+.055)/1.055)**2.4

  return x


# main

print("Color Contrast \n(0-255) \nBackground color:")

r1=int(input("red? "))

g1=int(input("green? "))

b1=int(input("blue? "))

print("Text color:")

r2=int(input("red? "))

g2=int(input("green? "))

b2=int(input("blue? "))


# calc

l1=lumin(r1,g1,b1)

l2=lumin(r2,g2,b2)

cntr=(max(l1,l2)+.05)/(min(l1,l2)+.05)


# draw

c1=color(r1,g1,b1)

c2=color(r2,g2,b2)

cb=color(0,0,0)

cw=color(255,255,255)

fill_rect(0,0,320,240,c1)

draw_string("Contrast test: Numworks",25,25,c2,c1)

draw_string("Contrast: "+str(cntr),25,50,cb,cw)

draw_string("Press OK to continue.",25,150,c2,c1)



Sources


"How to calculate colour contrast"  Accessibility Developer Guide (ADG*).  An initiative of Access for all.  Last Edited July 29, 2023.  Accessed August 8, 2023.

https://www.accessibility-developer-guide.com/knowledge/colours-and-contrast/how-to-calculate/


"Relative Luminance" Web Content Accessibility Guidelines (WCAG) 2.0.   W3C, Inc.  (World Wide Web Consortium, Inc.)   Last Edited December 11, 2008.  Accessed August 8, 2023.   https://www.w3.org/TR/WCAG20/#relativeluminancedef


Eddie 


All original content copyright, © 2011-2023.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Sunday, May 29, 2022

HP 42S/DM42: Base Programs

 HP 42S/DM42:   Base Programs


Unsigned NOT


The program UNOT applies a NOT to a binary integer (flips zeros to ones and ones to zeros) using unsigned binary integers.  The number of bits (size) is prompted.


HP 42S/DM42 Program UNOT


00  {40-Byte Prgm}

01  LBL "UNOT"

02  BINM

03  "BIN?"

04  PROMPT

05  STO 01

06  EXITALL

07  "SIZE?"

08  PROMPT

09  STO 02

10  2

11  X<>Y

12  Y↑X

13  RCL- 01

14  STO 02

15  1

16  -  

17  BINM

18  END


Examples:


Unsigned NOT of 10100, size 5:  1011  (01011)


Unsigned NOT of 10100, size 8:  11101011


Shift Left


Makes a binary integer shift left: a zero is added to the right side of the integer and "drops" off the left most digit.  The number of bits (size) is prompted.  The binary number is assumed to be non-negative. 


HP 42S/DM42 Program SL16


00  {35-Byte Prgm}

01  LBL "SL16"

02  BINM

03  "BIN?"

04  PROMPT

05  EXITALL

06  2

07  ×

08  "SIZE?"

09  PROMPT

10  2

11  X<>Y

12  Y↑X

13  MOD

14  BINM

15  END


Examples:


Shift Left:  10100, size 5:  1000   (01000)


Shift Left:  10100, size 8:  101000  (00101000)


Shift Right (Logical)


Makes a binary integer shift right: a zero is added to the left side of the integer and "drops" off the left most digit.  The binary number is assumed to be non-negative. A logical shift right divides an integer by 2 and taking the integer result.


HP 42S/DM42 Program SR16


00  {24-Byte Prgm}

01  LBL "SR16"

02  BINM

03  "BIN?"

04  PROMPT

05  EXITALL

06  2

07  ÷

08  IP

09  BINM

10  END


Examples:


Shift Right:  10100:  1010


Shift Right:  1010:  101


The next two programs deals with RGB and HEX codes for computer colors.


HP 42S/DM42 Program CLR→:   RBG to Hexadecimal Code


00  {51-Byte Prgm}

01  LBL "CLR→"

02  DECM

03  "RED?"

04  PROMPT

05  65536

06  BASE×

07  "GREEN?"

08  PROMPT

09  256

10  BASE×

11  BASE+

12  "BLUE?"

13  PROMPT

14  BASE+

15  HEXM

16  END


Example:

Red: 221, Green: 80, Blue 109

Result:  HEX Code:  DD506D


HP 42S/DM42 Program  →CLR:   Hexadecimal to RGB Code


00  {63-Byte Prgm}

01  LBL "→CLR"

02  HEXM

03  "HEX CODE?"

04  PROMPT

05  STO 00

06  DECM

07  65536

08  BASE÷

09  STOP   // Red

10  65536

11  BASE×

12  RCL 00

13  X<>Y

14  BASE-

15  STO 00

16  256

17  BASE÷

18  STOP   // Green

19  256

20  BASE×

21  RCL 00

22  X<>Y

23  BASE-

24  END


Example:  

HEX Code:  103E22

Result:  Red:  16, Green:  62,  Blue:  34


Eddie



All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Sunday, June 13, 2021

Numworks: Bezier Curve (Using Ion Module)

 Numworks: Bezier Curve (Using Ion Module)


Introduction


The script bezier1 plots a Bezier curve of degree 1, 2, or 3 in one of four colors: black (0), red (1), green (2), and blue (3).  The script uses the ion module, which allows input directly from the keyboard.


The ion module function keydown returns True if a certain key has been pressed, otherwise, False is returned.  Keys are designed by the declaration KEY_(key name).  For example: 


KEY_ZERO:  0 key

KEY_ONE:  1 key

KEY_TWO:  2 key

KEY_THREE: 3 key

KEY_FOUR: 4 key

KEY_FIVE: 5 key

KEY_SIX:  6 key

KEY_SEVEN:  7 key

KEY_EIGHT:  8 key

KEY_NINE:  9 key


Numworks script:   bezier1.py


# Bezier Curve 

# 2021-05-02 EWS


from ion import *

from math import *

from matplotlib.pyplot import *


# functions


# key press

def key():

  while True:

    if keydown(KEY_ONE):

      return 1

    if keydown(KEY_TWO):

      return 2

    if keydown(KEY_THREE):

      return 3


# linear plot

def linbez(x0,y0,x1,y1):

  xlist=[x0]

  ylist=[y0]

  t=0

  while t<1:

    t+=0.05

    xlist.append(x0*(1-t)+x1*t)

    ylist.append(y0*(1-t)+y1*t)

  return [xlist,ylist]


# quadratic plot

def quadbez(x0,y0,x1,y1,x2,y2):

  xlist=[x0]

  ylist=[y0]

  t=0

  while t<1:

    t+=0.05

    x=x0*(1-t)**2+2*x1*t*(1-t)+x2*t**2

    y=y0*(1-t)**2+2*y1*t*(1-t)+y2*t**2

    xlist.append(x)

    ylist.append(y)

  return [xlist,ylist]


# cubic plot

def cubbez(x0,y0,x1,y1,x2,y2,x3,y3):

  xlist=[x0]

  ylist=[y0]

  t=0

  while t<1:

    t+=0.05

    x=x0*(1-t)**3+3*x1*t*(1-t)**2+3*x2*t**2*(1-t)+x3*t**3

    y=y0*(1-t)**3+3*y1*t*(1-t)**2+3*y2*t**2*(1-t)+y3*t**3

    xlist.append(x)

    ylist.append(y)

  return [xlist,ylist]  


# color selection

def colsel():

  print("Choose a color:")

  print("0: black, 1: red \n2: green, 3: blue")

  while True:

    if keydown(KEY_ZERO):

      return 'black'

    if keydown(KEY_ONE):

      return 'red'

    if keydown(KEY_TWO):

      return 'green'

    if keydown(KEY_THREE):

      return 'blue'

      

# main program

print("Bezier Curve Plot")

print("Order? Press 1, 2, or 3.")

n=key()

x0=float(input("x0? "))

y0=float(input("y0? "))

x1=float(input("x1? "))

y1=float(input("y1? "))

if n==1:

  clist=linbez(x0,y0,x1,y1)

if n>1:

  x2=float(input("x2? "))

  y2=float(input("y2? "))

if n==2:

  clist=quadbez(x0,y0,x1,y1,x2,y2)

if n==3:

  x3=float(input("x3? "))

  y3=float(input("y3? "))

  clist=cubbez(x0,y0,x1,y1,x2,y2,x3,y3)

# color section

ch=colsel()

# plotting

xlist=clist[0]

ylist=clist[1]

xa=min(xlist)-1.5

xb=max(xlist)+1.5

ya=min(ylist)-1.5

yb=max(ylist)+1.5

# set axis and turn it on

axis((xa,xb,ya,yb))

axis("on")

# plot the curve

plot(xlist,ylist,color=ch)

show()


Program Size: 1995 bytes 


Eddie

All original content copyright, © 2011-2021.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 

Sunday, September 13, 2020

Numworks: Generating a Colorful Matrix

Numworks:  Generating a Colorful Matrix 

(updated 10/18/2021)


Introduction

Today's script generates a 3 x 3 matrix of random integers from 1 - 9 which each of the numbers are assigned a color.  The numbers are displayed in a 3 x 3 grid using the 320 x 240 pixel screen.  

The colors which are assigned to each number are:

1:  Shamrock Green  (0, 158, 96)

2:  Denim Blue (21, 96, 189)

3:  Navy Blue (0, 0, 128)

4:  Indigo (75, 0, 130)

5:  Red (255, 0, 0)

6:  Rose (255, 0, 127)

7:  Brown (101, 67, 33)

8:  Orange (255, 127, 39)

9:  Gold (255, 223, 0)


Numworks Python Script:  colormtx.py


from math import *

from random import *

from kandinsky import *


# 2020-08-25 EWS


# color arrays

# red

mr = [ 0, 21, 0, 75, 255, 255, 101, 255, 255 ]

# green

mg = [ 158, 96, 0, 0, 0, 0, 67, 127, 223 ]

# blue 

mb = [ 96, 189, 128, 130, 0, 127, 33, 39, 0 ]


# set up matrix

mat = [ [ 0, 0, 0 ], [ 0, 0, 0 ], [ 0, 0, 0 ] ]


# generate random numbers, assign colors 

for r in range(3): 

 for c in range(3):

  mat[ r ][ c ] = randint(1,9)

  x = 80 + 80 * c

  y = 60 + 60 * r

  s = mat[ r ][ c ]

  draw_string(str(s), x, y, color(mr[s-1], mg[s-1], mb[s-1]))


Download the code here:  https://my.numworks.com/python/ews31415/colormtx


Gratitude to Brian who let me know about my typo on the last line, it was missing the final right parenthesis.  


Remember that the index of arrays and matrices go from 0 to n-1.  

Examples






Eddie

All original content copyright, © 2011-2020.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Monday, August 5, 2019

TI-84 Plus CE and HP Prime: Calculating Color Temperature

TI-84 Plus CE and HP Prime:  Calculating Color Temperature

Introduction

We can estimate a color temperature for a given color.  However, the estimate is most useful when the color is close to white or the black body curve.  The color temperature, known as the CCT, is just one particular aspect of a color and its light quality. 

For more detailed information, please check the article by Waveform Lighting, https://www.waveformlighting.com/tech/calculate-color-temperature-cct-from-cie-1931-xy-coordinates.  The article will be listed in the Sources section at the end of this blog entry.

Calculation

The program RGBTEMP will estimate CCT from a color given its RGB (red-green-blue) coordinates. 

The calculation involves several steps:

1.  Scaling RGB values from a scale of 0-255 to 0-1.  This is accomplished by dividing each of the parameters of the color's RGB value by 255.  Standard RGB values (sRGB) are used. 

2.  The scaled RGB values will be converted to CIE 1931 XYZ color space values.  In 19031, the International Commission on Illumination created the CIE 1931 color space, designed to describe how the distribution of color wavelengths affect how colors are perceived.  The conversion is done in two parts.

2a.  Adjust each of the scaled RGB values to account for the gamma correction:

Let I be the scaled parameter for R, G, and B.  Then:

If I ≤ 0.04045, Then:

I_adj = I/12.92

Else:

I_adj = ( (I + 0.055) / 1.055) ^ 2.4

2b.  Calculate the XYZ values.   This can be accomplished by matrix multiplication:

[ [ X ] [ Y ] [ Z ] ] =

[[ 0.4124, 0.3576, 0.1805 ] [ 0.2126, 0.7152, 0.0722 ] [ 0.0193, 0.1192, 0.9504 ]]
*  [ [ R ] [ G ] [ B ] ]

3.  With the XYZ coordinates, calculate CIE Yxy coordinates.  Y is already done, so only (small) x and (small) y are needed:

x = X / (X + Y + Z)

y = Y / (X + Y + Z)

4.  Calculate the CCT.  There are several methods: one of them is a cubic approximation from Calvin McCamy:

n = (x - 0.3320) / (0.1858 - y)

CCT = 437 * n^3 + 3601 * n^2 + 6861 * n + 5517

CCT is in Kelvins.

TI-84 Plus Program RGBTEMP

"2019-07-11 EWS"
Disp "COLOR TEMP FROM RGB"
Input "RED   :",R
Input "GREEN :",G
Input "BLUE  :",B

[[R/255][G/255][B/255]]→[I]

For(I,1,3)
If [I](I,1)≤0.04045
Then
[I](I,1)/12.92→[I](I,1)
Else
(([I](I,1)+.055)/1.055)^2.4→[I](I,1)
End
End

[[.4124,.3576,.1805][.2126,.7152,.0722][.0193,.1192,.9504]]*[I]→[J]

[J](1,1)/([J](1,1)+[J](2,1)+[J](3,1))→X
[J](2,1)/([J](1,1)+[J](2,1)+[J](3,1))→Y

(X-.332)/(.1858-Y)→N
437*N^3+3601*N^2+6861*N+5517→C
Disp "CCT (K):",C

HP Prime Program RGBTEMP

The HP Prime version returns CCT, the XYZ coordinates, and the x and y parameters in a four element list.

EXPORT RGBTEMP(R,G,B)
BEGIN
// 2019-07-11 EWS
// RGB to color temperature
LOCAL M0,M1,X,Y,N,C;
LOCAL I,U,V,N,CCT;

// initialize
M0:=[[R/255],[G/255],[B/255]];

// correction
FOR I FROM 1 TO 3 DO
IF M0(I,1)≤0.04045 THEN
M0(I,1):=M0(I,1)/12.92;
ELSE
M0(I,1):=((M0(I,1)+0.055)
/1.055)^2.4;
END;
END;

// RGB to CIE XYZ 1931
M1:=[[0.4124,0.3576,0.1805],
[0.2126,0.7152,0.0722],
[0.0193,0.1192,0.9504]]*M0;

// XYZ to Yxy
X:=M1(1,1)/(M1(1,1)+M1(2,1)+
M1(3,1));
Y:=M1(2,1)/(M1(1,1)+M1(2,1)+
M1(3,1));

// xy to CCT (Kelvins)
// McCamy approximation
N:=(X-0.3320)/(.1858-Y);
C:=437*N^3+3601*N^2+6861*N+5517;

RETURN {C,M1,X,Y};

END;

Examples
(CCT rounded to four decimal places)

Remember the closer to the Black Body Curve, the more accurate the answer. 

Red:  RGB (255, 0, 0)
CCT:  3034.8988 K

Green:  RGB (0, 255, 0)
CCT:  6068.7576 K

Orange:  RGB (255, 165, 0)
CCT:  2429.5395 K

Sky Blue:  RGB (136, 206, 235)
CCT:  13207.1056 K

White:  RGB (255, 255, 255)
CCT:  6506.6551 K

Sources

"Convert color data into different standards and color spaces" and "Color math and programming code examples"   EASYRGB.  IRO Group Limited.  2019. https://www.easyrgb.com/en/convert.php  and https://www.easyrgb.com/en/math.php    Retrieved July 11, 2019

"Calculate color temperature (CCT) from CIE 1931 xy coordinates"  Waveform Lighting. 2019.  https://www.waveformlighting.com/tech/calculate-color-temperature-cct-from-cie-1931-xy-coordinates   Retrieved July 6, 2019

"sRGB"  Wikipedia.  Last edited May 18, 2019.  https://en.wikipedia.org/wiki/SRGB
Retrieved June 16, 2019.

Eddie

All original content copyright, © 2011-2019.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Sunday, May 27, 2018

HP Prime Colors (English and Spanish)


HP Prime Colors (English and Spanish)



Introduction

The program COLORES lets the user scroll through various colors (black/blanco, gray/gris, white/blanco, etc.) using the plus ( [+] ) and minus ( [ -] ) buttons.  End the program while pressing the escape button ([Esc]). 

That’s all there is to it.  Enjoy this program. 

HP Prime Program COLORES

drawnow(); // subroutine

EXPORT COLORES()
BEGIN
// 2018-05-27 EWS
// Colors in English and Spanish

// initialization
LOCAL i:=0,j:=1;
LOCAL lst:={{0,"black","negro"},
{#808080h,"gray","gris"},
{#FFFFFFh,"white","blanco"},
{#FF0000h,"red","rojo"},
{#800000h,"maroon","granate"},
{#FFC0C0h,"pink","rosado"},
{#FF00FFh,"magenta","magenta"},
{#400080h,"indigo","índigo"},
{#800080h,"purple","púrpura"},
{#000080h,"navy blue","azul marino"},
{#0000FFh,"blue","azul"},
{#00FFFFh,"cyan","cian"},
{#80D0FFh,"sky blue","cielo azul"},
{#008080h,"teal","verde azulado"},
{#003000h,"fir green","abeto verde"},
{#008000h,"green","verde"},
{#00FF00h,"lime","lima"},
{#FF8000h,"orange","naranja"},
{#D0B090h,"tan","bronceado"},
{#FFFF00h,"yellow","amarillo"}
};
LOCAL s:=SIZE(lst);

RECT();
TEXTOUT_P("Press [+] or [-] to start.",
10,45,4);

LOCAL k,j1,j2,j3;
REPEAT
k:=GETKEY;

// plus key
IF k==50 THEN
i:=i+1; j:=(i MOD s)+1;
j1:=lst(j,1); j2:=lst(j,2);
j3:=lst(j,3);
drawnow(j1,j2,j3);
END;

// minus key
IF k==45 THEN
i:=i-1; j:=(i MOD s)+1;
j1:=lst(j,1); j2:=lst(j,2);
j3:=lst(j,3);
drawnow(j1,j2,j3);
END;


UNTIL k=4; // ESC key
END;

// subroutine
drawnow(x1,x2,x3)
BEGIN
RECT();
// polygon
FILLPOLY_P({{10,10},{10,150},{150,150},
{150,10}},x1);
// text
TEXTOUT_P("English:",160,20,4);
TEXTOUT_P(x2,160,40,4);
TEXTOUT_P("Español:",160,70,4);
TEXTOUT_P(x3,160,90,4);
END;

Eddie

All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

Thursday, May 10, 2018

HP Prime: Pentcolor Demonstration





HP Prime: Pentcolor Demonstration

Introduction

The HP Prime program PENTCOLOR allows the cycler to through colors with the touch of the following buttons:

Key [ 1 ]:  Red
Key [ 2 ]:  Green
Key [ 3 ]:  Blue

Each color setting cycles through the values of 0, 64, 128, 192, and 255.  Exit the program with the Escape key ( [ Esc ] ).  This program allows the user to cycle through different colors using RGB values.

 I use two subroutines in PENTCOLOR.  The first draws the text every time the key is selected, which allows for crisp text.   The second is for value calculation.  In subroutines on the HP Prime, all variables that are used must be local.  Global variables are passed through the subroutine arguments.  





HP Prime Program:  PENTCOLOR

SBR1(); // sub routine text
// allows for crisp text

SBR2(); // sub routine calc
// saves space in main program

// main program
EXPORT PENTCOLOR()
BEGIN
// EWS 2018-05-07

LOCAL K,R,G,B;
// R,G,B are set at 0
RECT();

TEXTOUT_P("Ready! 1. Red,
2. Green, 3. Blue",0,20,4);

REPEAT
K:=GETKEY;

// Key 1, red
IF K==42 THEN
RECT();
R:=SBR2(R);
SBR1(R,G,B);
END;

// Key 2, green
IF K==43 THEN
RECT();
G:=SBR2(G);
SBR1(R,G,B);
END;

// Key 3, blue
IF K==44 THEN
RECT();
B:=SBR2(B);
SBR1(R,G,B);
END;

UNTIL K==4; // ESC key

END;

// sub routines
// all subroutines have
// all local variables
SBR1(x,y,z)
BEGIN
TEXTOUT_P("[ 1 ]: Red: "+x,
0,20,4,#FF0000h);
TEXTOUT_P("[ 2 ]: Green: "+y,
0,40,4,#00FF00h);
TEXTOUT_P("[ 3 ]: Blue: "+z,
0,60,4,#0000FFh);
TEXTOUT_P("[Esc]: Exit",
0,120,4);
// draw box
FILLPOLY_P({(160,20),(310,20),
(310,170),(160,170)},RGB(x,y,z));
END;

SBR2(t)
BEGIN
t:=t+64;
IF t==256 THEN t:=255; END;
IF t==319 THEN t:=0; END;
RETURN t;
END;

Eddie

All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues The programs are listed for the Swiss Micros DM42 an...