87,993
社区成员
发帖
与我相关
我的任务
分享
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Gridlab-d PowerFlow Simulator</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
span{
cursor:pointer;
color: #dffaff;
font-style: oblique;
}
button{
font-size: large;
font-style: oblique;
}
</style>
</head>
<body style="background: #dee0f1">
<div class = "col-md-5 col-md-offset-5" id="header">
<h1 style="color: #6d81b6"> power flow</h1>
</div>
<button id = "btn"type="button" class="btn btn-primary btn-lg btn-block">Run</button>
<canvas id = "myCanvas" class="myCanvas" width="1270" height="600" style="border:1px solid #767784; " >
<input type="text">
</canvas>
</body>
</html>
<script>
var c=document.getElementById("myCanvas");
var cxt=c.getContext("2d");
var button = document.getElementById('btn');
// var gen = new Image(); // 创建一个img元素
// gen.src = './images/generator.png'; // 设置图片源地址
// cxt.globalCompositeOperation='destination-over';
// cxt.beginPath();
// gen.onload = function () {//将图片放入canvas
// cxt.drawImage(gen,100-75,300-75);
// }
//
// var bus = new Image(); // 创建一个img元素
// bus.src = './images/bus.png'; // 设置图片源地址
// cxt.globalCompositeOperation='destination-over';
// cxt.beginPath();
// bus.onload = function () {//将图片放入canvas
// cxt.drawImage(bus,100-75+150,300-75);
// cxt.drawImage(bus,100-75+150*3,300-75);
// cxt.drawImage(bus,100-75+150*5,300-75);
// }
//
// var line = new Image(); // 创建一个img元素
// line.src = './images/line.png'; // 设置图片源地址
// cxt.globalCompositeOperation='destination-over';
// cxt.beginPath();
// line.onload = function () {//将图片放入canvas
// cxt.drawImage(line,100-75+150*2,300-75);
// }
//
// var tran = new Image(); // 创建一个img元素
// tran.src = './images/transformer.png'; // 设置图片源地址
// cxt.globalCompositeOperation='destination-over';
// cxt.beginPath();
// tran.onload = function () {//将图片放入canvas
// cxt.drawImage(tran,100-75+150*4,300-75);
// }
//
// var load = new Image(); // 创建一个img元素
// load.src = './images/load.png'; // 设置图片源地址
// cxt.globalCompositeOperation='destination-over';
// cxt.beginPath();
// load.onload = function () {//将图片放入canvas
// cxt.drawImage(load,50-25+150*6,300-25);
// }
button.onclick=function fillC(){
var gen = new Image(); // 创建一个img元素
gen.src = './images/generator.png'; // 设置图片源地址
cxt.globalCompositeOperation='destination-over';
cxt.beginPath();
gen.onload = function () {//将图片放入canvas
cxt.drawImage(gen,100-75,300-75);
}
var bus = new Image(); // 创建一个img元素
bus.src = './images/bus.png'; // 设置图片源地址
cxt.globalCompositeOperation='destination-over';
cxt.beginPath();
bus.onload = function () {//将图片放入canvas
cxt.drawImage(bus,100-75+150,300-75);
cxt.drawImage(bus,100-75+150*3,300-75);
cxt.drawImage(bus,100-75+150*5,300-75);
}
var line = new Image(); // 创建一个img元素
line.src = './images/line.png'; // 设置图片源地址
cxt.globalCompositeOperation='destination-over';
cxt.beginPath();
line.onload = function () {//将图片放入canvas
cxt.drawImage(line,100-75+150*2,300-75);
}
var tran = new Image(); // 创建一个img元素
tran.src = './images/transformer.png'; // 设置图片源地址
cxt.globalCompositeOperation='destination-over';
cxt.beginPath();
tran.onload = function () {//将图片放入canvas
cxt.drawImage(tran,100-75+150*4,300-75);
}
var load = new Image(); // 创建一个img元素
load.src = './images/load.png'; // 设置图片源地址
cxt.globalCompositeOperation='destination-over';
cxt.beginPath();
load.onload = function () {//将图片放入canvas
cxt.drawImage(load,50-25+150*6,300-25);
}
gradient(100+150,300);
gradient(100+150*3,300);
gradient(100+150*5,300);
cxt.globalCompositeOperation='destination-over';
cxt.fillStyle = 'rgba(0,255,0,0.5)';
cxt.fillRect(0,0,1270,600);/*绘制一个矩形,前两个参数决定开始位置,后两个分别是矩形的宽和高*/
}
function gradient(x,y){
var cInput = document.createElement('input');
var cP = document.createElement('span');
var body = document.getElementsByTagName('body')[0];
body.appendChild(cInput);
body.appendChild(cP);
cP.innerHTML = 'RUN';
cInput.style.position="absolute";
cInput.style.width=50+'px';
cInput.style.left = x+'px';
cInput.style.top = y-20-50+'px';
cP.style.position="absolute";
cP.style.width=50+'px';
cP.style.left = x+60+'px';
cP.style.top = y-20-50+'px';
cxt.beginPath();
cxt.fillStyle= 'rgba(0,255,0,0)';
//画圆
cxt.arc(x,y,200,0,Math.PI*2,true);
cxt.fill();
// //闭合路径
cxt.closePath();
var inside = '';
cP.onclick = function(){
inside = cInput.value;
//颜色环
var colorOne = '';
var colorTwo = '';
var colorThree = '';
var colorFour = '';
if(inside<=0.95){
colorOne = '#ff0000';
colorTwo = '#ffaa00';
colorThree = '#ffff00';
colorFour = '#aaff00';
}
if(0.95<inside && inside<0.97){
colorOne = '#ffaa00';
colorTwo = '#ffff00';
colorThree = '#aaff00';
colorFour = '#00ff00';
}
if(0.97<=inside && inside<0.99){
colorOne = '#ffff00';
colorTwo = '#aaff00';
colorThree = '#00ff00';
colorFour = '#00ff00';
}
if(0.99<=inside && inside<=1.01){
colorOne = '#00ff00';
colorTwo = '#00ff00';
colorThree = '#00ff00';
colorFour = '#00ff00';
}
if(1.01<inside && inside<=1.03){
colorOne = '#00ffff';
colorTwo = '#00ffaa';
colorThree = '#00ff00';
colorFour = '#00ff00';
}
if(1.03<inside && inside<1.05){
colorOne = '#00aaff';
colorTwo = '#00ffff';
colorThree = '#00ffaa';
colorFour = '#00ff00';
}
if(inside>=1.05){
colorOne = '#0000ff';
colorTwo = '#00aaff';
colorThree = '#00ffff';
colorFour = '#00ffaa';
}
var grd=cxt.createRadialGradient(x,y,60,x,y,150);
grd.addColorStop(0,colorOne);
grd.addColorStop(0.3,colorTwo);
grd.addColorStop(0.6,colorThree);
grd.addColorStop(0.9,colorFour);
grd.addColorStop(1,'#00ff00');
//开启路径
cxt.beginPath();
cxt.fillStyle=grd;
//画圆
cxt.arc(x,y,200,0,Math.PI*2,true);
cxt.fill();
// //闭合路径
cxt.closePath();
}
}
// gradient(100+150,300);
// gradient(100+150*3,300);
// gradient(100+150*5,300);
</script>