svlad

Check-in [8db91da57b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added color object to jo.geometry
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:8db91da57bcc19c49c6503b9252b03e78158f9d3
User & Date: severak 2012-04-21 22:38:29
Context
2012-04-22
00:22
Added simply plotting tool. check-in: d5c1e0dafa user: severak tags: trunk
2012-04-21
22:38
Added color object to jo.geometry check-in: 8db91da57b user: severak tags: trunk
19:55
Changed Jo's cloning to using metamethods as described in PIL. check-in: 735070cae7 user: severak tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to jo/geometry.lua.

1
2
3
4
5

6
7
8
9
10
11
12
..
26
27
28
29
30
31
32













































































module("jo.geometry",package.seeall)

require "math"
require "jo"
require "jo.utils"


point=jo.object:clone():rewriteSlots({
  x=0,
  y=0,
  
  with=function(self,x,y)
    self.x=x
................................................................................
vector=jo.object:clone():rewriteSlots({
  sx=0,
  sy=0,
  
  

})


















































































>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
..
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
module("jo.geometry",package.seeall)

require "math"
require "jo"
require "jo.utils"
require "string"

point=jo.object:clone():rewriteSlots({
  x=0,
  y=0,
  
  with=function(self,x,y)
    self.x=x
................................................................................
vector=jo.object:clone():rewriteSlots({
  sx=0,
  sy=0,
  
  

})

color=jo.object:clone():rewriteSlots({
  r=255,
  g=255,
  b=255,
  
  getHexa=function(self)
    return string.format("#%02x%02x%02x",self.r,self.g,self.b)
  end,
  
  setHexa=function(self,hexa)
    if hexa:len()==7 and hexa:sub(1,1)=="#" then
      self.r=tonumber(hexa:sub(2,3),16)
      self.g=tonumber(hexa:sub(4,5),16)
      self.b=tonumber(hexa:sub(6,7),16)
    end
    return self
  end,
  
  --RGB to HSV conversion taken from http://alvyray.com/Papers/CG/hsv2rgb.htm
  
  toHSV=function(self)
    local x=math.min(self.r,self.g,self.b)
    local v=math.max(self.r,self.g,self.b)
    if v==x then
      return nil,0,v
    end
    if self.r==x then
      f=self.g-self.b
    else
      if self.g==x then
        f=self.b-self.r
      else
        f=self.r-self.g
      end
    end
    if self.r==x then
      i=3
    else
      if self.g==x then
        i=5
      else
        i=1
      end
    end
    return (i-f/(v-x)),((v-x)/v),v
  end,
  
  --HSV to RGB conversion taken from http://alvyray.com/Papers/CG/hsv2rgb.htm
  
  toRGB=function(self,h,s,v)
    if h==nil then
      self.r,self.g,self.b=v,v,v
    end
    i=math.floor(h)
    f=h-i
    if i%2==0 then
      f=1-f
    end
    m=v*(1-s)
    n=v*(1-s*f)
    if i==6 or i==0 then
      self.r,self.g,self.b=v,n,m
    elseif i==1 then
      self.r,self.g,self.b=n,v,m
    elseif i==2 then
      self.r,self.g,self.b=m,v,n
    elseif i==3 then 
      self.r,self.g,self.b=m,n,v
    elseif i==4 then
      self.r,self.g,self.b=n,m,v
    elseif i==5 then
      self.r,self.g,self.b=v,m,n
    end
    return self
  end
})