Author Topic: Calculator  (Read 7779 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Calculator
« on: July 28, 2020, 03:17:08 pm »
Well, I did it.. lol. It took 3 days and some help from B+ on how to add the decimal point. B+, you were right, I didn't need your Function but what you did teach me is how to keep everything as a string, and that worked out perfectly. Thank you! Tempodibasic, you helped me a lot too in realizing that my "spaghetti code" was causing a lot of frustration so I labeled almost everything in the program and made it a lot easier to understand. I made this second topic because I want people to find the calculator easier with the Subject as just "Calculator". I'll put the URL to the topic where you guys helped me below. If for some reason anyone finds an error or problem, please tell me. I've tested it quite a bit but it's possible there are one or more sequences I haven't tested yet. I'll post a picture of it below too. Thanks again! Oh, and OldMoses, I made the buttons 3D like that by using loops while changing the shade color on a bunch of rectangles. You can see it under "Buttons". Thanks again guys, I feel great!

Code: QB64: [Select]
  1. 'Calculator
  2. 'By SierraKen on July 28, 2020.
  3. '------------------------------
  4. 'This is my very first regular calculator.
  5. 'Thank you to B+ and TempodiBasic for the help and everyone for the inspiration!
  6. 'This was a 3 day project and I've wanted to make this all my life. Ever since I was real little
  7. 'playing around with my parents' calculator.
  8.  
  9. _TITLE "Calculator"
  10. SCREEN _NEWIMAGE(400, 400, 32)
  11. 'Setup calculator
  12. LINE (50, 25)-(265, 50), _RGB32(255, 255, 255), B
  13. LINE (50, 75)-(350, 350), _RGB32(255, 255, 255), B
  14. 'Buttons
  15. FOR buttony = 75 TO 295 STEP 55
  16.     FOR buttonx = 50 TO 275 STEP 75
  17.         FOR bb = 0 TO 10
  18.             c = c + 10
  19.             LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  20.         NEXT bb
  21.         PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
  22.         c = 0
  23.     NEXT buttonx
  24. NEXT buttony
  25. buttonx = 275: buttony = 20
  26. 'Green C Button
  27. FOR bb = 0 TO 10
  28.     c = c + 10
  29.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  30. NEXT bb
  31. PAINT (buttonx + 12, buttony + 12), _RGB32(50, 100 + c, 50)
  32. COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
  33. c = 0
  34. 'Label Buttons
  35. _PRINTSTRING (312, 47), "C"
  36. COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  37. _PRINTSTRING (87, 102), CHR$(251) 'square root
  38. _PRINTSTRING (152, 102), "sin"
  39. _PRINTSTRING (227, 102), "cos"
  40. _PRINTSTRING (302, 102), "tan"
  41. _PRINTSTRING (87, 157), "7"
  42. _PRINTSTRING (162, 157), "8"
  43. _PRINTSTRING (237, 157), "9"
  44. _PRINTSTRING (312, 157), "/"
  45. _PRINTSTRING (87, 212), "4"
  46. _PRINTSTRING (162, 212), "5"
  47. _PRINTSTRING (237, 212), "6"
  48. _PRINTSTRING (312, 212), "x"
  49. _PRINTSTRING (87, 267), "1"
  50. _PRINTSTRING (162, 267), "2"
  51. _PRINTSTRING (237, 267), "3"
  52. _PRINTSTRING (312, 267), "-"
  53. _PRINTSTRING (87, 322), "0"
  54. _PRINTSTRING (162, 322), "."
  55. _PRINTSTRING (237, 322), "="
  56. _PRINTSTRING (312, 322), "+"
  57. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  58.     _LIMIT 20
  59.         mouseX = _MOUSEX
  60.         mouseY = _MOUSEY
  61.         mouseLeftButton = _MOUSEBUTTON(1)
  62.     LOOP
  63.     IF mouseLeftButton THEN
  64.         mouseLeftButton = 0
  65.  
  66.         'Clear
  67.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 20 AND mouseY < 75 THEN
  68.             a = 0: s = 0: t = 0: d = 0: num$ = ""
  69.             _PRINTSTRING (55, 30), "                          "
  70.             buttonx = 275: buttony = 20
  71.             GOSUB zero:
  72.         END IF
  73.  
  74.         'Square Root
  75.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 75 AND mouseY < 130 THEN
  76.             IF num < 0 THEN GOTO skip1:
  77.             num = VAL(num$)
  78.             num = SQR(num)
  79.             num$ = STR$(num)
  80.             skip1:
  81.             buttonx = 50: buttony = 75
  82.             GOSUB press:
  83.             GOSUB number:
  84.         END IF
  85.  
  86.         'Sine
  87.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 75 AND mouseY < 130 THEN
  88.             num = VAL(num$)
  89.             num = SIN(num)
  90.             num$ = STR$(num)
  91.             buttonx = 126: buttony = 75
  92.             GOSUB press:
  93.             GOSUB number:
  94.         END IF
  95.  
  96.         'Cosine
  97.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 75 AND mouseY < 130 THEN
  98.             num = VAL(num$)
  99.             num = COS(num)
  100.             num$ = STR$(num)
  101.             buttonx = 200: buttony = 75
  102.             GOSUB press:
  103.             GOSUB number:
  104.         END IF
  105.  
  106.         'Tangent
  107.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 75 AND mouseY < 130 THEN
  108.             num = VAL(num$)
  109.             num = TAN(num)
  110.             num$ = STR$(num)
  111.             buttonx = 275: buttony = 75
  112.             GOSUB press:
  113.             GOSUB number:
  114.         END IF
  115.  
  116.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 130 AND mouseY < 185 THEN
  117.             num$ = num$ + "7"
  118.             IF n = 1 THEN num$ = "-" + num$: n = 0
  119.             buttonx = 50: buttony = 130
  120.             GOSUB press:
  121.             GOSUB number:
  122.         END IF
  123.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 130 AND mouseY < 185 THEN
  124.             num$ = num$ + "8"
  125.             IF n = 1 THEN num$ = "-" + num$: n = 0
  126.             buttonx = 126: buttony = 130
  127.             GOSUB press:
  128.             GOSUB number:
  129.         END IF
  130.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 130 AND mouseY < 185 THEN
  131.             num$ = num$ + "9"
  132.             IF n = 1 THEN num$ = "-" + num$: n = 0
  133.             buttonx = 200: buttony = 130
  134.             GOSUB press:
  135.             GOSUB number:
  136.         END IF
  137.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 185 AND mouseY < 240 THEN
  138.             num$ = num$ + "4"
  139.             IF n = 1 THEN num$ = "-" + num$: n = 0
  140.             buttonx = 50: buttony = 185
  141.             GOSUB press:
  142.             GOSUB number:
  143.         END IF
  144.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 185 AND mouseY < 240 THEN
  145.             num$ = num$ + "5"
  146.             IF n = 1 THEN num$ = "-" + num$: n = 0
  147.             buttonx = 126: buttony = 185
  148.             GOSUB press:
  149.             GOSUB number:
  150.         END IF
  151.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 185 AND mouseY < 240 THEN
  152.             num$ = num$ + "6"
  153.             IF n = 1 THEN num$ = "-" + num$: n = 0
  154.             buttonx = 200: buttony = 185
  155.             GOSUB press:
  156.             GOSUB number:
  157.         END IF
  158.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 240 AND mouseY < 295 THEN
  159.             num$ = num$ + "1"
  160.             IF n = 1 THEN num$ = "-" + num$: n = 0
  161.             buttonx = 50: buttony = 240
  162.             GOSUB press:
  163.             GOSUB number:
  164.         END IF
  165.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 240 AND mouseY < 295 THEN
  166.             num$ = num$ + "2"
  167.             IF n = 1 THEN num$ = "-" + num$: n = 0
  168.             buttonx = 126: buttony = 240
  169.             GOSUB press:
  170.             GOSUB number:
  171.         END IF
  172.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 240 AND mouseY < 295 THEN
  173.             num$ = num$ + "3"
  174.             IF n = 1 THEN num$ = "-" + num$: n = 0
  175.             buttonx = 200: buttony = 240
  176.             GOSUB press:
  177.             GOSUB number:
  178.         END IF
  179.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 295 AND mouseY < 350 THEN
  180.             num$ = num$ + "0"
  181.             IF n = 1 THEN num$ = "-" + num$: n = 0
  182.             buttonx = 50: buttony = 295
  183.             GOSUB press:
  184.             GOSUB number:
  185.         END IF
  186.  
  187.         'Decimal
  188.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 295 AND mouseY < 350 THEN
  189.             buttonx = 126: buttony = 295
  190.             FOR check = 1 TO LEN(num$)
  191.                 IF MID$(num$, check, 1) = "." THEN GOTO skipdec:
  192.             NEXT check
  193.             num$ = num$ + "."
  194.             _PRINTSTRING (55, 30), num$
  195.             skipdec:
  196.             GOSUB press:
  197.         END IF
  198.  
  199.         'Equals
  200.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 295 AND mouseY < 350 THEN
  201.             IF a = 1 THEN num = VAL(oldnum$) + VAL(num$): a = 0
  202.             IF s = 1 THEN num = VAL(oldnum$) - VAL(num$): s = 0
  203.             IF t = 1 THEN num = VAL(oldnum$) * VAL(num$): t = 0
  204.             IF d = 1 THEN num = VAL(oldnum$) / VAL(num$): d = 0
  205.             buttonx = 200: buttony = 295
  206.             GOSUB press:
  207.             GOSUB number2:
  208.         END IF
  209.  
  210.         'Add
  211.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 295 AND mouseY < 350 THEN
  212.             IF a = 0 THEN
  213.                 d = 0: a = 1: s = 0: t = 0
  214.                 oldnum$ = num$
  215.                 calc = 1
  216.                 _PRINTSTRING (55, 30), "                          "
  217.                 num$ = ""
  218.                 GOTO nex4:
  219.             END IF
  220.             IF a = 1 THEN
  221.                 num = VAL(oldnum$) + VAL(num$)
  222.                 a = 0
  223.             END IF
  224.             calc = 0
  225.             GOSUB number2:
  226.             nex4:
  227.             buttonx = 275: buttony = 295
  228.             GOSUB press:
  229.         END IF
  230.  
  231.         'Subtract
  232.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 240 AND mouseY < 295 THEN
  233.             IF s = 0 THEN
  234.                 IF num$ = "0" OR num$ = "" OR num = 0 THEN n = 1: GOTO nex3:
  235.                 d = 0: a = 0: s = 1: t = 0
  236.                 oldnum$ = num$
  237.                 calc = 1
  238.                 _PRINTSTRING (55, 30), "                          "
  239.                 num$ = ""
  240.                 GOTO nex3:
  241.             END IF
  242.             IF s = 1 THEN
  243.                 num = VAL(oldnum$) - VAL(num$)
  244.                 s = 0
  245.             END IF
  246.             calc = 0
  247.             GOSUB number2:
  248.             nex3:
  249.             buttonx = 275: buttony = 240
  250.             GOSUB press:
  251.         END IF
  252.  
  253.         'Multiply
  254.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 185 AND mouseY < 240 THEN
  255.             IF t = 0 THEN
  256.                 d = 0: a = 0: s = 0: t = 1
  257.                 oldnum$ = num$
  258.                 calc = 1
  259.                 _PRINTSTRING (55, 30), "                          "
  260.                 num$ = ""
  261.                 GOTO nex2:
  262.             END IF
  263.             IF t = 1 THEN
  264.                 num = VAL(oldnum$) * VAL(num$)
  265.                 t = 0
  266.             END IF
  267.             calc = 0
  268.             GOSUB number2:
  269.             nex2:
  270.             buttonx = 275: buttony = 185
  271.             GOSUB press:
  272.         END IF
  273.  
  274.         'Divide
  275.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 130 AND mouseY < 185 THEN
  276.             IF d = 0 THEN
  277.                 d = 1: a = 0: s = 0: t = 0
  278.                 oldnum$ = num$
  279.                 calc = 1
  280.                 _PRINTSTRING (55, 30), "                          "
  281.                 num$ = ""
  282.                 GOTO nex1:
  283.             END IF
  284.             IF d = 1 AND num$ <> "" THEN
  285.                 num = VAL(oldnum$) / VAL(num$)
  286.                 d = 0
  287.             END IF
  288.             calc = 0
  289.             GOSUB number2:
  290.             nex1:
  291.             buttonx = 275: buttony = 130
  292.             GOSUB press:
  293.         END IF
  294.     END IF
  295. 'For Number Buttons.
  296. number:
  297. num = VAL(num$)
  298.  
  299. 'For Math
  300. number2:
  301. _PRINTSTRING (55, 30), "                          "
  302. num$ = STR$(num)
  303. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  304. _PRINTSTRING (55, 30), num$
  305.  
  306.  
  307. 'Pressing Each Button
  308. press:
  309. c = 110
  310. FOR bb = 0 TO 10
  311.     c = c - 10
  312.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  313. NEXT bb
  314. _DELAY .25
  315. FOR bb = 0 TO 10
  316.     c = c + 10
  317.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  318. NEXT bb
  319.  
  320. 'Pressing the Green C Button.
  321. zero:
  322. c = 110
  323. FOR bb = 0 TO 10
  324.     c = c - 10
  325.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  326. NEXT bb
  327. _DELAY .25
  328. FOR bb = 0 TO 10
  329.     c = c + 10
  330.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  331. NEXT bb
  332.  


Here is the forum topic of you guys helping me: https://www.qb64.org/forum/index.php?topic=2862.new
Ken's Calculator.jpg
* Ken's Calculator.jpg (Filesize: 28.9 KB, Dimensions: 401x426, Views: 251)
« Last Edit: July 28, 2020, 03:20:55 pm by SierraKen »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Calculator
« Reply #1 on: July 28, 2020, 04:00:21 pm »
That looks quite good. I'll have to try it out
Shuwatch!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Calculator
« Reply #2 on: July 28, 2020, 04:57:52 pm »
Nicely done, Ken!  Works so good it almost made me cry (because I used it to calculate my income for the month).  I plan to keep this in my QB64 folder for quick calculations, so I made a quick icon for it and put it in the code.  Here that is if you would like it.  Just add it in the code (no external .ico needed)

- Dav

Code: QB64: [Select]
  1. 'Load the icon - call this somewhere near the top of your program
  2. _ICON BASIMAGE1&
  3.  
  4.  
  5. FUNCTION BASIMAGE1& 'calculatio icon data
  6.     v& = _NEWIMAGE(54, 48, 32)
  7.     DIM m AS _MEM: m = _MEMIMAGE(v&)
  8.     A$ = ""
  9.     A$ = A$ + "haIkJ^eBK\557GZJOl02m5YDX5J1A:YC0aGE##Oc?0RUD5A:HDOA=N=2N96`"
  10.     A$ = A$ + ";87A#=X?hm4S6=N3_[XV4CRgn4]>co5=SJdI?IR9R7K2lSmNFke\bj?c<[I]"
  11.     A$ = A$ + "3QXknHbT9:]dB;Y`kblMd7Tn#B3cF=CZmYb:[Tb<c<Y<b83Ua8c5QJnTNjY["
  12.     A$ = A$ + "X[go?_W<f^AbX=I\7O8IGRiA[eSAbZ7[ZZ[nj[?Z`2;DgD#15lTf;ZXRXlc?"
  13.     A$ = A$ + "okdUEiL`Q<>Ua]nAb]4c3\?_<S8[;_Z[[4mmQIWMfDNiUg3eeTb\[<1T9\n#"
  14.     A$ = A$ + ":\4SR=obhEVAOUX[moCNM[n#j6965KQTImDj:U^BY;mZ[O4j7D>[T3Ukfin\"
  15.     A$ = A$ + "eEomg?EB9U`DLa5[#dfRLlm]7mi0PVb:[\R;MmY>o4mUom;D>NbQnn1OoEee"
  16.     A$ = A$ + "[kSNee7]lAjKcl=b#03T1o6NcX[Lg:Gjc3mIj[CmEbP_g>jjeLM3Ee5jg0m:"
  17.     A$ = A$ + "4DO85DRAaV?IFkER^V#V5TaUnAbU4c3\?WaGln3OT^Jc8gk=gCOLPT=9V7]F"
  18.     A$ = A$ + "GRkWOjYWVZYVJ8cV=cSA07;2]l1[okJn=mc6o9IbR9jG=o[4:8V>Lj#EM]jZ"
  19.     A$ = A$ + "[B3>hPdHS=6chS?^bX84i3FKTA6Q\Je:3V7;a<F1a2ilJ[]VZj2[=jXSB;_l"
  20.     A$ = A$ + "bdNk]7M`17#k_onlX8Dc74S=fH3Jb9WDAGH>\59n?7#<#^RLf[G_JZ[eGOM:"
  21.     A$ = A$ + "H`PdeGO=c=gLS#DcW#Q2aJ>JM1KQ37V^mfKe5ARKTSAlA^VBGYdE:Mmg]^6H"
  22.     A$ = A$ + "P1X012lRZ;\o\>k\CZWNjQjZ[^hl\nj[WkCIXQ6RlkgOL[[;_lBnk7onLK^i"
  23.     A$ = A$ + "VD]eF;eJ[]B]dB;D5ED1O^9;MeNk]CmfK_T=KfX>jX3Zk^kVeDS=f8EGMeAW"
  24.     A$ = A$ + "NjY?k[GUFJY\N#O:8VEGMeDIUE6IaRUTV^P]S>j8>o?olcY3?l#nN6TWhh[^"
  25.     A$ = A$ + "jZW]^>iTChc3SPc>k<VkO_`o7On:IFgh]FOD_EkkMa5GTOn<JJ^iV5RFnPeA"
  26.     A$ = A$ + "]5#\4?m2RYCW>EEG[\b:LmKD_;2AZo92]l1_GX]fJS1ce:Nj5TcNlhAhcGhn"
  27.     A$ = A$ + "TiVK>Fo^LiBID4RlIQ5FPVHR9D^?4cQ=]RI\2bETcaBM3<jcW?jR;^P1e65Q"
  28.     A$ = A$ + "JnPJck^k^?Z^1\Qed:^J1ba8ilOceiQ_hLR>>RnnN:k8gCTj:JBY[Dj2m5^m"
  29.     A$ = A$ + "fKcnnFBGc>k\DiUG>_?UMfIWTR^>nhSiL1m<mBY;DSMZYVRZZZZX]fJ[4^^P"
  30.     A$ = A$ + "?XoXIVIVGd[GH_3hMR3?l`lnCBdjJniWWO?WXW_CEgh^gMSn1`i1#>82el1e"
  31.     A$ = A$ + "FD[O3\VFaE;#>RL=Fd5je2g3\dB;A^MkFID4Rl1m>j`Q35MQi`VFa<F1iZFm"
  32.     A$ = A$ + "7RNRAoff]KG1lOVjn7oDXU?XWKlKS0`L]RWN1i\Xnian_JZYVDf[D4P=AXU?"
  33.     A$ = A$ + "Hm6JX1VH9Na3A_o[o3Ph%%L2"
  34.     btemp$ = ""
  35.     FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
  36.         IF INSTR(1, B$, "%") THEN
  37.             FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
  38.                 IF F$ <> "%" THEN C$ = C$ + F$
  39.             NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
  40.             IF MID$(B$, j, 1) = "#" THEN
  41.         MID$(B$, j) = "@": END IF: NEXT
  42.         FOR t% = LEN(B$) TO 1 STEP -1
  43.             B& = B& * 64 + ASC(MID$(B$, t%)) - 48
  44.             NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
  45.             X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
  46.     NEXT: btemp$ = btemp$ + X$: NEXT
  47.     btemp$ = _INFLATE$(btemp$)
  48.     _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
  49.     BASIMAGE1& = _COPYIMAGE(v&): _FREEIMAGE v&
  50.  
« Last Edit: July 28, 2020, 05:55:06 pm by Dav »

FellippeHeitor

  • Guest
Re: Calculator
« Reply #3 on: July 28, 2020, 05:03:06 pm »
Cool buttons, Ken!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calculator
« Reply #4 on: July 28, 2020, 08:34:04 pm »
Thanks Dav! I just added it and will put the updated version below with that code. I guess it's only supposed to show up on the program itself when running right? Not as a Windows icon for stuff like Windows Shortcuts? But it's still really cool, thank you! I usually use the yellow star icon for my own programs for their Windows shortcuts anyway.

Thank you Felippe! The buttons came out better than I expected. :)

Code: QB64: [Select]
  1. 'Calculator
  2. 'By SierraKen on July 28, 2020.
  3. '------------------------------
  4. 'This is my very first regular calculator.
  5. 'Thank you to B+ and TempodiBasic for the help and everyone for the inspiration!
  6. 'This was a 3 day project and I've wanted to make this all my life. Ever since I was real little
  7. 'playing around with my parents' calculator.
  8. 'Thank you Dav for the icon code!
  9.  
  10. 'Load the icon - call this somewhere near the top of your program
  11. _ICON BASIMAGE1&
  12.  
  13. _TITLE "Calculator"
  14. SCREEN _NEWIMAGE(400, 400, 32)
  15.  
  16. 'Setup calculator
  17. LINE (50, 25)-(265, 50), _RGB32(255, 255, 255), B
  18. LINE (50, 75)-(350, 350), _RGB32(255, 255, 255), B
  19. 'Buttons
  20. FOR buttony = 75 TO 295 STEP 55
  21.     FOR buttonx = 50 TO 275 STEP 75
  22.         FOR bb = 0 TO 10
  23.             c = c + 10
  24.             LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  25.         NEXT bb
  26.         PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
  27.         c = 0
  28.     NEXT buttonx
  29. NEXT buttony
  30. buttonx = 275: buttony = 20
  31. 'Green C Button
  32. FOR bb = 0 TO 10
  33.     c = c + 10
  34.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  35. NEXT bb
  36. PAINT (buttonx + 12, buttony + 12), _RGB32(50, 100 + c, 50)
  37. COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
  38. c = 0
  39. 'Label Buttons
  40. _PRINTSTRING (312, 47), "C"
  41. COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  42. _PRINTSTRING (87, 102), CHR$(251) 'square root
  43. _PRINTSTRING (152, 102), "sin"
  44. _PRINTSTRING (227, 102), "cos"
  45. _PRINTSTRING (302, 102), "tan"
  46. _PRINTSTRING (87, 157), "7"
  47. _PRINTSTRING (162, 157), "8"
  48. _PRINTSTRING (237, 157), "9"
  49. _PRINTSTRING (312, 157), "/"
  50. _PRINTSTRING (87, 212), "4"
  51. _PRINTSTRING (162, 212), "5"
  52. _PRINTSTRING (237, 212), "6"
  53. _PRINTSTRING (312, 212), "x"
  54. _PRINTSTRING (87, 267), "1"
  55. _PRINTSTRING (162, 267), "2"
  56. _PRINTSTRING (237, 267), "3"
  57. _PRINTSTRING (312, 267), "-"
  58. _PRINTSTRING (87, 322), "0"
  59. _PRINTSTRING (162, 322), "."
  60. _PRINTSTRING (237, 322), "="
  61. _PRINTSTRING (312, 322), "+"
  62. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  63.     _LIMIT 20
  64.         mouseX = _MOUSEX
  65.         mouseY = _MOUSEY
  66.         mouseLeftButton = _MOUSEBUTTON(1)
  67.     LOOP
  68.     IF mouseLeftButton THEN
  69.         mouseLeftButton = 0
  70.  
  71.         'Clear
  72.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 20 AND mouseY < 75 THEN
  73.             a = 0: s = 0: t = 0: d = 0: num$ = ""
  74.             _PRINTSTRING (55, 30), "                          "
  75.             buttonx = 275: buttony = 20
  76.             GOSUB zero:
  77.         END IF
  78.  
  79.         'Square Root
  80.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 75 AND mouseY < 130 THEN
  81.             IF num < 0 THEN GOTO skip1:
  82.             num = VAL(num$)
  83.             num = SQR(num)
  84.             num$ = STR$(num)
  85.             skip1:
  86.             buttonx = 50: buttony = 75
  87.             GOSUB press:
  88.             GOSUB number:
  89.         END IF
  90.  
  91.         'Sine
  92.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 75 AND mouseY < 130 THEN
  93.             num = VAL(num$)
  94.             num = SIN(num)
  95.             num$ = STR$(num)
  96.             buttonx = 126: buttony = 75
  97.             GOSUB press:
  98.             GOSUB number:
  99.         END IF
  100.  
  101.         'Cosine
  102.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 75 AND mouseY < 130 THEN
  103.             num = VAL(num$)
  104.             num = COS(num)
  105.             num$ = STR$(num)
  106.             buttonx = 200: buttony = 75
  107.             GOSUB press:
  108.             GOSUB number:
  109.         END IF
  110.  
  111.         'Tangent
  112.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 75 AND mouseY < 130 THEN
  113.             num = VAL(num$)
  114.             num = TAN(num)
  115.             num$ = STR$(num)
  116.             buttonx = 275: buttony = 75
  117.             GOSUB press:
  118.             GOSUB number:
  119.         END IF
  120.  
  121.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 130 AND mouseY < 185 THEN
  122.             num$ = num$ + "7"
  123.             IF n = 1 THEN num$ = "-" + num$: n = 0
  124.             buttonx = 50: buttony = 130
  125.             GOSUB press:
  126.             GOSUB number:
  127.         END IF
  128.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 130 AND mouseY < 185 THEN
  129.             num$ = num$ + "8"
  130.             IF n = 1 THEN num$ = "-" + num$: n = 0
  131.             buttonx = 126: buttony = 130
  132.             GOSUB press:
  133.             GOSUB number:
  134.         END IF
  135.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 130 AND mouseY < 185 THEN
  136.             num$ = num$ + "9"
  137.             IF n = 1 THEN num$ = "-" + num$: n = 0
  138.             buttonx = 200: buttony = 130
  139.             GOSUB press:
  140.             GOSUB number:
  141.         END IF
  142.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 185 AND mouseY < 240 THEN
  143.             num$ = num$ + "4"
  144.             IF n = 1 THEN num$ = "-" + num$: n = 0
  145.             buttonx = 50: buttony = 185
  146.             GOSUB press:
  147.             GOSUB number:
  148.         END IF
  149.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 185 AND mouseY < 240 THEN
  150.             num$ = num$ + "5"
  151.             IF n = 1 THEN num$ = "-" + num$: n = 0
  152.             buttonx = 126: buttony = 185
  153.             GOSUB press:
  154.             GOSUB number:
  155.         END IF
  156.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 185 AND mouseY < 240 THEN
  157.             num$ = num$ + "6"
  158.             IF n = 1 THEN num$ = "-" + num$: n = 0
  159.             buttonx = 200: buttony = 185
  160.             GOSUB press:
  161.             GOSUB number:
  162.         END IF
  163.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 240 AND mouseY < 295 THEN
  164.             num$ = num$ + "1"
  165.             IF n = 1 THEN num$ = "-" + num$: n = 0
  166.             buttonx = 50: buttony = 240
  167.             GOSUB press:
  168.             GOSUB number:
  169.         END IF
  170.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 240 AND mouseY < 295 THEN
  171.             num$ = num$ + "2"
  172.             IF n = 1 THEN num$ = "-" + num$: n = 0
  173.             buttonx = 126: buttony = 240
  174.             GOSUB press:
  175.             GOSUB number:
  176.         END IF
  177.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 240 AND mouseY < 295 THEN
  178.             num$ = num$ + "3"
  179.             IF n = 1 THEN num$ = "-" + num$: n = 0
  180.             buttonx = 200: buttony = 240
  181.             GOSUB press:
  182.             GOSUB number:
  183.         END IF
  184.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 295 AND mouseY < 350 THEN
  185.             num$ = num$ + "0"
  186.             IF n = 1 THEN num$ = "-" + num$: n = 0
  187.             buttonx = 50: buttony = 295
  188.             GOSUB press:
  189.             GOSUB number:
  190.         END IF
  191.  
  192.         'Decimal
  193.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 295 AND mouseY < 350 THEN
  194.             buttonx = 126: buttony = 295
  195.             FOR check = 1 TO LEN(num$)
  196.                 IF MID$(num$, check, 1) = "." THEN GOTO skipdec:
  197.             NEXT check
  198.             num$ = num$ + "."
  199.             _PRINTSTRING (55, 30), num$
  200.             skipdec:
  201.             GOSUB press:
  202.         END IF
  203.  
  204.         'Equals
  205.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 295 AND mouseY < 350 THEN
  206.             IF a = 1 THEN num = VAL(oldnum$) + VAL(num$): a = 0
  207.             IF s = 1 THEN num = VAL(oldnum$) - VAL(num$): s = 0
  208.             IF t = 1 THEN num = VAL(oldnum$) * VAL(num$): t = 0
  209.             IF d = 1 THEN num = VAL(oldnum$) / VAL(num$): d = 0
  210.             buttonx = 200: buttony = 295
  211.             GOSUB press:
  212.             GOSUB number2:
  213.         END IF
  214.  
  215.         'Add
  216.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 295 AND mouseY < 350 THEN
  217.             IF a = 0 THEN
  218.                 d = 0: a = 1: s = 0: t = 0
  219.                 oldnum$ = num$
  220.                 calc = 1
  221.                 _PRINTSTRING (55, 30), "                          "
  222.                 num$ = ""
  223.                 GOTO nex4:
  224.             END IF
  225.             IF a = 1 THEN
  226.                 num = VAL(oldnum$) + VAL(num$)
  227.                 a = 0
  228.             END IF
  229.             calc = 0
  230.             GOSUB number2:
  231.             nex4:
  232.             buttonx = 275: buttony = 295
  233.             GOSUB press:
  234.         END IF
  235.  
  236.         'Subtract
  237.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 240 AND mouseY < 295 THEN
  238.             IF s = 0 THEN
  239.                 IF num$ = "0" OR num$ = "" OR num = 0 THEN n = 1: GOTO nex3:
  240.                 d = 0: a = 0: s = 1: t = 0
  241.                 oldnum$ = num$
  242.                 calc = 1
  243.                 _PRINTSTRING (55, 30), "                          "
  244.                 num$ = ""
  245.                 GOTO nex3:
  246.             END IF
  247.             IF s = 1 THEN
  248.                 num = VAL(oldnum$) - VAL(num$)
  249.                 s = 0
  250.             END IF
  251.             calc = 0
  252.             GOSUB number2:
  253.             nex3:
  254.             buttonx = 275: buttony = 240
  255.             GOSUB press:
  256.         END IF
  257.  
  258.         'Multiply
  259.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 185 AND mouseY < 240 THEN
  260.             IF t = 0 THEN
  261.                 d = 0: a = 0: s = 0: t = 1
  262.                 oldnum$ = num$
  263.                 calc = 1
  264.                 _PRINTSTRING (55, 30), "                          "
  265.                 num$ = ""
  266.                 GOTO nex2:
  267.             END IF
  268.             IF t = 1 THEN
  269.                 num = VAL(oldnum$) * VAL(num$)
  270.                 t = 0
  271.             END IF
  272.             calc = 0
  273.             GOSUB number2:
  274.             nex2:
  275.             buttonx = 275: buttony = 185
  276.             GOSUB press:
  277.         END IF
  278.  
  279.         'Divide
  280.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 130 AND mouseY < 185 THEN
  281.             IF d = 0 THEN
  282.                 d = 1: a = 0: s = 0: t = 0
  283.                 oldnum$ = num$
  284.                 calc = 1
  285.                 _PRINTSTRING (55, 30), "                          "
  286.                 num$ = ""
  287.                 GOTO nex1:
  288.             END IF
  289.             IF d = 1 AND num$ <> "" THEN
  290.                 num = VAL(oldnum$) / VAL(num$)
  291.                 d = 0
  292.             END IF
  293.             calc = 0
  294.             GOSUB number2:
  295.             nex1:
  296.             buttonx = 275: buttony = 130
  297.             GOSUB press:
  298.         END IF
  299.     END IF
  300. 'For Number Buttons.
  301. number:
  302. num = VAL(num$)
  303.  
  304. 'For Math
  305. number2:
  306. _PRINTSTRING (55, 30), "                          "
  307. num$ = STR$(num)
  308. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  309. _PRINTSTRING (55, 30), num$
  310.  
  311.  
  312. 'Pressing Each Button
  313. press:
  314. c = 110
  315. FOR bb = 0 TO 10
  316.     c = c - 10
  317.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  318. NEXT bb
  319. _DELAY .25
  320. FOR bb = 0 TO 10
  321.     c = c + 10
  322.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  323. NEXT bb
  324.  
  325. 'Pressing the Green C Button.
  326. zero:
  327. c = 110
  328. FOR bb = 0 TO 10
  329.     c = c - 10
  330.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  331. NEXT bb
  332. _DELAY .25
  333. FOR bb = 0 TO 10
  334.     c = c + 10
  335.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  336. NEXT bb
  337.  
  338. FUNCTION BASIMAGE1& 'calculatio icon data
  339.     v& = _NEWIMAGE(54, 48, 32)
  340.     DIM m AS _MEM: m = _MEMIMAGE(v&)
  341.     A$ = ""
  342.     A$ = A$ + "haIkJ^eBK\557GZJOl02m5YDX5J1A:YC0aGE##Oc?0RUD5A:HDOA=N=2N96`"
  343.     A$ = A$ + ";87A#=X?hm4S6=N3_[XV4CRgn4]>co5=SJdI?IR9R7K2lSmNFke\bj?c<[I]"
  344.     A$ = A$ + "3QXknHbT9:]dB;Y`kblMd7Tn#B3cF=CZmYb:[Tb<c<Y<b83Ua8c5QJnTNjY["
  345.     A$ = A$ + "X[go?_W<f^AbX=I\7O8IGRiA[eSAbZ7[ZZ[nj[?Z`2;DgD#15lTf;ZXRXlc?"
  346.     A$ = A$ + "okdUEiL`Q<>Ua]nAb]4c3\?_<S8[;_Z[[4mmQIWMfDNiUg3eeTb\[<1T9\n#"
  347.     A$ = A$ + ":\4SR=obhEVAOUX[moCNM[n#j6965KQTImDj:U^BY;mZ[O4j7D>[T3Ukfin\"
  348.     A$ = A$ + "eEomg?EB9U`DLa5[#dfRLlm]7mi0PVb:[\R;MmY>o4mUom;D>NbQnn1OoEee"
  349.     A$ = A$ + "[kSNee7]lAjKcl=b#03T1o6NcX[Lg:Gjc3mIj[CmEbP_g>jjeLM3Ee5jg0m:"
  350.     A$ = A$ + "4DO85DRAaV?IFkER^V#V5TaUnAbU4c3\?WaGln3OT^Jc8gk=gCOLPT=9V7]F"
  351.     A$ = A$ + "GRkWOjYWVZYVJ8cV=cSA07;2]l1[okJn=mc6o9IbR9jG=o[4:8V>Lj#EM]jZ"
  352.     A$ = A$ + "[B3>hPdHS=6chS?^bX84i3FKTA6Q\Je:3V7;a<F1a2ilJ[]VZj2[=jXSB;_l"
  353.     A$ = A$ + "bdNk]7M`17#k_onlX8Dc74S=fH3Jb9WDAGH>\59n?7#<#^RLf[G_JZ[eGOM:"
  354.     A$ = A$ + "H`PdeGO=c=gLS#DcW#Q2aJ>JM1KQ37V^mfKe5ARKTSAlA^VBGYdE:Mmg]^6H"
  355.     A$ = A$ + "P1X012lRZ;\o\>k\CZWNjQjZ[^hl\nj[WkCIXQ6RlkgOL[[;_lBnk7onLK^i"
  356.     A$ = A$ + "VD]eF;eJ[]B]dB;D5ED1O^9;MeNk]CmfK_T=KfX>jX3Zk^kVeDS=f8EGMeAW"
  357.     A$ = A$ + "NjY?k[GUFJY\N#O:8VEGMeDIUE6IaRUTV^P]S>j8>o?olcY3?l#nN6TWhh[^"
  358.     A$ = A$ + "jZW]^>iTChc3SPc>k<VkO_`o7On:IFgh]FOD_EkkMa5GTOn<JJ^iV5RFnPeA"
  359.     A$ = A$ + "]5#\4?m2RYCW>EEG[\b:LmKD_;2AZo92]l1_GX]fJS1ce:Nj5TcNlhAhcGhn"
  360.     A$ = A$ + "TiVK>Fo^LiBID4RlIQ5FPVHR9D^?4cQ=]RI\2bETcaBM3<jcW?jR;^P1e65Q"
  361.     A$ = A$ + "JnPJck^k^?Z^1\Qed:^J1ba8ilOceiQ_hLR>>RnnN:k8gCTj:JBY[Dj2m5^m"
  362.     A$ = A$ + "fKcnnFBGc>k\DiUG>_?UMfIWTR^>nhSiL1m<mBY;DSMZYVRZZZZX]fJ[4^^P"
  363.     A$ = A$ + "?XoXIVIVGd[GH_3hMR3?l`lnCBdjJniWWO?WXW_CEgh^gMSn1`i1#>82el1e"
  364.     A$ = A$ + "FD[O3\VFaE;#>RL=Fd5je2g3\dB;A^MkFID4Rl1m>j`Q35MQi`VFa<F1iZFm"
  365.     A$ = A$ + "7RNRAoff]KG1lOVjn7oDXU?XWKlKS0`L]RWN1i\Xnian_JZYVDf[D4P=AXU?"
  366.     A$ = A$ + "Hm6JX1VH9Na3A_o[o3Ph%%L2"
  367.     btemp$ = ""
  368.     FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
  369.         IF INSTR(1, B$, "%") THEN
  370.             FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
  371.                 IF F$ <> "%" THEN C$ = C$ + F$
  372.             NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
  373.             IF MID$(B$, j, 1) = "#" THEN
  374.         MID$(B$, j) = "@": END IF: NEXT
  375.         FOR t% = LEN(B$) TO 1 STEP -1
  376.             B& = B& * 64 + ASC(MID$(B$, t%)) - 48
  377.             NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
  378.             X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
  379.     NEXT: btemp$ = btemp$ + X$: NEXT
  380.     btemp$ = _INFLATE$(btemp$)
  381.     _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
  382.     BASIMAGE1& = _COPYIMAGE(v&): _FREEIMAGE v&
  383.  

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Calculator
« Reply #5 on: July 28, 2020, 09:08:30 pm »
That's correct - the icon won't be seen by windows and not available for shortcuts.  That's the downside.  On the plus side however you don't need external image to have an icon when the program is running.  I can attach an icon image later if you'd like have it also (I'm on another pc at the moment)..

I've been playing with animated icons using this technique.  Remember the QBV video format player a while back?  I added _ICON later on where it _ICON'ed each frame image, so a mini movie played in the task bar, even when the video was minimized.  Worked great.

I agree with Fellippe - cool buttons!

- Dav
« Last Edit: July 28, 2020, 09:17:27 pm by Dav »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calculator
« Reply #6 on: July 28, 2020, 09:23:34 pm »
Awesome Dav. But nah, no need for an .ico. People can just choose one of the Windows ones they have on their Properties list if they want something different for Windows. :) Usually when I have a choice between 1 file or more, I pick just the 1 .bas file.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Calculator
« Reply #7 on: July 28, 2020, 10:34:58 pm »
Come to think of it - you may not need my icon stuff added at all.  Just do an _ICON _DISPLAY after drawing your calculator and that would look just as good.  Instant icon.  That would be a cool trick I suppose for showing game play in the task bar when playing games.

- Dav
« Last Edit: July 28, 2020, 10:39:49 pm by Dav »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calculator
« Reply #8 on: July 28, 2020, 10:48:39 pm »
Yeah true. But I'm sticking with your code just so I don't need 2 files. Would be nice for people making their own icons.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calculator
« Reply #9 on: July 28, 2020, 10:50:01 pm »
Unless you want me to remove it?

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Calculator
« Reply #10 on: July 28, 2020, 11:05:39 pm »
For your trig functions, don't forget that SIN, COS & TAN work with radians natively in QB64. If you want to use degrees, you'll have to use _D2R, or _PI / 180 in the calculation.

BTW, I like those buttons so well, I incorporated a modification of your algorithm in my solar system simulator. They have a cool 3D look to them, and really make the controls 'pop'.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calculator
« Reply #11 on: July 28, 2020, 11:13:23 pm »
Awesome OldMoses!! Yeah, I like the radians better for us programmers. :) Maybe someday I'll make a bigger calculator and make a button to auto-convert radians to degrees. Some people here have made incredible calculators, like the TI one I saw from a couple years ago or so. :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calculator
« Reply #12 on: July 28, 2020, 11:28:29 pm »
I'm learning new stuff every day! I just found the _CLIPBOARD$ command on the Wiki so I added that. If you left click the output number, the number will turn green for 1 second and it will put it as your Windows Clipboard where you can paste as any text on any other program that has Paste for text. If you want to see the commands I used, it's right after the Mouse commands near the start of the main loop. I also added those instructions in the _TITLE so people know.
Here is the update:

Code: QB64: [Select]
  1. 'Calculator
  2. 'By SierraKen on July 28, 2020.
  3. '------------------------------
  4. 'This is my very first regular calculator.
  5. 'Thank you to B+ and TempodiBasic for the help and everyone for the inspiration!
  6. 'This was a 3 day project and I've wanted to make this all my life. Ever since I was real little
  7. 'playing around with my parents' calculator.
  8. 'Thank you Dav for the icon code!
  9. 'Just added Clipboard by clicking the output number.
  10.  
  11. 'Load the icon - call this somewhere near the top of your program
  12. _ICON BASIMAGE1&
  13.  
  14. _TITLE "Calculator - Click output to copy."
  15. SCREEN _NEWIMAGE(400, 400, 32)
  16.  
  17.  
  18. 'Setup calculator
  19. LINE (50, 25)-(265, 50), _RGB32(255, 255, 255), B
  20. LINE (50, 75)-(350, 350), _RGB32(255, 255, 255), B
  21. 'Buttons
  22. FOR buttony = 75 TO 295 STEP 55
  23.     FOR buttonx = 50 TO 275 STEP 75
  24.         FOR bb = 0 TO 10
  25.             c = c + 10
  26.             LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  27.         NEXT bb
  28.         PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
  29.         c = 0
  30.     NEXT buttonx
  31. NEXT buttony
  32. buttonx = 275: buttony = 20
  33. 'Green C Button
  34. FOR bb = 0 TO 10
  35.     c = c + 10
  36.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  37. NEXT bb
  38. PAINT (buttonx + 12, buttony + 12), _RGB32(50, 100 + c, 50)
  39. COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
  40. c = 0
  41. 'Label Buttons
  42. _PRINTSTRING (312, 47), "C"
  43. COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  44. _PRINTSTRING (87, 102), CHR$(251) 'square root
  45. _PRINTSTRING (152, 102), "sin"
  46. _PRINTSTRING (227, 102), "cos"
  47. _PRINTSTRING (302, 102), "tan"
  48. _PRINTSTRING (87, 157), "7"
  49. _PRINTSTRING (162, 157), "8"
  50. _PRINTSTRING (237, 157), "9"
  51. _PRINTSTRING (312, 157), "/"
  52. _PRINTSTRING (87, 212), "4"
  53. _PRINTSTRING (162, 212), "5"
  54. _PRINTSTRING (237, 212), "6"
  55. _PRINTSTRING (312, 212), "x"
  56. _PRINTSTRING (87, 267), "1"
  57. _PRINTSTRING (162, 267), "2"
  58. _PRINTSTRING (237, 267), "3"
  59. _PRINTSTRING (312, 267), "-"
  60. _PRINTSTRING (87, 322), "0"
  61. _PRINTSTRING (162, 322), "."
  62. _PRINTSTRING (237, 322), "="
  63. _PRINTSTRING (312, 322), "+"
  64. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  65.     _LIMIT 20
  66.         mouseX = _MOUSEX
  67.         mouseY = _MOUSEY
  68.         mouseLeftButton = _MOUSEBUTTON(1)
  69.     LOOP
  70.     IF mouseLeftButton THEN
  71.         mouseLeftButton = 0
  72.  
  73.         'Clipboard
  74.         IF mouseX > 50 AND mouseX < 265 AND mouseY > 25 AND mouseY < 50 THEN
  75.             COLOR _RGB32(0, 255, 0), _RGB32(0, 0, 0)
  76.             _PRINTSTRING (55, 30), num$
  77.             _DELAY 1
  78.             _CLIPBOARD$ = num$
  79.             COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  80.             _PRINTSTRING (55, 30), num$
  81.         END IF
  82.  
  83.         'Clear
  84.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 20 AND mouseY < 75 THEN
  85.             a = 0: s = 0: t = 0: d = 0: num$ = ""
  86.             _PRINTSTRING (55, 30), "                          "
  87.             buttonx = 275: buttony = 20
  88.             GOSUB zero:
  89.         END IF
  90.  
  91.         'Square Root
  92.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 75 AND mouseY < 130 THEN
  93.             IF num < 0 THEN GOTO skip1:
  94.             num = VAL(num$)
  95.             num = SQR(num)
  96.             num$ = STR$(num)
  97.             skip1:
  98.             buttonx = 50: buttony = 75
  99.             GOSUB press:
  100.             GOSUB number:
  101.         END IF
  102.  
  103.         'Sine
  104.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 75 AND mouseY < 130 THEN
  105.             num = VAL(num$)
  106.             num = SIN(num)
  107.             num$ = STR$(num)
  108.             buttonx = 126: buttony = 75
  109.             GOSUB press:
  110.             GOSUB number:
  111.         END IF
  112.  
  113.         'Cosine
  114.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 75 AND mouseY < 130 THEN
  115.             num = VAL(num$)
  116.             num = COS(num)
  117.             num$ = STR$(num)
  118.             buttonx = 200: buttony = 75
  119.             GOSUB press:
  120.             GOSUB number:
  121.         END IF
  122.  
  123.         'Tangent
  124.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 75 AND mouseY < 130 THEN
  125.             num = VAL(num$)
  126.             num = TAN(num)
  127.             num$ = STR$(num)
  128.             buttonx = 275: buttony = 75
  129.             GOSUB press:
  130.             GOSUB number:
  131.         END IF
  132.  
  133.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 130 AND mouseY < 185 THEN
  134.             num$ = num$ + "7"
  135.             IF n = 1 THEN num$ = "-" + num$: n = 0
  136.             buttonx = 50: buttony = 130
  137.             GOSUB press:
  138.             GOSUB number:
  139.         END IF
  140.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 130 AND mouseY < 185 THEN
  141.             num$ = num$ + "8"
  142.             IF n = 1 THEN num$ = "-" + num$: n = 0
  143.             buttonx = 126: buttony = 130
  144.             GOSUB press:
  145.             GOSUB number:
  146.         END IF
  147.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 130 AND mouseY < 185 THEN
  148.             num$ = num$ + "9"
  149.             IF n = 1 THEN num$ = "-" + num$: n = 0
  150.             buttonx = 200: buttony = 130
  151.             GOSUB press:
  152.             GOSUB number:
  153.         END IF
  154.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 185 AND mouseY < 240 THEN
  155.             num$ = num$ + "4"
  156.             IF n = 1 THEN num$ = "-" + num$: n = 0
  157.             buttonx = 50: buttony = 185
  158.             GOSUB press:
  159.             GOSUB number:
  160.         END IF
  161.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 185 AND mouseY < 240 THEN
  162.             num$ = num$ + "5"
  163.             IF n = 1 THEN num$ = "-" + num$: n = 0
  164.             buttonx = 126: buttony = 185
  165.             GOSUB press:
  166.             GOSUB number:
  167.         END IF
  168.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 185 AND mouseY < 240 THEN
  169.             num$ = num$ + "6"
  170.             IF n = 1 THEN num$ = "-" + num$: n = 0
  171.             buttonx = 200: buttony = 185
  172.             GOSUB press:
  173.             GOSUB number:
  174.         END IF
  175.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 240 AND mouseY < 295 THEN
  176.             num$ = num$ + "1"
  177.             IF n = 1 THEN num$ = "-" + num$: n = 0
  178.             buttonx = 50: buttony = 240
  179.             GOSUB press:
  180.             GOSUB number:
  181.         END IF
  182.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 240 AND mouseY < 295 THEN
  183.             num$ = num$ + "2"
  184.             IF n = 1 THEN num$ = "-" + num$: n = 0
  185.             buttonx = 126: buttony = 240
  186.             GOSUB press:
  187.             GOSUB number:
  188.         END IF
  189.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 240 AND mouseY < 295 THEN
  190.             num$ = num$ + "3"
  191.             IF n = 1 THEN num$ = "-" + num$: n = 0
  192.             buttonx = 200: buttony = 240
  193.             GOSUB press:
  194.             GOSUB number:
  195.         END IF
  196.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 295 AND mouseY < 350 THEN
  197.             num$ = num$ + "0"
  198.             IF n = 1 THEN num$ = "-" + num$: n = 0
  199.             buttonx = 50: buttony = 295
  200.             GOSUB press:
  201.             GOSUB number:
  202.         END IF
  203.  
  204.         'Decimal
  205.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 295 AND mouseY < 350 THEN
  206.             buttonx = 126: buttony = 295
  207.             FOR check = 1 TO LEN(num$)
  208.                 IF MID$(num$, check, 1) = "." THEN GOTO skipdec:
  209.             NEXT check
  210.             num$ = num$ + "."
  211.             _PRINTSTRING (55, 30), num$
  212.             skipdec:
  213.             GOSUB press:
  214.         END IF
  215.  
  216.         'Equals
  217.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 295 AND mouseY < 350 THEN
  218.             IF a = 1 THEN num = VAL(oldnum$) + VAL(num$): a = 0
  219.             IF s = 1 THEN num = VAL(oldnum$) - VAL(num$): s = 0
  220.             IF t = 1 THEN num = VAL(oldnum$) * VAL(num$): t = 0
  221.             IF d = 1 THEN num = VAL(oldnum$) / VAL(num$): d = 0
  222.             buttonx = 200: buttony = 295
  223.             GOSUB press:
  224.             GOSUB number2:
  225.         END IF
  226.  
  227.         'Add
  228.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 295 AND mouseY < 350 THEN
  229.             IF a = 0 THEN
  230.                 d = 0: a = 1: s = 0: t = 0
  231.                 oldnum$ = num$
  232.                 calc = 1
  233.                 _PRINTSTRING (55, 30), "                          "
  234.                 num$ = ""
  235.                 GOTO nex4:
  236.             END IF
  237.             IF a = 1 THEN
  238.                 num = VAL(oldnum$) + VAL(num$)
  239.                 a = 0
  240.             END IF
  241.             calc = 0
  242.             GOSUB number2:
  243.             nex4:
  244.             buttonx = 275: buttony = 295
  245.             GOSUB press:
  246.         END IF
  247.  
  248.         'Subtract
  249.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 240 AND mouseY < 295 THEN
  250.             IF s = 0 THEN
  251.                 IF num$ = "0" OR num$ = "" OR num = 0 THEN n = 1: GOTO nex3:
  252.                 d = 0: a = 0: s = 1: t = 0
  253.                 oldnum$ = num$
  254.                 calc = 1
  255.                 _PRINTSTRING (55, 30), "                          "
  256.                 num$ = ""
  257.                 GOTO nex3:
  258.             END IF
  259.             IF s = 1 THEN
  260.                 num = VAL(oldnum$) - VAL(num$)
  261.                 s = 0
  262.             END IF
  263.             calc = 0
  264.             GOSUB number2:
  265.             nex3:
  266.             buttonx = 275: buttony = 240
  267.             GOSUB press:
  268.         END IF
  269.  
  270.         'Multiply
  271.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 185 AND mouseY < 240 THEN
  272.             IF t = 0 THEN
  273.                 d = 0: a = 0: s = 0: t = 1
  274.                 oldnum$ = num$
  275.                 calc = 1
  276.                 _PRINTSTRING (55, 30), "                          "
  277.                 num$ = ""
  278.                 GOTO nex2:
  279.             END IF
  280.             IF t = 1 THEN
  281.                 num = VAL(oldnum$) * VAL(num$)
  282.                 t = 0
  283.             END IF
  284.             calc = 0
  285.             GOSUB number2:
  286.             nex2:
  287.             buttonx = 275: buttony = 185
  288.             GOSUB press:
  289.         END IF
  290.  
  291.         'Divide
  292.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 130 AND mouseY < 185 THEN
  293.             IF d = 0 THEN
  294.                 d = 1: a = 0: s = 0: t = 0
  295.                 oldnum$ = num$
  296.                 calc = 1
  297.                 _PRINTSTRING (55, 30), "                          "
  298.                 num$ = ""
  299.                 GOTO nex1:
  300.             END IF
  301.             IF d = 1 AND num$ <> "" THEN
  302.                 num = VAL(oldnum$) / VAL(num$)
  303.                 d = 0
  304.             END IF
  305.             calc = 0
  306.             GOSUB number2:
  307.             nex1:
  308.             buttonx = 275: buttony = 130
  309.             GOSUB press:
  310.         END IF
  311.     END IF
  312. 'For Number Buttons.
  313. number:
  314. num = VAL(num$)
  315.  
  316. 'For Math
  317. number2:
  318. _PRINTSTRING (55, 30), "                          "
  319. num$ = STR$(num)
  320. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  321. _PRINTSTRING (55, 30), num$
  322.  
  323.  
  324. 'Pressing Each Button
  325. press:
  326. c = 110
  327. FOR bb = 0 TO 10
  328.     c = c - 10
  329.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  330. NEXT bb
  331. _DELAY .25
  332. FOR bb = 0 TO 10
  333.     c = c + 10
  334.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  335. NEXT bb
  336.  
  337. 'Pressing the Green C Button.
  338. zero:
  339. c = 110
  340. FOR bb = 0 TO 10
  341.     c = c - 10
  342.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  343. NEXT bb
  344. _DELAY .25
  345. FOR bb = 0 TO 10
  346.     c = c + 10
  347.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  348. NEXT bb
  349.  
  350.  
  351.  
  352.  
  353. FUNCTION BASIMAGE1& 'calculatio icon data
  354.     v& = _NEWIMAGE(54, 48, 32)
  355.     DIM m AS _MEM: m = _MEMIMAGE(v&)
  356.     A$ = ""
  357.     A$ = A$ + "haIkJ^eBK\557GZJOl02m5YDX5J1A:YC0aGE##Oc?0RUD5A:HDOA=N=2N96`"
  358.     A$ = A$ + ";87A#=X?hm4S6=N3_[XV4CRgn4]>co5=SJdI?IR9R7K2lSmNFke\bj?c<[I]"
  359.     A$ = A$ + "3QXknHbT9:]dB;Y`kblMd7Tn#B3cF=CZmYb:[Tb<c<Y<b83Ua8c5QJnTNjY["
  360.     A$ = A$ + "X[go?_W<f^AbX=I\7O8IGRiA[eSAbZ7[ZZ[nj[?Z`2;DgD#15lTf;ZXRXlc?"
  361.     A$ = A$ + "okdUEiL`Q<>Ua]nAb]4c3\?_<S8[;_Z[[4mmQIWMfDNiUg3eeTb\[<1T9\n#"
  362.     A$ = A$ + ":\4SR=obhEVAOUX[moCNM[n#j6965KQTImDj:U^BY;mZ[O4j7D>[T3Ukfin\"
  363.     A$ = A$ + "eEomg?EB9U`DLa5[#dfRLlm]7mi0PVb:[\R;MmY>o4mUom;D>NbQnn1OoEee"
  364.     A$ = A$ + "[kSNee7]lAjKcl=b#03T1o6NcX[Lg:Gjc3mIj[CmEbP_g>jjeLM3Ee5jg0m:"
  365.     A$ = A$ + "4DO85DRAaV?IFkER^V#V5TaUnAbU4c3\?WaGln3OT^Jc8gk=gCOLPT=9V7]F"
  366.     A$ = A$ + "GRkWOjYWVZYVJ8cV=cSA07;2]l1[okJn=mc6o9IbR9jG=o[4:8V>Lj#EM]jZ"
  367.     A$ = A$ + "[B3>hPdHS=6chS?^bX84i3FKTA6Q\Je:3V7;a<F1a2ilJ[]VZj2[=jXSB;_l"
  368.     A$ = A$ + "bdNk]7M`17#k_onlX8Dc74S=fH3Jb9WDAGH>\59n?7#<#^RLf[G_JZ[eGOM:"
  369.     A$ = A$ + "H`PdeGO=c=gLS#DcW#Q2aJ>JM1KQ37V^mfKe5ARKTSAlA^VBGYdE:Mmg]^6H"
  370.     A$ = A$ + "P1X012lRZ;\o\>k\CZWNjQjZ[^hl\nj[WkCIXQ6RlkgOL[[;_lBnk7onLK^i"
  371.     A$ = A$ + "VD]eF;eJ[]B]dB;D5ED1O^9;MeNk]CmfK_T=KfX>jX3Zk^kVeDS=f8EGMeAW"
  372.     A$ = A$ + "NjY?k[GUFJY\N#O:8VEGMeDIUE6IaRUTV^P]S>j8>o?olcY3?l#nN6TWhh[^"
  373.     A$ = A$ + "jZW]^>iTChc3SPc>k<VkO_`o7On:IFgh]FOD_EkkMa5GTOn<JJ^iV5RFnPeA"
  374.     A$ = A$ + "]5#\4?m2RYCW>EEG[\b:LmKD_;2AZo92]l1_GX]fJS1ce:Nj5TcNlhAhcGhn"
  375.     A$ = A$ + "TiVK>Fo^LiBID4RlIQ5FPVHR9D^?4cQ=]RI\2bETcaBM3<jcW?jR;^P1e65Q"
  376.     A$ = A$ + "JnPJck^k^?Z^1\Qed:^J1ba8ilOceiQ_hLR>>RnnN:k8gCTj:JBY[Dj2m5^m"
  377.     A$ = A$ + "fKcnnFBGc>k\DiUG>_?UMfIWTR^>nhSiL1m<mBY;DSMZYVRZZZZX]fJ[4^^P"
  378.     A$ = A$ + "?XoXIVIVGd[GH_3hMR3?l`lnCBdjJniWWO?WXW_CEgh^gMSn1`i1#>82el1e"
  379.     A$ = A$ + "FD[O3\VFaE;#>RL=Fd5je2g3\dB;A^MkFID4Rl1m>j`Q35MQi`VFa<F1iZFm"
  380.     A$ = A$ + "7RNRAoff]KG1lOVjn7oDXU?XWKlKS0`L]RWN1i\Xnian_JZYVDf[D4P=AXU?"
  381.     A$ = A$ + "Hm6JX1VH9Na3A_o[o3Ph%%L2"
  382.     btemp$ = ""
  383.     FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
  384.         IF INSTR(1, B$, "%") THEN
  385.             FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
  386.                 IF F$ <> "%" THEN C$ = C$ + F$
  387.             NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
  388.             IF MID$(B$, j, 1) = "#" THEN
  389.         MID$(B$, j) = "@": END IF: NEXT
  390.         FOR t% = LEN(B$) TO 1 STEP -1
  391.             B& = B& * 64 + ASC(MID$(B$, t%)) - 48
  392.             NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
  393.             X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
  394.     NEXT: btemp$ = btemp$ + X$: NEXT
  395.     btemp$ = _INFLATE$(btemp$)
  396.     _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
  397.     BASIMAGE1& = _COPYIMAGE(v&): _FREEIMAGE v&
  398.  
« Last Edit: July 28, 2020, 11:30:28 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calculator
« Reply #13 on: July 29, 2020, 01:40:35 am »
I just improved it even more with 4 new buttons on the bottom (I made the calculator window a bit longer). The new buttons are: Rad2Deg (which changes to Deg2Rad after used, and vice-versa). This changes degrees to radians and radians to degrees. The next button is second power, which times your number to itself (by the second power). The next one is logarithm. This one uses the Base 10 logarithm (which is what most calculators use I found out). Instead of num = LOG(num) it has num = LOG(num) / LOG(10.#). The wiki page of LOG helped me with that equation. I also checked the output using Google's calculator which also uses Base 10 Log. The last new button was the easiest, it just puts _PI on the screen for anyone that needs to use Pi. You can see I clicked the Pi button in the picture attachment below.

Note: I deleted this code because of a Log error I get when trying to get the Log of a negative number, which is true in math. Go to the next post for the update.



Ken's Calculator.jpg
* Ken's Calculator.jpg (Filesize: 43.93 KB, Dimensions: 403x479, Views: 116)
« Last Edit: July 29, 2020, 01:54:51 am by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calculator
« Reply #14 on: July 29, 2020, 01:53:49 am »
Here is the update with the Log fix.

Code: QB64: [Select]
  1. 'Calculator
  2. 'By SierraKen on July 28, 2020.
  3. '------------------------------
  4. 'This is my very first regular calculator.
  5. 'Thank you to B+ and TempodiBasic for the help and everyone for the inspiration!
  6. 'This was a 3 day project and I've wanted to make this all my life. Ever since I was real little
  7. 'playing around with my parents' calculator.
  8. 'Thank you Dav for the icon code!
  9. 'Just added Clipboard by clicking the output number.
  10. 'Just added Rad2Deg (and Deg2Rad), second power, Base 10 Logarithm, and Pi buttons.
  11.  
  12. 'Load the icon - call this somewhere near the top of your program
  13. _ICON BASIMAGE1&
  14.  
  15. _TITLE "Calculator - Click output to copy."
  16. SCREEN _NEWIMAGE(400, 450, 32)
  17.  
  18.  
  19. 'Setup calculator
  20. LINE (50, 25)-(265, 50), _RGB32(255, 255, 255), B
  21. LINE (50, 75)-(350, 350), _RGB32(255, 255, 255), B
  22. 'Buttons
  23. FOR buttony = 75 TO 350 STEP 55
  24.     FOR buttonx = 50 TO 275 STEP 75
  25.         FOR bb = 0 TO 10
  26.             c = c + 10
  27.             LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  28.         NEXT bb
  29.         PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
  30.         c = 0
  31.     NEXT buttonx
  32. NEXT buttony
  33. buttonx = 275: buttony = 20
  34. 'Green C Button
  35. FOR bb = 0 TO 10
  36.     c = c + 10
  37.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  38. NEXT bb
  39. PAINT (buttonx + 12, buttony + 12), _RGB32(50, 100 + c, 50)
  40. COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
  41. c = 0
  42. 'Label Buttons
  43. _PRINTSTRING (312, 47), "C"
  44. COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  45. _PRINTSTRING (87, 102), CHR$(251) 'square root
  46. _PRINTSTRING (152, 102), "sin"
  47. _PRINTSTRING (227, 102), "cos"
  48. _PRINTSTRING (302, 102), "tan"
  49. _PRINTSTRING (87, 157), "7"
  50. _PRINTSTRING (162, 157), "8"
  51. _PRINTSTRING (237, 157), "9"
  52. _PRINTSTRING (312, 157), "/"
  53. _PRINTSTRING (87, 212), "4"
  54. _PRINTSTRING (162, 212), "5"
  55. _PRINTSTRING (237, 212), "6"
  56. _PRINTSTRING (312, 212), "x"
  57. _PRINTSTRING (87, 267), "1"
  58. _PRINTSTRING (162, 267), "2"
  59. _PRINTSTRING (237, 267), "3"
  60. _PRINTSTRING (312, 267), "-"
  61. _PRINTSTRING (87, 322), "0"
  62. _PRINTSTRING (162, 322), "."
  63. _PRINTSTRING (237, 322), "="
  64. _PRINTSTRING (312, 322), "+"
  65. _PRINTSTRING (60, 377), "rad2deg"
  66. _PRINTSTRING (162, 377), "x" + CHR$(253) 'second power
  67. _PRINTSTRING (227, 377), "log"
  68. _PRINTSTRING (307, 377), "Pi"
  69.  
  70. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  71.     _LIMIT 20
  72.         mouseX = _MOUSEX
  73.         mouseY = _MOUSEY
  74.         mouseLeftButton = _MOUSEBUTTON(1)
  75.     LOOP
  76.     IF mouseLeftButton THEN
  77.         mouseLeftButton = 0
  78.  
  79.         'Clipboard
  80.         IF mouseX > 50 AND mouseX < 265 AND mouseY > 25 AND mouseY < 50 THEN
  81.             COLOR _RGB32(0, 255, 0), _RGB32(0, 0, 0)
  82.             _PRINTSTRING (55, 30), num$
  83.             _DELAY 1
  84.             num2$ = _TRIM$(num$)
  85.             _CLIPBOARD$ = num2$
  86.             COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  87.             _PRINTSTRING (55, 30), num$
  88.         END IF
  89.  
  90.         'Clear
  91.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 20 AND mouseY < 75 THEN
  92.             a = 0: s = 0: t = 0: d = 0: num$ = ""
  93.             _PRINTSTRING (55, 30), "                          "
  94.             buttonx = 275: buttony = 20
  95.             GOSUB zero:
  96.         END IF
  97.  
  98.         'Rad2Deg and Deg2Rad
  99.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 350 AND mouseY < 405 THEN
  100.             rad = rad + 1
  101.             IF rad = 2 THEN GOTO deg2rad:
  102.             COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  103.             _PRINTSTRING (60, 377), "deg2rad"
  104.             num = VAL(num$)
  105.             num = _R2D(num)
  106.             num$ = STR$(num)
  107.             GOTO skipdeg2rad:
  108.             deg2rad:
  109.             rad = 0
  110.             COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  111.             _PRINTSTRING (60, 377), "rad2deg"
  112.             num = VAL(num$)
  113.             num = _D2R(num)
  114.             num$ = STR$(num)
  115.             skipdeg2rad:
  116.             buttonx = 50: buttony = 350
  117.             GOSUB press:
  118.             GOSUB number:
  119.         END IF
  120.  
  121.         'Second Power
  122.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 350 AND mouseY < 405 THEN
  123.             num = VAL(num$)
  124.             num = num ^ 2
  125.             num$ = STR$(num)
  126.             buttonx = 126: buttony = 350
  127.             GOSUB press:
  128.             GOSUB number:
  129.         END IF
  130.  
  131.         'logarithm
  132.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 350 AND mouseY < 405 THEN
  133.             num = VAL(num$)
  134.             IF num < 0 THEN GOTO skiplog:
  135.             num = LOG(num) / LOG(10.#)
  136.             num$ = STR$(num)
  137.             skiplog:
  138.             buttonx = 200: buttony = 350
  139.             GOSUB press:
  140.             GOSUB number:
  141.         END IF
  142.  
  143.         'Pi
  144.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 350 AND mouseY < 405 THEN
  145.             num = _PI
  146.             num$ = STR$(num)
  147.             buttonx = 275: buttony = 350
  148.             GOSUB press:
  149.             GOSUB number:
  150.         END IF
  151.  
  152.         'Square Root
  153.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 75 AND mouseY < 130 THEN
  154.             IF num < 0 THEN GOTO skip1:
  155.             num = VAL(num$)
  156.             num = SQR(num)
  157.             num$ = STR$(num)
  158.             skip1:
  159.             buttonx = 50: buttony = 75
  160.             GOSUB press:
  161.             GOSUB number:
  162.         END IF
  163.  
  164.         'Sine
  165.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 75 AND mouseY < 130 THEN
  166.             num = VAL(num$)
  167.             num = SIN(num)
  168.             num$ = STR$(num)
  169.             buttonx = 126: buttony = 75
  170.             GOSUB press:
  171.             GOSUB number:
  172.         END IF
  173.  
  174.         'Cosine
  175.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 75 AND mouseY < 130 THEN
  176.             num = VAL(num$)
  177.             num = COS(num)
  178.             num$ = STR$(num)
  179.             buttonx = 200: buttony = 75
  180.             GOSUB press:
  181.             GOSUB number:
  182.         END IF
  183.  
  184.         'Tangent
  185.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 75 AND mouseY < 130 THEN
  186.             num = VAL(num$)
  187.             num = TAN(num)
  188.             num$ = STR$(num)
  189.             buttonx = 275: buttony = 75
  190.             GOSUB press:
  191.             GOSUB number:
  192.         END IF
  193.  
  194.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 130 AND mouseY < 185 THEN
  195.             num$ = num$ + "7"
  196.             IF n = 1 THEN num$ = "-" + num$: n = 0
  197.             buttonx = 50: buttony = 130
  198.             GOSUB press:
  199.             GOSUB number:
  200.         END IF
  201.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 130 AND mouseY < 185 THEN
  202.             num$ = num$ + "8"
  203.             IF n = 1 THEN num$ = "-" + num$: n = 0
  204.             buttonx = 126: buttony = 130
  205.             GOSUB press:
  206.             GOSUB number:
  207.         END IF
  208.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 130 AND mouseY < 185 THEN
  209.             num$ = num$ + "9"
  210.             IF n = 1 THEN num$ = "-" + num$: n = 0
  211.             buttonx = 200: buttony = 130
  212.             GOSUB press:
  213.             GOSUB number:
  214.         END IF
  215.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 185 AND mouseY < 240 THEN
  216.             num$ = num$ + "4"
  217.             IF n = 1 THEN num$ = "-" + num$: n = 0
  218.             buttonx = 50: buttony = 185
  219.             GOSUB press:
  220.             GOSUB number:
  221.         END IF
  222.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 185 AND mouseY < 240 THEN
  223.             num$ = num$ + "5"
  224.             IF n = 1 THEN num$ = "-" + num$: n = 0
  225.             buttonx = 126: buttony = 185
  226.             GOSUB press:
  227.             GOSUB number:
  228.         END IF
  229.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 185 AND mouseY < 240 THEN
  230.             num$ = num$ + "6"
  231.             IF n = 1 THEN num$ = "-" + num$: n = 0
  232.             buttonx = 200: buttony = 185
  233.             GOSUB press:
  234.             GOSUB number:
  235.         END IF
  236.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 240 AND mouseY < 295 THEN
  237.             num$ = num$ + "1"
  238.             IF n = 1 THEN num$ = "-" + num$: n = 0
  239.             buttonx = 50: buttony = 240
  240.             GOSUB press:
  241.             GOSUB number:
  242.         END IF
  243.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 240 AND mouseY < 295 THEN
  244.             num$ = num$ + "2"
  245.             IF n = 1 THEN num$ = "-" + num$: n = 0
  246.             buttonx = 126: buttony = 240
  247.             GOSUB press:
  248.             GOSUB number:
  249.         END IF
  250.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 240 AND mouseY < 295 THEN
  251.             num$ = num$ + "3"
  252.             IF n = 1 THEN num$ = "-" + num$: n = 0
  253.             buttonx = 200: buttony = 240
  254.             GOSUB press:
  255.             GOSUB number:
  256.         END IF
  257.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 295 AND mouseY < 350 THEN
  258.             num$ = num$ + "0"
  259.             IF n = 1 THEN num$ = "-" + num$: n = 0
  260.             buttonx = 50: buttony = 295
  261.             GOSUB press:
  262.             GOSUB number:
  263.         END IF
  264.  
  265.         'Decimal
  266.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 295 AND mouseY < 350 THEN
  267.             buttonx = 126: buttony = 295
  268.             FOR check = 1 TO LEN(num$)
  269.                 IF MID$(num$, check, 1) = "." THEN GOTO skipdec:
  270.             NEXT check
  271.             num$ = num$ + "."
  272.             _PRINTSTRING (55, 30), num$
  273.             skipdec:
  274.             GOSUB press:
  275.         END IF
  276.  
  277.         'Equals
  278.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 295 AND mouseY < 350 THEN
  279.             IF a = 1 THEN num = VAL(oldnum$) + VAL(num$): a = 0
  280.             IF s = 1 THEN num = VAL(oldnum$) - VAL(num$): s = 0
  281.             IF t = 1 THEN num = VAL(oldnum$) * VAL(num$): t = 0
  282.             IF d = 1 THEN num = VAL(oldnum$) / VAL(num$): d = 0
  283.             buttonx = 200: buttony = 295
  284.             GOSUB press:
  285.             GOSUB number2:
  286.         END IF
  287.  
  288.         'Add
  289.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 295 AND mouseY < 350 THEN
  290.             IF a = 0 THEN
  291.                 d = 0: a = 1: s = 0: t = 0
  292.                 oldnum$ = num$
  293.                 calc = 1
  294.                 _PRINTSTRING (55, 30), "                          "
  295.                 num$ = ""
  296.                 GOTO nex4:
  297.             END IF
  298.             IF a = 1 THEN
  299.                 num = VAL(oldnum$) + VAL(num$)
  300.                 a = 0
  301.             END IF
  302.             calc = 0
  303.             GOSUB number2:
  304.             nex4:
  305.             buttonx = 275: buttony = 295
  306.             GOSUB press:
  307.         END IF
  308.  
  309.         'Subtract
  310.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 240 AND mouseY < 295 THEN
  311.             IF s = 0 THEN
  312.                 IF num$ = "0" OR num$ = "" OR num = 0 THEN n = 1: GOTO nex3:
  313.                 d = 0: a = 0: s = 1: t = 0
  314.                 oldnum$ = num$
  315.                 calc = 1
  316.                 _PRINTSTRING (55, 30), "                          "
  317.                 num$ = ""
  318.                 GOTO nex3:
  319.             END IF
  320.             IF s = 1 THEN
  321.                 num = VAL(oldnum$) - VAL(num$)
  322.                 s = 0
  323.             END IF
  324.             calc = 0
  325.             GOSUB number2:
  326.             nex3:
  327.             buttonx = 275: buttony = 240
  328.             GOSUB press:
  329.         END IF
  330.  
  331.         'Multiply
  332.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 185 AND mouseY < 240 THEN
  333.             IF t = 0 THEN
  334.                 d = 0: a = 0: s = 0: t = 1
  335.                 oldnum$ = num$
  336.                 calc = 1
  337.                 _PRINTSTRING (55, 30), "                          "
  338.                 num$ = ""
  339.                 GOTO nex2:
  340.             END IF
  341.             IF t = 1 THEN
  342.                 num = VAL(oldnum$) * VAL(num$)
  343.                 t = 0
  344.             END IF
  345.             calc = 0
  346.             GOSUB number2:
  347.             nex2:
  348.             buttonx = 275: buttony = 185
  349.             GOSUB press:
  350.         END IF
  351.  
  352.         'Divide
  353.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 130 AND mouseY < 185 THEN
  354.             IF d = 0 THEN
  355.                 d = 1: a = 0: s = 0: t = 0
  356.                 oldnum$ = num$
  357.                 calc = 1
  358.                 _PRINTSTRING (55, 30), "                          "
  359.                 num$ = ""
  360.                 GOTO nex1:
  361.             END IF
  362.             IF d = 1 AND num$ <> "" THEN
  363.                 num = VAL(oldnum$) / VAL(num$)
  364.                 d = 0
  365.             END IF
  366.             calc = 0
  367.             GOSUB number2:
  368.             nex1:
  369.             buttonx = 275: buttony = 130
  370.             GOSUB press:
  371.         END IF
  372.     END IF
  373. 'For Number Buttons.
  374. number:
  375. num = VAL(num$)
  376.  
  377. 'For Math
  378. number2:
  379. COLOR _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  380. _PRINTSTRING (55, 30), "                          "
  381. num$ = STR$(num)
  382. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  383. _PRINTSTRING (55, 30), num$
  384.  
  385.  
  386. 'Pressing Each Button
  387. press:
  388. c = 110
  389. FOR bb = 0 TO 10
  390.     c = c - 10
  391.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  392. NEXT bb
  393. _DELAY .25
  394. FOR bb = 0 TO 10
  395.     c = c + 10
  396.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  397. NEXT bb
  398.  
  399. 'Pressing the Green C Button.
  400. zero:
  401. c = 110
  402. FOR bb = 0 TO 10
  403.     c = c - 10
  404.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  405. NEXT bb
  406. _DELAY .25
  407. FOR bb = 0 TO 10
  408.     c = c + 10
  409.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  410. NEXT bb
  411.  
  412.  
  413.  
  414.  
  415. FUNCTION BASIMAGE1& 'calculatio icon data
  416.     v& = _NEWIMAGE(54, 48, 32)
  417.     DIM m AS _MEM: m = _MEMIMAGE(v&)
  418.     A$ = ""
  419.     A$ = A$ + "haIkJ^eBK\557GZJOl02m5YDX5J1A:YC0aGE##Oc?0RUD5A:HDOA=N=2N96`"
  420.     A$ = A$ + ";87A#=X?hm4S6=N3_[XV4CRgn4]>co5=SJdI?IR9R7K2lSmNFke\bj?c<[I]"
  421.     A$ = A$ + "3QXknHbT9:]dB;Y`kblMd7Tn#B3cF=CZmYb:[Tb<c<Y<b83Ua8c5QJnTNjY["
  422.     A$ = A$ + "X[go?_W<f^AbX=I\7O8IGRiA[eSAbZ7[ZZ[nj[?Z`2;DgD#15lTf;ZXRXlc?"
  423.     A$ = A$ + "okdUEiL`Q<>Ua]nAb]4c3\?_<S8[;_Z[[4mmQIWMfDNiUg3eeTb\[<1T9\n#"
  424.     A$ = A$ + ":\4SR=obhEVAOUX[moCNM[n#j6965KQTImDj:U^BY;mZ[O4j7D>[T3Ukfin\"
  425.     A$ = A$ + "eEomg?EB9U`DLa5[#dfRLlm]7mi0PVb:[\R;MmY>o4mUom;D>NbQnn1OoEee"
  426.     A$ = A$ + "[kSNee7]lAjKcl=b#03T1o6NcX[Lg:Gjc3mIj[CmEbP_g>jjeLM3Ee5jg0m:"
  427.     A$ = A$ + "4DO85DRAaV?IFkER^V#V5TaUnAbU4c3\?WaGln3OT^Jc8gk=gCOLPT=9V7]F"
  428.     A$ = A$ + "GRkWOjYWVZYVJ8cV=cSA07;2]l1[okJn=mc6o9IbR9jG=o[4:8V>Lj#EM]jZ"
  429.     A$ = A$ + "[B3>hPdHS=6chS?^bX84i3FKTA6Q\Je:3V7;a<F1a2ilJ[]VZj2[=jXSB;_l"
  430.     A$ = A$ + "bdNk]7M`17#k_onlX8Dc74S=fH3Jb9WDAGH>\59n?7#<#^RLf[G_JZ[eGOM:"
  431.     A$ = A$ + "H`PdeGO=c=gLS#DcW#Q2aJ>JM1KQ37V^mfKe5ARKTSAlA^VBGYdE:Mmg]^6H"
  432.     A$ = A$ + "P1X012lRZ;\o\>k\CZWNjQjZ[^hl\nj[WkCIXQ6RlkgOL[[;_lBnk7onLK^i"
  433.     A$ = A$ + "VD]eF;eJ[]B]dB;D5ED1O^9;MeNk]CmfK_T=KfX>jX3Zk^kVeDS=f8EGMeAW"
  434.     A$ = A$ + "NjY?k[GUFJY\N#O:8VEGMeDIUE6IaRUTV^P]S>j8>o?olcY3?l#nN6TWhh[^"
  435.     A$ = A$ + "jZW]^>iTChc3SPc>k<VkO_`o7On:IFgh]FOD_EkkMa5GTOn<JJ^iV5RFnPeA"
  436.     A$ = A$ + "]5#\4?m2RYCW>EEG[\b:LmKD_;2AZo92]l1_GX]fJS1ce:Nj5TcNlhAhcGhn"
  437.     A$ = A$ + "TiVK>Fo^LiBID4RlIQ5FPVHR9D^?4cQ=]RI\2bETcaBM3<jcW?jR;^P1e65Q"
  438.     A$ = A$ + "JnPJck^k^?Z^1\Qed:^J1ba8ilOceiQ_hLR>>RnnN:k8gCTj:JBY[Dj2m5^m"
  439.     A$ = A$ + "fKcnnFBGc>k\DiUG>_?UMfIWTR^>nhSiL1m<mBY;DSMZYVRZZZZX]fJ[4^^P"
  440.     A$ = A$ + "?XoXIVIVGd[GH_3hMR3?l`lnCBdjJniWWO?WXW_CEgh^gMSn1`i1#>82el1e"
  441.     A$ = A$ + "FD[O3\VFaE;#>RL=Fd5je2g3\dB;A^MkFID4Rl1m>j`Q35MQi`VFa<F1iZFm"
  442.     A$ = A$ + "7RNRAoff]KG1lOVjn7oDXU?XWKlKS0`L]RWN1i\Xnian_JZYVDf[D4P=AXU?"
  443.     A$ = A$ + "Hm6JX1VH9Na3A_o[o3Ph%%L2"
  444.     btemp$ = ""
  445.     FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
  446.         IF INSTR(1, B$, "%") THEN
  447.             FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
  448.                 IF F$ <> "%" THEN C$ = C$ + F$
  449.             NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
  450.             IF MID$(B$, j, 1) = "#" THEN
  451.         MID$(B$, j) = "@": END IF: NEXT
  452.         FOR t% = LEN(B$) TO 1 STEP -1
  453.             B& = B& * 64 + ASC(MID$(B$, t%)) - 48
  454.             NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
  455.             X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
  456.     NEXT: btemp$ = btemp$ + X$: NEXT
  457.     btemp$ = _INFLATE$(btemp$)
  458.     _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
  459.     BASIMAGE1& = _COPYIMAGE(v&): _FREEIMAGE v&
  460.  
Ken's Calculator.jpg
* Ken's Calculator.jpg (Filesize: 43.93 KB, Dimensions: 403x479, Views: 119)
« Last Edit: July 29, 2020, 01:55:22 am by SierraKen »