Skip to content

Commit a3bf6dd

Browse files
committed
Added parallax compression sample
1 parent 0b76b9b commit a3bf6dd

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

samples/index.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ color 15,0
1616
print cat(3) + "SmallBASIC featured samples" + cat(0)
1717

1818
dim frm
19+
frm.inputs << bn("5002", "Parallax Compression")
1920
frm.inputs << bn("5000", "[Android] Stopit")
2021
frm.inputs << bn("5001", "[Android] Silly words")
2122
frm.inputs << bn("1407", "3d rotating cube with message [harixxx]") 'nice one harixxx!

samples/node/5002.bas

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'http://www.gibney.de/parallax_primes
2+
'https://news.ycombinator.com/item?id=17103157
3+
4+
packSize = 10 ' Number of integers per cell
5+
const cellSize = 8
6+
7+
func isPrime(n)
8+
local s = sqr(n)
9+
local i = 2
10+
while i <= s
11+
if (n % i == 0) then return false
12+
i++
13+
wend
14+
return n > 1
15+
end
16+
17+
func packHasPrimes(num, y)
18+
local i
19+
for i = 0 to packSize
20+
if (isPrime(num)) then return true
21+
num += y
22+
next i
23+
return false
24+
end
25+
26+
sub drawPattern
27+
local black = rgb(0,20,0)
28+
local red = rgb(120,0,0)
29+
local x, y, col, x1, y1
30+
local curNum = 1
31+
32+
for y = 1 to 80
33+
for x = 0 to y
34+
col = iff(packHasPrimes(curNum + x, y), black, red)
35+
x1 = xmax / 2 + (x * cellSize) - (y * cellSize / 2)
36+
y1 = (y * cellSize)
37+
rect x1, y1, x1 + cellSize, y1 + cellSize, col filled
38+
next x
39+
curNum += packSize * y
40+
next y
41+
end
42+
43+
color 1,rgb(40,50,0): cls
44+
for packSize = 1 to 50
45+
drawPattern
46+
showpage
47+
delay 100
48+
next
49+
pause

0 commit comments

Comments
 (0)