def basic_update Graphics.update Input.update end class Bitmap def draw_line(x1,y1,x2,y2,color = Color.new(255,255,255)) jarak_x = (x2-x1) jarak_y = (y2-y1) if jarak_y.abs == 0 || jarak_x.abs == 0 draw_horz(x1,y1,jarak_x,color) if jarak_y.abs == 0 draw_vert(x1,y1,jarak_y,color) if jarak_x.abs == 0 return end maximum = [jarak_x.abs,jarak_y.abs].max rasio_x = jarak_x / maximum.to_f rasio_y = jarak_y / maximum.to_f real_x = x1.to_f real_y = y1.to_f for i in 0..maximum Graphics.update set_pixel(x1,y1,color) real_x += rasio_x real_y += rasio_y x1 = real_x.round y1 = real_y.round end end def draw_horz(x,y,width,color = Color.new(255,255,255)) if width < 0 fill_rect(x+width+1,y,width.abs,1,color) return end fill_rect(x,y,width,1,color) end def draw_vert(x,y,height,color = Color.new(255,255,255)) if height < 0 fill_rect(x,y+height+1,1,height.abs,color) return end fill_rect(x,y,1,height,color) end def draw_elipse(x,y=0,horz=1,vert=1,color=Color.new(255,255,255),step=0.1) if x.is_a?(Ellipse) elipse = x x = elipse.x y = elipse.y horz = elipse.horz vert = elipse.vert end ori_x = x ori_y = y x += horz degree = 0.0 while degree <= 360 Graphics.update set_pixel(x,y,color) x = Math.cos(Math.radian(degree)) * horz + ori_x y = Math.sin(Math.radian(degree)) * vert + ori_y degree = [degree+step,360].min end end def draw_shape_params(x,y,params,length,color = Color.new(255,255,255)) return unless params.is_a?(Array) return unless params.size >= 3 degree_minus = 360 / params.size degree = 270 coordinate = [] params.each do |i| x_des = x + Math.cos(Math.radian(degree)) * (length*(i.to_f/params.max)) y_des = y + Math.sin(Math.radian(degree)) * (length*(i.to_f/params.max)) draw_line(x,y,x_des,y_des,color) degree += degree_minus coordinate.push(Coordinate.new(x_des,y_des)) end for i in -1..coordinate.size-2 c = coordinate draw_line(c[i].x,c[i].y,c[i+1].x,c[i+1].y) end end end class Coordinate attr_accessor :x,:y def initialize(x,y) @x = x @y = y end end module Math def self.radian(degree) return (degree.to_f/180) * Math::PI end def self.degree(radian) return (radian.to_f/Math::PI) * 180 end end class Ellipse attr_accessor :x, :y, :horz, :vert, end def updates basic_update end $sprite = Sprite.new $sprite.bitmap = Bitmap.new(Graphics.width,Graphics.height) #$sprite.bitmap.draw_elipse(200,200,100,100,Color.new(255,255,255),1) params = [] params += [100,50]*2 $sprite.bitmap.draw_shape_params(100,150,params,50) params = [] params += [100,50]*4 $sprite.bitmap.draw_shape_params(200,150,params,50) params = [] params += [100,50]*6 $sprite.bitmap.draw_shape_params(300,150,params,50) params = [] params += [100]*3 $sprite.bitmap.draw_shape_params(100,300,params,50) params = [] params += [100]*5 $sprite.bitmap.draw_shape_params(200,300,params,50) params = [] params += [100]*7 $sprite.bitmap.draw_shape_params(300,300,params,50) #$sprite.bitmap.draw_line(100,100,20,20) updates while true