Skip to content

Instantly share code, notes, and snippets.

@shallaa
Created January 5, 2014 07:56
Show Gist options
  • Save shallaa/8265625 to your computer and use it in GitHub Desktop.
Save shallaa/8265625 to your computer and use it in GitHub Desktop.
iAngleFinder
function setup()
displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_RIGHT)
bigNumbers = {"", "80", "70", "60", "50", "40", "30", "20", "10", "0",
"10", "20", "30", "40", "50", "60", "70", "80", ""}
smallNumbers = {"", "10", "20", "30", "40", "50", "60", "70", "80", "90",
"80", "70", "60", "50", "40", "30", "20", "10", ""}
end
function getAngleText(num)
if num < 10 then
return "0" .. num
else
return "" .. num
end
end
function draw()
background(0, 0, 0, 255)
stroke(255, 255, 255, 255)
strokeWidth(5)
noFill()
font("Futura-CondensedExtraBold")
lineCapMode(SQUARE)
translate(WIDTH * 0.5, 0)
ellipse(0,0,WIDTH,WIDTH)
ellipse(0,0,WIDTH - 300, WIDTH - 300)
radius = WIDTH * 0.5
smallRadius = (WIDTH - 300) * 0.5
fill(255, 255, 255, 255)
grav = vec2(Gravity.x * 300, Gravity.y * 300)
down = vec2(1, 0)
angle = down:angleBetween(grav)
cAngle = math.deg( angle )
if cAngle < -180 then
cAngle = -180
lineBlack = true
elseif cAngle > 0 then
cAngle = 0
lineBlack = true
else
lineBlack = false
end
txtAngle = math.abs( cAngle )
if txtAngle < 90 then
txtAngle = 90 - txtAngle
elseif txtAngle > 90 then
txtAngle = txtAngle - 90
else
txtAngle = 0
end
txtAngle = math.floor(txtAngle + 0.5)
fontSize( math.floor( smallRadius * 0.4 ) )
text( getAngleText( txtAngle ), 0, smallRadius * 0.5)
rotate(-90)
bigIndex = 1
smallIndex = 1
for i = 0, 180 do
if i % 10 == 0 then
lineStart = radius - 50
line(0, smallRadius, 0, smallRadius + 20)
fontSize(20)
text(bigNumbers[bigIndex], 0, radius - 60)
fontSize(15)
text(smallNumbers[smallIndex], 0, smallRadius + 30)
bigIndex = bigIndex + 1
smallIndex = smallIndex + 1
elseif i % 5 == 0 then
lineStart = radius - 40
line(0, smallRadius, 0, smallRadius + 20)
else
lineStart = radius - 30
end
line(0,lineStart,0,radius - 8)
rotate(1)
end
fill(255, 0, 0, 255)
noStroke()
ellipse(0,0,50,50)
rotate(-1)
rotate( cAngle )
stroke(255, 0, 0, 255)
strokeWidth(6)
if lineBlack == false then
line(0,0,0,radius)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment