Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as Ruby by snow win32 ( 12 years ago )
#!/usr/bin/env ruby
# -*- coding: gb18030 -*- 

require 'rubygems'
require 'windows/gdi/device_context'
require 'windows/gdi/bitmap'
require 'win32struct'
include Windows::GDI::DeviceContext
include Windows::GDI::Bitmap

class Rect < CStruct
   int32 :left
   int32 :top
   int32 :right
   int32 :bottom
end

module Windows
  module GDI
    module DeviceContext
      API.new('InvalidateRect','LPB','B','user32')
    end
  end
end

class Snow
  SnowNum = 500  
  ScrnWidth = 1280 
  ScrnHight = 1024  
  SnowColDown = 0xFFFFFF  
  SnowColDuck = 0xFFDDDD 
  SnowCol = 0xFEFfFE 

  def initialize
     
    @hDC1 = GetDC(0) 
    @vx=0
    @vy=0
    @px=[]
    @py=[]
    @pColor=[]
    SnowNum.times{|j|
      @px[j] = rand * ScrnWidth
      @py[j] = rand * ScrnHight / 1.5
      @pColor[j] = GetPixel(@hDC1, @px[j], @py[j])
    }
  end

  def timerStart 
    Thread.new{
      loop do
      sleep 0.01 
      draw rescue(p $!.message + $@[0])
      end
    }
    Thread.new{
      loop do 
      @vx = rand * 4 - 2
      @vy = rand + 2      
      sleep 1.4
      end
    }
  end
 
  def initP(i)
    @px[i] = rand * ScrnWidth
    @py[i] = rand * 3
    @pColor[i] = GetPixel(@hDC1, @px[i], @py[i]) 
  end
 
  def draw
    SnowNum.times{|i|
      if @pColor[i] != SnowCol 
        SetPixel @hDC1, @px[i],@py[i], @pColor[i]
      end 
      @pvx = rand * 2 - 1 + @vx * (i%3)
      @pvy = @vy * (i%3+1)
      @px[i] += @pvx
      @py[i] += @pvy
 
      @pColor[i] = GetPixel(@hDC1,@px[i],@py[i])
 
      if @pColor[i] == 0xFFFFFFFF
        initP i
      else 
        if @pColor[i] != SnowCol 
          if rand > 0.3 or getContrast(i) < 50
            SetPixel @hDC1,@px[i],@py[i], SnowCol 
          else
            SetPixel @hDC1,@px[i],@py[i] - 1, SnowColDuck
            SetPixel @hDC1,@px[i] - 1,@py[i], SnowColDuck
            SetPixel @hDC1,@px[i] + 1,@py[i], SnowColDown
            initP i
          end
        end
      end
    }
  end
 
  def getContrast(i)  
    if @pvy != 0
      slope = @pvx / @pvy
    else
      slope = 2
    end 
    if slope == 0
      colorCmp = GetPixel(@hDC1, @px[i], @py[i] + 1)
    elsif slope > 1
      colorCmp = GetPixel(@hDC1, @px[i] + 1, @py[i] + 1)
    else
      colorCmp = GetPixel(@hDC1, @px[i] - 1, @py[i] + 1)      
    end 
    if colorCmp == SnowCol
      return 0
    end 
    tempB = ((colorCmp & 0xFF0000).abs - (@pColor[i] & 0xFF0000)) / 0x10000
    tempG = ((colorCmp & 0xFF00).abs - (@pColor[i] & 0xFF00)) / 0x100
    tempR = ((colorCmp & 0xFF).abs - (@pColor[i] & 0xFF))
     
    (tempR + tempG + tempB) / 3
  end

  def cc
    ReleaseDC 0, @hDC1   
    InvalidateRect 0, 0, 0  
    exit
  end

  def run
    trap(:INT){cc} 
    timerStart  
 
    while(Thread.list.count != 1) do sleep 1 end     
    cc  
  end
end

Snow.new.run

 

Revise this Paste

Your Name: Code Language: