効率悪くサイコロを振り続ける
from random import shuffle | |
from math import floor | |
def setup(): | |
global array, loop_counter | |
array = [1, 2, 3, 4, 5, 6, 7, 8, 9] | |
loop_counter = 0 | |
size(1280, 720, P3D) | |
background(0) | |
frameRate(60) | |
def draw(): | |
global array, loop_counter | |
background(0) | |
denom1 = array[1] * 10 + array[2] | |
denom2 = array[4] * 10 + array[5] | |
denom3 = array[7] * 10 + array[8] | |
numera1 = array[0] * denom2 * denom3 | |
numera2 = array[3] * denom1 * denom3 | |
numera3 = array[6] * denom1 * denom2 | |
denominator = denom1 * denom2 * denom3 | |
print('%d / %d + %d / %d + %d / %d == 1??' % (array[0], denom1, array[3], denom2, array[6], denom3)) | |
print('answer[%d] %d : %d' % (loop_counter, numera1 + numera2 + numera3, denominator)) | |
if not (numera1 + numera2 + numera3 == denominator): | |
shuffle(array) | |
noStroke() | |
colorMode(HSB, 360, 100, 100) | |
fill((millis() / 100 + 240) % 360, 70, 50) | |
arc(800, 250, 300, 300, -PI / 2, 2 * (PI * (float(array[6]) / denom3)) - PI / 2, PIE) | |
arc(1100, 250, 300, 300, -PI / 2, 2 * (PI * (float(array[6]) / denom3)) - PI / 2 | |
+ 2 * (PI * (float(array[0]) / denom1)) | |
+ 2 * (PI * (float(array[3]) / denom2)) | |
, PIE) | |
fill((millis() / 100 + 120) % 360, 70, 50) | |
arc(500, 250, 300, 300, -PI / 2, 2 * (PI * (float(array[3]) / denom2)) - PI / 2, PIE) | |
arc(1100, 250, 300, 300, -PI / 2, 2 * (PI * (float(array[3]) / denom2)) - PI / 2 | |
+ 2 * (PI * (float(array[0]) / denom1)), PIE) | |
fill(millis() / 100 % 360, 70, 50) | |
arc(200, 250, 300, 300, -PI / 2, 2 * (PI * (float(array[0]) / denom1)) - PI / 2, PIE) | |
arc(1100, 250, 300, 300, -PI / 2, 2 * (PI * (float(array[0]) / denom1)) - PI / 2, PIE) | |
stroke(255) | |
fill(255) | |
strokeWeight(8) | |
rectMode(CENTER) | |
textSize(128) | |
text(1, 1050, 300) | |
textSize(96) | |
for i in range(3): | |
offset = 300 * i | |
text(array[0 + i * 3], 170 + offset, 200) | |
line(100 + offset, 250, 300 + offset, 250) | |
text(array[1 + i * 3], 125 + offset, 355) | |
text(array[2 + i * 3], 225 + offset, 355) | |
if (i < 2): | |
line(325 + offset, 250, 375 + offset, 250) | |
line(350 + offset, 225, 350 + offset, 275) | |
else: | |
line(350 + offset, 225, 400 + offset, 225) | |
line(350 + offset, 275, 400 + offset, 275) | |
loop_counter += 1 | |
rectMode(CORNER) | |
noStroke() | |
colorMode(RGB, 255) | |
fill( | |
map(float(array[0]) / denom1, 1.0/98, 9.0/12, 1, 255), | |
map(float(array[3]) / denom2, 1.0/98, 9.0/12, 1, 255), | |
map(float(array[6]) / denom3, 1.0/98, 9.0/12, 1, 255) | |
) | |
rect(140, 500, map(numera1 + numera2 + numera3, 0, 610000, 0, 1000),50) | |
colorMode(HSB, 360, 100, 100) | |
fill( | |
map(float(array[0]) / denom1, 1.0/98, 9.0/12, 1, 360), | |
map(float(array[3]) / denom2, 1.0/98, 9.0/12, 1, 100), | |
map(float(array[6]) / denom3, 1.0/98, 9.0/12, 1, 100) | |
) | |
rect(140, 550, map(denominator, 0, 610000, 0, 1000),50) | |
colorMode(RGB, 255) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment