Exponential increase of integers
in
Programming Questions
•
2 years ago
I am working on a car dashboard simulator, I have it working alright, but it is not realistic as the tachometer is a steady speed all the way from 0-100k rpms, is there any way to have it start slow but then slowly pick up speed, same thing with the speedometer as you change gears with the arrow keys
//Dashboard
//_________________________________________________
PFont letters;
PFont numbers;
PFont fast;
PFont gears;
int faceX=125;
int faceY=220;
int speedoX=340;
int speedoY=220;
int gearDisplayX=faceX;
int gearDisplayY=faceY+70;
int shiftLightX=faceX-95;
int shiftLightY=faceY-80;
int rpm=0;
int speed=0;
int gear=0;
TachGauge tach;
SpeedoGauge speedo;
void setup() {
size(450, 360);
smooth();
rectMode(CENTER);
frameRate(60);
letters = loadFont("SansSerif-10.vlw");
numbers = loadFont("SansSerif-20.vlw");
fast = loadFont("SansSerif-15.vlw");
gears = loadFont("Radioland-36.vlw");
tach = new TachGauge();
speedo= new SpeedoGauge();
}
void draw() {
PImage carbonFiber;
carbonFiber = loadImage("wallpaper.jpg");
background(carbonFiber);
noStroke();
smooth();
tach.display();
speedo.display();
//Dashes
int dash=99;
while (dash<=135) {
fill(255);
pushMatrix();
translate(faceX, faceY);
rotate(radians(dash*5));
rect(93, 0, 15, 2);
popMatrix();
dash++;
}
int speedoDash=122;
while (speedoDash<=151) {
fill(255);
pushMatrix();
translate(speedoX, speedoY);
rotate(radians(speedoDash*10));
rect(93, 0, 15, 2);
popMatrix();
speedoDash++;
}
//Raised Dashes
int raised=135;
while (raised<=142) {
fill(255);
pushMatrix();
translate(faceX, faceY);
rotate(radians(raised*25));
rect(90, 0, 20, 2);
popMatrix();
raised++;
}
int raisedSpeedo=133;
while (raisedSpeedo<=148) {
fill(255);
pushMatrix();
translate(speedoX, speedoY);
rotate(radians(raisedSpeedo *20));
rect(90, 0, 20, 2);
popMatrix();
raisedSpeedo++;
}
//Red Dashes
int rDashes=64;
while (rDashes<=70) {
fill(255,0,0);
pushMatrix();
translate(faceX, faceY);
rotate(radians(rDashes*5));
rect(93, 0, 15, 2);
popMatrix();
rDashes++;
}
//Raised Red Dashes
int raisedRed=215;
while (raisedRed<=215) {
fill(255,0,0);
pushMatrix();
translate(faceX, faceY);
rotate(radians(raisedRed*25));
rect(90, 0, 20, 2);
popMatrix();
raisedRed++;
}
//Solid Line
int solid=175;
while (solid<=195) {
fill(255,0,0);
pushMatrix();
translate(faceX, faceY);
rotate(radians(solid*2));
rect(93, 0, 20, 4);
popMatrix();
solid++;
}
//Numbers
textFont(letters);
fill(255);
String s = "x1000";
text(s,faceX-16,faceY+45);
textFont(letters);
fill(255);
String r = "RPM";
text(r,faceX-11,faceY+30);
textFont(numbers);
fill(255);
String a = "0";
text(a,faceX-57,faceY+56);
textFont(numbers);
fill(255);
String one = "1";
text(one,faceX-74,faceY+33);
textFont(numbers);
fill(255);
String two = "2";
text(two,faceX-77,faceY);
textFont(numbers);
fill(255);
String three = "3";
text(three,faceX-67,faceY-29);
textFont(numbers);
fill(255);
String four = "4";
text(four,faceX-47,faceY-52);
textFont(numbers);
fill(255);
String five = "5";
text(five,faceX-17,faceY-60);
textFont(numbers);
fill(255);
String six = "6";
text(six,faceX+12,faceY-57);
textFont(numbers);
fill(255);
String seven = "7";
text(seven,faceX+38,faceY-42);
textFont(numbers);
fill(255,0,0);
String eight = "8";
text(eight,faceX+58,faceY-22);
textFont(numbers);
fill(255,0,0);
String nine = "9";
text(nine,faceX+65,faceY+7);
textFont(numbers);
fill(255,0,0);
String onezero = "10";
text(onezero,faceX+45,faceY+37);
textFont(letters);
fill(255);
String mph = "MPH";
text(mph,speedoX-11,speedoY+30);
textFont(fast);
fill(255);
String zero = "0";
text(zero,speedoX-59,speedoY+51);
textFont(fast);
fill(255);
String ten = "10";
text(ten,speedoX-73,speedoY+30);
textFont(fast);
fill(255);
String twenty = "20";
text(twenty,speedoX-77,speedoY+5);
textFont(fast);
fill(255);
String thirty = "30";
text(thirty,speedoX-72,speedoY-21);
textFont(fast);
fill(255);
String fourty = "40";
text(fourty,speedoX-60,speedoY-40);
textFont(fast);
fill(255);
String fifty = "50";
text(fifty,speedoX-43,speedoY-54);
textFont(fast);
fill(255);
String sixty = "60";
text(sixty,speedoX-21,speedoY-64);
textFont(fast);
fill(255);
String seventy = "70";
text(seventy,speedoX+3,speedoY-64);
textFont(fast);
fill(255);
String eighty = "80";
text(eighty,speedoX+27,speedoY-54);
textFont(fast);
fill(255);
String ninety = "90";
text(ninety,speedoX+43,speedoY-38);
textFont(fast);
fill(255);
String hundred = "100";
text(hundred,speedoX+45,speedoY-17);
textFont(fast);
fill(255);
String hundredten = "110";
text(hundredten,speedoX+49,speedoY+5);
textFont(fast);
fill(255);
String hundredtwenty = "120";
text(hundredtwenty,speedoX+45,speedoY+25);
textFont(fast);
fill(255);
String hundredthirty = "130";
text(hundredthirty,speedoX+37,speedoY+44);
textFont(fast);
fill(255);
String hundredfourty = "140";
text(hundredfourty,speedoX+20,speedoY+60);
textFont(fast);
fill(255);
String hundredfifty = "150";
text(hundredfifty,speedoX+2,speedoY+75);
//Shifter Light Rim
fill(100);
ellipse(shiftLightX,shiftLightY,60,60);
//Shifter Light
fill(50,0,0);
ellipse(shiftLightX,shiftLightY,50,50);
noStroke();
if(rpm>175&&rpm<212) {
fill(0,0,255);
ellipse(shiftLightX,shiftLightY,50,50);
fill(0,0,255,100);
ellipse(shiftLightX,shiftLightY,60,60);
}
else if(rpm>212&&rpm<230 ) {
fill(0,255,0);
ellipse(shiftLightX,shiftLightY,50,50);
fill(0,255,0,100);
ellipse(shiftLightX,shiftLightY,60,60);
}
else if (rpm>230) {
fill(255,0,0);
ellipse(shiftLightX,shiftLightY,50,50);
fill(225,0,0,100);
ellipse(shiftLightX,shiftLightY,60,60);
}
//Gear Display Rim
fill(100);
rect(gearDisplayX,gearDisplayY,65,45);
//Gear Display Screen
fill(0);
rect(gearDisplayX,gearDisplayY,60,40);
textFont(gears);
//Number
fill(0,255,0);
if (gear ==-1) {
text('R',gearDisplayX-15,gearDisplayY+17);
}
else if (gear==0) {
text('N',gearDisplayX-15,gearDisplayY+17);
}
else {
text(gear,gearDisplayX-15,gearDisplayY+17);
}
if (keyPressed) {
if (key==' ') {
if(rpm<270) {
if(gear<=1) {
rpm=rpm+7;
}
else if(gear==2) {
rpm=rpm+6;
}
else if(gear==3) {
rpm=rpm+4;
}
else if(gear==4) {
rpm=rpm+3;
}
else if (gear==5) {
rpm=rpm+2;
}
else if (gear==6) {
rpm=rpm+1;
}
}
}
}
else {
if(rpm>1) {
rpm=rpm-9;
}
}
if (keyPressed) {
if (key==' ') {
if(speed<300) {
if (gear!=0) {
speed=speed+2;
}
else if(gear==2) {
speed=speed+1 ;
}
else if(gear==3) {
speed=speed+1;
}
else if(gear==4) {
speed=speed+2;
}
else if (gear==5) {
speed=speed+2;
}
else if (gear==6) {
speed=speed+2;
}
}
}
}
else {
if(speed>0) {
speed=speed-2 ;
}
}
}
// Gear Displayed On Screen
void keyReleased() {
if(key==CODED) {
if(keyCode==UP){
gear=gear+1;
}
if(key==CODED) {
if(keyCode==DOWN) {
gear=gear-1;
}
}
else {
gear=0;
}
}
gear= constrain(gear,-1,6);
}
//Tach
class TachGauge {
int tachgaugeX;
int tachgaugeY;
color r;
color f;
color n;
TachGauge() {
r = color(100);
f = color (0) ;
n = color(255,0,0);
tachgaugeX=125;
tachgaugeY=220;
}
void display(){
//Gauge Rim
fill(r);
ellipse(tachgaugeX,tachgaugeY,215,215);
//Gauge
fill(f);
ellipse(tachgaugeX,tachgaugeY,205,205);
//Needle
pushMatrix();
fill(n);
ellipse(tachgaugeX,tachgaugeY,21,21);
fill(n);
strokeWeight(4);
translate(tachgaugeX,tachgaugeY);
rotate(radians(rpm));
quad(0,0,0,-9,-62,62,9,0);
println(rpm);
translate(-tachgaugeX,-tachgaugeY);
popMatrix();
}
}
//Speedo
class SpeedoGauge {
int speedogaugeX;
int speedogaugeY;
color r;
color f;
color n;
SpeedoGauge() {
r = color(100);
f = color (0) ;
n = color(255,0,0);
speedogaugeX=340;
speedogaugeY=220;
}
void display(){
//Gauge Rim
fill(r);
ellipse(speedogaugeX,speedogaugeY,215,215);
//Gauge
fill(f);
ellipse(speedogaugeX,speedogaugeY,205,205);
//Needle
pushMatrix();
fill(n);
ellipse(speedogaugeX,speedogaugeY,21,21);
fill(n);
strokeWeight(4);
translate(speedogaugeX,speedogaugeY);
rotate(radians(speed));
quad(0,0,0,-9,-67,57,9,0);
println(speed);
translate(-speedogaugeX,-speedogaugeY);
popMatrix();
}
}
1