KRITSADA

Draw Circle with makecode and OLED

Jul 15th, 2021
1,218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function circleBres (xc: number, yc: number, r: number) {
  2.     y = r
  3.     d = 3 - 2 * r
  4.     drawCircle(xc, yc, x, y)
  5.     while (y >= x) {
  6.         x += 1
  7.         if (d > 0) {
  8.             y += -1
  9.             d = d + 4 * (x - y) + 10
  10.         } else {
  11.             d = d + 4 * x + 6
  12.         }
  13.         drawCircle(xc, yc, x, y)
  14.         basic.pause(100)
  15.     }
  16. }
  17. input.onButtonPressed(Button.B, function () {
  18.     circleBres(64, 32, 16)
  19. })
  20. function drawCircle (xc: number, yc: number, x: number, y: number) {
  21.     OLED12864_I2C.pixel(xc + x, yc + y, 1)
  22.     OLED12864_I2C.pixel(xc - x, yc + y, 1)
  23.     OLED12864_I2C.pixel(xc + x, yc - y, 1)
  24.     OLED12864_I2C.pixel(xc - x, yc - y, 1)
  25.     OLED12864_I2C.pixel(xc + y, yc + x, 1)
  26.     OLED12864_I2C.pixel(xc - y, yc + x, 1)
  27.     OLED12864_I2C.pixel(xc + y, yc - x, 1)
  28.     OLED12864_I2C.pixel(xc - y, yc - x, 1)
  29. }
  30. let x = 0
  31. let d = 0
  32. let y = 0
  33. OLED12864_I2C.init(60)
  34. OLED12864_I2C.zoom(false)
  35.  
Advertisement
Add Comment
Please, Sign In to add comment