Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for resistor.kix

(view source code of resistor.kix as plain text)

  1. ; Practice using E12 color codes for resistors
  2. ; Version 1.00
  3. ; (C) 1997 - 2004, Rob van der Woude
  4. ; http://www.robvanderwoude.com
  5. ; Last revision 2004/11/08
  6.  
  7. ; Use this program at your own risk.
  8. ; You may copy, distribute or even modify this program, provided
  9. ; you leave a note explaining your modifications in this header.
  10.  
  11.  
  12. Select
  13. 	Case InStr("@SYSLANG","Dutch") > 0
  14. 		$StrVal     = "Waarde:"
  15. 		$StrBlack   = "Zwart  "
  16. 		$StrBrown   = "Bruin  "
  17. 		$StrRed     = "Rood   "
  18. 		$StrOrange  = "Oranje "
  19. 		$StrYellow  = "Geel   "
  20. 		$StrGreen   = "Groen  "
  21. 		$StrBlue    = "Blauw  "
  22. 		$StrMagenta = "Magenta"
  23. 		$StrGrey    = "Grijs  "
  24. 		$StrWhite   = "Wit    "
  25. 		$StrGold    = "Goud   "
  26. 		$StrYourAns = "Uw antwoord:        "
  27. 		$StrCorrAns = "Correcte antwoord:  "
  28. 		$StrPressQ  = "Q om te stoppen, elke andere toets om door te gaan . . ."
  29. 		$StrCorrect = "Correct!                            "
  30. 		$StrWrong   = "Helaas . . .                        "
  31. 		$StrDelim   = ","
  32. 	Case 1
  33. 		$StrVal = "Value: "
  34. 		$StrBlack   = "Black  "
  35. 		$StrBrown   = "Brown  "
  36. 		$StrRed     = "Red    "
  37. 		$StrOrange  = "Orange "
  38. 		$StrYellow  = "Yellow "
  39. 		$StrGreen   = "Green  "
  40. 		$StrBlue    = "Blue   "
  41. 		$StrMagenta = "Magenta"
  42. 		$StrGrey    = "Grey   "
  43. 		$StrWhite   = "White  "
  44. 		$StrGold    = "Gold   "
  45. 		$StrYourAns = "Your answer:        "
  46. 		$StrCorrAns = "Correct answer:     "
  47. 		$StrPressQ  = "Press Q to quit, or any key to continue . . ."
  48. 		$StrCorrect = "Correct!                            "
  49. 		$StrWrong   = "Sorry . . .                         "
  50. 		$StrDelim   = "."
  51. EndSelect
  52.  
  53. ; Store E12 values in an array
  54. Dim $E12[11]
  55. $E12 = Split("10 12 15 18 22 27 33 39 47 56 68 82")
  56.  
  57. Cls
  58.  
  59. ; Show the color table at the top of the screen
  60. $RC = At(0,0)
  61. $RC = DispColor(0)
  62. $RC = DispColor(0)
  63. " 0"
  64. $RC = At(0,7)
  65. $RC = DispColor(1)
  66. $RC = DispColor(1)
  67. " 1"
  68. $RC = At(0,14)
  69. $RC = DispColor(2)
  70. $RC = DispColor(2)
  71. " 2"
  72. $RC = At(0,21)
  73. $RC = DispColor(3)
  74. $RC = DispColor(3)
  75. " 3"
  76. $RC = At(0,28)
  77. $RC = DispColor(4)
  78. $RC = DispColor(4)
  79. " 4"
  80. $RC = At(0,35)
  81. $RC = DispColor(5)
  82. $RC = DispColor(5)
  83. " 5"
  84. $RC = At(0,42)
  85. $RC = DispColor(6)
  86. $RC = DispColor(6)
  87. " 6"
  88. $RC = At(0,49)
  89. $RC = DispColor(7)
  90. $RC = DispColor(7)
  91. " 7"
  92. $RC = At(0,56)
  93. $RC = DispColor(8)
  94. $RC = DispColor(8)
  95. " 8"
  96. $RC = At(0,63)
  97. $RC = DispColor(9)
  98. $RC = DispColor(9)
  99. " 9"
  100. $RC = At(0,70)
  101. $RC = DispColor(-1)
  102. $RC = DispColor(-1)
  103. " x 0,1"
  104. $RC = At(1,0)
  105. "$StrBlack"
  106. "$StrBrown"
  107. "$StrRed"
  108. "$StrOrange"
  109. "$StrYellow"
  110. "$StrGreen"
  111. "$StrBlue"
  112. "$StrMagenta"
  113. "$StrGrey"
  114. "$StrWhite"
  115. "$StrGold"
  116.  
  117. ; Draw the wires at the center of the screen
  118. $RC = At(13,20)
  119. Color n+/n
  120. $i = 0
  121. $OldASCII = SetASCII( "ON" )
  122. While $i < 40
  123. 	$i = $i + 1
  124. 	Chr(196)
  125. Loop
  126. ; Draw the resistor's body
  127. $Row = 12
  128. While $Row < 15
  129. 	$Col = 29
  130. 	While $Col < 50
  131. 		$RC = At($Row,$Col)
  132. 		$RC = DispColor(20)
  133. 		$Col = $Col + 1
  134. 	Loop
  135. 	$Row = $Row + 1
  136. Loop
  137. $RC = SetASCII( "$OldASCII" )
  138. Color w/n
  139.  
  140. ; Randomize the randomizer's start value
  141. $RC = SRnd(10)
  142.  
  143. :Start
  144. ; Select a random value
  145. $Ftr = Rnd(11)
  146. $Ftr = $E12[$Ftr]
  147. $r1  = Val($Ftr) / 10
  148. $r1a = $r1 * 10
  149. $r2  = Val($Ftr) - $r1a
  150. $r3  = Rnd(9) - 1
  151.  
  152. $Resistance = Val("$Ftr")
  153. $i = $r3
  154. While $i > 0
  155. 	$Resistance = $Resistance * 10
  156. 	$i = $i - 1
  157. Loop
  158.  
  159. ; Draw the coloured rings
  160. $Row = 12
  161. While $Row < 15
  162. 	$RC = At($Row,31)
  163. 	$RC = DispColor($r1)
  164. 	$RC = At($Row,35)
  165. 	$RC = DispColor($r2)
  166. 	$RC = At($Row,39)
  167. 	$RC = DispColor($r3)
  168. 	$Row = $Row + 1
  169. Loop
  170.  
  171. $RC = At(23,15)
  172. "$StrVal                 "
  173. $RC = At(23,23)
  174. GetS $TryVal
  175.  
  176. $Val  = Val($TryVal)
  177. $Len1 = Len($TryVal)
  178. $Len2 = Len("$Val")
  179.  
  180. If $r3 = -1
  181. 	$Dec = LTrim(RTrim(SubStr("$TryVal",$Len2 + 1,1)))
  182. 	If $Dec <> "," & $Dec <> "."
  183. 		$Dec = $StrDelim
  184. 	EndIf
  185. 	$Resistance = SubStr($Ftr,1,Len($Ftr) - 1) + $Dec + SubStr($Ftr,Len($Ftr))
  186. 	If SubStr($Mult,1,1) = "," | SubStr($Mult,1,1) = "."
  187. 		$Val = $TryVal
  188. 	EndIf
  189. EndIf
  190.  
  191. If $len1 <> $Len2
  192. 	$Mult = LTrim(RTrim(SubStr("$TryVal",$Len2 + 1)))
  193. 	Select
  194. 		Case SubStr($Mult,1,1) = "," | SubStr($Mult,1,1) = "."
  195. 			If $r3 = -1
  196. 				$Val = $TryVal
  197. 				$Resistance = SubStr($Ftr,1,Len($Ftr) - 1) + SubStr($Mult,1,1) + SubStr($Ftr,Len($Ftr))
  198. 			Else
  199. 				$Val        = 0
  200. 			EndIf
  201. 		Case $Mult = "K"
  202. 			$Val = $Val * 1000
  203. 		Case $Mult = "M"
  204. 			$Val = $Val * 1000 * 1000
  205. 		Case $Mult = "G"
  206. 			$Val = $Val * 1000 * 1000 * 1000
  207. 		Case 1
  208. 			$Val = 0
  209. 	EndSelect
  210. EndIf
  211.  
  212. $RC = At(23,15)
  213. If $Val = $Resistance
  214. 	Color g+/n
  215. 	"$StrCorrect"
  216. 	Color w/n
  217. Else
  218. 	Color r+/n
  219. 	"$StrWrong"
  220. 	Color w/n
  221. EndIf
  222.  
  223. $RC = At(24,15)
  224. If $Val = 0
  225. 	"$StrYourAns $Val (or invalid)   "
  226. Else
  227. 	"$StrYourAns $Val                "
  228. EndIf
  229.  
  230. $RC = At(25,15)
  231. "$StrCorrAns $Resistance         "
  232.  
  233. $RC = At(27,15)
  234. "$StrPressQ"
  235. Get $PressQ
  236. If $PressQ <> "Q"
  237. 	$RC = At(24,15)
  238. 	"                                                               "
  239. 	$RC = At(25,15)
  240. 	"                                                               "
  241. 	$RC = At(27,15)
  242. 	"                                                               "
  243. 	GoTo "Start"
  244. EndIf
  245.  
  246. Function DispColor( $ColNum )
  247. 	$DispColor = 0
  248. 	$OldASCII = SetASCII( "ON" )
  249. 	Select
  250. 		Case $ColNum = -1
  251. 			Color y/y+
  252. 			Chr(176)
  253. 			Chr(176)
  254. 		Case $ColNum = 0
  255. 			Color n/n+
  256. 			Chr(219)
  257. 			Chr(219)
  258. 		Case $ColNum = 1
  259. 			Color y/n
  260. 			Chr(219)
  261. 			Chr(219)
  262. 		Case $ColNum = 2
  263. 			Color r+/n
  264. 			Chr(219)
  265. 			Chr(219)
  266. 		Case $ColNum = 3
  267. 			Color y+/r+
  268. 			Chr(177)
  269. 			Chr(177)
  270. 		Case $ColNum = 4
  271. 			Color y+/n
  272. 			Chr(219)
  273. 			Chr(219)
  274. 		Case $ColNum = 5
  275. 			Color g+/n
  276. 			Chr(219)
  277. 			Chr(219)
  278. 		Case $ColNum = 6
  279. 			Color b+/n
  280. 			Chr(219)
  281. 			Chr(219)
  282. 		Case $ColNum = 7
  283. 			Color m/n
  284. 			Chr(219)
  285. 			Chr(219)
  286. 		Case $ColNum = 8
  287. 			Color w/n+
  288. 			Chr(219)
  289. 			Chr(219)
  290. 		Case $ColNum = 9
  291. 			Color w+/n+
  292. 			Chr(219)
  293. 			Chr(219)
  294. 		Case $ColNum = "20"
  295. ;			Color m/y+
  296. 			Color r+/y
  297. 			Chr(177)
  298. 			Chr(177)
  299. 		Case 1
  300. 			$DispColor = 1
  301. 	EndSelect
  302. 	$RC = SetASCII( "$OldASCII" )
  303. 	Color w/n
  304. EndFunction
  305.  

page last uploaded: 2017-07-06, 12:37