Реализации алгоритмов/Алгоритм Брезенхэма: различия между версиями

Содержимое удалено Содержимое добавлено
Нет описания правки
м <source> -> <syntaxhighlight> (phab:T237267)
Строка 6:
== Рисование линий ==
=== Реализация на Verilog ===
<sourcesyntaxhighlight lang="verilog">
`define IDLE 0
`define LINEY 1
Строка 93:
endmodule
</syntaxhighlight>
</source>
 
=== Реализация на C++ ===
<syntaxhighlight>
<source>
void drawLine(int x1, int y1, int x2, int y2) {
const int deltaX = abs(x2 - x1);
Строка 124:
 
}
</syntaxhighlight>
</source>
 
=== Реализация на Java ===
<sourcesyntaxhighlight lang="java">
// Этот код "рисует" все 9 видов отрезков. Наклонные (из начала в конец и из конца в начало каждый), вертикальный и горизонтальный - тоже из начала в конец и из конца в начало, и точку.
private int sign (int x) {
Строка 205:
}
}
</syntaxhighlight>
</source>
 
=== Реализация на Python3 ===
<sourcesyntaxhighlight lang="python">
""" Имплементация алгоритма на языке Python(перевод с Java)
setPixel(x,y) - функция закрашивает пиксель, с координатами x и y"""
Строка 248:
t += 1
setPixel(x, y)
</syntaxhighlight>
</source>
 
=== Реализация на Object Pascal ===
 
<sourcesyntaxhighlight lang="pascal">
Procedure Swap(var x,y:Integer);
var t:Integer;
Строка 284:
end;
end;
</syntaxhighlight>
</source>
примечание<ref>переменная DX взята не удачно при написании фрагмента на [[Ассемблерная вставка|асм’е]] среда плохо переварит</ref>
 
=== Реализация на PascalABC ===
 
<sourcesyntaxhighlight lang="pascal">
procedure drawLine(x1, y1, x2, y2: integer);
var
Строка 335:
end;
end;
</syntaxhighlight>
</source>
 
== Рисование окружностей ==
Строка 364:
=== Для C++ ===
 
<sourcesyntaxhighlight lang="cpp">
void drawCircle(int x0, int y0, int radius) {
int x = 0;
Строка 392:
}
}
</syntaxhighlight>
</source>
 
=== Для Delphi 7 ===
 
<sourcesyntaxhighlight lang="pascal">
Edit1: TEdit;
Edit2: TEdit;
Строка 463:
end;
 
</syntaxhighlight>
</source>
 
=== Для TurboPascal ===
 
<sourcesyntaxhighlight lang="pascal">
procedure BrezenCircle(x0, y0, r: integer);
var
Строка 500:
end;
end;
</syntaxhighlight>
</source>
 
=== Для Python ===
 
<sourcesyntaxhighlight lang="python">
 
def draw_circle(x, y, r):
Строка 532:
delta = delta + (2 * (x - y))
y -= 1
</syntaxhighlight>
</source>
 
 
=== Модифицированный пример из книги Г.Шилдта «Си для профессиональных программистов» {{sfn|Шилдт|1989}} ===
<sourcesyntaxhighlight lang="c">
/* Вспомогательная функция, печатает точки, определяющие окружность */
void plot_circle(int x, int y, int x_center, int y_center, int color_code)
Строка 567:
if(x==y) plot_circle(x,y,x_center,y_center,color_code);
}
</syntaxhighlight>
</source>
 
== Реализация для Turbo Assembler ==
<sourcesyntaxhighlight lang="asm">
.model tiny
.stack 100h
Строка 695:
int 21h
end start
</syntaxhighlight>
</source>
 
 
Строка 702:
== Visual Basic ==
<ref>[http://encyclopedia.kids.net.au/page/br/Bresenham%27s_line_algorithm_Visual_basic_code Encyclopedia > Bresenham’s line algorithm Visual basic code] Bresenham’s line algorithm for Microsoft Visual Basic 6.0. Implementation by Robert Lee <rlee0001@maine.rr.com> July, 2002 Public Domain</ref>
<sourcesyntaxhighlight lang="qbasic">
Private Sub BresLine(InitialX As Long, InitialY As Long, FinalX As Long, FinalY As Long)
 
Строка 746:
End Sub
 
</syntaxhighlight>
</source>
 
== C++ для 3D-растра ==
Строка 765:
public domain as well.
</ref>
<sourcesyntaxhighlight lang="cpp">
void Bresenham3D(int x1, int y1, int z1, const int x2, const int y2, const int z2, WorldMap *output, int symbol){
Строка 842:
}
 
</syntaxhighlight>
</source>
== Примечания ==
{{примечания}}