User Tools

Site Tools


lua:codea:stargenerator:star.lua

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

lua:codea:stargenerator:star.lua [2013/01/24 04:05] (current)
Wayne Michael created
Line 1: Line 1:
 +<code lua>
 +Star = class()
  
 +function Star:init(init)
 +    -- you can accept and set parameters here
 +    self.mx = 500
 +    self.my = 400
 +    if init == true then
 +        self.x = math.random(self.mx-10,self.mx+10)
 +        self.y = math.random(self.my-10,self.my+10)
 +        self.size = math.random(1,3)
 +    else
 +        self.x = math.random(1,1200)
 +        self.y = math.random(1,1200)
 +        self.size = math.random(1,6)
 +    end
 +    self.xspeed = math.random(1,10)
 +    self.yspeed = math.random(1,10)
 +    
 +    self.maxsize =6
 +    self.sc1 = math.random(1,255)
 +    self.sc2 = math.random(1,255)
 +    self.sc3 = math.random(1,255)
 +    
 +end
 +
 +function Star:draw()
 +    -- Codea does not automatically call this method
 +    strokeWidth(self.size)
 +    --stroke(math.random(1,255),math.random(1,255), math.random(1,255))
 +    stroke(self.sc1,self.sc2,self.sc3)
 +    line(self.x,self.y,self.x,self.y)
 +end
 +
 +function Star:touched(touch)
 +    -- Codea does not automatically call this method
 +end
 +function Star:move()
 +
 +    if self.x <= self.mx and self.y <= self.my then
 +            self.x = self.x - self.xspeed
 +            self.y = self.y - self.yspeed
 +        end
 +        if self.x <= self.mx and self.y >= self.my then
 +            self.x = self.x - self.xspeed
 +            self.y = self.y + self.yspeed
 +        end
 +        
 +        
 +        if self.x >= self.mx and self.y >= self.my then
 +            self.x = self.x + self.xspeed
 +            self.y = self.y + self.yspeed
 +        end
 +        if self.x >= self.mx and self.y <= self.my then
 +            self.x = self.x + self.xspeed
 +            self.y = self.y - self.yspeed
 +        end
 +        
 +        if self.x <= 0 or self.y <= 0 then
 +            self:init(true)  
 +            return
 +        else 
 +            if self.y >= 1000 or self.x >= 1000 then
 +                self:init(true)  
 +                return
 +            end
 +        end
 + 
 +       if math.random(1,12) == 5 then 
 +            if self.size + 1 <= self.maxsize then
 +                self.size = self.size + 1
 +                return
 +            end
 +        end
 +        
 +        if self.yspeed + self.xspeed > 15 then
 +            if math.random(1,5) == 5 then 
 +                if self.size + 1 <= self.maxsize then
 +                    self.size = self.size + 1
 +                    return
 +                end
 +            end
 +            
 +        end
 +        
 +end
 +
 +</code>
advertising
lua/codea/stargenerator/star.lua.txt · Last modified: 2013/01/24 04:05 by Wayne Michael

Impressum Datenschutz