Created
April 25, 2016 17:19
-
-
Save interactivenyc/68ccfa71b0fb88afe799543fc3650299 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
displayMode(FULLSCREEN) | |
supportedOrientations(PORTRAIT) | |
function setup() | |
rectMode(CENTER) | |
w1,h1=230,300 -- starting positions for the coins | |
w2,h2=630,400 | |
w3,h3=530,800 | |
w4,h4=130,700 | |
tab={} | |
table.insert(tab,chips(w1,h1,"penny",0,1)) | |
table.insert(tab,chips(w1+100,h1,"nickel",0,5)) | |
table.insert(tab,chips(w1+200,h1,"dime",0,10)) | |
table.insert(tab,chips(w1+300,h1,"quarter",0,25)) | |
table.insert(tab,chips(w2,h2,"penny",90,1)) | |
table.insert(tab,chips(w2,h2+100,"nickel",90,5)) | |
table.insert(tab,chips(w2,h2+200,"dime",90,10)) | |
table.insert(tab,chips(w2,h2+300,"quarter",90,25)) | |
table.insert(tab,chips(w3,h3,"penny",180,1)) | |
table.insert(tab,chips(w3-100,h3,"nickel",180,5)) | |
table.insert(tab,chips(w3-200,h3,"dime",180,10)) | |
table.insert(tab,chips(w3-300,h3,"quarter",180,25)) | |
table.insert(tab,chips(w4,h4,"penny",270,1)) | |
table.insert(tab,chips(w4,h4-100,"nickel",270,5)) | |
table.insert(tab,chips(w4,h4-200,"dime",270,10)) | |
table.insert(tab,chips(w4,h4-300,"quarter",270,25)) | |
end | |
function draw() | |
background(40, 40, 50) | |
fill(0,255,0) | |
rect(380,550,450,450) | |
for a,b in pairs(tab) do | |
b:draw() | |
end | |
end | |
function touched(t) | |
for a,b in pairs(tab) do | |
b:touched(t) | |
end | |
end | |
chips=class() | |
function chips:init(x,y,n,a,v) | |
self.x=x | |
self.y=y | |
self.n=n -- name | |
self.a=a -- rotate angle | |
self.c=20 -- count | |
self.v=v*self.c -- coin values | |
self.col=color(255) -- coin color | |
end | |
function chips:draw() | |
fill(self.col) | |
translate(self.x,self.y) | |
rotate(self.a) | |
ellipse(0,0,80) | |
fill(255,0,0) | |
text(self.n,0,0) | |
text(self.c,0,-60) | |
text(self.v,0,-80) | |
rotate(-self.a) | |
translate(-self.x,-self.y) | |
end | |
function chips:touched(t) | |
if t.state==BEGAN then | |
if t.x>self.x-40 and t.x<self.x+40 and t.y>self.y-40 and t.y<self.y+40 then | |
self.col=color(0, 27, 255, 255) | |
end | |
end | |
if t.state==ENDED then | |
self.col=color(255) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment