# SmileyDrift: it smiles at you when you drift! # Date: 21-Aug-2013 # Filename: SmileyDrift.py # Install to: \apps\python\SmileyDrift\ import ac import acsys import math # Configuration, change these. # # Minimum time (in seconds) to hold a drift for it to be registered. Default: 0.5. SmileyShowTime = 0.5 # Minimum speed (in KMH) for a drift to be registered. Change to 0 to disable (ignores speed). Default: 50. DriftSpeedMin = 50 # Minimum drift angle (in degrees) to be registered. Default: 5. # Below SlipAngleMin = no drift. Above SlipAngleMin = ":)". SlipAngleMin = 5 # Medium drift angle (in degrees). Default: 15. # Below SlipAngleMid = ":)". Above SlipAngleMid = ":D". SlipAngleMid = 15 # High drift angle (in degrees). Default: 20. # Below SlipAngleHigh = ":D". Above SlipAngleHigh = ":O". SlipAngleHigh = 20 ### Code starts here, stay away! ### SmileyTimer = 0 SmileyText = 0 def acMain(ac_version): global SmileyText # Frame settings. appWindow = ac.newApp("SD") ac.setSize(appWindow, 120, 60) # Text settings. SmileyText = ac.addLabel(appWindow, ":|") ac.setPosition(SmileyText, 10, 30) ac.setFontAlignment(SmileyText, "center") ac.setSize(SmileyText, 100, 30) return "SmileyDrift" def acUpdate(deltaT): global SmileyText, SmileyTimer, SmileyShowTime, SlipAngleMin, SlipAngleMid, SlipAngleHigh # Smiley section. CurSpeed = ac.getCarState(0, acsys.CS.SpeedKMH) FL, FR, RL, RR = ac.getCarState(0, acsys.CS.SlipAngle) CurSlipAngle = math.fabs( round( (RL+RR)/2 ) ) if SmileyTimer > SmileyShowTime: if CurSpeed >= DriftSpeedMin or DriftSpeedMin < 1: if SlipAngleMin < CurSlipAngle < SlipAngleMid+1: ac.setText(SmileyText, ':)') elif SlipAngleMid < CurSlipAngle < SlipAngleHigh: ac.setText(SmileyText, ':D') elif CurSlipAngle >= SlipAngleHigh: ac.setText(SmileyText, ':O') else: ac.setText(SmileyText, ':|') SmileyTimer = 0 else: SmileyTimer += deltaT