Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <body>
- <input id="fg" type="button" value="Fussgaenger" align="top" onclick="fussgaenger();" >
- <input id="ns" type="button" value="Nebenstrasse" align="top" onclick="nebenstrasse();" >
- <input id="au" type="button" value="Automation" align="top" onclick="startautomation();" >
- <canvas id="canvas" width="600" height="400" style="border:1px solid #d3d3d3;">
- <script>
- // ---------Landschaft Gestaltung---------
- var canv=document.getElementById("canvas");
- var ctx = canv.getContext("2d");
- var active = false;
- var automationactive = false;
- ctx.fillStyle="green";
- ctx.fillRect(0,0,canv.width,canv.height);
- // Strasse
- ctx.beginPath();
- ctx.rect(0, 80, 600, 100);
- ctx.fillStyle = "gray";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(300, 80, 100, 520);
- ctx.fillStyle = "gray";
- ctx.fill();
- //Strassenlinien
- ctx.beginPath();
- ctx.rect(400, 130, 200, 5);
- ctx.fillStyle = "white";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(400, 85, 5, 45);
- ctx.fillStyle = "white";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(295, 130, 5, 45);
- ctx.fillStyle = "white";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(195, 130, 100, 5);
- ctx.fillStyle = "white";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(0, 130, 135, 5);
- ctx.fillStyle = "white";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(350, 180, 5, 420);
- ctx.fillStyle = "white";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(350, 180, 45, 5);
- ctx.fillStyle = "white";
- ctx.fill();
- // Fussgängerstreifen
- ctx.beginPath();
- ctx.rect(140, 85, 50, 10);
- ctx.fillStyle = "yellow";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(140, 105, 50, 10);
- ctx.fillStyle = "yellow";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(140, 125, 50, 10);
- ctx.fillStyle = "yellow";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(140, 145, 50, 10);
- ctx.fillStyle = "yellow";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(140, 165, 50, 10);
- ctx.fillStyle = "yellow";
- ctx.fill();
- //Ampeln
- //fussgänger unten
- ctx.beginPath();
- ctx.rect(155, 185, 20, 20);
- ctx.fillStyle = "red";
- ctx.fill();
- //fussgänger oben
- ctx.beginPath();
- ctx.rect(155, 55, 20, 20);
- ctx.fillStyle = "red";
- ctx.fill();
- //hauptstrasse unten
- ctx.beginPath();
- ctx.rect(260, 185, 20, 20);
- ctx.fillStyle = "lawngreen";
- ctx.fill();
- //hauptstrasse oben
- ctx.beginPath();
- ctx.rect(410, 55, 20, 20);
- ctx.fillStyle = "lawngreen";
- ctx.fill();
- //nebenstrasse
- ctx.beginPath();
- ctx.rect(410, 195, 20, 20);
- ctx.fillStyle = "red";
- ctx.fill();
- function fussgaenger() {
- if(active==false) {
- active==true;
- setTimeout(function(){
- ctx.beginPath();
- ctx.rect(260, 185, 20, 20);
- ctx.fillStyle = "chocolate";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(410, 55, 20, 20);
- ctx.fillStyle = "chocolate";
- ctx.fill();
- }, 2000);
- setTimeout(function(){
- ctx.beginPath();
- ctx.rect(260, 185, 20, 20);
- ctx.fillStyle = "red";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(410, 55, 20, 20);
- ctx.fillStyle = "red";
- ctx.fill();
- }, 5000);
- setTimeout(function(){
- ctx.beginPath();
- ctx.rect(155, 185, 20, 20);
- ctx.fillStyle = "lawngreen";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(155, 55, 20, 20);
- ctx.fillStyle = "lawngreen";
- ctx.fill();
- }, 7000);
- setTimeout(function(){
- ctx.beginPath();
- ctx.rect(155, 185, 20, 20);
- ctx.fillStyle = "red";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(155, 55, 20, 20);
- ctx.fillStyle = "red";
- ctx.fill();
- }, 15000);
- setTimeout(function(){
- ctx.beginPath();
- ctx.rect(260, 185, 20, 20);
- ctx.fillStyle = "chocolate";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(410, 55, 20, 20);
- ctx.fillStyle = "chocolate";
- ctx.fill();
- }, 18000);
- setTimeout(function(){
- ctx.beginPath();
- ctx.rect(260, 185, 20, 20);
- ctx.fillStyle = "lawngreen";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(410, 55, 20, 20);
- ctx.fillStyle = "lawngreen";
- ctx.fill();
- active=false;
- }, 20000);
- }
- }
- function nebenstrasse() {
- if(active==false) {
- active==true;
- setTimeout(function(){
- ctx.beginPath();
- ctx.rect(260, 185, 20, 20);
- ctx.fillStyle = "chocolate";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(410, 55, 20, 20);
- ctx.fillStyle = "chocolate";
- ctx.fill();
- }, 2000);
- setTimeout(function(){
- ctx.beginPath();
- ctx.rect(260, 185, 20, 20);
- ctx.fillStyle = "red";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(410, 55, 20, 20);
- ctx.fillStyle = "red";
- ctx.fill();
- }, 5000);
- setTimeout(function(){
- ctx.beginPath();
- ctx.rect(410, 195, 20, 20);
- ctx.fillStyle = "chocolate";
- ctx.fill();
- }, 7000);
- setTimeout(function(){
- ctx.beginPath();
- ctx.rect(410, 195, 20, 20);
- ctx.fillStyle = "lawngreen";
- ctx.fill();
- }, 9000);
- setTimeout(function(){
- ctx.beginPath();
- ctx.rect(410, 195, 20, 20);
- ctx.fillStyle = "chocolate";
- ctx.fill();
- }, 17000);
- setTimeout(function(){
- ctx.beginPath();
- ctx.rect(410, 195, 20, 20);
- ctx.fillStyle = "red";
- ctx.fill();
- }, 19000);
- setTimeout(function(){
- ctx.beginPath();
- ctx.rect(260, 185, 20, 20);
- ctx.fillStyle = "chocolate";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(410, 55, 20, 20);
- ctx.fillStyle = "chocolate";
- ctx.fill();
- }, 22000);
- setTimeout(function(){
- ctx.beginPath();
- ctx.rect(260, 185, 20, 20);
- ctx.fillStyle = "lawngreen";
- ctx.fill();
- ctx.beginPath();
- ctx.rect(410, 55, 20, 20);
- ctx.fillStyle = "lawngreen";
- ctx.fill();
- active=false;
- }, 24000);
- }
- }
- function automation() {
- fussgaenger();
- setTimeout(function(){
- nebenstrasse();
- }, 35000);
- }
- function startautomation() {
- automation()
- setInterval(automation, 67000);
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement