Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Subrutin membuat lingkaran dengan pusat (0,0) dan jari-jari radius.
- Dengan menggunakan persamaan parametrik.
- Lingkaran ini digambar penuh
- */
- void circle1(int xc, int yc, int radius){
- float density=0.5; //ganti nilai density untuk memperoleh gambar yg lebih baik
- int px,py;
- for (float i=0.0; i<45; i=i+density){ //cukup 45 derajat saja
- px=int(radius*cos(radians(i))); //x
- py=int(radius*sin(radians(i))); //y
- point(px+xc,py+yc); //transformasikan ke yang lain
- point(py+yc,px+xc);
- point(px+xc,-py+yc);
- point(py+yc,-px+xc);
- point(-px+xc,py+yc);
- point(-py+yc,px+xc);
- point(-px+xc,-py+yc);
- point(-py+yc,-px+xc);
- }
- }
- /*
- Subrutin membuat lingkaran dengan pusat (0,0) dan jari-jari radius.
- Dengan menggunakan persamaan quadratik lingkaran.
- Lingkaran ini digambar penuh
- */
- void circle2(int xc, int yc, int radius){
- int py=0;
- for (int px=0; px<=py; px++){ //mulai dari r sampai dengan x=y. pada garis x=y membentuk sudut 45 derajat
- py=int(sqrt(pow(radius,2)-pow(px,2))); // hitung dengan persamaan lingkaran
- point(px+xc,py+yc); //transfo ke yang lain
- point(py+yc,px+xc);
- point(px+xc,-py+yc);
- point(py+yc,-px+xc);
- point(-px+xc,py+yc);
- point(-py+yc,px+xc);
- point(-px+xc,-py+yc);
- point(-py+yc,-px+xc);
- }
- }
- /*
- Subrutin membuat lingkaran dengan pusat (0,0) dan jari-jari radius.
- Dengan menggunakan algoritma Bressenham.
- Lingkaran ini digambar tidak penuh, hanya 1/8 saja
- */
- void circle3(int xc, int yc, int radius){
- int px = 0;
- int py = radius;
- int d1 = 3 - (2 * radius);
- boolean rov=true;
- while (rov){
- if (px>=py){
- rov=false;}
- if (d1 < 0) {
- d1 = d1 + (4 * px) + 6; }
- else{
- d1 = d1 + 4 * (px-py) + 10; // (1)
- py = py-1;
- }
- point(px+xc,py+yc); //sama dengan yang sebelumnya
- point(py+yc,px+xc);
- point(px+xc,-py+yc);
- point(py+yc,-px+xc);
- point(-px+xc,py+yc);
- point(-py+yc,px+xc);
- point(-px+xc,-py+yc);
- point(-py+yc,-px+xc);
- px++;
- }
- }
- void setup(){
- size(700,700);
- stroke(200,0,0);
- circle1(width/2, height/2, 200);
- stroke(0,0,0);
- circle2(width/2, height/2, 250);
- stroke(0,0,255);
- circle3(width/2, height/2, 300);
- }
Add Comment
Please, Sign In to add comment