“Megasena” by Alex Flowers
https://openprocessing.org/sketch/2147613
License CreativeCommons Attribution NonCommercial ShareAlike
https://creativecommons.org/licenses/by-nc-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
CC Attribution NonCommercial ShareAlike
Megasena
Flowers
xxxxxxxxxx
// Mega-sena Dataviz!
// Feito por Alex Flowers
// simplesmente porque fiquei com tédio e achei a ideia divertida :-]
// (eu nem jogo na mega-sena)
// último update: dia 17 de janeiro de 2024! às 22h
var fonte;
var tabela;
var numbers = [];
var firstAppearance = [];
var lastAppearance = [];
var mostFrequent = 0;
var leastFrequent = 0;
var bgColor = 250;
var versao = "donut";
function preload() {
fonte = loadFont("Futura.otf");
tabela = loadTable("megasena.csv", "csv", "header");
}
function setup() {
if(windowHeight < windowWidth)
createCanvas(windowHeight*9/16, windowHeight);
else
createCanvas(windowWidth, windowWidth*16/9);
for(let i = 0; i < 60; i++) {
numbers[i] = 0;
firstAppearance[i] = 0;
lastAppearance[i] = 0;
}
for(let r = tabela.getRowCount()-1; r >= 0; r--) {
for(let c = 2; c < 8; c++) {
if(numbers[tabela.getNum(r, c)-1] == 0) {
firstAppearance[tabela.getNum(r, c)-1] = tabela.getString(r, 1);
}
numbers[tabela.getNum(r, c)-1]++;
lastAppearance[tabela.getNum(r, c)-1] = tabela.getString(r, 1);
}
}
for(let i = 1; i < 60; i++) {
if(numbers[i] > numbers[mostFrequent])
mostFrequent = i;
if(numbers[i] < numbers[leastFrequent])
leastFrequent = i;
}
//print(numbers);
}
/*
var thumbnail = false;
function keyPressed() {
//if(key == 't')
//thumbnail = true;
}
*/
function draw() {
background(bgColor);
drawLogo(); drawBlocks();
if(versao == "donut") {
drawDonut();
} else {
drawNumbers();
}
}
function mousePressed() {
if(versao == "donut")
versao = "cartela";
else
versao = "donut";
}
function drawDonut() {
noStroke();
angleMode(DEGREES);
let x = mouseX - width / 2;
let y = mouseY - height / 2;
let a = atan2(y, x);
let info = ["", ""];
var slice = 360/60;
//print(a);
if(a < -90) a = a + 360;
for(let n = 0; n < 60; n++) {
if(a > -90+(n*slice) && a < -90+(n+0.9)*slice && dist(width/2, height/2, mouseX, mouseY) < width*map(numbers[n], 225, 312, 0.6, 1)/2 && dist(width/2, height/2, mouseX, mouseY) > width/4) {
info[0] = "Bola "+(n+1);
info[1] = "Apareceu "+numbers[n]+" vezes";
}
//arc(width/2, height/2, width/2, height/2, 0, 90);
fill(lerpColor(color(210, 250, 200), color(130, 200, 120), map(numbers[n], 225, 312, 0, 1) ));
arc(width/2, height/2, width*map(numbers[n], 225, 312, 0.6, 1), width*map(numbers[n], 225, 312, 0.6, 1), -90+(n*slice), -90+((n+0.9)*slice));
}
fill(250, 245, 220);
circle(width/2, height/2, width/2);
fill(130, 200, 120); textAlign(CENTER, CENTER); textFont(fonte);
textSize(32); text(info[0], width/2, height/2-30);
textSize(20); text(info[1], width/2, height/2);
}
function drawNumbers() {
for(let r = 0; r < 6; r++) {
for(let c = 0; c < 10; c++) {
//fill(map(numbers[r*10+c], 225, 312, 255, 0));
fill(200, 90, 60);
textSize(12); textAlign(LEFT, CENTER); textFont("Arial");
text("["+nf(r*10+c+1, 2, 0)+"]", 18+c*30, 120+r*15);
if(mouseX > 18+c*30 && mouseX < 35+c*30 && mouseY > 115+r*15 && mouseY < 125+r*15) {
fill(120, 140, 170);
circle(28+c*30, 119+r*15, 10);
fill(200, 90, 60);
text("Informações:", 15, 242);
text("Esse número já apareceu em "+numbers[r*10+c]+" jogos.", 15, 262);
text("Sua primeira aparição foi em "+firstAppearance[r*10+c]+".", 15, 277);
text("Sua aparição mais recente foi em "+lastAppearance[r*10+c]+".", 15, 290);
if(r*10+c == mostFrequent)
text("Esse é o número que mais apareceu nos jogos! :D", 15, 303);
if(r*10+c == leastFrequent)
text("Esse é o número que menos apareceu nos jogos! :(", 15, 303);
}
}
}
fill(200, 90, 60);
text("Para anular este jogo, marque ao lado:", 15, 212);
if(mouseX > 290 && mouseX < 305 && mouseY > 205 && mouseY < 215)
text("[ X ]", 288, 212);
else
text("[ ]", 288, 212);
}
function drawBlocks() {
fill(250, 245, 220);
if(versao == "cartela"){
rect(10, 110, width-20, 110);
//rect(10, 230, width-20, 110);
//rect(10, 350, width-20, 110);
//rect(10, 490, width-20, 30);
}
fill(200, 90, 60);
textSize(10); textAlign(LEFT, CENTER); textFont("Arial");
//text("SURPRESINHA: Aqui o sistema escolhe os números por você! Indique quantas apostas deseja fazer:", 10, 455, width-20, 40);
// credits
fill(130, 200, 120);
rect(10, 530, width-20, 24);
fill(250);
textSize(13.5); textAlign(LEFT, CENTER); textFont(fonte);
text("ISSO É SÓ UMA SIMULAÇÃO COM FINS DE ENTRETENIMENTO!", 15, 540);
fill(130, 200, 120); textAlign(CENTER, CENTER);
text("Informações obtidas em 17 de janeiro de 2024.", width/2, height-70);
text("Feito por Alex Flowers", width/2, 565);
}
function drawLogo() {
angleMode(RADIANS);
// green rectangle
fill(130, 200, 120);
rect(10, 10, width-20, 70);
// megasena text
fill(250); noStroke();
textSize(44); textAlign(LEFT, CENTER); textFont(fonte);
text("MEGA-SENA", 100, 40);
// draw subtitle
fill(130, 200, 120); noStroke();
textSize(14); textAlign(CENTER, CENTER); textFont("Arial");
if(versao == "donut") {
text("PASSE O MOUSE POR CIMA DO GRÁFICO", width/2, 95);
text("E CLIQUE EM QUALQUER LUGAR PARA\nTROCAR A VISUALIZAÇÃO", width/2, 120);
} else {
text("PASSE O MOUSE NOS QUADRADINHOS", width/2, 95);
}
// lucky clover
push();
scale(0.75);
translate(20, 8);
push();
translate(40, 30);
fill(250);
rect(0, 0, 20, 20);
circle(10, 0, 20);
circle(0, 10, 20);
pop();
push();
translate(85, 30);
rotate(PI/2);
fill(210, 250, 200);
rect(0, 0, 20, 20);
circle(10, 0, 20);
circle(0, 10, 20);
pop();
push();
translate(85, 75);
rotate(PI);
fill(250);
rect(0, 0, 20, 20);
circle(10, 0, 20);
circle(0, 10, 20);
pop();
push();
translate(40, 75);
rotate(PI/2*3);
fill(210, 250, 200);
rect(0, 0, 20, 20);
circle(10, 0, 20);
circle(0, 10, 20);
pop();
pop();
}
See More Shortcuts
Please verify your email to comment
Verify Email