最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C++ 實(shí)現(xiàn)旋轉(zhuǎn)蛇錯(cuò)覺的詳細(xì)代碼

 更新時(shí)間:2021年09月27日 09:45:28   作者:cqu_shuai  
這篇文章主要介紹了C++ 實(shí)現(xiàn)旋轉(zhuǎn)蛇錯(cuò)覺的詳細(xì)代碼,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

參考 《C和C++游戲趣味編程》 童晶

“旋轉(zhuǎn)蛇”錯(cuò)覺

繪制錯(cuò)覺圖片,使靜止的圓盤看起來有在轉(zhuǎn)動(dòng)的錯(cuò)覺

繪制扇形

函數(shù)solidpie(left, top, right, bottom, stangle, endangle)可以繪制無邊框的填充扇形。其中(left, top)、(right, bottom)為扇形對(duì)應(yīng)圓的外切矩形的左上角、右下角坐標(biāo),stangle、endangle為扇形的起始角、終止角(單位為弧度)

#include <graphics.h>
#include <conio.h>
#include <stdio.h>

int main()
{
	float PI = 3.14159;
	initgraph(600, 600);
	int centerX = 300;
	int centerY = 300;
	int radius = 200;
	circle(centerX, centerY, radius);                   // 畫出對(duì)應(yīng)的圓邊框
	int left = centerX - radius;                        // 圓外切矩形左上角x坐標(biāo)
	int top = centerY - radius;                         // 圓外切矩形左上角y坐標(biāo)
	int right = centerX + radius;                       // 圓外切矩形右下角x坐標(biāo)
	int bottom = centerY + radius;                      // 圓外切矩形右下角y坐標(biāo)
	solidpie(left, top, right, bottom, PI / 6, PI / 3); // 畫出填充扇形
	_getch();
	closegraph();
	return 0;
}

RGB顏色模型

EasyX可以設(shè)定繪圖顏色:

setbkcolor(WHITE);                                  // 設(shè)置背景顏色為白色
setlinecolor(RED);                                  // 設(shè)置線條顏色為紅色
setfillcolor(GREEN);                                // 設(shè)置填充顏色為綠色
cleardevice();                                      // 以背景顏色清空畫布

也可以采用數(shù)字形式:

setbkcolor(RGB(255, 255, 255));                                  // 設(shè)置背景顏色為白色
setlinecolor(RGB(255, 0, 0));                                  // 設(shè)置線條顏色為紅色
setfillcolor(RGB(0, 255, 0));                                // 設(shè)置填充顏色為綠色

繪制一組扇形單元

人腦處理高對(duì)比度顏色(如黑和白)的時(shí)間,要比處理低對(duì)比度顏色(如紅與青)短很多。我們會(huì)先感知到黑白圖案,后感知到紅青圖案,這個(gè)時(shí)間差會(huì)讓圖片產(chǎn)生相對(duì)運(yùn)動(dòng)的效果,所以我們會(huì)有圖片的錯(cuò)覺

為了進(jìn)一步強(qiáng)化這種錯(cuò)覺,我們讓每個(gè)黑、白扇形的角度為PI/60,紅、青扇形的角度為PI/30。一組青、白、紅、黑扇形角度和為PI/10,逆時(shí)針依次繪制20組單元

#include <graphics.h>
#include <conio.h>
#include <stdio.h>

int main()
{
	float PI = 3.14159;
	initgraph(600, 600);
	setbkcolor(RGB(128, 128, 128));                                  // 設(shè)置背景顏色為白色
	cleardevice();                                      // 以背景顏色清空畫布

	int centerX = 300;
	int centerY = 300;
	int radius = 200;
	int left = centerX - radius;                        // 圓外切矩形左上角x坐標(biāo)
	int top = centerY - radius;                         // 圓外切矩形左上角y坐標(biāo)
	int right = centerX + radius;                       // 圓外切矩形右下角x坐標(biāo)
	int bottom = centerY + radius;                      // 圓外切矩形右下角y坐標(biāo)

	int i;
	float offset;
	for (i = 0; i < 20; i++)
	{
		offset = i * PI / 10;
		setfillcolor(RGB(0, 240, 220)); // 青色
		solidpie(left, top, right, bottom, offset, 2 * PI / 60 + offset);
		setfillcolor(RGB(255, 255, 255)); // 白色
		solidpie(left, top, right, bottom, 2 * PI / 60 + offset, 3 * PI / 60 + offset);
		setfillcolor(RGB(200, 0, 0)); // 紅色
		solidpie(left, top, right, bottom, 3 * PI / 60 + offset, 5 * PI / 60 + offset);
		setfillcolor(RGB(0, 0, 0)); // 黑色
		solidpie(left, top, right, bottom, 5 * PI / 60 + offset, 6 * PI / 60 + offset);
	}
	_getch();
	closegraph();
	return 0;
}

循環(huán)嵌套

利用雙重for循環(huán)語句,可以繪制出多層圓盤。先繪制半徑大的,在繪制半徑小的覆蓋。不同半徑的扇形之間有PI/20的角度偏移量。另外,對(duì)圓心坐標(biāo)進(jìn)行循環(huán)遍歷就可以實(shí)現(xiàn)多個(gè)圓盤效果

#include <graphics.h>
#include <conio.h>
#include <stdio.h>

int main()
{
	float PI = 3.14159;
	initgraph(1200, 800);
	setbkcolor(RGB(128, 128, 128));                                                                     // 設(shè)置背景顏色為灰色
	cleardevice();

	int centerX, centerY;
	int radius;
	int i;
	float offset;
	float totalOffset = 0;                                                                              // 不同半徑之間的角度偏移量
	
	for (centerX = 200; centerX < 1200; centerX += 400)
	{
		for (centerY = 200; centerY < 800; centerY += 400)
		{
			for (radius = 200; radius > 0; radius -= 50)
			{
				int left = centerX - radius;
				int top = centerY - radius;
				int right = centerX + radius;
				int bottom = centerY + radius;
				for (i = 0; i < 20; i++)
				{
					offset = i * PI / 10 + totalOffset;
					setfillcolor(RGB(0, 240, 220));                                                    // 青色
					solidpie(left, top, right, bottom, offset, 2 * PI / 60 + offset);
					setfillcolor(RGB(255, 255, 255));                                                  // 白色
					solidpie(left, top, right, bottom, 2 * PI / 60 + offset, 3 * PI / 60 + offset);
					setfillcolor(RGB(200, 0, 0));                                                      // 紅色
					solidpie(left, top, right, bottom, 3 * PI / 60 + offset, 5 * PI / 60 + offset);
					setfillcolor(RGB(0, 0, 0));                                                        // 黑色
					solidpie(left, top, right, bottom, 5 * PI / 60 + offset, 6 * PI / 60 + offset);
				}
				totalOffset += PI / 20;                                                                // 不同半徑間角度偏移
			}
		}
	}
	_getch();
	closegraph();
	return 0;
}

HSV顏色模型

HSV是一種根據(jù)顏色的直觀特性創(chuàng)建的顏色模型。H是Hue的首字母,表示色調(diào),取值范圍為0360,刻畫不同色彩;S是Saturation的首字母,表示飽和度,取值范圍為01,表示混合了白色的比例,值越高顏色越鮮艷;V是Value的首字母,表示明度,取值范圍為0~1,等于0時(shí)為黑色,等于1時(shí)最明亮

#include <graphics.h>
#include <conio.h>
#include <stdio.h>

int main()
{
	float PI = 3.14159;
	initgraph(600, 600);
	setbkcolor(RGB(255, 255, 255));
	cleardevice();

	int centerX = 300;
	int centerY = 300;
	int radius = 200;
	int left = centerX - radius;
	int top = centerY - radius;
	int right = centerX + radius;
	int bottom = centerY + radius;

	int i;
	int step = 10;
	COLORREF color;
	for (i = 0; i < 360; i += step)
	{
		color = HSVtoRGB(i, 1, 1);  // HSV設(shè)置的顏色
		setfillcolor(color);
		solidpie(left, top, right, bottom, i * PI / 180, (i + step) * PI / 180);
	}
	_getch();
	return 0;
}

按鍵切換效果

利用while循環(huán)和_getch()函數(shù),可以實(shí)現(xiàn)每次按鍵后,重新生成隨機(jī)顏色。另外,利用srand()函數(shù)對(duì)隨機(jī)函數(shù)初始化,避免每次運(yùn)行的隨機(jī)顏色都一樣

#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <time.h>

int main()
{
	float PI = 3.14159;
	initgraph(800, 600);
	setbkcolor(RGB(128, 128, 128));                                                                     // 設(shè)置背景顏色為灰色
	cleardevice();
	srand(time(0));                                                                                     // 隨機(jī)種子函數(shù)

	int centerX, centerY;
	int radius;
	int i;
	float offset;
	float totalOffset;                                                                              // 不同半徑之間的角度偏移量

	while (1)
	{
		for (centerX = 100; centerX < 800; centerX += 200)
		{
			for (centerY = 100; centerY < 600; centerY += 200)
			{
				totalOffset = 0;                                                                           // 同一半徑內(nèi)各組扇形之間的角度偏移量
				float h = rand() % 180;                                                                    // 隨機(jī)色調(diào)
				COLORREF color1 = HSVtoRGB(h, 0.9, 0.8);                                                   // 色調(diào)1生成的顏色1
				COLORREF color2 = HSVtoRGB(h + 180, 0.9, 0.8);                                             // 色調(diào)2生成的顏色2
				for (radius = 100; radius > 0; radius -= 20)
				{
					int left = centerX - radius;
					int top = centerY - radius;
					int right = centerX + radius;
					int bottom = centerY + radius;
					for (i = 0; i < 20; i++)
					{
						offset = i * PI / 10 + totalOffset;
						setfillcolor(color1);                                                    // 青色
						solidpie(left, top, right, bottom, offset, 2 * PI / 60 + offset);
						setfillcolor(RGB(255, 255, 255));                                                  // 白色
						solidpie(left, top, right, bottom, 2 * PI / 60 + offset, 3 * PI / 60 + offset);
						setfillcolor(color2);                                                      // 紅色
						solidpie(left, top, right, bottom, 3 * PI / 60 + offset, 5 * PI / 60 + offset);
						setfillcolor(RGB(0, 0, 0));                                                        // 黑色
						solidpie(left, top, right, bottom, 5 * PI / 60 + offset, 6 * PI / 60 + offset);
					}
					totalOffset += PI / 20;                                                                // 不同半徑間角度偏移
				}
			}
		}
		_getch();
	}
	closegraph();
	return 0;
}

在這里插入圖片描述

到此這篇關(guān)于C++ 實(shí)現(xiàn)旋轉(zhuǎn)蛇錯(cuò)覺的詳細(xì)代碼的文章就介紹到這了,更多相關(guān)C++旋轉(zhuǎn)蛇內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C++實(shí)現(xiàn)LeetCode(11.裝最多水的容器)

    C++實(shí)現(xiàn)LeetCode(11.裝最多水的容器)

    這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(11.裝最多水的容器),本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • C++ Boost PointerContainer智能指針詳解

    C++ Boost PointerContainer智能指針詳解

    智能指針是一種像指針的C++對(duì)象,但它能夠在對(duì)象不使用的時(shí)候自己銷毀掉。雖然STL提供了auto_ptr,但是由于不能同容器一起使用(不支持拷貝和賦值操作),因此很少有人使用。它是Boost各組件中,應(yīng)用最為廣泛的一個(gè)
    2022-11-11
  • C++基于CreateToolhelp32Snapshot獲取系統(tǒng)進(jìn)程實(shí)例

    C++基于CreateToolhelp32Snapshot獲取系統(tǒng)進(jìn)程實(shí)例

    這篇文章主要介紹了C++基于CreateToolhelp32Snapshot獲取系統(tǒng)進(jìn)程實(shí)例,是Windows應(yīng)用程序設(shè)計(jì)中非常實(shí)用的技巧,需要的朋友可以參考下
    2014-10-10
  • Opencv透視變換綜合實(shí)例詳解

    Opencv透視變換綜合實(shí)例詳解

    這篇文章主要為大家詳細(xì)介紹了Opencv透視變換綜合實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • C++設(shè)計(jì)模式之模板方法模式

    C++設(shè)計(jì)模式之模板方法模式

    這篇文章主要介紹了C++設(shè)計(jì)模式之模板方法模式,本文講解了什么是模板方法模式、模板方法模式的UML類圖、模板方法模式的使用場(chǎng)合等內(nèi)容,需要的朋友可以參考下
    2014-10-10
  • C++中的std::initializer_list使用解讀

    C++中的std::initializer_list使用解讀

    這篇文章主要介紹了C++中的std::initializer_list使用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • Qt實(shí)現(xiàn)給窗口繪制陰影的示例代碼

    Qt實(shí)現(xiàn)給窗口繪制陰影的示例代碼

    這篇文章主要為大家詳細(xì)介紹了Qt實(shí)現(xiàn)給窗口繪制陰影的方法,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Qt有一定的幫助,感興趣的可以了解一下
    2022-11-11
  • C++遞歸算法處理島嶼問題詳解

    C++遞歸算法處理島嶼問題詳解

    這篇文章主要介紹了用遞歸算法解決島嶼問題的流程,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2022-10-10
  • C++智能指針模板應(yīng)用詳細(xì)介紹

    C++智能指針模板應(yīng)用詳細(xì)介紹

    從比較簡(jiǎn)單的層面來看,智能指針是RAII(Resource Acquisition Is Initialization,資源獲取即初始化)機(jī)制對(duì)普通指針進(jìn)行的一層封裝。這樣使得智能指針的行為動(dòng)作像一個(gè)指針,本質(zhì)上卻是一個(gè)對(duì)象,這樣可以方便管理一個(gè)對(duì)象的生命周期
    2022-08-08
  • C++中的運(yùn)算符和運(yùn)算符優(yōu)先級(jí)總結(jié)

    C++中的運(yùn)算符和運(yùn)算符優(yōu)先級(jí)總結(jié)

    這篇文章主要介紹了C++中的運(yùn)算符和運(yùn)算符優(yōu)先級(jí)總結(jié),主要整理了算術(shù)、關(guān)系、邏輯、位和賦值運(yùn)算符的用法,需要的朋友可以參考下
    2016-05-05

最新評(píng)論

津市市| 宽甸| 吉林市| 高邑县| 巴中市| 临江市| 潍坊市| 清涧县| 涿鹿县| 泗水县| 湟源县| 平泉县| 西乌| 车致| 太仆寺旗| 罗定市| 白水县| 和硕县| 静海县| 新河县| 五大连池市| 四川省| 罗定市| 和林格尔县| 阜宁县| 黑龙江省| 江阴市| 陵川县| 西青区| 扶沟县| 佳木斯市| 乌鲁木齐县| 四平市| 桃江县| 海阳市| 青冈县| 孟连| 黔西县| 会昌县| 沧源| 陆川县|