Advertisement
Guest User

LEDCube_P2

a guest
Jan 7th, 2014
3,264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 107.80 KB | None | 0 0
  1.  
  2.  
  3. /***************************************************************************************
  4. * Name : LED CUBE 8x8x8 74HC595
  5. * By :
  6. ****************************************************************************************/
  7.  
  8. #include <TimerOne.h>
  9. #include <string.h>
  10. #define AXIS_X 1
  11. #define AXIS_Y 2
  12. #define AXIS_Z 3
  13.  
  14. //--- Pin connected to ST_CP of 74HC595
  15. //--- Gelbe Leitung RCK
  16. int latchPin = 10;
  17. //--- Pin connected to SH_CP of 74HC595
  18. //--- Schwarze Leitung SCK
  19. int clockPin = 13;
  20. //--- Pin connected to DS of 74HC595
  21. //--- Lila Leitung SI
  22. int dataPin = 11;
  23. //--- Used for faster latching
  24. int latchPinPORTB = latchPin - 8;
  25. //holds value for all the pins, [x][y][z]
  26. byte cube[8][8];
  27.  
  28. //Counts through the layers
  29. int current_layer = 0;
  30.  
  31. //--- This process is run by the timer and does the PWM control
  32. void iProcess(){
  33. //last layer store
  34. int oldLayerBit = current_layer + 2;
  35.  
  36. //increment layer count
  37. current_layer++;
  38. if(current_layer >= 8){
  39. current_layer = 0;
  40. }
  41.  
  42. //--- Run through all the shift register values and send them (last one first)
  43. // latching in the process
  44. latchOff();
  45. for (int i = 0 ; i < 8 ; i++){
  46. spi_transfer(cube[current_layer][i]);
  47. }
  48.  
  49. //Hide the old layer
  50. digitalWrite(oldLayerBit, LOW);
  51. //New data on the pins
  52. latchOn();
  53. //new layer high
  54. digitalWrite(current_layer + 2, HIGH);
  55. }
  56.  
  57. //--- Direct port access latching
  58. void latchOn(){
  59. bitSet(PORTB,latchPinPORTB);
  60. }
  61. void latchOff(){
  62. bitClear(PORTB,latchPinPORTB);
  63. }
  64.  
  65. //--- Used to setup SPI based on current pin setup
  66. // this is called in the setup routine;
  67. void setupSPI(){
  68. byte clr;
  69. SPCR |= ( (1<<SPE) | (1<<MSTR) ); // enable SPI as master
  70. SPCR &= ~( (1<<SPR1) | (1<<SPR0) ); // clear prescaler bits
  71. clr=SPSR; // clear SPI status reg
  72. clr=SPDR; // clear SPI data reg
  73. SPSR |= (1<<SPI2X); // set prescaler bits
  74. delay(10);
  75. }
  76.  
  77. //--- The really fast SPI version of shiftOut
  78. byte spi_transfer(byte data)
  79. {
  80. SPDR = data; // Start the transmission
  81. loop_until_bit_is_set(SPSR, SPIF);
  82. return SPDR; // return the received byte, we don't need that
  83. }
  84.  
  85. void setup() {
  86. Serial.begin(9600);
  87.  
  88. //layer pins
  89. for(int i = 2; i < 10; i++)
  90. {
  91. pinMode(i, OUTPUT);
  92. }
  93.  
  94. pinMode(latchPin, OUTPUT);
  95. pinMode(clockPin, OUTPUT);
  96. pinMode(dataPin, OUTPUT);
  97.  
  98. digitalWrite(latchPin,LOW);
  99. digitalWrite(dataPin,LOW);
  100. digitalWrite(clockPin,LOW);
  101.  
  102. //--- Setup to run SPI
  103. setupSPI();
  104.  
  105. //--- Activate the PWM timer
  106. Timer1.initialize(100); // Timer for updating pwm pins
  107. Timer1.attachInterrupt(iProcess);
  108. }
  109.  
  110.  
  111. void loop(){
  112. int i,x,y,z;
  113.  
  114. while (true)
  115. {
  116. effect_wormsqueeze (2, AXIS_Z, -1, 100, 1000);
  117. effect_rand_patharound(200,500);
  118. effect_intro();
  119. sinelines(4000,10);
  120. effect_random_sparkle();
  121. side_ripples (300, 500);
  122. mirror_ripples(600,400);
  123. quad_ripples (600,300);
  124. linespin(1500,10);
  125. fireworks(10,30,500);
  126.  
  127.  
  128. effect_box_wamp(1000);
  129.  
  130. effect_rain(100);
  131.  
  132. effect_planboing(AXIS_Z, 700);
  133. effect_planboing(AXIS_Y, 700);
  134. effect_planboing(AXIS_X, 700);
  135.  
  136. effect_blinky2();
  137.  
  138. effect_random_filler(75,1);
  139. effect_random_filler(75,0);
  140.  
  141. effect_boxside_randsend_parallel (AXIS_X, 0, 200, 1);
  142. effect_boxside_randsend_parallel (AXIS_X, 1, 200, 1);
  143. effect_boxside_randsend_parallel (AXIS_Y, 0, 300, 1);
  144. effect_boxside_randsend_parallel (AXIS_Y, 1, 300, 1);
  145. effect_boxside_randsend_parallel (AXIS_Z, 0, 600, 1);
  146. effect_boxside_randsend_parallel (AXIS_Z, 1, 600, 1);
  147. effect_axis_updown_randsuspend(AXIS_Z, 550,5000,0);
  148. effect_axis_updown_randsuspend(AXIS_Z, 550,5000,1);
  149. effect_axis_updown_randsuspend(AXIS_Z, 550,5000,0);
  150. effect_axis_updown_randsuspend(AXIS_Z, 550,5000,1);
  151. effect_axis_updown_randsuspend(AXIS_X, 550,5000,0);
  152. effect_axis_updown_randsuspend(AXIS_X, 550,5000,1);
  153. effect_axis_updown_randsuspend(AXIS_Y, 550,5000,0);
  154. effect_axis_updown_randsuspend(AXIS_Y, 550,5000,1);
  155. effect_text(1000);
  156. }
  157. }
  158.  
  159. // ==========================================================================================
  160. // TEXT Functions
  161. // ==========================================================================================
  162. char font_data[128][8] = {
  163. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 0 :
  164. // | |
  165. // | |
  166. // | |
  167. // | |
  168. // | |
  169. // | |
  170. // | |
  171. // | |
  172.  
  173. { 0x00, 0x3E, 0x41, 0x55, 0x41, 0x55, 0x49, 0x3E }, // 1 : 
  174. // | |
  175. // | ***** |
  176. // | * * |
  177. // | * * * * |
  178. // | * * |
  179. // | * * * * |
  180. // | * * * |
  181. // | ***** |
  182.  
  183. { 0x00, 0x3E, 0x7F, 0x6B, 0x7F, 0x6B, 0x77, 0x3E }, // 2 : 
  184. // | |
  185. // | ***** |
  186. // | ******* |
  187. // | ** * ** |
  188. // | ******* |
  189. // | ** * ** |
  190. // | *** *** |
  191. // | ***** |
  192.  
  193. { 0x00, 0x22, 0x77, 0x7F, 0x7F, 0x3E, 0x1C, 0x08 }, // 3 : 
  194. // | |
  195. // | * * |
  196. // | *** *** |
  197. // | ******* |
  198. // | ******* |
  199. // | ***** |
  200. // | *** |
  201. // | * |
  202.  
  203. { 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x3E, 0x1C, 0x08 }, // 4 : 
  204. // | |
  205. // | * |
  206. // | *** |
  207. // | ***** |
  208. // | ******* |
  209. // | ***** |
  210. // | *** |
  211. // | * |
  212.  
  213. { 0x00, 0x08, 0x1C, 0x2A, 0x7F, 0x2A, 0x08, 0x1C }, // 5 : 
  214. // | |
  215. // | * |
  216. // | *** |
  217. // | * * * |
  218. // | ******* |
  219. // | * * * |
  220. // | * |
  221. // | *** |
  222.  
  223. { 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x3E, 0x08, 0x1C }, // 6 : 
  224. // | |
  225. // | * |
  226. // | *** |
  227. // | ***** |
  228. // | ******* |
  229. // | ***** |
  230. // | * |
  231. // | *** |
  232.  
  233. { 0x00, 0x00, 0x1C, 0x3E, 0x3E, 0x3E, 0x1C, 0x00 }, // 7 : 
  234. // | |
  235. // | |
  236. // | *** |
  237. // | ***** |
  238. // | ***** |
  239. // | ***** |
  240. // | *** |
  241. // | |
  242.  
  243. { 0xFF, 0xFF, 0xE3, 0xC1, 0xC1, 0xC1, 0xE3, 0xFF }, // 8 : 
  244. // | ******** |
  245. // | ******** |
  246. // | *** ** |
  247. // | ** * |
  248. // | ** * |
  249. // | ** * |
  250. // | *** ** |
  251. // | ******** |
  252.  
  253. { 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00 }, // 9 :
  254. // | |
  255. // | |
  256. // | *** |
  257. // | * * |
  258. // | * * |
  259. // | * * |
  260. // | *** |
  261. // | |
  262.  
  263. { 0xFF, 0xFF, 0xE3, 0xDD, 0xDD, 0xDD, 0xE3, 0xFF }, // 10 :
  264.  
  265. // | ******** |
  266. // | ******** |
  267. // | *** ** |
  268. // | ** *** * |
  269. // | ** *** * |
  270. // | ** *** * |
  271. // | *** ** |
  272. // | ******** |
  273.  
  274. { 0x00, 0x0F, 0x03, 0x05, 0x39, 0x48, 0x48, 0x30 }, // 11 :
  275. // | |
  276. // | **** |
  277. // | ** |
  278. // | * * |
  279. // | *** * |
  280. // | * * |
  281. // | * * |
  282. // | ** |
  283.  
  284. { 0x00, 0x08, 0x3E, 0x08, 0x1C, 0x22, 0x22, 0x1C }, // 12 :
  285. // | |
  286. // | * |
  287. // | ***** |
  288. // | * |
  289. // | *** |
  290. // | * * |
  291. // | * * |
  292. // | *** |
  293.  
  294. { 0x00, 0x18, 0x14, 0x10, 0x10, 0x30, 0x70, 0x60 }, // 13 :
  295.  
  296. // | |
  297. // | ** |
  298. // | * * |
  299. // | * |
  300. // | * |
  301. // | ** |
  302. // | *** |
  303. // | ** |
  304.  
  305. { 0x00, 0x0F, 0x19, 0x11, 0x13, 0x37, 0x76, 0x60 }, // 14 : 
  306. // | |
  307. // | **** |
  308. // | ** * |
  309. // | * * |
  310. // | * ** |
  311. // | ** *** |
  312. // | *** ** |
  313. // | ** |
  314.  
  315. { 0x00, 0x08, 0x2A, 0x1C, 0x77, 0x1C, 0x2A, 0x08 }, // 15 : 
  316. // | |
  317. // | * |
  318. // | * * * |
  319. // | *** |
  320. // | *** *** |
  321. // | *** |
  322. // | * * * |
  323. // | * |
  324.  
  325. { 0x00, 0x60, 0x78, 0x7E, 0x7F, 0x7E, 0x78, 0x60 }, // 16 : 
  326. // | |
  327. // | ** |
  328. // | **** |
  329. // | ****** |
  330. // | ******* |
  331. // | ****** |
  332. // | **** |
  333. // | ** |
  334.  
  335. { 0x00, 0x03, 0x0F, 0x3F, 0x7F, 0x3F, 0x0F, 0x03 }, // 17 : 
  336. // | |
  337. // | ** |
  338. // | **** |
  339. // | ****** |
  340. // | ******* |
  341. // | ****** |
  342. // | **** |
  343. // | ** |
  344.  
  345. { 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x2A, 0x1C, 0x08 }, // 18 : 
  346. // | |
  347. // | * |
  348. // | *** |
  349. // | * * * |
  350. // | * |
  351. // | * * * |
  352. // | *** |
  353. // | * |
  354.  
  355. { 0x00, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x66 }, // 19 : 
  356. // | |
  357. // | ** ** |
  358. // | ** ** |
  359. // | ** ** |
  360. // | ** ** |
  361. // | |
  362. // | ** ** |
  363. // | ** ** |
  364.  
  365. { 0x00, 0x3F, 0x65, 0x65, 0x3D, 0x05, 0x05, 0x05 }, // 20 : 
  366. // | |
  367. // | ****** |
  368. // | ** * * |
  369. // | ** * * |
  370. // | **** * |
  371. // | * * |
  372. // | * * |
  373. // | * * |
  374.  
  375. { 0x00, 0x0C, 0x32, 0x48, 0x24, 0x12, 0x4C, 0x30 }, // 21 : 
  376. // | |
  377. // | ** |
  378. // | ** * |
  379. // | * * |
  380. // | * * |
  381. // | * * |
  382. // | * ** |
  383. // | ** |
  384.  
  385. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x7F }, // 22 : 
  386. // | |
  387. // | |
  388. // | |
  389. // | |
  390. // | |
  391. // | ******* |
  392. // | ******* |
  393. // | ******* |
  394.  
  395. { 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x2A, 0x1C, 0x3E }, // 23 : 
  396. // | |
  397. // | * |
  398. // | *** |
  399. // | * * * |
  400. // | * |
  401. // | * * * |
  402. // | *** |
  403. // | ***** |
  404.  
  405. { 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x1C, 0x1C, 0x1C }, // 24 : 
  406. // | |
  407. // | * |
  408. // | *** |
  409. // | ***** |
  410. // | ******* |
  411. // | *** |
  412. // | *** |
  413. // | *** |
  414.  
  415. { 0x00, 0x1C, 0x1C, 0x1C, 0x7F, 0x3E, 0x1C, 0x08 }, // 25 : 
  416. // | |
  417. // | *** |
  418. // | *** |
  419. // | *** |
  420. // | ******* |
  421. // | ***** |
  422. // | *** |
  423. // | * |
  424.  
  425. { 0x00, 0x08, 0x0C, 0x7E, 0x7F, 0x7E, 0x0C, 0x08 }, // 26 : 
  426. // | |
  427. // | * |
  428. // | ** |
  429. // | ****** |
  430. // | ******* |
  431. // | ****** |
  432. // | ** |
  433. // | * |
  434.  
  435. { 0x00, 0x08, 0x18, 0x3F, 0x7F, 0x3F, 0x18, 0x08 }, // 27 : 
  436. // | |
  437. // | * |
  438. // | ** |
  439. // | ****** |
  440. // | ******* |
  441. // | ****** |
  442. // | ** |
  443. // | * |
  444.  
  445. { 0x00, 0x00, 0x00, 0x70, 0x70, 0x70, 0x7F, 0x7F }, // 28 : 
  446. // | |
  447. // | |
  448. // | |
  449. // | *** |
  450. // | *** |
  451. // | *** |
  452. // | ******* |
  453. // | ******* |
  454.  
  455. { 0x00, 0x00, 0x14, 0x22, 0x7F, 0x22, 0x14, 0x00 }, // 29 : 
  456. // | |
  457. // | |
  458. // | * * |
  459. // | * * |
  460. // | ******* |
  461. // | * * |
  462. // | * * |
  463. // | |
  464.  
  465. { 0x00, 0x08, 0x1C, 0x1C, 0x3E, 0x3E, 0x7F, 0x7F }, // 30 : 
  466. // | |
  467. // | * |
  468. // | *** |
  469. // | *** |
  470. // | ***** |
  471. // | ***** |
  472. // | ******* |
  473. // | ******* |
  474.  
  475. { 0x00, 0x7F, 0x7F, 0x3E, 0x3E, 0x1C, 0x1C, 0x08 }, // 31 : 
  476. // | |
  477. // | ******* |
  478. // | ******* |
  479. // | ***** |
  480. // | ***** |
  481. // | *** |
  482. // | *** |
  483. // | * |
  484.  
  485. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 32 :
  486. // | |
  487. // | |
  488. // | |
  489. // | |
  490. // | |
  491. // | |
  492. // | |
  493. // | |
  494.  
  495. { 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18 }, // 33 : !
  496. // | |
  497. // | ** |
  498. // | ** |
  499. // | ** |
  500. // | ** |
  501. // | ** |
  502. // | |
  503. // | ** |
  504.  
  505. { 0x00, 0x36, 0x36, 0x14, 0x00, 0x00, 0x00, 0x00 }, // 34 : "
  506. // | |
  507. // | ** ** |
  508. // | ** ** |
  509. // | * * |
  510. // | |
  511. // | |
  512. // | |
  513. // | |
  514.  
  515. { 0x00, 0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36 }, // 35 : #
  516. // | |
  517. // | ** ** |
  518. // | ** ** |
  519. // | ******* |
  520. // | ** ** |
  521. // | ******* |
  522. // | ** ** |
  523. // | ** ** |
  524.  
  525. { 0x00, 0x08, 0x1E, 0x20, 0x1C, 0x02, 0x3C, 0x08 }, // 36 : $
  526. // | |
  527. // | * |
  528. // | **** |
  529. // | * |
  530. // | *** |
  531. // | * |
  532. // | **** |
  533. // | * |
  534.  
  535. { 0x00, 0x60, 0x66, 0x0C, 0x18, 0x30, 0x66, 0x06 }, // 37 : %
  536. // | |
  537. // | ** |
  538. // | ** ** |
  539. // | ** |
  540. // | ** |
  541. // | ** |
  542. // | ** ** |
  543. // | ** |
  544.  
  545. { 0x00, 0x3C, 0x66, 0x3C, 0x28, 0x65, 0x66, 0x3F }, // 38 : &
  546. // | |
  547. // | **** |
  548. // | ** ** |
  549. // | **** |
  550. // | * * |
  551. // | ** * * |
  552. // | ** ** |
  553. // | ****** |
  554.  
  555. { 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00 }, // 39 : '
  556. // | |
  557. // | ** |
  558. // | ** |
  559. // | ** |
  560. // | ** |
  561. // | |
  562. // | |
  563. // | |
  564.  
  565. { 0x00, 0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60 }, // 40 : (
  566. // | |
  567. // | ** |
  568. // | ** |
  569. // | ** |
  570. // | ** |
  571. // | ** |
  572. // | ** |
  573. // | ** |
  574.  
  575. { 0x00, 0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06 }, // 41 : )
  576. // | |
  577. // | ** |
  578. // | ** |
  579. // | ** |
  580. // | ** |
  581. // | ** |
  582. // | ** |
  583. // | ** |
  584.  
  585. { 0x00, 0x00, 0x36, 0x1C, 0x7F, 0x1C, 0x36, 0x00 }, // 42 : *
  586. // | |
  587. // | |
  588. // | ** ** |
  589. // | *** |
  590. // | ******* |
  591. // | *** |
  592. // | ** ** |
  593. // | |
  594.  
  595. { 0x00, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00 }, // 43 : +
  596. // | |
  597. // | |
  598. // | * |
  599. // | * |
  600. // | ***** |
  601. // | * |
  602. // | * |
  603. // | |
  604.  
  605. { 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x60 }, // 44 : ,
  606. // | |
  607. // | |
  608. // | |
  609. // | |
  610. // | ** |
  611. // | ** |
  612. // | ** |
  613. // | ** |
  614.  
  615. { 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00 }, // 45 : -
  616. // | |
  617. // | |
  618. // | |
  619. // | |
  620. // | **** |
  621. // | |
  622. // | |
  623. // | |
  624.  
  625. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60 }, // 46 : .
  626. // | |
  627. // | |
  628. // | |
  629. // | |
  630. // | |
  631. // | |
  632. // | ** |
  633. // | ** |
  634.  
  635. { 0x00, 0x00, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x00 }, // 47 : /
  636. // | |
  637. // | |
  638. // | ** |
  639. // | ** |
  640. // | ** |
  641. // | ** |
  642. // | ** |
  643. // | |
  644.  
  645. { 0x00, 0x3C, 0x66, 0x6E, 0x76, 0x66, 0x66, 0x3C }, // 48 : 0
  646. // | |
  647. // | **** |
  648. // | ** ** |
  649. // | ** *** |
  650. // | *** ** |
  651. // | ** ** |
  652. // | ** ** |
  653. // | **** |
  654.  
  655. { 0x00, 0x18, 0x18, 0x38, 0x18, 0x18, 0x18, 0x7E }, // 49 : 1
  656. // | |
  657. // | ** |
  658. // | ** |
  659. // | *** |
  660. // | ** |
  661. // | ** |
  662. // | ** |
  663. // | ****** |
  664.  
  665. { 0x00, 0x3C, 0x66, 0x06, 0x0C, 0x30, 0x60, 0x7E }, // 50 : 2
  666. // | |
  667. // | **** |
  668. // | ** ** |
  669. // | ** |
  670. // | ** |
  671. // | ** |
  672. // | ** |
  673. // | ****** |
  674.  
  675. { 0x00, 0x3C, 0x66, 0x06, 0x1C, 0x06, 0x66, 0x3C }, // 51 : 3
  676. // | |
  677. // | **** |
  678. // | ** ** |
  679. // | ** |
  680. // | *** |
  681. // | ** |
  682. // | ** ** |
  683. // | **** |
  684.  
  685. { 0x00, 0x0C, 0x1C, 0x2C, 0x4C, 0x7E, 0x0C, 0x0C }, // 52 : 4
  686. // | |
  687. // | ** |
  688. // | *** |
  689. // | * ** |
  690. // | * ** |
  691. // | ****** |
  692. // | ** |
  693. // | ** |
  694.  
  695. { 0x00, 0x7E, 0x60, 0x7C, 0x06, 0x06, 0x66, 0x3C }, // 53 : 5
  696. // | |
  697. // | ****** |
  698. // | ** |
  699. // | ***** |
  700. // | ** |
  701. // | ** |
  702. // | ** ** |
  703. // | **** |
  704.  
  705. { 0x00, 0x3C, 0x66, 0x60, 0x7C, 0x66, 0x66, 0x3C }, // 54 : 6
  706. // | |
  707. // | **** |
  708. // | ** ** |
  709. // | ** |
  710. // | ***** |
  711. // | ** ** |
  712. // | ** ** |
  713. // | **** |
  714.  
  715. { 0x00, 0x7E, 0x66, 0x0C, 0x0C, 0x18, 0x18, 0x18 }, // 55 : 7
  716. // | |
  717. // | ****** |
  718. // | ** ** |
  719. // | ** |
  720. // | ** |
  721. // | ** |
  722. // | ** |
  723. // | ** |
  724.  
  725. { 0x00, 0x3C, 0x66, 0x66, 0x3C, 0x66, 0x66, 0x3C }, // 56 : 8
  726. // | |
  727. // | **** |
  728. // | ** ** |
  729. // | ** ** |
  730. // | **** |
  731. // | ** ** |
  732. // | ** ** |
  733. // | **** |
  734.  
  735. { 0x00, 0x3C, 0x66, 0x66, 0x3E, 0x06, 0x66, 0x3C }, // 57 : 9
  736. // | |
  737. // | **** |
  738. // | ** ** |
  739. // | ** ** |
  740. // | ***** |
  741. // | ** |
  742. // | ** ** |
  743. // | **** |
  744.  
  745. { 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00 }, // 58 : :
  746. // | |
  747. // | |
  748. // | ** |
  749. // | ** |
  750. // | |
  751. // | ** |
  752. // | ** |
  753. // | |
  754.  
  755. { 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x30 }, // 59 : ;
  756. // | |
  757. // | |
  758. // | ** |
  759. // | ** |
  760. // | |
  761. // | ** |
  762. // | ** |
  763. // | ** |
  764.  
  765. { 0x00, 0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06 }, // 60 : <
  766. // | |
  767. // | ** |
  768. // | ** |
  769. // | ** |
  770. // | ** |
  771. // | ** |
  772. // | ** |
  773. // | ** |
  774.  
  775. { 0x00, 0x00, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x00 }, // 61 : =
  776. // | |
  777. // | |
  778. // | |
  779. // | **** |
  780. // | |
  781. // | **** |
  782. // | |
  783. // | |
  784.  
  785. { 0x00, 0x60, 0x30, 0x18, 0x0C, 0x18, 0x30, 0x60 }, // 62 : >
  786. // | |
  787. // | ** |
  788. // | ** |
  789. // | ** |
  790. // | ** |
  791. // | ** |
  792. // | ** |
  793. // | ** |
  794.  
  795. { 0x00, 0x3C, 0x66, 0x06, 0x1C, 0x18, 0x00, 0x18 }, // 63 : ?
  796. // | |
  797. // | **** |
  798. // | ** ** |
  799. // | ** |
  800. // | *** |
  801. // | ** |
  802. // | |
  803. // | ** |
  804.  
  805. { 0x00, 0x38, 0x44, 0x5C, 0x58, 0x42, 0x3C, 0x00 }, // 64 : @
  806. // | |
  807. // | *** |
  808. // | * * |
  809. // | * *** |
  810. // | * ** |
  811. // | * * |
  812. // | **** |
  813. // | |
  814.  
  815. { 0x00, 0x3C, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66 }, // 65 : A
  816. // | |
  817. // | **** |
  818. // | ** ** |
  819. // | ** ** |
  820. // | ****** |
  821. // | ** ** |
  822. // | ** ** |
  823. // | ** ** |
  824.  
  825. { 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x66, 0x66, 0x7C }, // 66 : B
  826. // | |
  827. // | ***** |
  828. // | ** ** |
  829. // | ** ** |
  830. // | ***** |
  831. // | ** ** |
  832. // | ** ** |
  833. // | ***** |
  834.  
  835. { 0x00, 0x3C, 0x66, 0x60, 0x60, 0x60, 0x66, 0x3C }, // 67 : C
  836. // | |
  837. // | **** |
  838. // | ** ** |
  839. // | ** |
  840. // | ** |
  841. // | ** |
  842. // | ** ** |
  843. // | **** |
  844.  
  845. { 0x00, 0x7C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7C }, // 68 : D
  846. // | |
  847. // | ***** |
  848. // | ** ** |
  849. // | ** ** |
  850. // | ** ** |
  851. // | ** ** |
  852. // | ** ** |
  853. // | ***** |
  854.  
  855. { 0x00, 0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x7E }, // 69 : E
  856. // | |
  857. // | ****** |
  858. // | ** |
  859. // | ** |
  860. // | ***** |
  861. // | ** |
  862. // | ** |
  863. // | ****** |
  864.  
  865. { 0x00, 0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x60 }, // 70 : F
  866. // | |
  867. // | ****** |
  868. // | ** |
  869. // | ** |
  870. // | ***** |
  871. // | ** |
  872. // | ** |
  873. // | ** |
  874.  
  875. { 0x00, 0x3C, 0x66, 0x60, 0x60, 0x6E, 0x66, 0x3C }, // 71 : G
  876. // | |
  877. // | **** |
  878. // | ** ** |
  879. // | ** |
  880. // | ** |
  881. // | ** *** |
  882. // | ** ** |
  883. // | **** |
  884.  
  885. { 0x00, 0x66, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66 }, // 72 : H
  886. // | |
  887. // | ** ** |
  888. // | ** ** |
  889. // | ** ** |
  890. // | ****** |
  891. // | ** ** |
  892. // | ** ** |
  893. // | ** ** |
  894.  
  895. { 0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C }, // 73 : I
  896. // | |
  897. // | **** |
  898. // | ** |
  899. // | ** |
  900. // | ** |
  901. // | ** |
  902. // | ** |
  903. // | **** |
  904.  
  905. { 0x00, 0x1E, 0x0C, 0x0C, 0x0C, 0x6C, 0x6C, 0x38 }, // 74 : J
  906. // | |
  907. // | **** |
  908. // | ** |
  909. // | ** |
  910. // | ** |
  911. // | ** ** |
  912. // | ** ** |
  913. // | *** |
  914.  
  915. { 0x00, 0x66, 0x6C, 0x78, 0x70, 0x78, 0x6C, 0x66 }, // 75 : K
  916. // | |
  917. // | ** ** |
  918. // | ** ** |
  919. // | **** |
  920. // | *** |
  921. // | **** |
  922. // | ** ** |
  923. // | ** ** |
  924.  
  925. { 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x7E }, // 76 : L
  926. // | |
  927. // | ** |
  928. // | ** |
  929. // | ** |
  930. // | ** |
  931. // | ** |
  932. // | ** |
  933. // | ****** |
  934.  
  935. { 0x00, 0x63, 0x77, 0x7F, 0x6B, 0x63, 0x63, 0x63 }, // 77 : M
  936. // | |
  937. // | ** ** |
  938. // | *** *** |
  939. // | ******* |
  940. // | ** * ** |
  941. // | ** ** |
  942. // | ** ** |
  943. // | ** ** |
  944.  
  945. { 0x00, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x63, 0x63 }, // 78 : N
  946. // | |
  947. // | ** ** |
  948. // | *** ** |
  949. // | **** ** |
  950. // | ** **** |
  951. // | ** *** |
  952. // | ** ** |
  953. // | ** ** |
  954.  
  955. { 0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C }, // 79 : O
  956. // | |
  957. // | **** |
  958. // | ** ** |
  959. // | ** ** |
  960. // | ** ** |
  961. // | ** ** |
  962. // | ** ** |
  963. // | **** |
  964.  
  965. { 0x00, 0x7C, 0x66, 0x66, 0x66, 0x7C, 0x60, 0x60 }, // 80 : P
  966. // | |
  967. // | ***** |
  968. // | ** ** |
  969. // | ** ** |
  970. // | ** ** |
  971. // | ***** |
  972. // | ** |
  973. // | ** |
  974.  
  975. { 0x00, 0x3C, 0x66, 0x66, 0x66, 0x6E, 0x3C, 0x06 }, // 81 : Q
  976. // | |
  977. // | **** |
  978. // | ** ** |
  979. // | ** ** |
  980. // | ** ** |
  981. // | ** *** |
  982. // | **** |
  983. // | ** |
  984.  
  985. { 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x78, 0x6C, 0x66 }, // 82 : R
  986. // | |
  987. // | ***** |
  988. // | ** ** |
  989. // | ** ** |
  990. // | ***** |
  991. // | **** |
  992. // | ** ** |
  993. // | ** ** |
  994.  
  995. { 0x00, 0x3C, 0x66, 0x60, 0x3C, 0x06, 0x66, 0x3C }, // 83 : S
  996. // | |
  997. // | **** |
  998. // | ** ** |
  999. // | ** |
  1000. // | **** |
  1001. // | ** |
  1002. // | ** ** |
  1003. // | **** |
  1004.  
  1005. { 0x00, 0x7E, 0x5A, 0x18, 0x18, 0x18, 0x18, 0x18 }, // 84 : T
  1006. // | |
  1007. // | ****** |
  1008. // | * ** * |
  1009. // | ** |
  1010. // | ** |
  1011. // | ** |
  1012. // | ** |
  1013. // | ** |
  1014.  
  1015. { 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3E }, // 85 : U
  1016. // | |
  1017. // | ** ** |
  1018. // | ** ** |
  1019. // | ** ** |
  1020. // | ** ** |
  1021. // | ** ** |
  1022. // | ** ** |
  1023. // | ***** |
  1024.  
  1025. { 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18 }, // 86 : V
  1026. // | |
  1027. // | ** ** |
  1028. // | ** ** |
  1029. // | ** ** |
  1030. // | ** ** |
  1031. // | ** ** |
  1032. // | **** |
  1033. // | ** |
  1034.  
  1035. { 0x00, 0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63 }, // 87 : W
  1036. // | |
  1037. // | ** ** |
  1038. // | ** ** |
  1039. // | ** ** |
  1040. // | ** * ** |
  1041. // | ******* |
  1042. // | *** *** |
  1043. // | ** ** |
  1044.  
  1045. { 0x00, 0x63, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x63 }, // 88 : X
  1046. // | |
  1047. // | ** ** |
  1048. // | ** ** |
  1049. // | ** ** |
  1050. // | *** |
  1051. // | ** ** |
  1052. // | ** ** |
  1053. // | ** ** |
  1054.  
  1055. { 0x00, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x18 }, // 89 : Y
  1056. // | |
  1057. // | ** ** |
  1058. // | ** ** |
  1059. // | ** ** |
  1060. // | **** |
  1061. // | ** |
  1062. // | ** |
  1063. // | ** |
  1064.  
  1065. { 0x00, 0x7E, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x7E }, // 90 : Z
  1066. // | |
  1067. // | ****** |
  1068. // | ** |
  1069. // | ** |
  1070. // | ** |
  1071. // | ** |
  1072. // | ** |
  1073. // | ****** |
  1074.  
  1075. { 0x00, 0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E }, // 91 : [
  1076. // | |
  1077. // | **** |
  1078. // | ** |
  1079. // | ** |
  1080. // | ** |
  1081. // | ** |
  1082. // | ** |
  1083. // | **** |
  1084.  
  1085. { 0x00, 0x00, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x00 }, // 92 : \
  1086. // | |
  1087. // | |
  1088. // | ** |
  1089. // | ** |
  1090. // | ** |
  1091. // | ** |
  1092. // | ** |
  1093. // | |
  1094.  
  1095. { 0x00, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78 }, // 93 : ]
  1096. // | |
  1097. // | **** |
  1098. // | ** |
  1099. // | ** |
  1100. // | ** |
  1101. // | ** |
  1102. // | ** |
  1103. // | **** |
  1104.  
  1105. { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00, 0x00 }, // 94 : ^
  1106. // | |
  1107. // | * |
  1108. // | * * |
  1109. // | * * |
  1110. // | * * |
  1111. // | |
  1112. // | |
  1113. // | |
  1114.  
  1115. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F }, // 95 : _
  1116. // | |
  1117. // | |
  1118. // | |
  1119. // | |
  1120. // | |
  1121. // | |
  1122. // | |
  1123. // | ******* |
  1124.  
  1125. { 0x00, 0x0C, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00 }, // 96 : `
  1126. // | |
  1127. // | ** |
  1128. // | ** |
  1129. // | ** |
  1130. // | |
  1131. // | |
  1132. // | |
  1133. // | |
  1134.  
  1135. { 0x00, 0x00, 0x00, 0x3C, 0x06, 0x3E, 0x66, 0x3E }, // 97 : a
  1136. // | |
  1137. // | |
  1138. // | |
  1139. // | **** |
  1140. // | ** |
  1141. // | ***** |
  1142. // | ** ** |
  1143. // | ***** |
  1144.  
  1145. { 0x00, 0x60, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x7C }, // 98 : b
  1146. // | |
  1147. // | ** |
  1148. // | ** |
  1149. // | ** |
  1150. // | ***** |
  1151. // | ** ** |
  1152. // | ** ** |
  1153. // | ***** |
  1154.  
  1155. { 0x00, 0x00, 0x00, 0x3C, 0x66, 0x60, 0x66, 0x3C }, // 99 : c
  1156. // | |
  1157. // | |
  1158. // | |
  1159. // | **** |
  1160. // | ** ** |
  1161. // | ** |
  1162. // | ** ** |
  1163. // | **** |
  1164.  
  1165. { 0x00, 0x06, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3E }, // 100 : d
  1166. // | |
  1167. // | ** |
  1168. // | ** |
  1169. // | ** |
  1170. // | ***** |
  1171. // | ** ** |
  1172. // | ** ** |
  1173. // | ***** |
  1174.  
  1175. { 0x00, 0x00, 0x00, 0x3C, 0x66, 0x7E, 0x60, 0x3C }, // 101 : e
  1176. // | |
  1177. // | |
  1178. // | |
  1179. // | **** |
  1180. // | ** ** |
  1181. // | ****** |
  1182. // | ** |
  1183. // | **** |
  1184.  
  1185. { 0x00, 0x1C, 0x36, 0x30, 0x30, 0x7C, 0x30, 0x30 }, // 102 : f
  1186. // | |
  1187. // | *** |
  1188. // | ** ** |
  1189. // | ** |
  1190. // | ** |
  1191. // | ***** |
  1192. // | ** |
  1193. // | ** |
  1194.  
  1195. { 0x00, 0x00, 0x3E, 0x66, 0x66, 0x3E, 0x06, 0x3C }, // 103 : g
  1196. // | |
  1197. // | |
  1198. // | ***** |
  1199. // | ** ** |
  1200. // | ** ** |
  1201. // | ***** |
  1202. // | ** |
  1203. // | **** |
  1204.  
  1205. { 0x00, 0x60, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x66 }, // 104 : h
  1206. // | |
  1207. // | ** |
  1208. // | ** |
  1209. // | ** |
  1210. // | ***** |
  1211. // | ** ** |
  1212. // | ** ** |
  1213. // | ** ** |
  1214.  
  1215. { 0x00, 0x00, 0x18, 0x00, 0x18, 0x18, 0x18, 0x3C }, // 105 : i
  1216. // | |
  1217. // | |
  1218. // | ** |
  1219. // | |
  1220. // | ** |
  1221. // | ** |
  1222. // | ** |
  1223. // | **** |
  1224.  
  1225. { 0x00, 0x0C, 0x00, 0x0C, 0x0C, 0x6C, 0x6C, 0x38 }, // 106 : j
  1226. // | |
  1227. // | ** |
  1228. // | |
  1229. // | ** |
  1230. // | ** |
  1231. // | ** ** |
  1232. // | ** ** |
  1233. // | *** |
  1234.  
  1235. { 0x00, 0x60, 0x60, 0x66, 0x6C, 0x78, 0x6C, 0x66 }, // 107 : k
  1236. // | |
  1237. // | ** |
  1238. // | ** |
  1239. // | ** ** |
  1240. // | ** ** |
  1241. // | **** |
  1242. // | ** ** |
  1243. // | ** ** |
  1244.  
  1245. { 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 }, // 108 : l
  1246. // | |
  1247. // | ** |
  1248. // | ** |
  1249. // | ** |
  1250. // | ** |
  1251. // | ** |
  1252. // | ** |
  1253. // | ** |
  1254.  
  1255. { 0x00, 0x00, 0x00, 0x63, 0x77, 0x7F, 0x6B, 0x6B }, // 109 : m
  1256. // | |
  1257. // | |
  1258. // | |
  1259. // | ** ** |
  1260. // | *** *** |
  1261. // | ******* |
  1262. // | ** * ** |
  1263. // | ** * ** |
  1264.  
  1265. { 0x00, 0x00, 0x00, 0x7C, 0x7E, 0x66, 0x66, 0x66 }, // 110 : n
  1266. // | |
  1267. // | |
  1268. // | |
  1269. // | ***** |
  1270. // | ****** |
  1271. // | ** ** |
  1272. // | ** ** |
  1273. // | ** ** |
  1274.  
  1275. { 0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C }, // 111 : o
  1276. // | |
  1277. // | |
  1278. // | |
  1279. // | **** |
  1280. // | ** ** |
  1281. // | ** ** |
  1282. // | ** ** |
  1283. // | **** |
  1284.  
  1285. { 0x00, 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0x60 }, // 112 : p
  1286. // | |
  1287. // | |
  1288. // | ***** |
  1289. // | ** ** |
  1290. // | ** ** |
  1291. // | ***** |
  1292. // | ** |
  1293. // | ** |
  1294.  
  1295. { 0x00, 0x00, 0x3C, 0x6C, 0x6C, 0x3C, 0x0D, 0x0F }, // 113 : q
  1296. // | |
  1297. // | |
  1298. // | **** |
  1299. // | ** ** |
  1300. // | ** ** |
  1301. // | **** |
  1302. // | ** * |
  1303. // | **** |
  1304.  
  1305. { 0x00, 0x00, 0x00, 0x7C, 0x66, 0x66, 0x60, 0x60 }, // 114 : r
  1306. // | |
  1307. // | |
  1308. // | |
  1309. // | ***** |
  1310. // | ** ** |
  1311. // | ** ** |
  1312. // | ** |
  1313. // | ** |
  1314.  
  1315. { 0x00, 0x00, 0x00, 0x3E, 0x40, 0x3C, 0x02, 0x7C }, // 115 : s
  1316. // | |
  1317. // | |
  1318. // | |
  1319. // | ***** |
  1320. // | * |
  1321. // | **** |
  1322. // | * |
  1323. // | ***** |
  1324.  
  1325. { 0x00, 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x18 }, // 116 : t
  1326. // | |
  1327. // | |
  1328. // | ** |
  1329. // | ** |
  1330. // | ****** |
  1331. // | ** |
  1332. // | ** |
  1333. // | ** |
  1334.  
  1335. { 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3E }, // 117 : u
  1336. // | |
  1337. // | |
  1338. // | |
  1339. // | ** ** |
  1340. // | ** ** |
  1341. // | ** ** |
  1342. // | ** ** |
  1343. // | ***** |
  1344.  
  1345. { 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x3C, 0x18 }, // 118 : v
  1346. // | |
  1347. // | |
  1348. // | |
  1349. // | |
  1350. // | ** ** |
  1351. // | ** ** |
  1352. // | **** |
  1353. // | ** |
  1354.  
  1355. { 0x00, 0x00, 0x00, 0x63, 0x6B, 0x6B, 0x6B, 0x3E }, // 119 : w
  1356. // | |
  1357. // | |
  1358. // | |
  1359. // | ** ** |
  1360. // | ** * ** |
  1361. // | ** * ** |
  1362. // | ** * ** |
  1363. // | ***** |
  1364.  
  1365. { 0x00, 0x00, 0x00, 0x66, 0x3C, 0x18, 0x3C, 0x66 }, // 120 : x
  1366. // | |
  1367. // | |
  1368. // | |
  1369. // | ** ** |
  1370. // | **** |
  1371. // | ** |
  1372. // | **** |
  1373. // | ** ** |
  1374.  
  1375. { 0x00, 0x00, 0x00, 0x66, 0x66, 0x3E, 0x06, 0x3C }, // 121 : y
  1376. // | |
  1377. // | |
  1378. // | |
  1379. // | ** ** |
  1380. // | ** ** |
  1381. // | ***** |
  1382. // | ** |
  1383. // | **** |
  1384.  
  1385. { 0x00, 0x00, 0x00, 0x3C, 0x0C, 0x18, 0x30, 0x3C }, // 122 : z
  1386. // | |
  1387. // | |
  1388. // | |
  1389. // | **** |
  1390. // | ** |
  1391. // | ** |
  1392. // | ** |
  1393. // | **** |
  1394.  
  1395. { 0x00, 0x0E, 0x18, 0x18, 0x30, 0x18, 0x18, 0x0E }, // 123 : {
  1396. // | |
  1397. // | *** |
  1398. // | ** |
  1399. // | ** |
  1400. // | ** |
  1401. // | ** |
  1402. // | ** |
  1403. // | *** |
  1404.  
  1405. { 0x00, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18 }, // 124 : |
  1406. // | |
  1407. // | ** |
  1408. // | ** |
  1409. // | ** |
  1410. // | |
  1411. // | ** |
  1412. // | ** |
  1413. // | ** |
  1414.  
  1415. { 0x00, 0x70, 0x18, 0x18, 0x0C, 0x18, 0x18, 0x70 }, // 125 : }
  1416. // | |
  1417. // | *** |
  1418. // | ** |
  1419. // | ** |
  1420. // | ** |
  1421. // | ** |
  1422. // | ** |
  1423. // | *** |
  1424.  
  1425. { 0x00, 0x00, 0x00, 0x3A, 0x6C, 0x00, 0x00, 0x00 }, // 126 : ~
  1426. // | |
  1427. // | |
  1428. // | |
  1429. // | *** * |
  1430. // | ** ** |
  1431. // | |
  1432. // | |
  1433. // | |
  1434.  
  1435. { 0x00, 0x08, 0x1C, 0x36, 0x63, 0x41, 0x41, 0x7F } // 127 : 
  1436. // | |
  1437. // | * |
  1438. // | *** |
  1439. // | ** ** |
  1440. // | ** ** |
  1441. // | * * |
  1442. // | * * |
  1443. // | ******* |
  1444.  
  1445.  
  1446. };
  1447.  
  1448. // Define display string here
  1449. const int charNum = 28;
  1450. char string[charNum] = {'D','A','N','K','E','-','F','U','E','R','S','-','Z','U','S','C','H','A','U','E','N',};
  1451.  
  1452. void effect_text(int delayt){
  1453. fill(0x00);
  1454. for (int ltr = 0; ltr < charNum; ltr++){// For each letter in string array
  1455. for(int dist = 0; dist < 8; dist++) { //bring letter forward
  1456. fill(0x00);//blank last row
  1457. int rev = 0;
  1458. for (int rw = 7; rw >= 0; rw--) {//copy rows
  1459. cube[rev][dist] = bitswap(font_data[string[ltr]][rw]);
  1460. rev++;
  1461. }
  1462. delay_ms(delayt);
  1463. }
  1464. }
  1465. }
  1466.  
  1467. unsigned char bitswap (unsigned char x)//Reverses a byte (so letters aren't backwards);
  1468. { byte result;
  1469.  
  1470. asm("mov __tmp_reg__, %[in] \n\t"
  1471. "lsl __tmp_reg__ \n\t" /* shift out high bit to carry */
  1472. "ror %[out] \n\t" /* rotate carry __tmp_reg__to low bit (eventually) */
  1473. "lsl __tmp_reg__ \n\t" /* 2 */
  1474. "ror %[out] \n\t"
  1475. "lsl __tmp_reg__ \n\t" /* 3 */
  1476. "ror %[out] \n\t"
  1477. "lsl __tmp_reg__ \n\t" /* 4 */
  1478. "ror %[out] \n\t"
  1479.  
  1480. "lsl __tmp_reg__ \n\t" /* 5 */
  1481. "ror %[out] \n\t"
  1482. "lsl __tmp_reg__ \n\t" /* 6 */
  1483. "ror %[out] \n\t"
  1484. "lsl __tmp_reg__ \n\t" /* 7 */
  1485. "ror %[out] \n\t"
  1486. "lsl __tmp_reg__ \n\t" /* 8 */
  1487. "ror %[out] \n\t"
  1488. : [out] "=r" (result) : [in] "r" (x));
  1489. return(result);
  1490. }
  1491.  
  1492. // ==========================================================================================
  1493. // Effect functions
  1494. // ==========================================================================================
  1495. void effect_wormsqueeze (int size, int axis, int direction, int iterations, int delay)
  1496. {
  1497. int x, y, i,j,k, dx, dy;
  1498. int cube_size;
  1499. int origin = 0;
  1500.  
  1501. if (direction == -1)
  1502. origin = 7;
  1503.  
  1504. cube_size = 8-(size-1);
  1505.  
  1506. x = rand()%cube_size;
  1507. y = rand()%cube_size;
  1508.  
  1509. for (i=0; i<iterations; i++)
  1510. {
  1511. dx = ((rand()%3)-1);
  1512. dy = ((rand()%3)-1);
  1513.  
  1514. if ((x+dx) > 0 && (x+dx) < cube_size)
  1515. x += dx;
  1516.  
  1517. if ((y+dy) > 0 && (y+dy) < cube_size)
  1518. y += dy;
  1519.  
  1520. shift(axis, direction);
  1521.  
  1522.  
  1523. for (j=0; j<size;j++)
  1524. {
  1525. for (k=0; k<size;k++)
  1526. {
  1527. if (axis == AXIS_Z)
  1528. setvoxel(x+j,y+k,origin);
  1529.  
  1530. if (axis == AXIS_Y)
  1531. setvoxel(x+j,origin,y+k);
  1532.  
  1533. if (axis == AXIS_X)
  1534. setvoxel(origin,y+j,x+k);
  1535. }
  1536. }
  1537.  
  1538. delay_ms(delay);
  1539. }
  1540. }
  1541.  
  1542.  
  1543. volatile const unsigned char font[910] [5] = {
  1544. //volatile const unsigned char font[455] EEMEM = {
  1545. 0x00,0x00,0x00,0x00,0x00,0x00,0x5f,0x5f,0x00,0x00, // !
  1546. 0x00,0x03,0x00,0x03,0x00,0x14,0x7f,0x14,0x7f,0x14, // "#
  1547. 0x24,0x2a,0x7f,0x2a,0x12,0x23,0x13,0x08,0x64,0x62, // $%
  1548. 0x36,0x49,0x55,0x22,0x50,0x00,0x05,0x03,0x00,0x00, // &'
  1549. 0x00,0x1c,0x22,0x41,0x00,0x00,0x41,0x22,0x1c,0x00, // ()
  1550. 0x14,0x08,0x3e,0x08,0x14,0x08,0x08,0x3e,0x08,0x08, // *+
  1551. 0x00,0x50,0x30,0x00,0x00,0x08,0x08,0x08,0x08,0x08, // ,-
  1552. 0x00,0x60,0x60,0x00,0x00,0x20,0x10,0x08,0x04,0x02, // ./
  1553. 0x3e,0x51,0x49,0x45,0x3e,0x00,0x42,0x7f,0x40,0x00, // 01
  1554. 0x42,0x61,0x51,0x49,0x46,0x21,0x41,0x45,0x4b,0x31, // 23
  1555. 0x18,0x14,0x12,0x7f,0x10,0x27,0x45,0x45,0x45,0x39, // 45
  1556. 0x3c,0x4a,0x49,0x49,0x30,0x01,0x71,0x09,0x05,0x03, // 67
  1557. 0x36,0x49,0x49,0x49,0x36,0x06,0x49,0x49,0x29,0x1e, // 89
  1558. 0x00,0x36,0x36,0x00,0x00,0x00,0x56,0x36,0x00,0x00, // :;
  1559. 0x08,0x14,0x22,0x41,0x00,0x14,0x14,0x14,0x14,0x14, // <=
  1560. 0x00,0x41,0x22,0x14,0x08,0x02,0x01,0x51,0x09,0x06, // >?
  1561. 0x32,0x49,0x79,0x41,0x3e,0x7e,0x11,0x11,0x11,0x7e, // @A
  1562. 0x7f,0x49,0x49,0x49,0x36,0x3e,0x41,0x41,0x41,0x22, // BC
  1563. 0x7f,0x41,0x41,0x22,0x1c,0x7f,0x49,0x49,0x49,0x41, // DE
  1564. 0x7f,0x09,0x09,0x09,0x01,0x3e,0x41,0x49,0x49,0x7a, // FG
  1565. 0x7f,0x08,0x08,0x08,0x7f,0x00,0x41,0x7f,0x41,0x00, // HI
  1566. 0x20,0x40,0x41,0x3f,0x01,0x7f,0x08,0x14,0x22,0x41, // JK
  1567. 0x7f,0x40,0x40,0x40,0x40,0x7f,0x02,0x0c,0x02,0x7f, // LM
  1568. 0x7f,0x04,0x08,0x10,0x7f,0x3e,0x41,0x41,0x41,0x3e, // NO
  1569. 0x7f,0x09,0x09,0x09,0x06,0x3e,0x41,0x51,0x21,0x5e, // PQ
  1570. 0x7f,0x09,0x19,0x29,0x46,0x46,0x49,0x49,0x49,0x31, // RS
  1571. 0x01,0x01,0x7f,0x01,0x01,0x3f,0x40,0x40,0x40,0x3f, // TU
  1572. 0x1f,0x20,0x40,0x20,0x1f,0x3f,0x40,0x38,0x40,0x3f, // VW
  1573. 0x63,0x14,0x08,0x14,0x63,0x07,0x08,0x70,0x08,0x07, // XY
  1574. 0x61,0x51,0x49,0x45,0x43,0x00,0x7f,0x41,0x41,0x00, // Z[
  1575. 0x02,0x04,0x08,0x10,0x20,0x00,0x41,0x41,0x7f,0x00, // \]
  1576. 0x04,0x02,0x01,0x02,0x04,0x40,0x40,0x40,0x40,0x40, // ^_
  1577. 0x00,0x01,0x02,0x04,0x00,0x20,0x54,0x54,0x54,0x78, // `a
  1578. 0x7f,0x48,0x44,0x44,0x38,0x38,0x44,0x44,0x44,0x20, // bc
  1579. 0x38,0x44,0x44,0x48,0x7f,0x38,0x54,0x54,0x54,0x18, // de
  1580. 0x08,0x7e,0x09,0x01,0x02,0x0c,0x52,0x52,0x52,0x3e, // fg
  1581. 0x7f,0x08,0x04,0x04,0x78,0x00,0x44,0x7d,0x40,0x00, // hi
  1582. 0x20,0x40,0x44,0x3d,0x00,0x7f,0x10,0x28,0x44,0x00, // jk
  1583. 0x00,0x41,0x7f,0x40,0x00,0x7c,0x04,0x18,0x04,0x78, // lm
  1584. 0x7c,0x08,0x04,0x04,0x78,0x38,0x44,0x44,0x44,0x38, // no
  1585. 0x7c,0x14,0x14,0x14,0x08,0x08,0x14,0x14,0x18,0x7c, // pq
  1586. 0x7c,0x08,0x04,0x04,0x08,0x48,0x54,0x54,0x54,0x20, // rs
  1587. 0x04,0x3f,0x44,0x40,0x20,0x3c,0x40,0x40,0x20,0x7c, // tu
  1588. 0x1c,0x20,0x40,0x20,0x1c,0x3c,0x40,0x30,0x40,0x3c, // vw
  1589. 0x44,0x28,0x10,0x28,0x44,0x0c,0x50,0x50,0x50,0x3c, // xy
  1590. 0x44,0x64,0x54,0x4c,0x44 // z
  1591. };
  1592.  
  1593. volatile const unsigned char bitmaps[13][8] = {
  1594. // volatile const unsigned char bitmaps[13][8] EEMEM = {
  1595. {0xc3,0xc3,0x00,0x18,0x18,0x81,0xff,0x7e}, // smiley 3 small
  1596. {0x3c,0x42,0x81,0x81,0xc3,0x24,0xa5,0xe7}, // Omega
  1597. {0x00,0x04,0x06,0xff,0xff,0x06,0x04,0x00}, // Arrow
  1598. {0x81,0x42,0x24,0x18,0x18,0x24,0x42,0x81}, // X
  1599. {0xBD,0xA1,0xA1,0xB9,0xA1,0xA1,0xA1,0x00}, // ifi
  1600. {0xEF,0x48,0x4B,0x49,0x4F,0x00,0x00,0x00}, // TG
  1601. {0x38,0x7f,0xE6,0xC0,0xE6,0x7f,0x38,0x00}, // Commodore symbol
  1602. {0x00,0x22,0x77,0x7f,0x3e,0x3e,0x1c,0x08}, // Heart
  1603. {0x1C,0x22,0x55,0x49,0x5d,0x22,0x1c,0x00}, // face
  1604. {0x37,0x42,0x22,0x12,0x62,0x00,0x7f,0x00}, // ST
  1605. {0x89,0x4A,0x2c,0xF8,0x1F,0x34,0x52,0x91}, // STAR
  1606. {0x18,0x3c,0x7e,0xdb,0xff,0x24,0x5a,0xa5}, // Space Invader
  1607. {0x00,0x9c,0xa2,0xc5,0xc1,0xa2,0x9c,0x00} // Fish
  1608. };
  1609.  
  1610. const unsigned char paths[44] PROGMEM = {0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x67,0x57,0x47,0x37,0x27,0x17,
  1611. 0x04,0x03,0x12,0x21,0x30,0x40,0x51,0x62,0x73,0x74,0x65,0x56,0x47,0x37,0x26,0x15}; // circle, len 16, offset 28
  1612.  
  1613. void font_getpath (unsigned char path, unsigned char *destination, int length)
  1614. {
  1615. int i;
  1616. int offset = 0;
  1617.  
  1618. if (path == 1)
  1619. offset=28;
  1620.  
  1621. for (i = 0; i < length; i++)
  1622. destination[i] = pgm_read_byte(&paths[i+offset]);
  1623. }
  1624.  
  1625. void effect_pathmove (unsigned char *path, int length)
  1626. {
  1627. int i,z;
  1628. unsigned char state;
  1629.  
  1630. for (i=(length-1);i>=1;i--)
  1631. {
  1632. for (z=0;z<8;z++)
  1633. {
  1634.  
  1635. state = getvoxel(((path[(i-1)]>>4) & 0x0f), (path[(i-1)] & 0x0f), z);
  1636. altervoxel(((path[i]>>4) & 0x0f), (path[i] & 0x0f), z, state);
  1637. }
  1638. }
  1639. for (i=0;i<8;i++)
  1640. clrvoxel(((path[0]>>4) & 0x0f), (path[0] & 0x0f),i);
  1641. }
  1642.  
  1643. void effect_rand_patharound (int iterations, int delay)
  1644. {
  1645. int z, dz, i;
  1646. z = 4;
  1647. unsigned char path[28];
  1648.  
  1649. font_getpath(0,path,28);
  1650.  
  1651. for (i = 0; i < iterations; i++)
  1652. {
  1653. dz = ((rand()%3)-1);
  1654. z += dz;
  1655.  
  1656. if (z>7)
  1657. z = 7;
  1658.  
  1659. if (z<0)
  1660. z = 0;
  1661.  
  1662. effect_pathmove(path, 28);
  1663. setvoxel(0,7,z);
  1664. delay_ms(delay);
  1665. }
  1666. }
  1667.  
  1668.  
  1669. void effect_intro(){
  1670. int cnt,cnt_2,time;
  1671.  
  1672. //Bottom To Top
  1673.  
  1674. for(cnt=0;cnt<=7;cnt++){
  1675. box_wireframe(0, 0, 0, 7, 7, cnt);
  1676. delay_ms(2000);
  1677. }
  1678. for(cnt=0;cnt<7;cnt++){
  1679. clrplane_z(cnt);
  1680. delay_ms(2000);
  1681. }
  1682.  
  1683. //Shift Things Right
  1684. //1
  1685. shift(AXIS_Y,-1);
  1686. for(cnt=0;cnt<=7;cnt++){
  1687. setvoxel(cnt,0,6);
  1688. }
  1689. delay_ms(2000);
  1690. //2
  1691. shift(AXIS_Y,-1);
  1692. for(cnt=0;cnt<=7;cnt++){
  1693. setvoxel(cnt,0,5);
  1694. }
  1695. setvoxel(0,0,6);
  1696. setvoxel(7,0,6);
  1697. delay_ms(2000);
  1698. //3
  1699. shift(AXIS_Y,-1);
  1700. for(cnt=0;cnt<=7;cnt++){
  1701. setvoxel(cnt,0,4);
  1702. }
  1703. setvoxel(0,0,5);
  1704. setvoxel(7,0,5);
  1705. setvoxel(0,0,6);
  1706. setvoxel(7,0,6);
  1707. delay_ms(2000);
  1708.  
  1709. //4
  1710. shift(AXIS_Y,-1);
  1711. for(cnt=0;cnt<=7;cnt++){
  1712. setvoxel(cnt,0,3);
  1713. }
  1714. setvoxel(0,0,4);
  1715. setvoxel(7,0,4);
  1716. setvoxel(0,0,5);
  1717. setvoxel(7,0,5);
  1718. setvoxel(0,0,6);
  1719. setvoxel(7,0,6);
  1720. delay_ms(2000);
  1721.  
  1722. //5
  1723. shift(AXIS_Y,-1);
  1724. for(cnt=0;cnt<=7;cnt++){
  1725. setvoxel(cnt,0,2);
  1726. }
  1727. setvoxel(0,0,3);
  1728. setvoxel(7,0,3);
  1729. setvoxel(0,0,4);
  1730. setvoxel(7,0,4);
  1731. setvoxel(0,0,5);
  1732. setvoxel(7,0,5);
  1733. setvoxel(0,0,6);
  1734. setvoxel(7,0,6);
  1735. delay_ms(2000);
  1736.  
  1737. //6
  1738. shift(AXIS_Y,-1);
  1739. for(cnt=0;cnt<=7;cnt++){
  1740. setvoxel(cnt,0,1);
  1741. }
  1742. setvoxel(0,0,2);
  1743. setvoxel(7,0,2);
  1744. setvoxel(0,0,3);
  1745. setvoxel(7,0,3);
  1746. setvoxel(0,0,4);
  1747. setvoxel(7,0,4);
  1748. setvoxel(0,0,5);
  1749. setvoxel(7,0,5);
  1750. delay_ms(2000);
  1751.  
  1752.  
  1753. //7
  1754. shift(AXIS_Y,-1);
  1755. for(cnt=0;cnt<=7;cnt++){
  1756. setvoxel(cnt,0,0);
  1757. }
  1758. setvoxel(0,0,1);
  1759. setvoxel(7,0,1);
  1760. setvoxel(0,0,2);
  1761. setvoxel(7,0,2);
  1762. setvoxel(0,0,3);
  1763. setvoxel(7,0,3);
  1764. setvoxel(0,0,4);
  1765. setvoxel(7,0,4);
  1766. setvoxel(0,0,5);
  1767. setvoxel(7,0,5);
  1768. delay_ms(2000);
  1769.  
  1770. //Right To Left
  1771. for(cnt=0;cnt<=7;cnt++){
  1772. box_wireframe(0, 0, 0, 7, cnt, 7);
  1773. delay_ms(2000);
  1774. }
  1775. for(cnt=0;cnt<7;cnt++){
  1776. clrplane_y(cnt);
  1777. delay_ms(2000);
  1778. }
  1779.  
  1780. //Shift to the bottom
  1781. for(cnt_2=6;cnt_2>=0;cnt_2--){
  1782. shift(AXIS_Z,-1);
  1783. for(cnt=0;cnt<=7;cnt++){
  1784. setvoxel(cnt,cnt_2,0);
  1785. }
  1786. for(cnt=6;cnt>cnt_2;cnt--){
  1787. setvoxel(0,cnt,0);
  1788. setvoxel(7,cnt,0);
  1789. }
  1790.  
  1791. delay_ms(2000);
  1792. }
  1793.  
  1794. //Make All Wall Box
  1795.  
  1796. for(cnt=0;cnt<=6;cnt++){
  1797. fill(0x00);
  1798. box_walls(0,0,0,7,7,cnt);
  1799. delay_ms(2000);
  1800. }
  1801.  
  1802. time = 2000;
  1803. for(cnt_2=0;cnt_2<5;cnt_2++){
  1804. time = time - 300;
  1805. //Make Box Smaller
  1806. for(cnt=0;cnt<=3;cnt++){
  1807. fill(0x00);
  1808. box_walls(cnt,cnt,cnt,7-cnt,7-cnt,7-cnt);
  1809. delay_ms(time);
  1810. }
  1811.  
  1812. //Make Box Bigger
  1813. for(cnt=0;cnt<=3;cnt++){
  1814. fill(0x00);
  1815. box_walls(3-cnt,3-cnt,3-cnt,4+cnt,4+cnt,4+cnt);
  1816. delay_ms(time);
  1817. }
  1818. }
  1819. for(cnt_2=0;cnt_2<5;cnt_2++){
  1820. time = time + 300;
  1821. //Make Box Smaller
  1822. for(cnt=0;cnt<=3;cnt++){
  1823. fill(0x00);
  1824. box_walls(cnt,cnt,cnt,7-cnt,7-cnt,7-cnt);
  1825. delay_ms(time);
  1826. }
  1827.  
  1828. //Make Box Bigger
  1829. for(cnt=0;cnt<=3;cnt++){
  1830. fill(0x00);
  1831. box_walls(3-cnt,3-cnt,3-cnt,4+cnt,4+cnt,4+cnt);
  1832. delay_ms(time);
  1833. }
  1834. }
  1835. delay_ms(2000);
  1836.  
  1837. }
  1838. void sinelines (int iterations, int delay)
  1839. {
  1840. int i,x;
  1841.  
  1842. float left, right, sine_base, x_dividor,ripple_height;
  1843.  
  1844. for (i=0; i<iterations; i++)
  1845. {
  1846. for (x=0; x<8 ;x++)
  1847. {
  1848. x_dividor = 2 + sin((float)i/100)+1;
  1849. ripple_height = 3 + (sin((float)i/200)+1)*6;
  1850.  
  1851. sine_base = (float) i/40 + (float) x/x_dividor;
  1852.  
  1853. left = 4 + sin(sine_base)*ripple_height;
  1854. right = 4 + cos(sine_base)*ripple_height;
  1855. right = 7-left;
  1856.  
  1857. //printf("%i %i \n", (int) left, (int) right);
  1858.  
  1859. line_3d(0-3, x, (int) left, 7+3, x, (int) right);
  1860. //line_3d((int) right, 7, x);
  1861. }
  1862.  
  1863. // delay_ms(delay);
  1864. fill(0x00);
  1865. }
  1866. }
  1867. void effect_random_sparkle_flash (int iterations, int voxels, int delay)
  1868. {
  1869. int i;
  1870. int v;
  1871. for (i = 0; i < iterations; i++)
  1872. {
  1873. for (v=0;v<=voxels;v++)
  1874. setvoxel(rand()%8,rand()%8,rand()%8);
  1875.  
  1876. delay_ms(delay);
  1877. fill(0x00);
  1878. }
  1879. }
  1880.  
  1881.  
  1882.  
  1883. void draw_positions_axis (char axis, unsigned char positions[64], int invert)
  1884. {
  1885. int x, y, p;
  1886.  
  1887. fill(0x00);
  1888.  
  1889. for (x=0; x<8; x++)
  1890. {
  1891. for (y=0; y<8; y++)
  1892. {
  1893. if (invert)
  1894. {
  1895. p = (7-positions[(x*8)+y]);
  1896. } else
  1897. {
  1898. p = positions[(x*8)+y];
  1899. }
  1900.  
  1901. if (axis == AXIS_Z)
  1902. setvoxel(x,y,p);
  1903.  
  1904. if (axis == AXIS_Y)
  1905. setvoxel(x,p,y);
  1906.  
  1907. if (axis == AXIS_X)
  1908. setvoxel(p,y,x);
  1909. }
  1910. }
  1911.  
  1912. }
  1913.  
  1914. void effect_random_sparkle (void)
  1915. {
  1916. int i;
  1917.  
  1918. for (i=1;i<20;i++)
  1919. {
  1920. effect_random_sparkle_flash(5,i,200);
  1921. }
  1922.  
  1923. for (i=20;i>=1;i--)
  1924. {
  1925. effect_random_sparkle_flash(5,i,200);
  1926. }
  1927.  
  1928. }
  1929.  
  1930. void side_ripples(int iterations, int delay)
  1931. {
  1932. // 16 values for square root of a^2+b^2. index a*4+b = 10*sqrt
  1933. // This gives the distance to 3.5,3.5 from the point
  1934. unsigned char sqrt_LUT[]={49,43,38,35,43,35,29,26,38,29,21,16,35,25,16,7};
  1935. //LUT_START // Macro from new tottymath. Commented and replaced with full code
  1936. unsigned char LUT[65];
  1937. init_LUT(LUT);
  1938. int i;
  1939. unsigned char x,y,height,distance;
  1940. for (i=0;i<iterations*4;i+=4)
  1941. {
  1942. fill(0x00);
  1943. for (x=0;x<4;x++)
  1944. for(y=0;y<4;y++)
  1945. {
  1946. // x+y*4 gives no. from 0-15 for sqrt_LUT
  1947. distance=sqrt_LUT[x+y*4];// distance is 0-50 roughly
  1948. // height is sin of distance + iteration*4
  1949. //height=4+totty_sin(LUT,distance+i)/52;
  1950. height=(196+totty_sin(LUT,distance+i))/49;
  1951. // Use 4-way mirroring to save on calculations
  1952. setvoxel(x,height,y);
  1953. setvoxel(7-x,height,y);
  1954. setvoxel(x,height,7-y);
  1955. setvoxel(7-x,height,7-y);
  1956. setvoxel(x,7-height,y);
  1957. setvoxel(7-x,7-height,y);
  1958. setvoxel(x,7-height,7-y);
  1959. setvoxel(7-x,7-height,7-y);
  1960.  
  1961. }
  1962. delay_ms(delay);
  1963. }
  1964. }
  1965.  
  1966. void mirror_ripples(int iterations, int delay)
  1967. {
  1968. // 16 values for square root of a^2+b^2. index a*4+b = 10*sqrt
  1969. // This gives the distance to 3.5,3.5 from the point
  1970. unsigned char sqrt_LUT[]={49,43,38,35,43,35,29,26,38,29,21,16,35,25,16,7};
  1971. //LUT_START // Macro from new tottymath. Commented and replaced with full code
  1972. unsigned char LUT[65];
  1973. init_LUT(LUT);
  1974. int i;
  1975. unsigned char x,y,height,distance;
  1976. for (i=0;i<iterations*4;i+=4)
  1977. {
  1978. fill(0x00);
  1979. for (x=0;x<4;x++)
  1980. for(y=0;y<4;y++)
  1981. {
  1982. // x+y*4 gives no. from 0-15 for sqrt_LUT
  1983. distance=sqrt_LUT[x+y*4];// distance is 0-50 roughly
  1984. // height is sin of distance + iteration*4
  1985. //height=4+totty_sin(LUT,distance+i)/52;
  1986. height=(196+totty_sin(LUT,distance+i))/49;
  1987. // Use 4-way mirroring to save on calculations
  1988. setvoxel(x,y,height);
  1989. setvoxel(7-x,y,height);
  1990. setvoxel(x,7-y,height);
  1991. setvoxel(7-x,7-y,height);
  1992. setvoxel(x,y,7-height);
  1993. setvoxel(7-x,y,7-height);
  1994. setvoxel(x,7-y,7-height);
  1995. setvoxel(7-x,7-y,7-height);
  1996.  
  1997. }
  1998. delay_ms(delay);
  1999. }
  2000. }
  2001.  
  2002. void quad_ripples(int iterations, int delay)
  2003. {
  2004. // 16 values for square root of a^2+b^2. index a*4+b = 10*sqrt
  2005. // This gives the distance to 3.5,3.5 from the point
  2006. unsigned char sqrt_LUT[]={49,43,38,35,43,35,29,26,38,29,21,16,35,25,16,7};
  2007. //LUT_START // Macro from new tottymath. Commented and replaced with full code
  2008. unsigned char LUT[65];
  2009. init_LUT(LUT);
  2010. int i;
  2011. unsigned char x,y,height,distance;
  2012. for (i=0;i<iterations*4;i+=4)
  2013. {
  2014. fill(0x00);
  2015. for (x=0;x<4;x++)
  2016. for(y=0;y<4;y++)
  2017. {
  2018. // x+y*4 gives no. from 0-15 for sqrt_LUT
  2019. distance=sqrt_LUT[x+y*4];// distance is 0-50 roughly
  2020. // height is sin of distance + iteration*4
  2021. //height=4+totty_sin(LUT,distance+i)/52;
  2022. height=(196+totty_sin(LUT,distance+i))/49;
  2023. // Use 4-way mirroring to save on calculations
  2024. setvoxel(x,y,height);
  2025. setvoxel(7-x,y,height);
  2026. setvoxel(x,7-y,height);
  2027. setvoxel(7-x,7-y,height);
  2028. setvoxel(x,y,7-height);
  2029. setvoxel(7-x,y,7-height);
  2030. setvoxel(x,7-y,7-height);
  2031. setvoxel(7-x,7-y,7-height);
  2032. setvoxel(x,height,y);
  2033. setvoxel(7-x,height,y);
  2034. setvoxel(x,height,7-y);
  2035. setvoxel(7-x,height,7-y);
  2036. setvoxel(x,7-height,y);
  2037. setvoxel(7-x,7-height,y);
  2038. setvoxel(x,7-height,7-y);
  2039. setvoxel(7-x,7-height,7-y);
  2040.  
  2041.  
  2042. }
  2043. delay_ms(delay);
  2044. }
  2045. }
  2046.  
  2047. void init_LUT(unsigned char LUT[65])
  2048. {
  2049. unsigned char i;
  2050. float sin_of,sine;
  2051. for (i=0;i<65;i++)
  2052. {
  2053. sin_of=i*PI/64; // Just need half a sin wave
  2054. sine=sin(sin_of);
  2055. // Use 181.0 as this squared is <32767, so we can multiply two sin or cos without overflowing an int.
  2056. LUT[i]=sine*181.0;
  2057. }
  2058. }
  2059. void effect_axis_updown_randsuspend (char axis, int delay, int sleep, int invert)
  2060. {
  2061. unsigned char positions[64];
  2062. unsigned char destinations[64];
  2063.  
  2064. int i,px;
  2065.  
  2066. // Set 64 random positions
  2067. for (i=0; i<64; i++)
  2068. {
  2069. positions[i] = 0; // Set all starting positions to 0
  2070. destinations[i] = rand()%8;
  2071. }
  2072.  
  2073. // Loop 8 times to allow destination 7 to reach all the way
  2074. for (i=0; i<8; i++)
  2075. {
  2076. // For every iteration, move all position one step closer to their destination
  2077. for (px=0; px<64; px++)
  2078. {
  2079. if (positions[px]<destinations[px])
  2080. {
  2081. positions[px]++;
  2082. }
  2083. }
  2084. // Draw the positions and take a nap
  2085. draw_positions_axis (axis, positions,invert);
  2086. delay_ms(delay);
  2087. }
  2088.  
  2089. // Set all destinations to 7 (opposite from the side they started out)
  2090. for (i=0; i<64; i++)
  2091. {
  2092. destinations[i] = 7;
  2093. }
  2094.  
  2095. // Suspend the positions in mid-air for a while
  2096. delay_ms(sleep);
  2097.  
  2098. // Then do the same thing one more time
  2099. for (i=0; i<8; i++)
  2100. {
  2101. for (px=0; px<64; px++)
  2102. {
  2103. if (positions[px]<destinations[px])
  2104. {
  2105. positions[px]++;
  2106. }
  2107. if (positions[px]>destinations[px])
  2108. {
  2109. positions[px]--;
  2110. }
  2111. }
  2112. draw_positions_axis (axis, positions,invert);
  2113. delay_ms(delay);
  2114. }
  2115. }
  2116.  
  2117. void linespin (int iterations, int delay)
  2118. {
  2119. float top_x, top_y, top_z, bot_x, bot_y, bot_z, sin_base;
  2120. float center_x, center_y;
  2121.  
  2122. center_x = 4;
  2123. center_y = 4;
  2124.  
  2125. int i, z;
  2126. for (i=0;i<iterations;i++)
  2127. {
  2128.  
  2129. //printf("Sin base %f \n",sin_base);
  2130.  
  2131. for (z = 0; z < 8; z++)
  2132. {
  2133.  
  2134. sin_base = (float)i/50 + (float)z/(10+(7*sin((float)i/200)));
  2135.  
  2136. top_x = center_x + sin(sin_base)*5;
  2137. top_y = center_x + cos(sin_base)*5;
  2138. //top_z = center_x + cos(sin_base/100)*2.5;
  2139.  
  2140. bot_x = center_x + sin(sin_base+3.14)*10;
  2141. bot_y = center_x + cos(sin_base+3.14)*10;
  2142. //bot_z = 7-top_z;
  2143.  
  2144. bot_z = z;
  2145. top_z = z;
  2146.  
  2147. // setvoxel((int) top_x, (int) top_y, 7);
  2148. // setvoxel((int) bot_x, (int) bot_y, 0);
  2149.  
  2150. //printf("P1: %i %i %i P2: %i %i %i \n", (int) top_x, (int) top_y, 7, (int) bot_x, (int) bot_y, 0);
  2151.  
  2152. //line_3d((int) top_x, (int) top_y, (int) top_z, (int) bot_x, (int) bot_y, (int) bot_z);
  2153. line_3d((int) top_z, (int) top_x, (int) top_y, (int) bot_z, (int) bot_x, (int) bot_y);
  2154. }
  2155.  
  2156. // delay_ms(delay);
  2157. fill(0x00);
  2158. }
  2159.  
  2160. }
  2161. void line_3d (int x1, int y1, int z1, int x2, int y2, int z2)
  2162. {
  2163. int i, dx, dy, dz, l, m, n, x_inc, y_inc, z_inc,
  2164. err_1, err_2, dx2, dy2, dz2;
  2165. int pixel[3];
  2166. pixel[0] = x1;
  2167. pixel[1] = y1;
  2168. pixel[2] = z1;
  2169. dx = x2 - x1;
  2170. dy = y2 - y1;
  2171. dz = z2 - z1;
  2172. x_inc = (dx < 0) ? -1 : 1;
  2173. l = abs(dx);
  2174. y_inc = (dy < 0) ? -1 : 1;
  2175. m = abs(dy);
  2176. z_inc = (dz < 0) ? -1 : 1;
  2177. n = abs(dz);
  2178. dx2 = l << 1;
  2179. dy2 = m << 1;
  2180. dz2 = n << 1;
  2181. if ((l >= m) && (l >= n)) {
  2182. err_1 = dy2 - l;
  2183. err_2 = dz2 - l;
  2184. for (i = 0; i < l; i++) {
  2185. //PUT_PIXEL(pixel);
  2186. setvoxel(pixel[0],pixel[1],pixel[2]);
  2187. //printf("Setting %i %i %i \n", pixel[0],pixel[1],pixel[2]);
  2188. if (err_1 > 0) {
  2189. pixel[1] += y_inc;
  2190. err_1 -= dx2;
  2191. }
  2192. if (err_2 > 0) {
  2193. pixel[2] += z_inc;
  2194. err_2 -= dx2;
  2195. }
  2196. err_1 += dy2;
  2197. err_2 += dz2;
  2198. pixel[0] += x_inc;
  2199. }
  2200. } else if ((m >= l) && (m >= n)) {
  2201. err_1 = dx2 - m;
  2202. err_2 = dz2 - m;
  2203. for (i = 0; i < m; i++) {
  2204. //PUT_PIXEL(pixel);
  2205. setvoxel(pixel[0],pixel[1],pixel[2]);
  2206. //printf("Setting %i %i %i \n", pixel[0],pixel[1],pixel[2]);
  2207. if (err_1 > 0) {
  2208. pixel[0] += x_inc;
  2209. err_1 -= dy2;
  2210. }
  2211. if (err_2 > 0) {
  2212. pixel[2] += z_inc;
  2213. err_2 -= dy2;
  2214. }
  2215. err_1 += dx2;
  2216. err_2 += dz2;
  2217. pixel[1] += y_inc;
  2218. }
  2219. } else {
  2220. err_1 = dy2 - n;
  2221. err_2 = dx2 - n;
  2222. for (i = 0; i < n; i++) {
  2223. setvoxel(pixel[0],pixel[1],pixel[2]);
  2224. //printf("Setting %i %i %i \n", pixel[0],pixel[1],pixel[2]);
  2225. //PUT_PIXEL(pixel);
  2226. if (err_1 > 0) {
  2227. pixel[1] += y_inc;
  2228. err_1 -= dz2;
  2229. }
  2230. if (err_2 > 0) {
  2231. pixel[0] += x_inc;
  2232. err_2 -= dz2;
  2233. }
  2234. err_1 += dy2;
  2235. err_2 += dx2;
  2236. pixel[2] += z_inc;
  2237. }
  2238. }
  2239. setvoxel(pixel[0],pixel[1],pixel[2]);
  2240. //printf("Setting %i %i %i \n", pixel[0],pixel[1],pixel[2]);
  2241. //PUT_PIXEL(pixel);
  2242. }
  2243.  
  2244.  
  2245. // ******************************************
  2246.  
  2247.  
  2248. int totty_sin(unsigned char LUT[65],int sin_of)
  2249. {
  2250. unsigned char inv=0;
  2251. if (sin_of<0)
  2252. {
  2253. sin_of=-sin_of;
  2254. inv=1;
  2255. }
  2256. sin_of&=0x7f; //127
  2257. if (sin_of>64)
  2258. {
  2259. sin_of-=64;
  2260. inv=1-inv;
  2261. }
  2262. if (inv)
  2263. return -LUT[sin_of];
  2264. else
  2265. return LUT[sin_of];
  2266. }
  2267.  
  2268. void fireworks (int iterations, int n, int delay)
  2269. {
  2270. fill(0x00);
  2271.  
  2272. int i,f,e;
  2273.  
  2274. float origin_x = 3;
  2275. float origin_y = 3;
  2276. float origin_z = 3;
  2277.  
  2278. int rand_y, rand_x, rand_z;
  2279.  
  2280. float slowrate, gravity;
  2281.  
  2282. // Particles and their position, x,y,z and their movement, dx, dy, dz
  2283. float particles[n][6];
  2284.  
  2285. for (i=0; i<iterations; i++)
  2286. {
  2287.  
  2288. origin_x = rand()%4;
  2289. origin_y = rand()%4;
  2290. origin_z = rand()%2;
  2291. origin_z +=5;
  2292. origin_x +=2;
  2293. origin_y +=2;
  2294.  
  2295. // shoot a particle up in the air
  2296. for (e=0;e<origin_z;e++)
  2297. {
  2298. setvoxel(origin_x,origin_y,e);
  2299. delay_ms(600+500*e);
  2300. fill(0x00);
  2301. }
  2302.  
  2303. // Fill particle array
  2304. for (f=0; f<n; f++)
  2305. {
  2306. // Position
  2307. particles[f][0] = origin_x;
  2308. particles[f][1] = origin_y;
  2309. particles[f][2] = origin_z;
  2310.  
  2311. rand_x = rand()%200;
  2312. rand_y = rand()%200;
  2313. rand_z = rand()%200;
  2314.  
  2315. // Movement
  2316. particles[f][3] = 1-(float)rand_x/100; // dx
  2317. particles[f][4] = 1-(float)rand_y/100; // dy
  2318. particles[f][5] = 1-(float)rand_z/100; // dz
  2319. }
  2320.  
  2321. // explode
  2322. for (e=0; e<25; e++)
  2323. {
  2324. slowrate = 1+tan((e+0.1)/20)*10;
  2325.  
  2326. gravity = tan((e+0.1)/20)/2;
  2327.  
  2328. for (f=0; f<n; f++)
  2329. {
  2330. particles[f][0] += particles[f][3]/slowrate;
  2331. particles[f][1] += particles[f][4]/slowrate;
  2332. particles[f][2] += particles[f][5]/slowrate;
  2333. particles[f][2] -= gravity;
  2334.  
  2335. setvoxel(particles[f][0],particles[f][1],particles[f][2]);
  2336.  
  2337.  
  2338. }
  2339.  
  2340. delay_ms(delay);
  2341. fill(0x00);
  2342. }
  2343.  
  2344. }
  2345.  
  2346. }
  2347.  
  2348.  
  2349. void effect_box_wamp(int delayt)
  2350. {
  2351. for(int k = 0; k < 3; k++){
  2352. for(int i = 0; i < 4; i++){
  2353. fill(0x00);
  2354. box_filled(3 - i, 3 - i, 3 - i, 4 + i, 4 + i, 4 + i);
  2355. delay_ms(delayt);
  2356. }
  2357. for(int i = 3; i >= 0; i--){
  2358. fill(0x00);
  2359. box_filled(3 - i, 3 - i, 3 - i, 4 + i, 4 + i, 4 + i);
  2360. delay_ms(delayt);
  2361. }
  2362. }
  2363.  
  2364. for(int k = 0; k < 3; k++){
  2365. for(int i = 0; i < 4; i++){
  2366. fill(0x00);
  2367. box_walls(3 - i, 3 - i, 3 - i, 4 + i, 4 + i, 4 + i);
  2368. delay_ms(delayt);
  2369. }
  2370. for(int i = 3; i >= 0; i--){
  2371. fill(0x00);
  2372. box_walls(3 - i, 3 - i, 3 - i, 4 + i, 4 + i, 4 + i);
  2373. delay_ms(delayt);
  2374. }
  2375. }
  2376.  
  2377. for(int k = 0; k < 3; k++){
  2378. for(int i = 0; i < 4; i++){
  2379. fill(0x00);
  2380. box_wireframe(3 - i, 3 - i, 3 - i, 4 + i, 4 + i, 4 + i);
  2381. delay_ms(delayt);
  2382. }
  2383. for(int i = 3; i >= 0; i--){
  2384. fill(0x00);
  2385. box_wireframe(3 - i, 3 - i, 3 - i, 4 + i, 4 + i, 4 + i);
  2386. delay_ms(delayt);
  2387. }
  2388. }
  2389. }
  2390.  
  2391.  
  2392. void effect_boxside_randsend_parallel (char axis, int origin, int delayt, int mode)
  2393. {
  2394. int i;
  2395. int done;
  2396. unsigned char cubepos[64];
  2397. unsigned char pos[64];
  2398. int notdone = 1;
  2399. int notdone2 = 1;
  2400. int sent = 0;
  2401.  
  2402. for (i=0;i<64;i++)
  2403. {
  2404. pos[i] = 0;
  2405. }
  2406.  
  2407. while (notdone)
  2408. {
  2409. if (mode == 1)
  2410. {
  2411. notdone2 = 1;
  2412. while (notdone2 && sent<64)
  2413. {
  2414. i = rand()%64;
  2415. if (pos[i] == 0)
  2416. {
  2417. sent++;
  2418. pos[i] += 1;
  2419. notdone2 = 0;
  2420. }
  2421. }
  2422. } else if (mode == 2)
  2423. {
  2424. if (sent<64)
  2425. {
  2426. pos[sent] += 1;
  2427. sent++;
  2428. }
  2429. }
  2430.  
  2431. done = 0;
  2432. for (i=0;i<64;i++)
  2433. {
  2434. if (pos[i] > 0 && pos[i] <7)
  2435. {
  2436. pos[i] += 1;
  2437. }
  2438.  
  2439. if (pos[i] == 7)
  2440. done++;
  2441. }
  2442.  
  2443. if (done == 64)
  2444. notdone = 0;
  2445.  
  2446. for (i=0;i<64;i++)
  2447. {
  2448. if (origin == 0)
  2449. {
  2450. cubepos[i] = pos[i];
  2451. } else
  2452. {
  2453. cubepos[i] = (7-pos[i]);
  2454. }
  2455. }
  2456.  
  2457.  
  2458. delay_ms(delayt);
  2459. draw_positions_axis(axis,cubepos,0);
  2460.  
  2461. }
  2462.  
  2463. }
  2464.  
  2465.  
  2466. void effect_rain (int iterations)
  2467. {
  2468. int i, ii;
  2469. int rnd_x;
  2470. int rnd_y;
  2471. int rnd_num;
  2472.  
  2473. for (ii=0;ii<iterations;ii++)
  2474. {
  2475. rnd_num = rand()%4;
  2476.  
  2477. for (i=0; i < rnd_num;i++)
  2478. {
  2479. rnd_x = rand()%8;
  2480. rnd_y = rand()%8;
  2481. setvoxel(rnd_x,rnd_y,7);
  2482. }
  2483.  
  2484. delay_ms(1000);
  2485. shift(AXIS_Z,-1);
  2486. }
  2487. }
  2488.  
  2489. // Set or clear exactly 512 voxels in a random order.
  2490. void effect_random_filler (int delayt, int state)
  2491. {
  2492. int x,y,z;
  2493. int loop = 0;
  2494.  
  2495.  
  2496. if (state == 1)
  2497. {
  2498. fill(0x00);
  2499. } else
  2500. {
  2501. fill(0xff);
  2502. }
  2503.  
  2504. while (loop<511)
  2505. {
  2506. x = rand()%8;
  2507. y = rand()%8;
  2508. z = rand()%8;
  2509.  
  2510. if ((state == 0 && getvoxel(x,y,z) == 0x01) || (state == 1 && getvoxel(x,y,z) == 0x00))
  2511. {
  2512. altervoxel(x,y,z,state);
  2513. delay_ms(delayt);
  2514. loop++;
  2515. }
  2516. }
  2517. }
  2518.  
  2519.  
  2520. void effect_blinky2()
  2521. {
  2522. int i,r;
  2523. fill(0x00);
  2524.  
  2525. for (r=0;r<2;r++)
  2526. {
  2527. i = 750;
  2528. while (i>0)
  2529. {
  2530. fill(0x00);
  2531. delay_ms(i);
  2532.  
  2533. fill(0xff);
  2534. delay_ms(100);
  2535.  
  2536. i = i - (15+(1000/(i/10)));
  2537. }
  2538.  
  2539. delay_ms(1000);
  2540.  
  2541. i = 750;
  2542. while (i>0)
  2543. {
  2544. fill(0x00);
  2545. delay_ms(751-i);
  2546.  
  2547. fill(0xff);
  2548. delay_ms(100);
  2549.  
  2550. i = i - (15+(1000/(i/10)));
  2551. }
  2552. }
  2553.  
  2554. }
  2555.  
  2556. // Draw a plane on one axis and send it back and forth once.
  2557. void effect_planboing (int plane, int speedd)
  2558. {
  2559. int i;
  2560. for (i=0;i<8;i++)
  2561. {
  2562. fill(0x00);
  2563. setplane(plane, i);
  2564. delay_ms(speedd);
  2565. }
  2566.  
  2567. for (i=7;i>=0;i--)
  2568. {
  2569. fill(0x00);
  2570. setplane(plane,i);
  2571. delay_ms(speedd);
  2572. }
  2573. }
  2574.  
  2575.  
  2576. // ==========================================================================================
  2577. // Draw functions
  2578. // ==========================================================================================
  2579.  
  2580.  
  2581. // Set a single voxel to ON
  2582. void setvoxel(int x, int y, int z)
  2583. {
  2584. if (inrange(x,y,z))
  2585. cube[z][y] |= (1 << x);
  2586. }
  2587.  
  2588.  
  2589. // Set a single voxel to ON
  2590. void clrvoxel(int x, int y, int z)
  2591. {
  2592. if (inrange(x,y,z))
  2593. cube[z][y] &= ~(1 << x);
  2594. }
  2595.  
  2596.  
  2597.  
  2598. // This function validates that we are drawing inside the cube.
  2599. unsigned char inrange(int x, int y, int z)
  2600. {
  2601. if (x >= 0 && x < 8 && y >= 0 && y < 8 && z >= 0 && z < 8)
  2602. {
  2603. return 0x01;
  2604. } else
  2605. {
  2606. // One of the coordinates was outside the cube.
  2607. return 0x00;
  2608. }
  2609. }
  2610.  
  2611. // Get the current status of a voxel
  2612. unsigned char getvoxel(int x, int y, int z)
  2613. {
  2614. if (inrange(x,y,z))
  2615. {
  2616. if (cube[z][y] & (1 << x))
  2617. {
  2618. return 0x01;
  2619. } else
  2620. {
  2621. return 0x00;
  2622. }
  2623. } else
  2624. {
  2625. return 0x00;
  2626. }
  2627. }
  2628.  
  2629. // In some effect we want to just take bool and write it to a voxel
  2630. // this function calls the apropriate voxel manipulation function.
  2631. void altervoxel(int x, int y, int z, int state)
  2632. {
  2633. if (state == 1)
  2634. {
  2635. setvoxel(x,y,z);
  2636. } else
  2637. {
  2638. clrvoxel(x,y,z);
  2639. }
  2640. }
  2641.  
  2642. // Flip the state of a voxel.
  2643. // If the voxel is 1, its turned into a 0, and vice versa.
  2644. void flpvoxel(int x, int y, int z)
  2645. {
  2646. if (inrange(x, y, z))
  2647. cube[z][y] ^= (1 << x);
  2648. }
  2649.  
  2650. // Makes sure x1 is alwas smaller than x2
  2651. // This is usefull for functions that uses for loops,
  2652. // to avoid infinite loops
  2653. void argorder(int ix1, int ix2, int *ox1, int *ox2)
  2654. {
  2655. if (ix1>ix2)
  2656. {
  2657. int tmp;
  2658. tmp = ix1;
  2659. ix1= ix2;
  2660. ix2 = tmp;
  2661. }
  2662. *ox1 = ix1;
  2663. *ox2 = ix2;
  2664. }
  2665.  
  2666. // Sets all voxels along a X/Y plane at a given point
  2667. // on axis Z
  2668. void setplane_z (int z)
  2669. {
  2670. int i;
  2671. if (z>=0 && z<8)
  2672. {
  2673. for (i=0;i<8;i++)
  2674. cube[z][i] = 0xff;
  2675. }
  2676. }
  2677.  
  2678. // Clears voxels in the same manner as above
  2679. void clrplane_z (int z)
  2680. {
  2681. int i;
  2682. if (z>=0 && z<8)
  2683. {
  2684. for (i=0;i<8;i++)
  2685. cube[z][i] = 0x00;
  2686. }
  2687. }
  2688.  
  2689. void setplane_x (int x)
  2690. {
  2691. int z;
  2692. int y;
  2693. if (x>=0 && x<8)
  2694. {
  2695. for (z=0;z<8;z++)
  2696. {
  2697. for (y=0;y<8;y++)
  2698. {
  2699. cube[z][y] |= (1 << x);
  2700. }
  2701. }
  2702. }
  2703. }
  2704.  
  2705. void clrplane_x (int x)
  2706. {
  2707. int z;
  2708. int y;
  2709. if (x>=0 && x<8)
  2710. {
  2711. for (z=0;z<8;z++)
  2712. {
  2713. for (y=0;y<8;y++)
  2714. {
  2715. cube[z][y] &= ~(1 << x);
  2716. }
  2717. }
  2718. }
  2719. }
  2720.  
  2721. void setplane_y (int y)
  2722. {
  2723. int z;
  2724. if (y>=0 && y<8)
  2725. {
  2726. for (z=0;z<8;z++)
  2727. cube[z][y] = 0xff;
  2728. }
  2729. }
  2730.  
  2731. void clrplane_y (int y)
  2732. {
  2733. int z;
  2734. if (y>=0 && y<8)
  2735. {
  2736. for (z=0;z<8;z++)
  2737. cube[z][y] = 0x00;
  2738. }
  2739. }
  2740.  
  2741. void setplane (char axis, unsigned char i)
  2742. {
  2743. switch (axis)
  2744. {
  2745. case AXIS_X:
  2746. setplane_x(i);
  2747. break;
  2748.  
  2749. case AXIS_Y:
  2750. setplane_y(i);
  2751. break;
  2752.  
  2753. case AXIS_Z:
  2754. setplane_z(i);
  2755. break;
  2756. }
  2757. }
  2758.  
  2759. void clrplane (char axis, unsigned char i)
  2760. {
  2761. switch (axis)
  2762. {
  2763. case AXIS_X:
  2764. clrplane_x(i);
  2765. break;
  2766.  
  2767. case AXIS_Y:
  2768. clrplane_y(i);
  2769. break;
  2770.  
  2771. case AXIS_Z:
  2772. clrplane_z(i);
  2773. break;
  2774. }
  2775. }
  2776.  
  2777. // Fill a value into all 64 byts of the cube buffer
  2778. // Mostly used for clearing. fill(0x00)
  2779. // or setting all on. fill(0xff)
  2780. void fill (unsigned char pattern)
  2781. {
  2782. int z;
  2783. int y;
  2784. for (z=0;z<8;z++)
  2785. {
  2786. for (y=0;y<8;y++)
  2787. {
  2788. cube[z][y] = pattern;
  2789. }
  2790. }
  2791. }
  2792.  
  2793.  
  2794.  
  2795. // Draw a box with all walls drawn and all voxels inside set
  2796. void box_filled(int x1, int y1, int z1, int x2, int y2, int z2)
  2797. {
  2798. int iy;
  2799. int iz;
  2800.  
  2801. argorder(x1, x2, &x1, &x2);
  2802. argorder(y1, y2, &y1, &y2);
  2803. argorder(z1, z2, &z1, &z2);
  2804.  
  2805. for (iz=z1;iz<=z2;iz++)
  2806. {
  2807. for (iy=y1;iy<=y2;iy++)
  2808. {
  2809. cube[iz][iy] |= byteline(x1,x2);
  2810. }
  2811. }
  2812.  
  2813. }
  2814.  
  2815. // Darw a hollow box with side walls.
  2816. void box_walls(int x1, int y1, int z1, int x2, int y2, int z2)
  2817. {
  2818. int iy;
  2819. int iz;
  2820.  
  2821. argorder(x1, x2, &x1, &x2);
  2822. argorder(y1, y2, &y1, &y2);
  2823. argorder(z1, z2, &z1, &z2);
  2824.  
  2825. for (iz=z1;iz<=z2;iz++)
  2826. {
  2827. for (iy=y1;iy<=y2;iy++)
  2828. {
  2829. if (iy == y1 || iy == y2 || iz == z1 || iz == z2)
  2830. {
  2831. cube[iz][iy] = byteline(x1,x2);
  2832. } else
  2833. {
  2834. cube[iz][iy] |= ((0x01 << x1) | (0x01 << x2));
  2835. }
  2836. }
  2837. }
  2838.  
  2839. }
  2840.  
  2841. // Draw a wireframe box. This only draws the corners and edges,
  2842. // no walls.
  2843. void box_wireframe(int x1, int y1, int z1, int x2, int y2, int z2)
  2844. {
  2845. int iy;
  2846. int iz;
  2847.  
  2848. argorder(x1, x2, &x1, &x2);
  2849. argorder(y1, y2, &y1, &y2);
  2850. argorder(z1, z2, &z1, &z2);
  2851.  
  2852. // Lines along X axis
  2853. cube[z1][y1] = byteline(x1,x2);
  2854. cube[z1][y2] = byteline(x1,x2);
  2855. cube[z2][y1] = byteline(x1,x2);
  2856. cube[z2][y2] = byteline(x1,x2);
  2857.  
  2858. // Lines along Y axis
  2859. for (iy=y1;iy<=y2;iy++)
  2860. {
  2861. setvoxel(x1,iy,z1);
  2862. setvoxel(x1,iy,z2);
  2863. setvoxel(x2,iy,z1);
  2864. setvoxel(x2,iy,z2);
  2865. }
  2866.  
  2867. // Lines along Z axis
  2868. for (iz=z1;iz<=z2;iz++)
  2869. {
  2870. setvoxel(x1,y1,iz);
  2871. setvoxel(x1,y2,iz);
  2872. setvoxel(x2,y1,iz);
  2873. setvoxel(x2,y2,iz);
  2874. }
  2875.  
  2876. }
  2877.  
  2878. // Returns a byte with a row of 1's drawn in it.
  2879. // byteline(2,5) gives 0b00111100
  2880. char byteline (int start, int end)
  2881. {
  2882. return ((0xff<<start) & ~(0xff<<(end+1)));
  2883. }
  2884.  
  2885. // Flips a byte 180 degrees.
  2886. // MSB becomes LSB, LSB becomes MSB.
  2887. char flipbyte (char byte)
  2888. {
  2889. char flop = 0x00;
  2890.  
  2891. flop = (flop & 0b11111110) | (0b00000001 & (byte >> 7));
  2892. flop = (flop & 0b11111101) | (0b00000010 & (byte >> 5));
  2893. flop = (flop & 0b11111011) | (0b00000100 & (byte >> 3));
  2894. flop = (flop & 0b11110111) | (0b00001000 & (byte >> 1));
  2895. flop = (flop & 0b11101111) | (0b00010000 & (byte << 1));
  2896. flop = (flop & 0b11011111) | (0b00100000 & (byte << 3));
  2897. flop = (flop & 0b10111111) | (0b01000000 & (byte << 5));
  2898. flop = (flop & 0b01111111) | (0b10000000 & (byte << 7));
  2899. return flop;
  2900. }
  2901.  
  2902. // Draw a line between any coordinates in 3d space.
  2903. // Uses integer values for input, so dont expect smooth animations.
  2904. void line(int x1, int y1, int z1, int x2, int y2, int z2)
  2905. {
  2906. float xy; // how many voxels do we move on the y axis for each step on the x axis
  2907. float xz; // how many voxels do we move on the y axis for each step on the x axis
  2908. unsigned char x,y,z;
  2909. unsigned char lasty,lastz;
  2910.  
  2911. // We always want to draw the line from x=0 to x=7.
  2912. // If x1 is bigget than x2, we need to flip all the values.
  2913. if (x1>x2)
  2914. {
  2915. int tmp;
  2916. tmp = x2; x2 = x1; x1 = tmp;
  2917. tmp = y2; y2 = y1; y1 = tmp;
  2918. tmp = z2; z2 = z1; z1 = tmp;
  2919. }
  2920.  
  2921.  
  2922. if (y1>y2)
  2923. {
  2924. xy = (float)(y1-y2)/(float)(x2-x1);
  2925. lasty = y2;
  2926. } else
  2927. {
  2928. xy = (float)(y2-y1)/(float)(x2-x1);
  2929. lasty = y1;
  2930. }
  2931.  
  2932. if (z1>z2)
  2933. {
  2934. xz = (float)(z1-z2)/(float)(x2-x1);
  2935. lastz = z2;
  2936. } else
  2937. {
  2938. xz = (float)(z2-z1)/(float)(x2-x1);
  2939. lastz = z1;
  2940. }
  2941.  
  2942.  
  2943.  
  2944. // For each step of x, y increments by:
  2945. for (x = x1; x<=x2;x++)
  2946. {
  2947. y = (xy*(x-x1))+y1;
  2948. z = (xz*(x-x1))+z1;
  2949. setvoxel(x,y,z);
  2950. }
  2951.  
  2952. }
  2953.  
  2954. // Delay loop.
  2955. // This is not calibrated to milliseconds,
  2956. // but we had allready made to many effects using this
  2957. // calibration when we figured it might be a good idea
  2958. // to calibrate it.
  2959. void delay_ms(uint16_t x)
  2960. {
  2961. uint8_t y, z;
  2962. for ( ; x > 0 ; x--){
  2963. for ( y = 0 ; y < 90 ; y++){
  2964. for ( z = 0 ; z < 6 ; z++){
  2965. asm volatile ("nop");
  2966. }
  2967. }
  2968. }
  2969. }
  2970.  
  2971.  
  2972.  
  2973. // Shift the entire contents of the cube along an axis
  2974. // This is great for effects where you want to draw something
  2975. // on one side of the cube and have it flow towards the other
  2976. // side. Like rain flowing down the Z axiz.
  2977. void shift (char axis, int direction)
  2978. {
  2979. int i, x ,y;
  2980. int ii, iii;
  2981. int state;
  2982.  
  2983. for (i = 0; i < 8; i++)
  2984. {
  2985. if (direction == -1)
  2986. {
  2987. ii = i;
  2988. } else
  2989. {
  2990. ii = (7-i);
  2991. }
  2992.  
  2993.  
  2994. for (x = 0; x < 8; x++)
  2995. {
  2996. for (y = 0; y < 8; y++)
  2997. {
  2998. if (direction == -1)
  2999. {
  3000. iii = ii+1;
  3001. } else
  3002. {
  3003. iii = ii-1;
  3004. }
  3005.  
  3006. if (axis == AXIS_Z)
  3007. {
  3008. state = getvoxel(x,y,iii);
  3009. altervoxel(x,y,ii,state);
  3010. }
  3011.  
  3012. if (axis == AXIS_Y)
  3013. {
  3014. state = getvoxel(x,iii,y);
  3015. altervoxel(x,ii,y,state);
  3016. }
  3017.  
  3018. if (axis == AXIS_X)
  3019. {
  3020. state = getvoxel(iii,y,x);
  3021. altervoxel(ii,y,x,state);
  3022. }
  3023. }
  3024. }
  3025. }
  3026.  
  3027. if (direction == -1)
  3028. {
  3029. i = 7;
  3030. } else
  3031. {
  3032. i = 0;
  3033. }
  3034.  
  3035. for (x = 0; x < 8; x++)
  3036. {
  3037. for (y = 0; y < 8; y++)
  3038. {
  3039. if (axis == AXIS_Z)
  3040. clrvoxel(x,y,i);
  3041.  
  3042. if (axis == AXIS_Y)
  3043. clrvoxel(x,i,y);
  3044.  
  3045. if (axis == AXIS_X)
  3046. clrvoxel(i,y,x);
  3047. }
  3048. }
  3049. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement