【HtmlC++MatlabPython】那些调皮有灵魂的代码

11 篇文章 7 订阅
9 篇文章 8 订阅

html心形。

<!DOCTYPE html>
<html>
<head>
	<title></title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<script type = "text/javascript">
		var limit = 300;
		var unit = 200;//心形线单位一
		var width = 800,
			height = 600;
		var ctx = null;
		var balls = [];
		var side = [];
		function inHeart(b){
			//(x ^ 2 +y^ 2 - 1) - x ^ 2 * y ^ 3 == 0,心形函数
			var x = b.x / unit;
			var y = -b.y / unit;//因为坐标y轴是向下的
			var part = x * x + y * y - 1;
			return (part * part * part < x * x * y * y * y);
		}
 
		function randomColor(){
			var x = Math.floor(Math.random() * 155) + 100;
			var y = Math.floor(Math.random() * 155) + 100; 
			var z = Math.floor(Math.random() * 155) + 100;
			return "rgb(" + x + "," + y + "," + z + ")";
		}
 
		function createBall(){
			return {
				x : (Math.random() - Math.random()) * width * 0.1,
				y : (Math.random() - Math.random()) * height * 0.2 - height * 0.1,
				vx : (Math.random() - Math.random()) * 7,
				vy : (Math.random() - Math.random()) * 7,
				r : Math.random() * 5,
				color : randomColor()
			}
		}
 
		function init(){
			var cvs = document.createElement("canvas");
			cvs.width = width;
			cvs.height = height;
			ctx = cvs.getContext("2d");
 
			ctx.translate(width / 2, height / 2);
 
			document.body.appendChild(cvs);
 
			for(i = 0; i < limit; i++){
				balls.push(createBall());
			}
			for(i = 0; i < limit / 5; i++){
				side.push(undefined);
			}
		}
 
		function drawBall(ctx, ball){
			ctx.fillStyle = ball.color;
			ctx.beginPath();
			ctx.arc(ball.x, ball.y, ball.r, 0, Math.PI * 2, false);
			ctx.closePath();
			ctx.fill();
		}
 
		function start(){
			document.body.removeChild(document.getElementById("start"));
 
			setInterval(function(){
				ctx.fillStyle = "rgba(0, 0, 0, 0.3)";
				ctx.fillRect(-width / 2, -height / 2, width, height);
				for(i in balls){
					var b = balls[i];
					drawBall(ctx, b);
					b.x += b.vx;
					b.y += b.vy;
					if(!inHeart(b)){
						side[Math.floor(Math.random() * side.length)] = balls[i];
						balls[i] = createBall();
					}
				}
 
				for(var i in side){
					var b = side[i];
					if(b != undefined){
						drawBall(ctx, b);
					}
				}
			}, 33);
		}
	</script>
</head>
<body onload = "init();">
	<button id = "start" onclick = "start();">click me!</button>
	<br />
</body>
</html>

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
作为AI助手,我可以为您提供一些关于使用HTML、CSS、JS进行前端登录和使用Python做后端的基本信息。 1. HTML、CSS、JS登录 HTML、CSS、JS是用于Web开发的三种基础语言,其中HTML用于定义Web页面的内容结构,CSS用于定义页面的样式和布局,JS则用于实现页面的交互效果和动态效果。 在Web开发中,登录功能是非常常见的一个功能,下面是一个使用HTML、CSS、JS实现登录的示例: HTML代码: ```html <form> <label for="username">用户名:</label> <input type="text" id="username" name="username"><br><br> <label for="password">密码:</label> <input type="password" id="password" name="password"><br><br> <input type="button" value="登录" onclick="login()"> </form> ``` CSS代码: ```css form { width: 300px; margin: 0 auto; text-align: center; } label { display: inline-block; width: 80px; text-align: right; } input[type="text"], input[type="password"] { width: 150px; height: 20px; margin: 5px; padding: 5px; border-radius: 5px; border: 1px solid #ccc; } input[type="button"] { width: 100px; height: 30px; margin-top: 10px; border-radius: 5px; border: none; background-color: #007acc; color: #fff; } input[type="button"]:hover { background-color: #005c99; cursor: pointer; } ``` JS代码: ```javascript function login() { var username = document.getElementById("username").value; var password = document.getElementById("password").value; if (username == "admin" && password == "123456") { alert("登录成功!"); } else { alert("用户名或密码错误!"); } } ``` 2. Python做后端 Python是一种高级编程语言,广泛用于Web开发、数据分析、人工智能等领域。在Web开发中,Python可以用于实现后端服务,处理前端发送的请求并返回相应的数据。 下面是一个使用Python实现登录功能的示例: Python代码: ```python from flask import Flask, request, jsonify app = Flask(__name__) @app.route("/login", methods=["POST"]) def login(): username = request.form["username"] password = request.form["password"] if username == "admin" and password == "123456": return jsonify({"code": 200, "msg": "登录成功!"}) else: return jsonify({"code": 400, "msg": "用户名或密码错误!"}) if __name__ == "__main__": app.run() ``` 在这个例子中,我们使用了Flask框架来实现后端服务,定义了一个/login接口,并在接口中处理了前端发送的请求,判断用户名和密码是否正确,并返回相应的信息。通过这种方式,前端和后端可以实现数据的交互和处理,从而实现完整的Web应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值