日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

C語言控制臺打印3D愛心圖案

 孔實 2017-07-14

來源:碼農(nóng)網(wǎng)


很多程序員都覺得自己的編程工作十分的鼓噪乏味,一整天面對的都是一些寫不完的代碼和改不完的Bug。今天我們要給大家分享一些有趣的C語言代碼,或許可以為你無聊的工作帶來一絲樂趣。這些代碼可以完成幾個不同的愛心圖案,其中有一個例子甚至可以在黑色背景的控制臺上打印出跳動的3D愛心動畫,效果相當震撼。

我用的是Visual Studio 2015開發(fā)環(huán)境,如果你也使用這個開發(fā)環(huán)境,可以直接拷貝下面的代碼進行效果演示。

普通的愛心圖案

C語言代碼:

#include 'stdafx.h'#include #include int main(){ float y, x, a; for (y = 1.5f;y > -1.5f;y -= 0.1f) { for (x = -1.5f;x < 1.5f;x="" +="0.05f)" {="" a="x*x" +="" y*y="" -="" 1;="" putchar(a*a*a="" -="" x*x*y*y*y=""><= 0.0f="" '*'="" :="" '="" ');="" }="" putchar('\n');="" }="" return="">

效果圖:

帶花紋的愛心圖案

C語言代碼:

#include 'stdafx.h'#include #include 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="">

效果圖:

跳動的3D愛心圖案

C語言代碼:

#include 'stdafx.h'#include #include #include #include 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);="">

效果圖

跳動的愛心動畫需要你運行程序后才可以看到。

你還有更有趣的方案嗎?歡迎告訴我們!

本文鏈接:http://www./article/c-3d-heart.html

本文鏈接:http://www./article/c-3d-heart.html
本文作者:碼農(nóng)網(wǎng) – 小峰

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多