Уроки, алгоритмы, программы, примеры

Материалы по разделам

Построения
на плоскости (2D)
Графика
в пространстве (3D)
Вычислительная
геометрия
Физическое
моделирование
Фрактальная
графика

Новые комментарии

У меня проблема вот с этим: gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);. Вылезает ошибка: CS1061 "object" не содержит определения "GL_COLOR_BUFFER_BIT", и не удалось найти доступный метод расширения "GL_COLOR_BUFFER_BIT",...
Большое спасибо. Единственный код который прошел без каких либо ошибок. Ура!!!
Скажите пожалуйста, подскажите алгоритм по которому по заданным точкам можно определить тип многогранника, скажем это куб или прямоугольный параллелепипед. Нашел теорию по этим фигурам: https://www.mat... https://www.mat... Акцентировать внимание...
Всем у кого не работает. файл wizard.script Ещё одно упоминание Glut32 в строке "if (!VerifyLibFile(dir_nomacro_lib, _T("glut32"), _T("GLUT's"))) return false;" меняем на "if (!VerifyLibFile(dir_nomacro_lib, _T("freeglut"), _T("GLUT's"))) return...
Не получается, емаё

Счетчики и рейтинг

Рейтинг@Mail.ru Яндекс.Метрика
Язык программирования: 
Javascript
Среда программирования: 
Visual Studio Code

<html>
  <head>
    <meta charset="utf-8">
    <title>demo</title>
  </head>
  <body>
  <div align = "center">
    <canvas id="canvas" width = "600px" height = "600px"></canvas>
  </div>
	<script>
   		var canvas = document.getElementById('canvas');
   		var ctx = canvas.getContext('2d');
 
		var growthspeed = 200; //скорость роста
		var rotationspeed = 1; //скорость вращения
		var beginSize = 10; //начальный размер
		var difSize = 40; //разница размеров между соседними 
 
		var params = function(size, rotation) {
			this.size = size;
			this.rotation = rotation;
		} 
		var Squares = []; // массив с параметрами квадратов
 
  		function play(){ //анимация
			now = Date.now();
			dt = (now - last)/1000;
 
			render();
		    update(dt);
 
			requestAnimationFrame(play);
			last = now;
		}
 
		function update(dt){
 
			var p = Squares.length;
			if(p == 0 || Squares[p-1].size >= difSize) Squares.push(new params(beginSize, 0)); //создание нового квадрата
			for(var i in Squares){//пересчет параметров 
				Squares[i].size += growthspeed*dt;
				Squares[i].rotation += rotationspeed*dt;
				if(Squares[i].size >= canvas.width*2) Squares.splice(i, 1); // удаление квадрата
			}
		}
 
		function render(){//отрисовка всех квадратов
			ctx.fillStyle = 'black';
			ctx.fillRect(0,0,canvas.width, canvas.height);
			for(var i in Squares){
				drawCenterSquare(0, 0, Squares[i].size, Squares[i].rotation);
			}
		}
 
		function drawCenterSquare(centerX, centerY, size, angle=0){
			var v1x = centerX - size/2,
				v2x = centerX + size/2,
				v3x = centerX + size/2,
				v4x = centerX - size/2,
				v1y = centerY - size/2,
				v2y = centerY - size/2,
				v3y = centerY + size/2,
				v4y = centerY + size/2;
 
			var t1x = v1x,
				t2x = v2x,
				t1y = v1y,
				t2y = v3y;
			v1x = t1x*Math.cos(angle) - t1y*Math.sin(angle);
			v1y = t1x*Math.sin(angle) + t1y*Math.cos(angle);
 
			v2x = t2x*Math.cos(angle) - t1y*Math.sin(angle);
			v2y = t2x*Math.sin(angle) + t1y*Math.cos(angle);
 
			v3x = t2x*Math.cos(angle) - t2y*Math.sin(angle);
			v3y = t2x*Math.sin(angle) + t2y*Math.cos(angle);
 
			v4x = t1x*Math.cos(angle) - t2y*Math.sin(angle);
			v4y = t1x*Math.sin(angle) + t2y*Math.cos(angle);
 
			ctx.lineWidth = '4';
			ctx.strokeStyle = 'white';
			ctx.beginPath();
			ctx.moveTo(canvas.width/2 + v1x, canvas.height/2 - v1y);
			ctx.lineTo(canvas.width/2 + v2x, canvas.height/2 -  v2y);
			ctx.lineTo(canvas.width/2 + v3x, canvas.height/2 -  v3y);
			ctx.lineTo(canvas.width/2 + v4x, canvas.height/2 -  v4y);
			ctx.closePath();
			ctx.stroke();
		}
 
		var last = Date.now();
		play();
 
	</script>
  </body>
</html>

Прикрепленный файлРазмер
Borseitov_hypnotic_square.zip1.27 кб