Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function setup()
- displayMode(FULLSCREEN)
- --creating random table
- --you can also set custome table with tbl={num1,num2...}
- tbl={}
- for i=0,25 do
- table.insert(tbl,math.random(0,100))
- end
- --setting temp var for comparison
- --set to the first value in the table
- max=tbl[1]
- min=tbl[1]
- --initializing line position
- lmn=1
- lmx=1
- --finds max value
- --compares every instance to max
- --if it is bigger, change var max
- for i=2, #tbl do
- if tbl[i]>max then
- max=tbl[i]
- lmx=i
- end
- end
- --finds min value
- for i=2, #tbl do
- if tbl[i]<min then
- min=tbl[i]
- lmn=i
- end
- end
- end
- function draw()
- --setting draw values
- background(0, 0, 0, 255)
- textAlign(CENTER)
- strokeWidth(2)
- --draw the table centered
- for i=1, #tbl do
- fill(255,255,255,tbl[i]*2)
- rect(WIDTH/2-(#tbl*30)/2+i*30-15,HEIGHT/2-tbl[i],30,tbl[i]*2)
- fill(255,255,255,255)
- text(tbl[i],WIDTH/2-(#tbl*30)/2+i*30,HEIGHT/2)
- end
- --draw min/max values and lines
- fill(255,255,255,255)
- stroke(255,255,255,255)
- text(max,WIDTH/2,HEIGHT/2+150)
- line(WIDTH/2-(#tbl*30)/2+lmx*30,HEIGHT/2+max,WIDTH/2,HEIGHT/2+140)
- text(min,WIDTH/2,HEIGHT/2-150)
- line(WIDTH/2-(#tbl*30)/2+lmn*30,HEIGHT/2-10-min,WIDTH/2,HEIGHT/2-140)
- fill(255, 255, 255, 255)
- text("Touch to run again",WIDTH/2,HEIGHT-20)
- end
- function touched(touch)
- --touch to run again
- if touch.state==BEGAN then
- setup()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement