Slide rule

Here is a program I wrote yesterday while watching the Olympics. The older group members should know how this works, while some of the younger members won’t know what this is. Slide your finger above the rule to move the C scale at a 1:1 ratio, while below the rule is a 1:10 ratio.


-- slide rule
-- use your finger to move the C scale
-- 1:1 ratio above the rule, 1:10 ratio below the rule

function setup()
    supportedOrientations(LANDSCAPE_LEFT)
    displayMode(FULLSCREEN)
    lineCapMode(PROJECT)
    yy=50
    yz=50
end

function draw()
    background(40, 40, 50)
    c_scale()
    d_scale()
end

function touched(t)
    local d = 1
    if t.y<400 then
        d=10
    end
    if t.state==BEGAN then
        xstart=yz-t.x/d
    elseif t.state==MOVING then
        yz=xstart+t.x/d
    end  
end 

function d_scale()
    fill(255,255,255,255)    
    stroke(255)
    rect(10,330,980,70)
    
    stroke(0)
    strokeWidth(4)
    for y=1,10 do
        l=math.log10(y)*900
        line(l+yy,370,l+yy,400)
    end
    for y=1,10, .5 do
        l=math.log10(y)*900
        line(l+yy,375,l+yy,400)
    end 
    for y=1,10, .1 do
        l=math.log10(y)*900
        line(l+yy,380,l+yy,400)
    end
    for y=1,3, .02 do
        l=math.log10(y)*900 
        line(l+yy,390,l+yy,400)
    end 
    for y=3,8, .05 do
        l=math.log10(y)*900
        line(l+yy,390,l+yy,400)
    end 
    
    fill(0)
    --xx=math.log10(1)*900+yy
    fontSize(20) 
    text("D",30,370) 
    text("D",970,370)
    
    y3=355
    y4=365

    text("1",50,y3)
    text("2",320,y3)
    text("3",480,y3)
    text("4",590,y3)
    text("5",680,y3)
    text("6",750,y3)
    text("7",810,y3)
    text("8",863,y3)
    text("9",910,y3)
    text("1",950,y3)
    
    fontSize(12)
    text(".5",210,y4)    
    text(".5",410,y4)  
    text(".5",540,y4)    
    text(".5",640,y4) 
    text(".5",720,y4)    
    text(".5",780,y4)  
    text(".5",840,y4)    
    text(".5",890,y4)  
    text(".5",930,y4) 
    
    fontSize(10)
    text("dave1707",80,340)
    
    fill(255)    
    fontSize(40)
    text("Slide rule",WIDTH/2,700) 
    
    fontSize(20) 
    text("use your finger to move the C scale",WIDTH/2,650)
    text("ratio of 1:1 above the rule, 1:10 below the rule",WIDTH/2,625)
end 
 
function c_scale()
    fill(255,255,255,255) 
    stroke(255)
    rect(yz-40,400,980,70)
    
    stroke(0)
    strokeWidth(4)
    for y=1,10 do
        l=math.log10(y)*900
        line(l+yz,400,l+yz,430)
    end
    for y=1,10, .5 do
        l=math.log10(y)*900
        line(l+yz,420,l+yz,425)
    end 
    for y=1,10, .1 do
        l=math.log10(y)*900
        line(l+yz,400,l+yz,420)
    end
    for y=1,3, .02 do
        l=math.log10(y)*900 
        line(l+yz,400,l+yz,410)
    end 
    for y=3,8, .05 do
        l=math.log10(y)*900
        line(l+yz,400,l+yz,410)
    end 
        
    fill(0)
    --xx=math.log10(1)*900+yz
    fontSize(20) 
    
    y1=445
    y2=435
    
    text("C",-20+yz,420)
    text("C",920+yz,420)
    text("1",yz,y1)
    text("2",270+yz,y1)
    text("3",430+yz,y1)
    text("4",540+yz,y1)
    text("5",620+yz,y1)
    text("6",700+yz,y1)
    text("7",760+yz,y1)
    text("8",813+yz,y1)
    text("9",860+yz,y1)
    text("1",900+yz,y1)
    
    fontSize(12)
    text(".5",160+yz,y2)    
    text(".5",360+yz,y2)  
    text(".5",490+yz,y2)    
    text(".5",590+yz,y2) 
    text(".5",670+yz,y2)    
    text(".5",730+yz,y2)  
    text(".5",790+yz,y2)    
    text(".5",840+yz,y2)  
    text(".5",880+yz,y2)                                     
end              
        

I still have my slide rule - it is probably a collectors item.

You will have to do an abacus next.

My wife and I started going to antique stores and I’ve been buying slide rules. I’m up to 8 different ones now. That’s what gave me the idea to write this code.

Great dave1707!

Good job dave. I used slide rules at Uni and then bought my first calc for $82 AU in the 70s. It could do +*-/ !!!
I think the slide rule was faster… :wink:

@Allomerus That sounds like my first calculator. A commodore C8 (8 digits) with orange gas filled tubes showing the digits. I still have it and it still works. I recently bought a commodore US 10 (10 digits) at a flea market for $5. It also has the orange tubes and that one works too. As for slide rules, I’m up to 21 different ones now. There’s a lot on eBay, but I’m sticking to garage sales, flea markets, and antique stores. Makes the hunt more interesting.

@Reefwing

Here is the abacus you mentioned earlier. I didn’t spend a lot of time doing this, so there are things that I didn’t try to fix. For example, you can overlap the beads if you move too fast. Also, moving a lot of beads at once isn’t very smooth. This is kind of dumb, but it gave me something to do while watching football. The double row of beads at the top instead of a single row allows for the adding and subtraction of HEX.


function setup()
    displayMode(FULLSCREEN)
    init()
end

function init()
    if reset then
        for a=1,70 do
            tab[a]:destroy()
            tab[a]=nil
        end
    end
    
    tab={}    
    reset=false
    offset=0
    row=0
    z=0
    
    -- create lower physics bodies
    for a=1,10 do
        for b=1,5 do
            z = z + 1
            tab[z]=physics.body(CIRCLE,15)
            tab[z].x=50+60*a
            tab[z].y=110+30*b
            tab[z].gravityScale=0
            tab[z].sleepingAllowed=false
        end
    end
    
    -- create upper physics bodies
    for a=1,10 do
        for b=1,2 do
            z = z + 1
            tab[z]=physics.body(CIRCLE,15)
            tab[z].x=50+60*a
            tab[z].y=510+30*b
            tab[z].gravityScale=0
            tab[z].sleepingAllowed=false
        end
    end 
end    

function draw()
    background(30,30,50)
    
    fill(255)
    text("RESET",380,750)
    
    if reset then
        init()
    end
    
    -- draw lines
    for a=1,10 do
        stroke(255)
        strokeWidth(4)
        line(50+60*a,120,50+60*a,675)
    end

    -- draw dividing lines
    strokeWidth(2)
    line(80,300,700,300)
    line(80,600,700,600)
    
    -- draw frame
    strokeWidth(2)
    fill(84, 63, 36, 255)
    rect(78,675,604,40)
    rect(78,480,604,40)
    rect(78,80,604,40)
    rect(40,80,40,635)
    rect(680,80,40,635)
    
    
    -- draw lower beads
    strokeWidth(1)
    z=0
    for a=1,10 do
        for b=1,5 do
            z = z + 1
            tab[z].x=50+60*a
            if tab[z].y<140 then
                tab[z].y=140
            end
            if tab[z].y>460 then
                tab[z].y=460
            end
            fill(235, 22, 22, 255)
            ellipse(tab[z].x,tab[z].y,50,30)
        end
    end
    
    -- draw upper beads
    for a=1,10 do
        for b=1,2 do
            z = z + 1
            tab[z].x=50+60*a
            if tab[z].y<540 then
                tab[z].y=540
            end
            if tab[z].y>660 then
                tab[z].y=660
            end
            fill(235, 22, 22, 255)
            ellipse(tab[z].x,tab[z].y,50,30)
        end
    end 
end

function touched(t)
    if t.state==BEGAN then
        if t.y>730 then
            reset=true
            return
        end
        
        z=0
        -- check which lower bead is selected
        for a=1,10 do 
            for b=1,5 do
                z = z + 1
                if (t.x-tab[z].x)^2+(t.y-tab[z].y)^2<400 then
                    offset=z
                    row=a
                    return
                end
            end
        end
        
        -- check which upper bead is selected
        for a=1,10 do 
            for b=1,2 do
                z = z + 1
                if (t.x-tab[z].x)^2+(t.y-tab[z].y)^2<400 then
                    offset=z
                    row=a
                    return
                end
            end
        end 
    elseif t.state==MOVING and offset>0 then
        tab[offset].x=50+60*row
        tab[offset].y=t.y
    elseif t.state==ENDED then
        offset=0
    end      
end

Hey @dave1707 - I was only kidding but brilliant! You can add it to your series on calculating machines through the ages. What’s next, Pascal’s calculator? Or for something much more challenging emulate the Apollo Guidance Computer (http://www.ibiblio.org/apollo/) since the code is now open source…