⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mclock.py

📁 Python语言编译器
💻 PY
📖 第 1 页 / 共 2 页
字号:
	# Obsolete code:	if Gl.alarm_on:		return Gl.fg	else:		return Gl.bgdef clearall():	Gl.c3i(rgb_bg())	clear()	if Gl.doublebuffer:		swapbuffers()		clear()def draw_alarm(color):	frontbuffer(TRUE)	Gl.c3i(color)	pushmatrix()	rotate(-((Gl.alarm_time/12)%3600), 'z')	bgnpolygon()	v2f( 0.00,1.00)	v2f( 0.04,1.05)	v2f(-0.04,1.05)	endpolygon()	popmatrix()	#	pushmatrix()	rotate(-((Gl.alarm_time)%3600), 'z')	bgnpolygon()	v2f( 0.00,1.05)	v2f( 0.07,1.10)	v2f(-0.07,1.10)	endpolygon()	popmatrix()	#	cmov2(-1.06, -1.06)	charstr(string.rjust(`Gl.alarm_time/3600`,2))	charstr(':')	charstr(string.zfill((Gl.alarm_time/60)%60,2))	frontbuffer(FALSE)def render(list, (little_hand, big_hand, seconds_hand)):	#	if Gl.colormap:		resetindex()	#	if not list:		Gl.c3i((255, 255, 255)) # White		circf(0.0, 0.0, 1.0)	else:		list.append((3600, 0, 255)) # Sentinel	#	rgb = [255, 255, 255]	a_prev = 0	for a, icolor, value in list:		if a <> a_prev:			[r, g, b] = rgb			if Gl.debug > 1:				print rgb, a_prev, a			Gl.c3i((r, g, b))			arcf(0.0, 0.0, 1.0, a_prev, a)		rgb[icolor] = value		a_prev = a	#	if Gl.black or not Gl.colorsubset:		#		# Draw the hands -- in black		#		Gl.c3i((0, 0, 0))		#		if Gl.update == 1 and not Gl.iconic:			# Seconds hand is only drawn if we update every second			pushmatrix()			rotate(seconds_hand, 'z')			bgnline()			v2f(0.0, 0.0)			v2f(1.0, 0.0)			endline()			popmatrix()		#		pushmatrix()		rotate(big_hand, 'z')		rectf(0.0, -0.01, 0.97, 0.01)		circf(0.0, 0.0, 0.01)		circf(0.97, 0.0, 0.01)		popmatrix()		#		pushmatrix()		rotate(little_hand, 'z')		rectf(0.04, -0.02, 0.63, 0.02)		circf(0.04, 0.0, 0.02)		circf(0.63, 0.0, 0.02)		popmatrix()		#		# Draw the alarm time, if set or being set		#		if Gl.alarm_set:			draw_alarm(rgb_fg())	#	if Gl.doublebuffer: swapbuffers()def makewindow():	#	if Gl.debug or Gl.foreground:		foreground()	#	if Gl.fullscreen:		scrwidth, scrheight = getgdesc(GD_XPMAX), getgdesc(GD_YPMAX)		prefposition(0, scrwidth-1, 0, scrheight-1)	else:		keepaspect(1, 1)		prefsize(80, 80)	#	if not Gl.border:		noborder()	wid = winopen(Gl.name)	wintitle(Gl.title)	#	if not Gl.fullscreen:		keepaspect(1, 1)		minsize(10, 10)		maxsize(2000, 2000)		iconsize(66, 66)		winconstraints()	#	nplanes = getplanes()	nmaps = getgdesc(GD_NMMAPS)	if Gl.warnings:		print nplanes, 'color planes,', nmaps, 'color maps'	#	if Gl.doublebuffer and not Gl.colormap and nplanes < 12:		if Gl.warnings: print 'forcing single buffer mode'		Gl.doublebuffer = 0	#	if Gl.colormap:		if not Gl.colormap:			Gl.colormap = nmaps - 1			if Gl.warnings:				print 'not enough color planes available',				print 'for RGB mode; forcing colormap mode'				print 'using color map number', Gl.colormap		if not Gl.colorsubset:			needed = 3		else:			needed = Gl.cyan + Gl.magenta + Gl.yellow		needed = needed*Gl.nparts		if Gl.bg <> (0, 0, 0):			needed = needed+1		if Gl.fg <> (0, 0, 0):			needed = needed+1		if Gl.doublebuffer:			if needed > available(nplanes/2):				Gl.doublebuffer = 0				if Gl.warnings:					print 'not enough colors available',					print 'for double buffer mode;',					print 'forcing single buffer mode'			else:				nplanes = nplanes/2		if needed > available(nplanes):			# Do this warning always			print 'still not enough colors available;',			print 'parts will be left white'			print '(needed', needed, 'but have only',			print available(nplanes), 'colors available)'	#	if Gl.doublebuffer:		doublebuffer()		gconfig()	#	if Gl.colormap:		Gl.c3i = pseudo_c3i		fixcolormap()	else:		Gl.c3i = c3i		RGBmode()		gconfig()	#	if Gl.fullscreen:		# XXX Should find out true screen size using getgdesc()		ortho2(-1.1*1.280, 1.1*1.280, -1.1*1.024, 1.1*1.024)	else:		ortho2(-1.1, 1.1, -1.1, 1.1)	#	return widdef available(nplanes):	return pow(2, nplanes) - 1	# Reserve one pixel for blackdef fixcolormap():	multimap()	gconfig()	nplanes = getplanes()	if Gl.warnings:		print 'multimap mode has', nplanes, 'color planes'	imap = Gl.colormap	Gl.startindex = pow(2, nplanes) - 1	Gl.stopindex = 1	setmap(imap)	mapcolor(0, 0, 0, 0) # Fixed entry for black	if Gl.bg <> (0, 0, 0):		r, g, b = Gl.bg		mapcolor(1, r, g, b) # Fixed entry for Gl.bg		Gl.stopindex = 2	if Gl.fg <> (0, 0, 0):		r, g, b = Gl.fg		mapcolor(2, r, g, b) # Fixed entry for Gl.fg		Gl.stopindex = 3	Gl.overflow_seen = 0	resetindex()def resetindex():	Gl.index = Gl.startindexr0g0b0 = (0, 0, 0)def pseudo_c3i(rgb):	if rgb == r0g0b0:		index = 0	elif rgb == Gl.bg:		index = 1	elif rgb == Gl.fg:		index = 2	else:		index = definecolor(rgb)	color(index)def definecolor(rgb):	index = Gl.index	if index < Gl.stopindex:		if Gl.debug: print 'definecolor hard case', rgb		# First see if we already have this one...		for index in range(Gl.stopindex, Gl.startindex+1):			if rgb == getmcolor(index):				if Gl.debug: print 'return', index				return index		# Don't clobber reserverd colormap entries		if not Gl.overflow_seen:			# Shouldn't happen any more, hence no Gl.warnings test			print 'mclock: out of colormap entries'			Gl.overflow_seen = 1		return Gl.stopindex	r, g, b = rgb	if Gl.debug > 1: print 'mapcolor', (index, r, g, b)	mapcolor(index, r, g, b)	Gl.index = index - 1	return index# Compute n**idef pow(n, i):	x = 1	for j in range(i): x = x*n	return xdef mouseclick(mouse, updown, x, y):	if updown == 1:		# mouse button came down, start tracking		if Gl.debug:			print 'mouse', mouse, 'down at', x, y		if mouse == 2:			Gl.mouse2down = 1			mouse2track(x, y)		elif mouse == 3:			Gl.mouse3down = 1			mouse3track(x, y)		else:			print 'fatal error'		qdevice(MOUSEX)		qdevice(MOUSEY)		return 0	else:		# mouse button came up, stop tracking		if Gl.debug:			print 'mouse', mouse, 'up at', x, y		unqdevice(MOUSEX)		unqdevice(MOUSEY)		if mouse == 2:			mouse2track(x, y)			Gl.mouse2down = 0		elif mouse == 3:			mouse3track(x, y)			Gl.mouse3down = 0		else:			print 'fatal error'		Gl.alarm_set = 1		return 1def mouse3track(x, y):	# first compute polar coordinates from x and y	cx, cy = Gl.ox + Gl.cx/2, Gl.oy + Gl.cy/2	x, y = x - cx, y - cy	if (x, y) == (0, 0): return	# would cause an exception	minutes = int(30.5 + 30.0*math.atan2(float(-x), float(-y))/pi)	if minutes == 60: minutes = 0	a,b = Gl.alarm_minutes/15, minutes/15	if (a,b) == (0,3):		# Moved backward through 12 o'clock:		Gl.alarm_hours = Gl.alarm_hours - 1		if Gl.alarm_hours < 0: Gl.alarm_hours = Gl.alarm_hours + 24	if (a,b) == (3,0):		# Moved forward through 12 o'clock:		Gl.alarm_hours = Gl.alarm_hours + 1		if Gl.alarm_hours >= 24: Gl.alarm_hours = Gl.alarm_hours - 24	Gl.alarm_minutes = minutes	seconds = Gl.alarm_hours * HOUR + Gl.alarm_minutes * MINUTE	if seconds <> Gl.alarm_time:		draw_alarm(rgb_bg())		Gl.alarm_time = seconds		draw_alarm(rgb_fg())def mouse2track(x, y):	# first compute polar coordinates from x and y	cx, cy = Gl.ox + Gl.cx/2, Gl.oy + Gl.cy/2	x, y = x - cx, y - cy	if (x, y) == (0, 0): return	# would cause an exception	hours = int(6.5 - float(Gl.alarm_minutes)/60.0 + 6.0*math.atan2(float(-x), float(-y))/pi)	if hours == 12: hours = 0	if (Gl.alarm_hours,hours) == (0,11):		# Moved backward through midnight:		Gl.alarm_hours = 23	elif (Gl.alarm_hours,hours) == (12,11):		# Moved backward through noon:		Gl.alarm_hours = 11	elif (Gl.alarm_hours,hours) == (11,0):		# Moved forward through noon:		Gl.alarm_hours = 12	elif (Gl.alarm_hours,hours) == (23,0):		# Moved forward through midnight:		Gl.alarm_hours = 0	elif Gl.alarm_hours < 12:		Gl.alarm_hours = hours	else:		Gl.alarm_hours = hours + 12	seconds = Gl.alarm_hours * HOUR + Gl.alarm_minutes * MINUTE	if seconds <> Gl.alarm_time:		draw_alarm(rgb_bg())		Gl.alarm_time = seconds		draw_alarm(rgb_fg())def initmenu():	Gl.pup = pup = newpup()	addtopup(pup, 'M Clock%t|Alarm On/Off|Seconds Hand On/Off|Quit', 0)def handlemenu():	item = dopup(Gl.pup)	if item == 1:		# Toggle alarm		if Gl.alarm_set:			Gl.alarm_set = 0			Gl.alarm_on = 0		else:			Gl.alarm_set = 1		Gl.change = 1		clearall()	elif item == 2:		# Toggle Seconds Hand		if Gl.update == 1:			Gl.update = 60			Gl.timernoise = 60		else:			Gl.update = 1			Gl.timernoise = 6		Gl.change = 1	elif item == 3:		if Gl.debug: print 'Exit'		sys.exit(0)main()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -