Deleted? -> forum.processing.org/topic/traffic-light-functions-help
in
Programming Questions
•
8 months ago
Seems like
stephenoconnor may have deleted his own post.
Anyways, here's his code using parameters to function drawTrafficLight() :
Anyways, here's his code using parameters to function drawTrafficLight() :
/** * Traffic Light (v3.0) * by Stephen o'Connor (2013/Jan) * * http://forum.processing.org/topic/traffic-light-functions-help */ PImage bg; void setup() { size(700, 550); smooth(); frameRate(50); rectMode(CORNER); imageMode(CORNER); background(0); bg = loadImage("background.png"); // Street background image image(bg, 0, 0, width, height); fill(50); // Colour of traffic light pole/hanger rect(200, 125, width-50, 40); // Position of traffic light pole/hanger rectMode(CENTER); ellipseMode(CENTER); fill(242, 201, 0); // Traffic light box colour rect(350, 225, 125, 275); // Position of traffic light box drawTrafficLight( 350, 140, 75, color(90, 25, 15) ); // Unlit red stop light drawTrafficLight( 350, 225, 75, color(40, 30, 10) ); // Unlit yellow stop light drawTrafficLight( 350, 310, 75, color(0, 0100, 0) ); // Unlit green stop light bg = get(); // Store reference to current canvas buffer } void draw() { background(bg); turnLightOn(); } void turnLightOn() { if (mouseX > 312 && mouseX < 388 && mouseY > 102 && mouseY < 178) drawTrafficLight( 350, 140, 75, color(240, 20, 10) ); // Lit red stop light else if (mouseX > 312 && mouseX < 388 && mouseY > 187 && mouseY < 263) drawTrafficLight( 350, 225, 75, color(225, 250, 5) ); // Lit green stop light else if (mouseX > 312 && mouseX < 388 && mouseY > 272 && mouseY < 348) drawTrafficLight( 350, 310, 75, color(55, 255, 20) ); // Lit blue stop light } void drawTrafficLight(int x, int y, int sz, color colour) { fill(colour); // Unlit stop light ellipse(x, y, sz, sz); // Position of stop light }
1