Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Bitmap
- def draw_line(x1,y1,x2,y2,color = Color.new(255,255,255),color_set_skip = false)
- jarak_x = (x2-x1)
- jarak_y = (y2-y1)
- if jarak_y == 0 || jarak_x == 0
- if jarak_y == 0
- draw_horz(x1,y1,jarak_x,color)
- for j in 0..jarak_x
- yield [x1,y1]
- x1 += 1
- end if block_given?
- elsif jarak_x.abs == 0
- draw_vert(x1,y1,jarak_y,color)
- for k in 0..jarak_y
- yield [x1,y1]
- y1 += 1
- end if block_given?
- end
- 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
- if get_pixel(x1,y1).same?(color) || color_set_skip ? !get_pixel(x1,y1).empty? : false
- x1 = real_x.round
- y1 = real_y.round
- real_x += rasio_x
- real_y += rasio_y
- next
- end
- Graphics.update
- set_pixel(x1,y1,color)
- real_x += rasio_x
- real_y += rasio_y
- yield [x1,y1] if block_given?
- x1 = real_x.round
- y1 = real_y.round
- end
- end
- def gradient_line(x1,y1,x2,y2,color1 = Color.new(255,255,255),color2 = color1)
- jarak_x = (x2-x1)
- jarak_y = (y2-y1)
- radius = Math.sqrt((jarak_x**2) + (jarak_y**2))
- red_diff = (color2.red - color1.red) / radius
- green_diff = (color2.green - color1.green) / radius
- blue_diff = (color2.blue - color1.blue) / radius
- alpha_diff = (color2.alpha - color1.alpha) / radius
- red = color1.red
- green = color1.green
- blue = color1.blue
- alpha = color1.alpha
- if jarak_y.abs == 0 || jarak_x.abs == 0
- gradient_fill_rect(x1,y1,1,jarak_y,color1,color2,true) if jarak_y.abs == 0
- gradient_fill_rect(x1,y1,jarak_x,1,color1,color2) if jarak_x.abs == 0
- yield [x1,y2] if block_given?
- 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
- set_pixel(x1,y1,Color.new(red,green,blue,alpha))
- real_x += rasio_x
- real_y += rasio_y
- yield [x1,y1] if block_given?
- x1 = real_x.round
- y1 = real_y.round
- red += red_diff
- blue += blue_diff
- green += green_diff
- alpha += alpha_diff
- 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_ellipse(x,y=0,horz=1,vert=1,think=1,color=Color.new(255,255,255),step=0.1)
- return if think < 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
- 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,361].min
- end
- if think > 1
- draw_ellipse(ori_x+1,ori_y+1,horz,vert,think-1,color,step)
- draw_ellipse(ori_x-1,ori_y-1,horz,vert,think-1,color,step)
- draw_ellipse(ori_x+1,ori_y-1,horz,vert,think-1,color,step)
- draw_ellipse(ori_x-1,ori_y+1,horz,vert,think-1,color,step)
- end
- end
- def fill_ellipse(x,y,horz,vert,color,step=1)
- degree = 0.0
- target_x = x+horz
- target_y = y
- while degree <= 360
- draw_line(x,y,target_x,target_y,color)
- target_x = Math.cos(Math.radian(degree)) * horz + x
- target_y = Math.sin(Math.radian(degree)) * vert + y
- degree = [degree+step,361].min
- end
- end
- def gradient_fill_ellipse(x,y,horz,vert,color1,color2,step=0.1)
- degree = 0.0
- target_x = x+horz
- target_y = y
- while degree <= 360
- gradient_line(x,y,target_x,target_y,color1,color2)
- target_x = Math.cos(Math.radian(degree)) * horz + x
- target_y = Math.sin(Math.radian(degree)) * vert + y
- degree = [degree+step,361].min
- end
- end
- def draw_shape_params(x,y,params,length,color1 = Color.new(255,255,255),fill=true,color2 = color1)
- return unless params.is_a?(Array)
- return unless params.size >= 3
- degree_minus = 360 / params.size
- degree = 270
- coordinate = []
- edge = []
- 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,color2)
- 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) {|cor| edge.push(cor)}
- end
- return unless fill
- edge.each do |line|
- draw_line(x,y,line[0],line[1],color2,true)
- end
- for i in 0..1
- for baris in 0..length*2
- Graphics.update
- Input.update
- for kolom in 0..length*2
- pos_x = baris-length+x
- pos_y = kolom-length+y
- syarat = (get_pixel(pos_x+1,pos_y).same?(color1,color2) &&
- get_pixel(pos_x-1,pos_y).same?(color1,color2)) ||
- (get_pixel(pos_x,pos_y-1).same?(color1,color2) &&
- get_pixel(pos_x,pos_y+1).same?(color1,color2)) ||
- (get_pixel(pos_x+1,pos_y+1).same?(color1,color2) &&
- get_pixel(pos_x-1,pos_y-1).same?(color1,color2)) ||
- (get_pixel(pos_x-1,pos_y+1).same?(color1,color2) &&
- get_pixel(pos_x+1,pos_y-1).same?(color1,color2))
- if syarat
- set_pixel(pos_x,pos_y,color2)
- end
- end
- end
- 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) #{|cor| edge.push(cor)}
- end
- end
- def draw_test
- edge = []
- draw_line(10,10,30,300) {|cor| edge.push(cor)}
- edge.each do |line|
- draw_line(300,10,line[0],line[1])
- 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
- class Color
- def same?(*args)
- return false unless args.all? {|c| c.is_a?(Color)}
- return args.any?{|color| self.red == color.red &&
- self.green == color.green && self.blue == color.blue &&
- self.alpha == color.alpha}
- end
- def empty?
- return self.alpha <= 0
- end
- end
- class Radar < Sprite
- attr_accessor :line_color
- def initialize(x,y,width,height,speed = 10,outline=false,viewport=nil)
- super(viewport)
- self.bitmap = Bitmap.new(width*2,height*2)
- self.x = x
- self.y = y
- self.ox = self.width/2
- self.oy = self.height/2
- @radar_w = width
- @radar_h = height
- @outline = outline
- @degree = 0.0
- @speed = speed
- @line_color = Color.new(255,255,255)
- end
- def update
- self.bitmap.clear
- cx = self.width/2
- cy = self.height/2
- to_x = cx + Math.cos(Math.radian(@degree)) * @radar_w
- to_y = cy + Math.sin(Math.radian(@degree)) * @radar_h
- self.bitmap.draw_line(cx,cy,to_x,to_y,@line_color)
- @degree += @speed
- end
- def dispose
- self.bitmap.dispose
- super
- end
- end
- def updates
- Graphics.update
- Input.update
- #~ $radar.update
- #~ if Input.repeat?(:LEFT)
- #~ $nilai -= 0.1
- #~ $sprite.bitmap.clear
- #~ $sprite.bitmap.fill_ellipse($tengah_x,$tengah_y,200,100,Color.new(255,255,255),$nilai)
- #~ elsif Input.repeat?(:RIGHT)
- #~ $nilai += 0.1
- #~ $sprite.bitmap.clear
- #~ $sprite.bitmap.fill_ellipse($tengah_x,$tengah_y,200,100,Color.new(255,255,255),$nilai)
- #~ end
- end
- #~ $back = Sprite.new
- #~ $back.bitmap = Bitmap.new(Graphics.width,Graphics.height)
- #~ $back.bitmap.fill_rect(0,0,Graphics.width,Graphics.height,Color.new(255,255,255))
- color2 = Color.new(0,0,0,255)
- color1 = Color.new(0,0,0,0)
- color3 = Color.new(255,255,255)
- $sprite = Sprite.new
- $tengah_x = Graphics.width/2
- $tengah_y = Graphics.height/2
- #~ $radar = Radar.new($tengah_x,$tengah_y,200,200)
- $nilai = 1
- $sprite.bitmap = Bitmap.new(Graphics.width,Graphics.height)
- #~ $sprite.z += 9999
- #~ $sprite.bitmap.gradient_fill_ellipse($tengah_x,$tengah_y,Graphics.width/1.4,Graphics.height/1.4,color1,color2)
- #~ $sprite.bitmap.gradient_line(0,0,200,200,Color.new(255,255,255,0),Color.new(255,255,255,255))
- #~ $sprite.bitmap.draw_ellipse($tengah_x,$tengah_y,200,100,2,Color.new(255,255,255),0.1)
- #~ $sprite.bitmap.fill_ellipse($tengah_x,$tengah_y,200,100,Color.new(255,255,255),$nilai)
- params = []
- params += [100,50]*2
- $sprite.bitmap.draw_shape_params(100,150,params,50,color3,true,Color.new(0,255,0))
- params = []
- params += [100,50]*4
- $sprite.bitmap.draw_shape_params(200,150,params,50,color3,true,Color.new(0,255,0))
- params = []
- params += [100,50]*6
- $sprite.bitmap.draw_shape_params(300,150,params,50,color3,true,Color.new(0,255,0))
- params = []
- params += [100]*3
- $sprite.bitmap.draw_shape_params(100,300,params,50,color3,true,Color.new(0,255,0))
- params = []
- params += [100]*5
- $sprite.bitmap.draw_shape_params(200,300,params,50,color3,true,Color.new(0,255,0))
- params = []
- params += [100]*7
- $sprite.bitmap.draw_shape_params(300,300,params,50,color3,true,Color.new(0,255,0))
- params = []
- params += [100,45,69,78,59,70,34,87]
- $sprite.bitmap.draw_shape_params(50,50,params,50,color3,true,Color.new(0,255,0))
- #$sprite.bitmap.draw_line(100,100,20,20)
- #~ $sprite.bitmap.draw_test
- #~ $sprite.bitmap.fill_rect(50,200,300,300,Color.new(255,255,255,255))
- #~ $sprite.bitmap.fill_rect(200,50,300,300,Color.new(255,255,255,255))
- #~ $sprite.bitmap.draw_line(0,0,Graphics.width,Graphics.height)
- updates while true
- class Scene_Base
- alias asd start
- def start
- asd
- $sprite.viewport = @viewport
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment