Skip to content
This repository has been archived by the owner on Oct 9, 2018. It is now read-only.

Methods and Strings 1 (Solution)

dimituri edited this page Oct 18, 2010 · 1 revision

Sample solution

require 'panda_canvas'

PandaCanvas.draw do

  pixel_count = 50
  angle = 2 * Math::PI / pixel_count
  x = 0
  y = -150
  i = 0
  while i < pixel_count
    new_x = x * Math.cos(angle) - y * Math.sin(angle)
    new_y = x * Math.sin(angle) + y * Math.cos(angle)
    x = new_x
    y = new_y
    pixel x + 320, y + 240
    i += 1
  end

end

Experiments

Try changing the pixel count and radius of the circle. Can you draw a solid line? Can you calculate how many pixels are required to draw a solid line for a given radius?

Move on

Next problem