Ask Learn
Preview
Please sign in to use this experience.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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.
Please sign in to use this experience.
Sign in