Board Logo
« Winter fun 2016 Light Table »

Welcome Guest. Please Login or Register.
Jan 21st, 2018, 12:57am


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Please use the forums Search feature before asking.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is too long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Winter fun 2016 Light Table  (Read 899 times)
Rod
Administrator
ImageImageImageImageImage


member is offline

Avatar

Graphics = Goosebumps!


PM

Gender: Male
Posts: 3151
xx Winter fun 2016 Light Table
« Thread started on: Nov 1st, 2016, 04:56am »

We have a good few educators as members of the forum many with science backgrounds so this one is for you.

Create a science class light table. One where objects can be placed like prisms or lenses and the path of the rays of white light traced in 2D.


You may even split the light into its color components if you are feeling adventurous.
User IP Logged

tenochtitlanuk ( John F)
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 430
xx Re: Winter fun 2016 Light Table
« Reply #1 on: Nov 2nd, 2016, 5:08pm »

OK here's a starter. The red blob is the ray source, and shines at a fixed point on a glass block. Reflected and refracted rays are shown.
REM /unREM the lines below depending if you like pretty patterns!
User Image
Code:
            '#wg "cls"
            '#wg "drawbmp scr 0 0 ; flush"
 

Code:
    nomainwin

    WindowWidth  =1000
    WindowHeight = 700
    UpperLeftX   =  50
    UpperLeftY   =  50

    open "Optic bench." for graphics_nsb as #wg

        #wg     "trapclose quit"

        #wg     "down ; fill black ; color 50 180 190 ; backcolor 50 120 130"
        #wg     "size 4 ; up ; goto 0 404 ; down ; boxfilled 1000 700"

        #wg     "getbmp scr 0 0 1000 700"

        for incidentAngle =-90 to 90 step 2
            #wg "north ; up ; goto 500 400 ; down"
            green   =int( ( incidentAngle +90) /180 *255)
            #wg "color "; str$( 256 -green); " "; str$( green); " 60"
            #wg "turn "; incidentAngle
            #wg "go 360 ; size 16 ; go 1 ; size 4"

            #wg "north ; up ; goto 500 400 ; down"
            #wg "turn "; 0 -incidentAngle
            #wg "go 1000"

            #wg "north ; up ; goto 500 400 ; down"
            refractedAngle =asn( sinRad( incidentAngle) /1.5) *180 /3.14159265
            #wg "turn "; refractedAngle +180
            #wg "go 500"

            timer 200, [carryOn]
            wait
          [carryOn]
            timer 0

            '#wg "cls"
            '#wg "drawbmp scr 0 0 ; flush"
        next incidentAngle

        scan

        wait

    sub quit h$
        close #wg
        end
    end sub

    function sinRad( th)
        sinRad =sin( th *3.14159265 /180)
    end function
 
User IP Logged

Visit my LB/JB pages at http://www.diga.me.uk/index.html
I use XP and Ubuntu Linux on old machines!
bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Winter fun 2016 Light Table
« Reply #2 on: Nov 6th, 2016, 08:52am »

I don't know if John was attempting to illustrate this but isn't that what plants do, absorb red wavelengths and reflect green...

Green on a color wheel is the opposite of red but if wavelengths are on a spectrum of numbers in a positive range how can one real number be the opposite of another (assuming there is no negative wavelengths) huh

Oh wait, take white light, the whole spectrum, suck out all the red and what gets reflected is what is left, anything not red >> blue + yellow = green.

« Last Edit: Nov 6th, 2016, 10:58am by bplus » User IP Logged

B+
Rod
Administrator
ImageImageImageImageImage


member is offline

Avatar

Graphics = Goosebumps!


PM

Gender: Male
Posts: 3151
xx Re: Winter fun 2016 Light Table
« Reply #3 on: Nov 9th, 2016, 02:33am »

My light table flickers into life. The maths isn't right but it will eventually have RGB light RGB filters and RGB spread from the prism and lenses.

Maths gurus will love this challenge but you can cheat as well.

« Last Edit: Nov 12th, 2016, 04:08am by Rod » User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Winter fun 2016 Light Table
« Reply #4 on: Nov 10th, 2016, 9:47pm »

Something to reflect upon:

Code:
'house of mirrors.txt for Just Basic v1.01 [B+=MGA] 2016-11-11

global H$, XMAX, YMAX, lastX, lastY, leftLimit, rightLimit, topLimit, botLimit
H$ = "gr"
XMAX = 1200 '< actual drawing space needed
YMAX = 600  '< actual drawing space needed
leftLimit = XMAX/3
rightLimit = XMAX*.67
topLimit = YMAX/3
botLimit = YMAX*.67

nomainwin

WindowWidth = XMAX + 8
WindowHeight = YMAX + 32
UpperLeftX = (1200 - XMAX) / 2  'or delete if XMAX is 1200 or above
UpperLeftY = (700 - YMAX) / 2   'or delete if YMAX is 700 or above

menu #gr, "Screen", "Clear", clearance
open "House of Mirrors:     draw or write in center section" for graphics_nsb_nf as #gr
#gr "setfocus"
#gr "trapclose quit"
#gr "when leftButtonDown lBD"
#gr "when leftButtonMove mWrite"
#gr "when leftButtonUp lBU"
#gr "when characterInput charIn"
#gr "down"
#gr "size 2"
call clearance
wait

sub clearance
    #gr "cls"
    #gr "color black"
    #gr "line ";leftLimit;" ";0;" ";leftLimit;" ";YMAX
    #gr "line ";rightLimit;" ";0;" ";rightLimit;" ";YMAX
    #gr "line ";0;" ";topLimit;" ";XMAX;" ";topLimit
    #gr "line ";0;" ";botLimit;" ";XMAX;" ";botLimit
    #gr "color blue"
    #gr "flush"
end sub

sub lBD H$, mx, my
    if mx > leftLimit and mx < rightLimit and my > topLimit and my < botLimit then
        lastX = mx
        lastY = my
    end if
end sub

sub mWrite H$, mx, my
    if mx > leftLimit and mx < rightLimit and my > topLimit and my < botLimit then
        #gr "line ";lastX;" ";lastY;" ";mx;" ";my
        dy1 = my - topLimit
        dy2 = lastY - topLimit
        #gr "line ";lastX;" ";topLimit-dy2;" ";mx;" ";topLimit-dy1
        dy1 = botLimit - my
        dy2 = botLimit - lastY
        #gr "line ";lastX;" ";botLimit+dy2;" ";mx;" ";botLimit+dy1
        dx1 = lastX - leftLimit
        dx2 = mx - leftLimit
        #gr "line ";leftLimit-dx1;" ";lastY;" ";leftLimit-dx2;" ";my
        dx1 = rightLimit - lastX
        dx2 = rightLimit - mx
        #gr "line ";rightLimit+dx1;" ";lastY;" ";rightLimit+dx2;" ";my
        lastX = mx
        lastY = my
    end if
end sub

sub lBU H$, mx, my
    #gr "flush"
end sub

sub quit H$
    close #H$ 
    end
end sub

 
User IP Logged

B+
bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Winter fun 2016 Light Table
« Reply #5 on: Nov 11th, 2016, 12:07pm »

Looking Glass:

Code:
'bottle and cake.txt for Just Basic v1.01 [B+=MGA] 2016-11-11
' Lens effects: magnification or demagnification of image

' The paper note tied around the neck of the bottle said,
' "DRINK ME", in large letters. The note on the cake said,
' "EAT ME", beautifully marked in currants.
' (Any similarities to fictional characters is pure coincidence;-)

'Well I guess will be testing Andy's Atan2 function also.

global H$, XMAX, YMAX, PI, DEG, RAD
global lastX, lastY, leftLimit, rightLimit, topLimit, botLimit
global smallX, medX, bigX, cY, lsX, lsY, lbX, lbY

H$ = "gr"
XMAX = 1200 '< actual drawing space needed
YMAX = 600  '< actual drawing space needed
PI = acs(-1)
DEG = 180 / PI
RAD = PI / 180

' drawing box
leftLimit = .5 * XMAX / 9.5
rightLimit = 1.5 * XMAX / 9.5
topLimit = YMAX / 2 - .0675 * YMAX
botLimit = YMAX / 2 + .0675 * YMAX

'centers for shrinking and growing
smallX = int(leftLimit / 2)
medX = int((rightLimit - leftLimit) / 2 + leftLimit)
bigX = int((XMAX - rightLimit) / 2 + rightLimit)
cY = YMAX / 2

nomainwin

WindowWidth = XMAX + 8
WindowHeight = YMAX + 32
UpperLeftX = (1200 - XMAX) / 2  'or delete if XMAX is 1200 or above
UpperLeftY = (700 - YMAX) / 2   'or delete if YMAX is 700 or above

menu #gr, "Screen", "Clear", clearance
open "Bottle and Cake:     draw or write, Alice, inside box" for graphics_nsb_nf as #gr
#gr "setfocus"
#gr "trapclose quit"
#gr "when leftButtonDown lBD"
#gr "when leftButtonMove mWrite"
#gr "when leftButtonUp lBU"
#gr "when characterInput charIn"
#gr "down"
call clearance
wait

sub clearance
    #gr "cls"
    #gr "size 2"
    #gr "color black"
    #gr "place ";leftLimit;" ";topLimit
    #gr "box ";rightLimit+1;" ";botLimit
    #gr "color blue"
    #gr "flush"
end sub

sub charIn H$, c$ 
    call quit H$
end sub

sub quit H$
    close #H$ 
    end
end sub

sub lBD H$, mx, my
    if mx > leftLimit and mx < rightLimit and my > topLimit and my < botLimit then
        lastX = mx
        lastY = my
        dy = my - cY
        dx = mx - medX
        ang = Atan2(dy, dx)
        dist = (dx ^ 2 + dy ^ 2) ^ .5
        lsX = smallX + .5 * dist * cos(ang)
        lsY = cY + .5 * dist * sin(ang)
        lbX = bigX + 8 * dist * cos(ang)
        lbY = cY + 8 * dist * sin(ang)
    end if
end sub

sub mWrite H$, mx, my
    if mx > leftLimit and mx < rightLimit and my > topLimit and my < botLimit then
        #gr "size 2"
        #gr "line ";lastX;" ";lastY;" ";mx;" ";my
        dy = my - cY
        dx = mx - medX
        ang = Atan2(dy, dx)
        dist = (dx ^ 2 + dy ^ 2) ^ .5
        nextsX = smallX + .5 * dist * cos(ang)
        nextsY = cY + .5 * dist * sin(ang)
        nextbX = bigX + 8 * dist * cos(ang)
        nextbY = cY + 8 * dist * sin(ang)
        #gr "size 1"
        #gr "line ";lsX;" ";lsY;" ";nextsX;" ";nextsY
        #gr "size 16"
        #gr "line ";lbX;" ";lbY;" ";nextbX;" ";nextbY
        lastX = mx
        lastY = my
        lsX = nextsX
        lsY = nextsY
        lbX = nextbX
        lbY = nextbY
    end if
end sub

sub lBU H$, mx, my
    #gr "flush"
end sub

Function Atan2(y, x)    'thanks Andy Amaya
    'Atan2 is a function which determines the angle between points
    'x1, y1 and x2, y2. The angle returned is in radians
    'The angle returned is always in the range of
    '-PI to PI radians (-180 to 180 degrees)
    '==============================================================
    'NOTE the position of Y and X arguments
    'This keeps Atan2 function same as other language versions
    '==============================================================
   If x = 0 Then
       If y < 0 Then
            Atan2 = -1.5707963267948967
        Else
            Atan2 = 1.5707963267948967
        End If
   Else
       chk = atn(y/x) 'fix for JB
       If x < 0 Then
           If y < 0 Then
                chk = chk - 3.1415926535897932
            Else
                chk = chk + 3.1415926535897932
            End If
       End If
       Atan2 = chk
   End If
End Function

 


Append:
It should also be noted for Atan2 how the x, y parameters are calculated:
y is the difference y2 - y1 and x is the difference x2- x1.

But then there is the trick of figuring out which point is x1, y1 and which point x2, y2. In the above case, it worked out x1, y1 was the center and x2, y2 was the mouse position about that center.

If you try this and are 180 degrees off (half a circle) just reverse point 1 and point 2. If you get a bunch of errors and 0's then try atn instead of atan in the Atan2 function :))
« Last Edit: Nov 11th, 2016, 2:06pm by bplus » User IP Logged

B+
Rod
Administrator
ImageImageImageImageImage


member is offline

Avatar

Graphics = Goosebumps!


PM

Gender: Male
Posts: 3151
xx Re: Winter fun 2016 Light Table
« Reply #6 on: Nov 12th, 2016, 03:59am »

This is my light table stumbling into life. Please don't take it as model, create your own. But it shows what I am thinking about. Eventually you will be able to drag and drop lenses and filters, you will be able to change the light source color. I hope eventually for the rays to be traced as R G B colors rather than plain white.

I have tweaked Richards getpixel function to return the color triplet. My changes are messy so again don't take any of this code as a model.

http://gamebin.webs.com/Liberty/JBLight.zip

User Image


« Last Edit: Nov 12th, 2016, 04:11am by Rod » User IP Logged

aspagnito
New Member
Image


member is offline

Avatar




PM


Posts: 1
xx Re: Winter fun 2016 Light Table
« Reply #7 on: Nov 13th, 2016, 05:35am »

Tsup,
It's been a while since I coded, but my mind hasn't changed about it. I will code, I promise.
There was a very important question here of how to do the color math? I have a pure hypothesis and I am sure this was never made like that in any software. That's why it's gonna work, so buckle your seatbelt Dorothy, cause Cansas is goin' bye-bye. I will need suggestions for this task.
The question is to guess the direct order of 16 colors. Synesthesia tells me a sollution.
1 - white
2 - yellow
3 - green
4 - red
5 - blue
6 - black
7 - light brown
8 - dark brown
9 - purple (bordo - dark red plus violet)
10 - transparent
11 - grey
12 - golden
13 - light green (seledyn)
14 - pink
15 - sky blue
16 - ying yang - black plus white

If I can have the direct order of colors, I can make transformations on them. Let's say 1+1 is 2 which in first instance means two whites make yellow. But that is not what I am searching for. I will have to have all of the combinations, so 2 is also 6-4 and 15-13. If I somehow manage how by adding something to something I can make a minus, like in binary logic, I can get 16 results and make an average, which would be my color. But if I searched for the color 2658 for an ecample the color math should be that universal, that I have to make an average of only 16 results. I am not that good in math to create such revolutionairy transformation only by myself, so I am asking for suggestions, please.

There are 2 clues. If such math is possible, each of basic 16 colors have to be a result of such transformation and the other clue is that when it comes to 10, the transparent, there should be a division by zero. If such math is possible it would not only enable the count of infinite number of colors, but make the renderer a lot simpler and more beautiful. Yet simplicity is not the best word here, but the word is obviousness, which I understand as unique simplicity and the optimal count of simple ideas.

Right now I am suspending this idea till I get any suggestions on how to do this. I will start programming from something I can do, which is the geometry of a renderer. I got interested into that project, because I believe something better than blender should be done in a basic computer language (mostly thanks to redundance). If such a renderer which would be first intuitional would be done, it would get a lot more support fom people even learning the programming for the first time and the project would evolve a lot quicker than blender, written in python, which is a lot more complicated.
Do not get me wrong. Blender is very good, but very good sollutions are only proper and are not right. Yet the right sollutions are not always the best ones. If something, that is very strong gets weakend, it gets absolutistic and that's what I am up to. Rendering is a very difficult thing to program, but as something very strong fueled by something so fragile and soft as a basic programming language - the idea can be universal. Basic language has a feature other laguages do not have. It gives the must of operating with very simple ideas to create something greater - but on the other hand it makes people create genius scratches one can accomodate into a great project, with practically perfect elimination of errors. That is why I am interested in this project and I am starting programming with the geometry of the renderer.
« Last Edit: Nov 13th, 2016, 06:36am by aspagnito » User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Winter fun 2016 Light Table
« Reply #8 on: Nov 13th, 2016, 09:58am »

Hi aspagnito,

Color is complex subject! If Kansas was old BASIC's 16 colors then OZ is the RGB system available now with JB.

I just discovered RGB system is not covered very well in Help files (only mentioned under color command), basically you can add, subtract, mix and match 3 color components red, green, blue = RGB.

We can discuss how it works in General or Novice boards if you want to start a thread there, meanwhile check it out on Internet.
« Last Edit: Nov 13th, 2016, 10:15am by bplus » User IP Logged

B+
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls