赞
踩
大家好,我是kekedeLa,这是我的第一个作品,废话不多说,进入正题。
说到用c++写爱心,是每个单身程序猿的必修课。
- #include<bits/stdc++.h>
- #include <unistd.h>
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- int main(){
- //倒数 3 2 1 时间到:
- for (int i=3;i>0;i--){
- cout<<i<<endl;
- sleep(1);
- }
- cout<<"时间到!"<<endl;
- sleep(1);
- cout<<"准备好开始了吗?";
- sleep(1);
- system("cls");
- //爱心:
- int i,j,k,l,m;
- char c='/*';
- cout<<endl;
- for (i=1;i<=3;i++){
- for (j=1;j<=32-2*i;j++)
- cout<<" ";
- for (k=1;k<=4*i+1;k++)
- cout<<c;
- for (l=1;l<=13-4*i;l++)
- cout<<" ";
- for (m=1;m<=4*i+1;m++)
- cout<<c;
- cout<<endl;
- }
- for (i=1;i<=3;i++){
- for (j=1;j<=24+1;j++)
- cout<<" ";
- for (k=1;k<=29;k++)
- cout<<c;
- cout<<endl;
- }
- for (i=7;i>=1;i--){
- for (j=1;j<=40-2*i;j++)
- cout<<" ";
- for (k=1;k<=4*i-1;k++)
- cout<<c;
- cout<<endl;
- }
- for (i=1;i<=39;i++)
- cout<<" ";
- cout<<c<<endl;
- return 0;
- }
以上只是简简单单的爱心,成品图:
- #include<bits/stdc++.h>
- using namespace std;
- int main() {
- float x,y,a;
- for (y=1.5;y>-1.5;y-=0.1){
- for (x=-1.5;x<1.5;x+=0.05){
- a=x*x+y*y-1;
- putchar(a * a * a - x * x * y * y * y <= 0.0 ? '*' : ' ');
- }
- system("color 0c");
- putchar('\n');
- }
- return 0;
- }
成品图:
- #include <stdio.h>
- #include <math.h>
- #include <windows.h>
- #include <tchar.h>
-
- float f(float x, float y, float z)
- {
- float a = x * x + 9.0f / 4.0f * y * y + z * z - 1;
-
- return a * a * a - x * x * z * z * z - 9.0f / 80.0f * y * y * z * z * z;
- }
-
- float h(float x, float z)
- {
- for (float y = 1.0f; y >= 0.0f; y -= 0.001f)
- if (f(x, y, z) <= 0.0f)
- return y;
- return 0.0f;
- }
-
- int main()
- {
- HANDLE o = GetStdHandle(STD_OUTPUT_HANDLE);
- _TCHAR buffer[25][80] = { _T(' ') };
- _TCHAR ramp[] = _T(".:-=+*#%@");
-
- for (float t = 0.0f;; t += 0.1f)
- {
- int sy = 0;
- float s = sinf(t);
- float a = s * s * s * s * 0.2f;
- for (float z = 1.3f; z > -1.2f; z -= 0.1f)
- {
- _TCHAR* p = &buffer[sy++][0];
- float tz = z * (1.2f - a);
- for (float x = -1.5f; x < 1.5f; x += 0.05f)
- {
- float tx = x * (1.2f + a);
- float v = f(tx, 0.0f, tz);
- if (v <= 0.0f)
- {
- float y0 = h(tx, tz);
- float ny = 0.01f;
- float nx = h(tx + ny, tz) - y0;
- float nz = h(tx, tz + ny) - y0;
- float nd = 1.0f / sqrtf(nx * nx + ny * ny + nz * nz);
- float d = (nx + ny - nz) * nd * 0.5f + 0.5f;
- *p++ = ramp[(int)(d * 5.0f)];
- }
- else
- *p++ = ' ';
- }
- }
- for (sy = 0; sy < 25; sy++)
- {
- COORD coord = { 0, sy };
- SetConsoleCursorPosition(o, coord);
- WriteConsole(o, buffer[sy], 79, NULL, 0);
- }
- Sleep(33);
- }
- }
- #include<iostream>
- #include<cmath>
- #include<Windows.h>
- using namespace std;
- void big_heart(){
- double x_1,y_1,m_1,n_1;
- for(y_1=1.5;y_1>-1.5;y_1-=0.1){
- for(x_1=-1.5;x_1<=1.5;x_1+=0.05){
- m_1=x_1*x_1+y_1*y_1-1;
- n_1=pow(m_1,3)-pow(x_1,2)*pow(y_1,3);
- n_1<0? cout<<'x': cout<<' ';
- }
- Sleep(100);
- cout<<endl;
- }
- }
- void big_heart_2(){
- double x_1,y_1,m_1,n_1;
- for(y_1=1.5;y_1>-1.5;y_1-=0.1){
- for(x_1=-1.5;x_1<=1.5;x_1+=0.05){
- m_1=x_1*x_1+y_1*y_1-1;
- n_1=pow(m_1,3)-pow(x_1,2)*pow(y_1,3);
- n_1<0? cout<<'x': cout<<' ';
- }
- cout<<endl;
- }
- }
- void small_heart(){
- double x,y,m,n;
- for(y=3.0;y>-3.0;y-=0.2){
- for(x=-3.0;x<=3.0;x+=0.1){
- m=x*x+y*y-1;
- n=pow(m,3)-pow(x,2)*pow(y,3);
- n<0? cout<<'x': cout<<' ';
- }
- cout<<endl;
- }
- }
- HANDLE han=GetStdHandle(-11);
- void hide(){
- CONSOLE_CURSOR_INFO cursor;
- cursor.bVisible = 0;
- cursor.dwSize = 1;
- SetConsoleCursorInfo(han,&cursor);
- }
- int main(){
- hide();
- system("color C");
- big_heart();
- int a=1;
- while(1){
- system("cls");
- if(a%2==0){
- small_heart();
- Sleep(400);
- }
- else{
- big_heart_2();
- Sleep(100);
- }
- a++;
- }
- return 0;
- }
好了,今天的内容就到这里,还是感谢你认真看完我的作品
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。