Learn Abstract and Concrete with Small Basic


I wrote some programs for learning abstract and concrete.  At first I made a subroutine Average().  This routine calculates (a + b) / 2.  The concept average is a special (concrete) case of a wider concept.  Secondly, I made a subroutine Intermediate().  The concept of this routine is wider and more abstract than Average().  Intermediate() needs one more parameter k.  And if k = 0.5, the result is the same as Average().  The output of this program is:

Average(a=10, b=20) = 15
Intermediate(a=10, b=20, k=0) = 10
Intermediate(a=10, b=20, k=0.25) = 12.50
Intermediate(a=10, b=20, k=0.50) = 15.00
Intermediate(a=10, b=20, k=0.75) = 17.50
Intermediate(a=10, b=20, k=1.00) = 20.00

Press any key to continue...

The code is here.

' Abstract and Concrete
' Version 0.1
' Copyright © 2016 Nonki Takahashi. The MIT License.
' Program ID HRX565
 
TextWindow.Title = "Abstract and Concrete 0.1"
 
' average value
a = 10
b = 20
Average()
TextWindow.WriteLine("Average(a=" + a + ", b=" + b + ") = " + c)
 
' intermediate value
For k = 0 To 1 Step 0.25
  Intermediate()
  TextWindow.WriteLine("Intermediate(a=" + a + ", b=" + b + ", k=" + k + ") = " + c)
EndFor
TextWindow.WriteLine("")
 
Sub Average
  ' param a - the first value
  ' param b - the second value
  ' return c - the average of the given values
  c = (a + b) / 2
EndSub
 
Sub Intermediate
  ' param a - the first value
  ' param b - the second value
  ' param k - ratio between a and b (0 ≦ k ≦ 1)
  ' return c - the intermediate value between a and b
  c = a * (1 - k) + b * k
EndSub

I sometimes use the code like Intermediate(). So I also wrote application samples of Intermediate() for points and colors. The program ID is HRX565-0.  This program is also text base.

One more sample is HRX565-1.  This is a graphical demo animation program for these concepts.

Screen shot of a program Abstract and Concrete 0.3

Comments (2)

  1. YLed says:

    Hello Nonki
    Very nice demonstration of the way 2 colors in paint, would be mixed to get a new color.
    take a look on this web site: http://trycolors.com/
    we can mix our colors online and it works almost identical to your program, for example I did a few tests:

    I mix red FF0000 with a 005B00 normally in oïl painting , green + red green gives brownish hue, and here’s the result of your program: 7F5A00, so very real.

    Here is a visual and simplified version only for colors average and mixing:
    VWL407

    Also, I tried the ultimate test:
    black + white = middle gray
    000000 + 7F7F7F = FFFFFF
    and Yes PERFECT your program gives 7F7F7F!
    in decimal
    0 + 255 = (255/2 += 127.5)
    127 in hexadecimal gives 7F

    Perfect score !!

  2. YLed says:

    error in line : should read like this:
    000000+FFFFFF = 7F7F7F

Skip to main content