C语言的浪漫

宝,过七夕了

环境:对象、centos7vim/vi编辑器写C语言
刚刚逛街遇到一个美丽的爱心,然后就想起了你们。
在这里插入图片描述
源代码

#include <stdio.h>
#include <math.h>
#include <stdio.h>

int main()
{
    float y, x, z, f;
    for (y = 1.5f; y > -1.5f; y-=0.1f)
    {
        for (x = -1.5f; x < 1.5f; x += 0.05f)
        {
            z = x*x + y*y -1;
            f = z*z*z - x*x*y*y*y;
            putchar(f <= 0.0f ? "**-*-*-*"[(int)(f*-8.0f)]:' ');
        }
        putchar('\n');
    }

    getchar();
    return 0;
}

我也刚刚学C,就不跟你们解释代码了哈哈哈。
PS:祝有钱人终成眷属
在这里插入图片描述

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
vs2017环境下成功编译,vc6.0编译不通过 #include "stdafx.h" #include #include #include #include // 使用该计时器必须包含的文件 #pragma comment ( lib, "Winmm.lib" ) using namespace std; #define LONG 800 // 窗口长 #define WIDE 500 // 窗口宽 #define NUM 13 // 烟花种类数量宏定义 void Init_Fire(); // 初始化烟花 void Load_Image(); // 加载烟花图片 void Shoot(); // 发射烟花 void Chose(DWORD& t1); // 筛选烟花 void Show(DWORD* pMem); // 绽放烟花 void Erase(DWORD* pMem); // 随机擦除像素点 // 烟花结构 struct FIRE { int r; // 当前爆炸半径 int max_r; // 爆炸中心距离边缘最大半径 int x, y; // 爆炸中心在窗口的坐标 int cen_x, cen_y; // 爆炸中心相对图片左上角的坐标 int width, height; // 图片的宽高 int xy[240][240]; // 储存图片像素点 bool show; // 是否绽放 bool draw; // 开始输出像素点 DWORD t1, t2, dt; // 绽放速度 }Fire[NUM]; // 烟花弹结构 struct JET { int x, y; // 喷射点坐标 int hx, hy; // 最高点坐标------将赋值给 FIRE 里面的 x, y int height; // 烟花高度 bool shoot; // 是否可以发射 DWORD t1, t2, dt; // 发射速度 IMAGE img[2]; // 储存花弹一亮一暗图片 byte n : 1; // 图片下标 }Jet[NUM]; // 初始化烟花参数 void Init_Fire() { // 分别为:烟花中心到图片边缘的最远距离、烟花中心到图片左上角的距离 (x、y) 两个分量 int r[13] = { 120, 120, 155, 123, 130, 147, 138, 138, 130, 135, 140, 132, 155 }; int x[13] = { 120, 120, 110, 117, 110, 93, 102, 102, 110, 105, 100, 108, 110 }; int y[13] = { 120, 120, 85, 118, 120, 103, 105, 110, 110, 120, 120, 104, 85 }; for (int i = 0; i < NUM; i++) // 初始化烟花 { Fire[i].x = 0; // 烟花中心坐标 Fire[i].y = 0; Fire[i].width = 240; // 图片宽 Fire[i].height = 240; // 图片高 Fire[i].max_r = r[i]; // 最大半径 Fire[i].cen_x = x[i]; // 中心距左上角距离 Fire[i].cen_y = y[i]; Fire[i].show = false; // 是否绽放 Fire[i].dt = 5; // 绽放时间间隔 Fire[i].t1 = timeGetTime(); Fire[i].r = 0; // 从 0 开始绽放 Jet[i].x = -240; // 烟花弹左上角坐标 Jet[i].y = -240; Jet[i].hx = -240; // 烟花弹发射最高点坐标 Jet[i].hy = -240; Jet[i].height = 0; // 发射高度 Jet[i].t1 = timeGetTime(); Jet[i].dt = rand() % 10; // 发射速度时间间隔 Jet[i].n = 0; // 烟花弹闪烁图片下标 Jet[i].shoot = false; // 是否发射 } } // 加载图片 void Load_Image() { IMAGE fm, gm; loadimage(&fm, _T("fire/flower.jpg"), 3120, 240); for (int i = 0; i < NUM; i++) { SetWorkingImage(&fm); getimage(&gm, i * 240, 0, 240, 240); SetWorkingImage(&gm); for (int a = 0; a < 240; a++) for (int b = 0; b < 240; b++) Fire[i].xy[a][b] = getpixel(a, b); } IMAGE sm; loadimage(&sm, _T("fire/shoot.jpg"), 200, 50); for (int i = 0; i 100) { int n = rand() % 20; if (n < 13 && Jet[n].shoot == false && Fire[n].show == false) { Jet[n].x = rand() % LONG; Jet[n].y = rand() % 100 + LONG / 2; Jet[n].hx = Jet[n].x; Jet[n].hy = rand() % LONG / 3; Jet[n].height = Jet[n].y - Jet[n].hy; Jet[n].shoot = true; putimage(Jet[n].x, Jet[n].y, &Jet[n].img[Jet[n].n], SRCINVERT); } t1 = t2; } } // 扫描烟花弹并发射 void Shoot() { for (int i = 0; i Jet[i].dt&& Jet[i].shoot == true) { putimage(Jet[i].x, Jet[i].y, &Jet[i].img[Jet[i].n], SRCINVERT); // 烟花弹的上升 if (Jet[i].y > Jet[i].hy) { Jet[i].n++; Jet[i].y -= 5; } putimage(Jet[i].x, Jet[i].y, &Jet[i].img[Jet[i].n], SRCINVERT); if ((Jet[i].y - Jet[i].hy) * 4 < Jet[i].height) // 上升到高度的 3 / 4,减速 Jet[i].dt = rand() % 4 + 10; if (Jet[i].y <= Jet[i].hy) // 上升到最大高度 { putimage(Jet[i].x, Jet[i].y, &Jet[i].img[Jet[i].n], SRCINVERT); // 擦掉烟花弹 Fire[i].x = Jet[i].hx + 10; // 在烟花弹中间爆炸 Fire[i].y = Jet[i].hy; // 在最高点绽放 Fire[i].show = true; // 开始绽放 Jet[i].shoot = false; // 停止发射 } Jet[i].t1 = Jet[i].t2; } } } // 绽放烟花 void Show(DWORD* pMem) { // 烟花个阶段绽放时间间隔,制作变速绽放效果 int drt[16] = { 5, 5, 5, 5, 5, 6, 25, 25, 25, 25, 55, 55, 55, 55, 55 }; for (int i = 0; i Fire[i].dt&& Fire[i].show == true) { if (Fire[i].r = Fire[i].max_r - 1) { Fire[i].draw = false; Init_Fire(); } Fire[i].t1 = Fire[i].t2; } // 如果该号炮花可爆炸,根据当前爆炸半径画烟花,颜色值接近黑色的不输出。 if (Fire[i].draw) { for (double a = 0; a <= 6.28; a += 0.01) { int x1 = (int)(Fire[i].cen_x + Fire[i].r * cos(a)); // 相对于图片左上角的坐标 int y1 = (int)(Fire[i].cen_y -
``` <!DOCTYPE html> <html> <head> <title></title> </head> <style> * { padding: 0; margin: 0; } html, body { height: 100%; padding: 0; margin: 0; background: #000; } canvas { position: absolute; width: 100%; height: 100%; } .aa { position: fixed; left: 50%; bottom: 10px; color: #ccc; } </style> <body> <canvas id="pinkboard"></canvas> <script> /* * Settings */ var settings = { particles: { length: 500, // maximum amount of particles duration: 2, // particle duration in sec velocity: 100, // particle velocity in pixels/sec effect: -0.75, // play with this for a nice effect size: 30 // particle size in pixels } }; /* * RequestAnimationFrame polyfill by Erik M?ller */ (function () { var b = 0; var c = ["ms", "moz", "webkit", "o"]; for (var a = 0; a < c.length && !window.requestAnimationFrame; ++a) { window.requestAnimationFrame = window[c[a] + "RequestAnimationFrame"]; window.cancelAnimationFrame = window[c[a] + "CancelAnimationFrame"] || window[c[a] + "CancelRequestAnimationFrame"]; } if (!window.requestAnimationFrame) { window.requestAnimationFrame = function (h, e) { var d = new Date().getTime(); var f = Math.max(0, 16 - (d - b)); var g = window.setTimeout(function () { h(d + f); }, f); b = d + f; return g; }; } if (!window.cancelAnimationFrame) { window.cancelAnimationFrame = function (d) { clearTimeout(d); }; } })(); /* * Point class */ var Point = (function () { function Point(x, y) { this.x = typeof x !== "undefined" ? x : 0; this.y = typeof y !== "undefined" ? y : 0; } Point.prototype.clone = function () { return new Point(this.x, this.y); }; Point.prototype.length = function (length) { if (typeof length == "undefined") return Math.sqrt(this.x * this.x + this.y * this.y); this.normalize(); this.x *= length; this.y *= length; return this; }; Point.prototype.normalize = function () { var length = this.length(); this.x /= length; this.y /= length; return this; }; return Point; })(); /* * Particle class */ var Particle = (function () { function Particle() { this.position = new Point(); this.velocity = new Point(); this.acceleration = new Point(); this.age = 0; } Particle.prototype.initialize = function (x, y, dx, dy) { this.position.x = x; this.position.y = y; this.velocity.x = dx; this.velocity.y = dy; this.acceleration.x = dx * settings.particles.effect; this.acceleration.y = dy * settings.particles.effect; this.age = 0; }; Particle.prototype.update = function (deltaTime) { this.position.x += this.velocity.x * deltaTime; this.position.y += this.velocity.y * deltaTime; this.velocity.x += this.acceleration.x * deltaTime; this.velocity.y += this.acceleration.y * deltaTime; this.age += deltaTime; }; Particle.prototype.draw = function (context, image) { function ease(t) { return --t * t * t + 1; } var size = image.width * ease(this.age / settings.particles.duration); context.globalAlpha = 1 - this.age / settings.particles.duration; context.drawImage( image, this.position.x - size / 2, this.position.y - size / 2, size, size ); }; return Particle; })(); /* * ParticlePool class */ var ParticlePool = (function () { var particles, firstActive = 0, firstFree = 0, duration = settings.particles.duration; function ParticlePool(length) { // create and populate particle pool particles = new Array(length); for (var i = 0; i < particles.length; i++) particles[i] = new Particle(); } ParticlePool.prototype.add = function (x, y, dx, dy) { particles[firstFree].initialize(x, y, dx, dy); // handle circular queue firstFree++; if (firstFree == particles.length) firstFree = 0; if (firstActive == firstFree) firstActive++; if (firstActive == particles.length) firstActive = 0; }; ParticlePool.prototype.update = function (deltaTime) { var i; // update active particles if (firstActive < firstFree) { for (i = firstActive; i < firstFree; i++) particles[i].update(deltaTime); } if (firstFree < firstActive) { for (i = firstActive; i < particles.length; i++) particles[i].update(deltaTime); for (i = 0; i < firstFree; i++) particles[i].update(deltaTime); } // remove inactive particles while ( particles[firstActive].age >= duration && firstActive != firstFree ) { firstActive++; if (firstActive == particles.length) firstActive = 0; } }; ParticlePool.prototype.draw = function (context, image) { // draw active particles if (firstActive < firstFree) { for (i = firstActive; i < firstFree; i++) particles[i].draw(context, image); } if (firstFree < firstActive) { for (i = firstActive; i < particles.length; i++) particles[i].draw(context, image); for (i = 0; i < firstFree; i++) particles[i].draw(context, image); } }; return ParticlePool; })(); /* * Putting it all together */ (function (canvas) { var context = canvas.getContext("2d"), particles = new ParticlePool(settings.particles.length), particleRate = settings.particles.length / settings.particles.duration, // particles/sec time; // get point on heart with -PI <= t <= PI function pointOnHeart(t) { return new Point( 160 * Math.pow(Math.sin(t), 3), 130 * Math.cos(t) - 50 * Math.cos(2 * t) - 20 * Math.cos(3 * t) - 10 * Math.cos(4 * t) + 25 ); } // creating the particle image using a dummy canvas var image = (function () { var canvas = document.createElement("canvas"), context = canvas.getContext("2d"); canvas.width = settings.particles.size; canvas.height = settings.particles.size; // helper function to create the path function to(t) { var point = pointOnHeart(t); point.x = settings.particles.size / 2 + (point.x * settings.particles.size) / 350; point.y = settings.particles.size / 2 - (point.y * settings.particles.size) / 350; return point; } // create the path context.beginPath(); var t = -Math.PI; var point = to(t); context.moveTo(point.x, point.y); while (t < Math.PI) { t += 0.01; // baby steps! point = to(t); context.lineTo(point.x, point.y); } context.closePath(); // create the fill context.fillStyle = "#ea80b0"; context.fill(); // create the image var image = new Image(); image.src = canvas.toDataURL(); return image; })(); // render that thing! function render() { // next animation frame requestAnimationFrame(render); // update time var newTime = new Date().getTime() / 1000, deltaTime = newTime - (time || newTime); time = newTime; // clear canvas context.clearRect(0, 0, canvas.width, canvas.height); // create new particles var amount = particleRate * deltaTime; for (var i = 0; i < amount; i++) { var pos = pointOnHeart(Math.PI - 2 * Math.PI * Math.random()); var dir = pos.clone().length(settings.particles.velocity); particles.add( canvas.width / 2 + pos.x, canvas.height / 2 - pos.y, dir.x, -dir.y ); } // update and draw particles particles.update(deltaTime); particles.draw(context, image); } // handle (re-)sizing of the canvas function onResize() { canvas.width = canvas.clientWidth; canvas.height = canvas.clientHeight; } window.onresize = onResize; // delay rendering bootstrap setTimeout(function () { onResize(); render(); }, 10); })(document.getElementById("pinkboard")); </script> </body> </html> ``` ![示例图片](https://devbit-static.oss-cn-beijing.aliyuncs.com/devbit-static/img/heart.png)

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值